web hacking ๐Ÿ–ฅ/techniques โŒ principles

Advanced Request Smuggling

Kortsec1 2024. 12. 15. 18:39

๋” ๋†’์€ ์ˆ˜์ค€์˜ HTTP request smuggling ๊ธฐ์ˆ ์€ ๋ฌผ๋ก  ์กด์žฌํ•œ๋‹ค. HTTP/2๋Š” request smuggling์˜ ์ƒˆ๋กœ์šด ์˜์—ญ์„ ์ „๊ฐœํ•˜๋ฉฐ ๊ธฐ์กด์˜ ์•ˆ์ „ํ•œ ํ™˜๊ฒฝ์„ ์œ„ํ˜‘ํ•˜๊ณ ์žˆ๋‹ค.

01. HTTP/2 requeste smuggling

Request smuggling์€ ๊ทผ๋ณธ์ ์œผ๋กœ ์„œ๋ฒ„๋“ค์˜ ์š”์ฒญ ๊ธธ์ด ํŒ๋‹จ์˜ ๋ถˆ์ผ์น˜๋กœ ์ผ์–ด๋‚œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  HTTP/2๋Š” ์˜ค๋žœ๊ธฐ๊ฐ„ ๊ฐ•๋ ฅํ•œ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ๋ฐ”ํƒ•์œผ๋กœ ์ด์— ๋„๋–ก์—†๋‹ค๊ณ  ์—ฌ๊ฒจ์กŒ๋‹ค. HTTP/2๋Š” ์š”์ฒญ์„ ํ”„๋ ˆ์ž„ ๋‹จ์œ„๋กœ ๋‚˜๋ˆ„์–ด ์ „๋‹ฌํ•˜๊ณ  ์ด ํ”„๋ ˆ์ž„ ๊ธธ์ด์˜ ์ดํ•ฉ์ด ์š”์ฒญ์˜ ๊ธธ์ด๊ฐ€ ๋œ๋‹ค. ์ด๋ก ์ƒ ์ด๋Ÿฌํ•œ ๋ฉ”์ปค๋‹ˆ์ฆ˜์€ ๊ณต๊ฒฉ์ž๋กœ ํ•˜์—ฌ๊ธˆ ์• ๋งค๋ชจํ˜ธํ•œ ์š”์ฒญ ๊ธธ์ด๋ฅผ ๋ณด๋‚ด๋Š” ์‹œ๋„์กฐ์ฐจ ํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ํ•œ๋‹ค. ํ•˜์ง€๋งŒ ํ˜„์‹ค์€ ํ”ํ•˜์ง€๋Š” ์•Š์ง€๋งŒ HTTP/2 downgrading ์ด๋ผ๋Š” ์œ„ํ—˜์ด ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

1) HTTP/2 downgrading

HTTP/2 downgrading์€ HTTP/2 ์š”์ฒญ์„ ๋™๋“ฑํ•œ ๋‚ด์šฉ์˜ HTTP/1 ์š”์ฒญ์œผ๋กœ rewritingํ•˜๋Š” ๊ณผ์ •์ด๋‹ค. ์ด๋Š” ์˜ค์ง HTTP/1 ํ˜•ํƒœ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” back-end ์„œ๋ฒ„์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๊ธฐ ์œ„ํ•ด ์›น์„œ๋ฒ„๋‚˜ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๊ฐ€ ์ฃผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค. ๋ฌผ๋ก  back-end์—์„œ ๋ฐœ์ƒํ•œ ์‘๋‹ต์— ๋Œ€ํ•ด์„œ front-end๋Š” HTTP/2 ํ˜•์‹์œผ๋กœ ๋˜๋Œ๋ ค ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด๋‚ธ๋‹ค.

์ด๋Š” HTTP/1 ๊ณผ HTTP/2 ๋Š” ๊ฐ™์€ ์ •๋ณด์— ๋Œ€ํ•ด ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•๋งŒ ๋‹ค๋ฅผ ๋ฟ ๊ฑฐ์˜ ๋™์ผํ•œ ๋ฉ”์„ธ์ง€๋ฅผ ๋‹ด๊ณ  ์žˆ๊ธฐ์— ๊ฐ€๋Šฅํ•˜๋‹ค.

[IMG1] HTTP/1 ๊ณผ HTTP/2 ์˜ ๊ตฌ์กฐ

๊ฒฐ๊ณผ์ ์œผ๋กœ ์ด ๋•๋ถ„์— ๋‘ ํ”„๋กœํ† ์ฝœ๊ฐ„ ๋ณ€ํ™˜์ด ์ž์—ฐ์Šค๋Ÿฌ์›Œ์ง€๋Š” ๊ฒƒ์ด๋‹ค. ์ƒ๋‹น์ˆ˜์˜ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๋Š” HTTP/2 downgrading์„ ์ง€์›ํ•˜๊ณ  ์žˆ๊ณ , ์‹ฌ์ง€์–ด ๋น„ํ™œ์„ฑํ™” ํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค.

2) H2.CL ์ทจ์•ฝ์ 

HTTP/2 ์š”์ฒญ์€ ํŠน๋ณ„ํžˆ ๊ทธ ๊ธธ์ด๋ฅผ ํ—ค๋”์— ๋ช…์‹œํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค. ์ด๋ง์€ downgrading ๊ณผ์ •์—์„œ front-end ์„œ๋ฒ„๋Š” HTTP/1 Content-Length ํ—ค๋”๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค๋Š” ์†Œ๋ฆฌ๋‹ค. ๋˜ํ•œ HTTP/2๋Š” Content-Length ํ—ค๋”๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š”๋ฐ ์ด๋–„ front-end๋Š” ์ด๋ฅผ ์žฌ์‚ฌ์šฉํ•˜์—ฌ HTTP/1 ์š”์ฒญ์„ ๋งŒ๋“ ๋‹ค.

์—ฌ๊ธฐ์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. Downgrading ๊ณผ์ •์—์„œ HTTP/2 ๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ ๊ธธ์ด์˜ Content-Length ํ—ค๋”๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๋‹ค๋ฉด HTTP/1์€ ์ด๋Ÿฌํ•œ ์ž˜๋ชป๋œ ํ—ค๋”๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค. ๋ฌผ๋ก  front-end ์„œ๋ฒ„ ์ƒ์—์„œ๋Š” ์ •ํ™•ํ•œ HTTP/2 ๊ธธ์ด๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์š”์ฒญ์„ ๋๋‚ด์ง€๋งŒ, HTTP/1 back-end ์„œ๋ฒ„๋Š” ์ž˜๋ชป๋œ ํ—ค๋”๋ฅผ ๋ฐ›๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ “Desync”๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

[IMG2] Front-end (HTTP/2)
[IMG3] Back-end (HTTP/1)

3) H2.TE ์ทจ์•ฝ์ 

Transfer Encoding ํ—ค๋”๋Š” front-end ์„œ๋ฒ„ ์ฐจ์›์—์„œ ์ „์ ์œผ๋กœ ํ†ตํ•˜์ง€ ์•Š๋Š”๋‹ค. ํ•˜์ง€๋งŒ downgrading์„ ํ†ตํ•ด Transfer Encoding์„ ์ง€์›ํ•˜๋Š” HTTP/1 back-end ์„œ๋ฒ„๋กœ ๊ฐ„๋‹ค๋ฉด HRS ๊ณต๊ฒฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

[IMG4] Front-end (HTTP/2)
[IMG5] Back-end (HTTP/1)

4) ์ˆจ๊ฒจ์ง„ HTTP/2 ์ง€์› ํ™˜๊ฒฝ

๋ธŒ๋ผ์šฐ์ €์™€ ๊ธฐํƒ€ ํด๋ผ์ด์–ธํŠธ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ TLS handshake ๊ณผ์ •์—์„œ ALPN(Application-Layer Protocol Negotiation)์„ ํ†ตํ•ด ์„œ๋ฒ„๊ฐ€ HTTP/2๋ฅผ ์ง€์›ํ•œ๋‹ค๊ณ  ๋ช…์‹œํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ HTTP/2๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•œ๋‹ค. ํ•˜์ง€๋งŒ ๋ช‡๋ช‡ ์„œ๋ฒ„๋“ค์€ HTTP/2๋ฅผ ์ง€์› ํ•จ์—๋„ ์ด๋ฅผ ์ ์ ˆํžˆ ํ‘œํ˜„ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ, ํด๋ผ์ด์–ธํŠธ๋Š” ๊ธฐ๋ณธ ์˜ต์…˜์— ๋”ฐ๋ผ ์„œ๋ฒ„๊ฐ€ HTTP/1.1๋งŒ์„ ์ง€์›ํ•œ๋‹ค๊ณ  ์˜คํ•ดํ•˜๊ณ , ๊ฒฐ๊ณผ์ ์œผ๋กœ ์œ„์—์„œ ์‚ดํŽด๋ณธ HTTP/2 ๊ณต๊ฒฉ ๊ฐ€๋Šฅ์„ฑ์„ ๊ฐ„๊ณผํ•  ์ˆ˜ ์žˆ๋‹ค.

02. Response Queue Poisoning

Response queue poisoning์€ back-end ์„œ๋ฒ„์—์„œ ์˜จ ์‘๋‹ต์„ front-end๊ฐ€ ์ž˜๋ชป๋œ ์š”์ฒญ๊ณผ ์—ฐ๊ฒฐ์ง“๊ฒŒ ๋งŒ๋“œ๋Š” ๊ฐ•๋ ฅํ•œ HRS ๊ณต๊ฒฉ์ด๋‹ค. ์œ„ ํ™˜๊ฒฝ์—์„œ์˜ ๋ชจ๋“  ์‚ฌ์šฉ์ž๋“ค์€ ์ง€์†์ ์œผ๋กœ ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ ์˜๋„ํ•œ ์‘๋‹ต์„ ์ „ํ•ด๋ฐ›๊ฒŒ ๋˜๋Š”๊ฒƒ์ด๋‹ค.

ํ๊ฐ€ ํ•œ๋ฒˆ ์žฅ์•…๋˜๋ฉด, ๊ณต๊ฒฉ์ž๋Š” ๊ฐ„๋‹จํžˆ ํ›„์† ์š”์ฒญ ํ•˜๋‚˜๋กœ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์˜ ์‘๋‹ต์„ ๊ฐ€๋กœ์ฑŒ ์ˆ˜ ์žˆ๋‹ค. ๊ทธ ์‘๋‹ต์†์—๋Š” ์„ธ์…˜ ํ† ํฐ๊ณผ ๊ฐ™์€ ๋ฏผ๊ฐํ•œ ์ •๋ณด๊ฐ€ ๋“ค์–ด์žˆ์„์ˆ˜ ์žˆ๋‹ค. ๋ถ€์ˆ˜์ ์ธ ํ”ผํ•ด๋กœ ๊ฐ™์€ TCP ์—ฐ๊ฒฐ์„ ์‚ฌ์šฉํ•˜๋Š” ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๋“ค์—๊ฒŒ ๋žœ๋ค๊ณผ ๊ฐ™์€ ์‘๋‹ต์„ ๋ณด๋‚ด, ์ •์ƒ์ ์ธ ์ผ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ธฐ์กด HRS ๊ณต๊ฒฉ์„ ๋ณด๋ฉด, ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๋กœ ๋ถ€ํ„ฐ ์˜จ ๋‹ค๋ฅธ ์š”์ฒญ๋“ค์€ ์ •์ƒ์ ์ธ ๊ตฌ์กฐ๋ฅผ ์ด๋ฃจ์ง€ ๋ชปํ•˜์—ฌ ์—ฐ๊ฒฐ์ด ๋Š์–ด์ง„๋‹ค.

[IMG6] Normal HRS attack

์„œ๋ฒ„์™€์˜ ์—ฐ๊ฒฐ์„ ์œ ์ง€ํ•˜๋ฉฐ queue poisoning ๊ณต๊ฒฉ์„ ์ˆ˜ํ–‰ํ•˜๋ ค๋ฉด ์ •ํ™•ํžˆ ๋‘ ๊ฐœ์˜ ์™„์ „ํ•œ ์š”์ฒญ์„ ํ•˜๋‚˜๋กœ ๋ฌถ์–ด ๋ณด๋‚ด์•ผ ํ•œ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด back-end ์„œ๋ฒ„๋Š” ๋ชจ๋‘๊ฐ€ ์œ ํšจํ•œ ์š”์ฒญ์ด๊ธฐ์— ์—ฐ๊ฒฐ์„ ๋Š์ง€์•Š๋Š”๋‹ค.

[IMG7] Response queue poisoning attack
[IMG8] RQP ์ดํ•ด๋ฅผ ์œ„ํ•œ ๊ทธ๋ฆผ

์ด ๊ณต๊ฒฉ์€ HTTP/1๊ณผ HTTP/2 downgrading ํ™˜๊ฒฝ ๋ชจ๋‘ ๊ณต๊ฒฉ ๊ฐ€๋Šฅํ•˜๋‹ค. Body ์—์„œ์˜ ๋ถ„ํ• ์ด ์•„๋‹Œ, ํ—ค๋”์—์„œ๋„ ๊ฐ€๋Šฅํ•œ๋ฐ ์•„๋ž˜ HTTP/2 Request Splitting์—์„œ ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค.

03. CRLF ์‚ฝ์ž…๊ณต๊ฒฉ์„ ํ†ตํ•œ HRS

๋งŽ์€ ์›น์‚ฌ์ดํŠธ๋“ค์ด H2.CL์ด๋‚˜ H2.TE ๊ณต๊ฒฉ์„ ๋ฐฉ์–ดํ•˜๊ธฐ ์œ„ํ•ด Content-Length ๊ฐ’์„ ๊ฒ€์ฆํ•˜๊ณ  Transfer-Encoding ํ—ค๋”๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๊ณผ์ •์„ ๊ฑฐ์นœ๋‹ค. ๊ทธ๋Ÿผ์—๋„ HTTP/2 ํ™˜๊ฒฝ ์† binary ํ˜•์‹์€ ์‹ ๋ฐ•ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ front-end์˜ ๋…ธ๋ ฅ์„ ๋ฌด์‚ฐ์‹œํ‚จ๋‹ค.

HTTP/1์—์„œ๋Š” ๊ฐ€๋” ๊ฐœํ–‰๋ฌธ์ž “\n”์„ ์ด์šฉํ•˜์—ฌ exploit์„ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. back-end๋Š” ์ด๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์‚ผ์ง€๋งŒ, front-end๋Š” ๊ทธ๋ ‡์ง€ ์•Š์„ ๋•Œ front-end๋Š” ๊ทธ ๋‹ค์Œ ํ—ค๋”๋ฅผ ๋ฐœ๊ฒฌํ•˜๋Š” ๊ฒƒ์กฐ์ฐจ ์‹คํŒจํ•  ๊ฒƒ์ด๋‹ค. CRLF(”\r\n”)๋Š” ๋ชจ๋“  HTTP/1 ์„œ๋ฒ„์—์„œ ํ—ค๋” ์ข…๊ฒฐ์˜ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ธฐ์— ํ•ด๋‹น๋˜์ง€ ์•Š๋Š”๋‹ค.

X: X\\nTransfer-Encoding: chunked

์ด์™€ ๋ฐ˜๋Œ€๋กœ HTTP/2 ๋ฉ”์‹œ์ง€๋“ค์€ text ํ˜•์‹์ด ์•„๋‹Œ, binary ํ˜•์‹์ด๊ธฐ์— ๊ฐ ํ—ค๋”์˜ ๊ฒฝ๊ณ„๊ฐ€ ๋ช…ํ™•ํ•˜๋‹ค. CRLF์™€ ๊ฐ™์€ ๊ฒฝ๊ณ„ ๊ธฐํ˜ธ๋ณด๋‹ค ์ด๋ฏธ ์ •ํ•ด์ง„ offset๋“ค์„ ๋”ฐ๋ฅด๊ธฐ์— CRLF๋Š” ๋”์ด์ƒ ํฐ ์˜๋ฏธ๋ฅผ ๊ฐ–์ง€ ์•Š๋Š”๋‹ค. ์ด๋Š” ํ—ค๋” ๊ฐ’์— ํฌํ•จ๋˜์–ด์žˆ๋”๋ผ๋„ front-end๋Š” ๊ฒŒ์˜์น˜ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์„ ๋œปํ•œ๋‹ค.

X: X\\r\\nTransfer-Encoding: chunked

front-end ์„œ๋ฒ„์—์„œ๋Š” ๋ณ„ ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š๋Š”๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์—ฌ๋„ HTTP/1 back-end ์„œ๋ฒ„๋Š” ์ด๋ฅผ ๋‘ ๊ฐœ์˜ ํ—ค๋”๋กœ ์ธ์‹ํ•œ๋‹ค.

X: X
Transfer-Encoding: chunked

04. HTTP/2 Request Splitting

์•ž์„œ response queue poisoning์—์„œ ํ•˜๋‚˜์˜ HTTP ์š”์ฒญ์—์„œ ๋‘ ์™„์ „ํ•œ ์š”์ฒญ์„ back-end๋กœ ๋ณด๋‚ด๋Š” ๊ณผ์ •์„ ๋ณด์•˜๋‹ค. HTTP/2 downgrading ํ™˜๊ฒฝ์—์„œ CRLF ์‚ฝ์ž…๊ณต๊ฒฉ๊ณผ ์ด๋ฅผ ์ ‘๋ชฉํ•˜์—ฌ ํ—ค๋” ์•ˆ์—์„œ๋„ ๋‘ ์™„์ „ํ•œ ์š”์ฒญ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

HTTP/2 request splitting ๊ณต๊ฒฉ์€ GET method๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, content-length๋Š” ์œ ํšจํ•˜์ง€๋งŒ, back-end์„œ๋ฒ„๋Š” chunked encoding์„ ์ง€์›ํ•˜์ง€ ์•Š์„ ๋•Œ์—๋„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์–ด ๊ต‰์žฅํžˆ ์œ ์šฉํ•˜๋‹ค.

[IMG9] HTTP/2 request splitting ์˜ˆ์‹œ ํ—ค๋”

์—ฌ๊ธฐ์„œ ํŠน๋ณ„ํ•œ ์กฐ๊ฑด์ด ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋‹ค. Front-end ์„œ๋ฒ„์—์„œ downgrading ํ•˜๋Š” ๊ณผ์ •์—์„œ header์˜ ๋ณ€ํ™”๋ฅผ ์•Œ์•„์•ผ ํ•œ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด Front-end ์„œ๋ฒ„๋Š” ์ฃผ๋กœ “:authority”๋ผ๋Š” ์ž„์‹œ ํ—ค๋”๋ฅผ Host๋กœ ๋ณ€ํ™˜ ํ›„ back-end ์„œ๋ฒ„๋กœ ๋ณด๋‚ธ๋‹ค.

[IMG9]๋ฅผ ๋ณด๋ฉด, X ํ—ค๋” ์† Host ๊ฐ€ ๋์— ์œ„์น˜ํ•˜๊ณ ์žˆ๋‹ค. Front-end ์„œ๋ฒ„๋Š” downgrading์„ ์ง„ํ–‰ํ•˜๋ฉฐ X ํ—ค๋” ๋‹ค์Œ์— Host ํ—ค๋”๋ฅผ ์œ„์น˜์‹œํ‚จ๋‹ค. ๊ฒฐ๊ตญ “wrapper” ์š”์ฒญ์€ Host๊ฐ€ ์—†๊ณ  “smuggled” ์š”์ฒญ์€ Host๊ฐ€ ๋‘๊ฐœ๋‚˜ ์กด์žฌํ•˜๊ฒŒ ๋œ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅํ•˜๋‹ค.

[IMG10] Host ๋ฌธ์ œ ํ•ด๊ฒฐ ์˜ˆ์‹œ

์›ํ™œํ•œ ๊ณต๊ฒฉ์„ ์œ„ํ•ด์„  Host ํ—ค๋” ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ๋‚ด๋ถ€์ ์ธ ํ—ค๋”๋“ค ๋˜ํ•œ ์‹ ๊ฒฝ์จ์•ผ ํ•œ๋‹ค.

05. HTTP Request Tunnelling

๋Œ€๋‹ค์ˆ˜์˜ HRS ๊ณต๊ฒฉ์€ front-end ์™€ back-end ์‚ฌ์ด์˜ ๋™์ผํ•œ ์—ฐ๊ฒฐ์ด ๋‹ค์ˆ˜์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ์— ๊ฐ€๋Šฅํ•˜๋‹ค. ์ด์™€๊ฐ™์ด ์—ฐ๊ฒฐ์„ ์žฌ์‚ฌ์šฉํ•˜๋Š” ์„œ๋ฒ„๋„ ์žˆ์ง€๋งŒ, ๋” ์—„๊ฒฉํ•œ ์ •์ฑ…์„ ๊ฐ€์ง„ ์„œ๋ฒ„๋„ ์กด์žฌํ•œ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด ๋™์ผํ•œ IP ๋ผ๋ฆฌ๋งŒ ์š”์ฒญ์„ ๋ฌถ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์†Œ์ผ“ poisoning์„ ํ†ตํ•ด ํƒ€ ์ด์šฉ์ž์˜ ์š”์ฒญ์— ๊ฐ„์„ญํ•˜๋Š” ๊ธฐ๋ณธ์ ์ธ HRS ๊ณต๊ฒฉ์ด ํ†ตํ•˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค.

ํ•˜์ง€๋งŒ ํ•˜๋‚˜์˜ ์š”์ฒญ์†์— ๋‹ค๋ฅธ ์š”์ฒญ์„ ์ˆจ๊ฒจ back-end๋กœ ์ „ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ์ „ํžˆ ๊ฐ€๋Šฅํ•˜๋‹ค. ์ด๋Š” ์š”์ฒญ์„ ์ˆจ๊ธฐ๊ณ  front-end ์—์„œ ์‘๋‹ต์„ ์žฌ ๋งค์นญํ•˜์—ฌ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์†Œ๋ฆฌ๋‹ค. ํŠน์ • ์š”์ฒญ์„ ๋ง‰๋Š” front-end ๋ณด์•ˆ ์ •์ฑ…์„ ์šฐํšŒํ•˜์—ฌ ์ ‘๊ทผ์„ ์‹œ๋„ํ•  ์ˆ˜ ์žˆ๋‹ค.

[IMG11] HTTP request tunnelling

๋งŽ์€ ์„œ๋ฒ„๋“ค์€ HRS๋ฅผ ๋ง‰๊ธฐ ์œ„ํ•ด ๋‹ค์–‘ํ•œ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ๊ตฌํ˜„ํ•ด๋†จ๋‹ค. ํ•˜์ง€๋งŒ request tunnelling์„ ๋ง‰๊ธฐ์—” ๋ถ€์กฑํ•œ๊ฒŒ ํ˜„์‹ค์ด๋‹ค.

1) HTTP/2 ํ™˜๊ฒฝ์˜ Request Tunnelling

Request tunnelling์€ HTTP/1๊ณผ HTTP/2 ๋‘ ํ™˜๊ฒฝ๋ชจ๋‘ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ HTTP/1 ๋งŒ์„ ์‚ฌ์šฉํ•˜๋Š” ํ™˜๊ฒฝ์—์„œ๋Š” ๋ฐœ๊ฒฌํ•˜๊ธฐ ํž˜๋“ค๋‹ค. HTTP/1 ์—์„œ ์—ฐ๊ฒฐ์„ ์ง€์†ํ•˜๋Š” ์†์„ฑ(keep-alive) ๋•Œ๋ฌธ์— ๋‘ ์‘๋‹ต์„ ์ „ํ•ด๋ฐ›์•„๋„ ์„ฑ๊ณต์ ์œผ๋กœ smuggle ๋˜์—ˆ๋Š”์ง€ ์•Œ๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค.

๋ฐ˜๋ฉด, HTTP/2๋Š” ๊ฐ “stream”์ƒ ํ•˜๋‚˜์˜ ์š”์ฒญ๊ณผ ์‘๋‹ต๋งŒ์„ ํฌํ•จํ•œ๋‹ค. ์ด๋•Œ๋ฌธ์— ๋งŒ์ผ HTTP/2 ์‘๋‹ต body ์†์— HTTP/1 ์ฒ˜๋Ÿผ๋ณด์ด๋Š” ์‘๋‹ต์ด ๋“ค์–ด์žˆ๋‹ค๋ฉด tunnelling์„ ์„ฑ๊ณต์ ์œผ๋กœ ์ง„ํ–‰ํ–ˆ๋‹ค๊ณ  ํ™•์‹ ํ•  ์ˆ˜ ์žˆ๋‹ค.

2) ๋‚ด๋ถ€ ํ—ค๋” ์œ ์ถœ

HTTP/2 downgrading ์ƒํ™ฉ์† request tunnelling์„ ํ†ตํ•ด ๋‚ด๋ถ€ ํ—ค๋”๋ฅผ ์œ ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‚ด๋ถ€ ํ—ค๋”๋ฅผ back-end ์—์„œ body๊ฐ€ ๋  ์ˆจ๊ฒจ๊ธด ์š”์ฒญ ๋’ค์— ์˜ค๊ฒŒํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

[IMG12] Leaking internal headers

Front-end๋Š” ์šฐ๋ฆฌ๊ฐ€ ์ฃผ์ž…ํ•œ ํ˜•์‹์„ ํ—ค๋”์˜ ์ผ๋ถ€๋กœ ๋ฐ›์•„๋“ค์ด๊ณ  ์ƒˆ๋กœ์šด ๋‚ด๋ถ€์ ์ธ ํ—ค๋”๋ฅผ “q=”๋‹ค์Œ์— ์œ„์น˜์‹œํ‚จ๋‹ค. ๋ฐ˜๋ฉด back-end๋Š” “\r\n\r\n”์„ ํ—ค๋”์˜ ๋์œผ๋กœ ํŒ๋‹จํ•˜์—ฌ “q=”๋ถ€ํ„ฐ์˜ ์ถ”๊ฐ€ ํ—ค๋”๋ฅผ body์˜ ์ผ๋ถ€๋กœ ๋ฐ›์•„๋“ค์ธ๋‹ค. ์ด๋ ‡๊ฒŒ ๋‚ด๋ถ€์ ์ธ ํ—ค๋”๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

POST /search HTTP/1.1
Host: kortsec1.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 200

q=Secret-Header: kanyewestContent-Length: 3
x=x

3) Request Tunnelling using HEAD

์–ด๋–ค ๊ฒฝ์šฐ์—๋Š” front-end์—์„œ ์‘๋‹ต์„ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ๊ณผ์ •์—์„œ Content-Length ํ—ค๋” ์† ๋ช…์‹œ๋œ bytes ๋งŒํผ ๋ณด๋‚ด๊ธฐ์— tunnelled ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์„ ๋ณผ ์ˆ˜ ์—†์„ ์ˆ˜๋„ ์žˆ๋‹ค. Blind request tunnelling์ด ๋ฐ”๋กœ ์ด๋Ÿฐ ๊ฒƒ์ด๋‹ค.

ํ•˜์ง€๋งŒ, HEAD๋ฅผ ์ด์šฉํ•˜์—ฌ non-blind request tunnelling์œผ๋กœ ๋ฐ”๊พธ๋Š” ๋ฐฉ๋ฒ•์ด ์กด์žฌํ•œ๋‹ค. HEAD method ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์€ ๋ณธ์ธ์˜ body๊ฐ€ ์—†๋”๋ผ๋„ ์ฃผ๋กœ ๊ฐ™์€ ์š”์ฒญ์„ GET์œผ๋กœ ๋ณด๋ƒˆ์„ ๋•Œ์˜ ์‘๋‹ต ์ž์› ๊ธธ์ด๋ฅผ content-length ํ—ค๋”์†์— ํฌํ•จ์‹œํ‚จ๋‹ค.

[IMG13] HEAD Request
[IMG14] HEAD Response

[IMG14]์˜ ์˜ˆ์‹œ ์ฒ˜๋Ÿผ tunnelled ์š”์ฒญ์˜ ๊ฒฐ๊ณผ๊ฐ€ HEAD์˜ Content-Length ๋ณด๋‹ค ๊ธธ๋‹ค๋ฉด, ์งค๋ฆฐ ์ƒํƒœ๋กœ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์•„ ์›ํ•˜๋Š” ์ •๋ณด๋ฅผ ์–ป๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ๋‹ค. ๋ฐ˜๋Œ€๋กœ, tunnelled ์š”์ฒญ์˜ ๊ฒฐ๊ณผ๊ฐ€ HEAD์˜ Content-Length ๋ณด๋‹ค ์งง๋‹ค๋ฉด, front-end ์„œ๋ฒ„๋Š” ์ถ”๊ฐ€์ ์ธ ์ •๋ณด๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋‹ค timeout ์—๋Ÿฌ๋ฅผ ๋ณด๋‚ด๊ฒŒ ๋œ๋‹ค. ์ด ๋‘ ๊ฒฝ์šฐ๋ฅผ ๊ณ ๋ คํ•ด HEAD ์š”์ฒญ์ด๋‚˜ tunnelled ์š”์ฒญ ์† ์ ์ ˆํ•œ reflected input์„ ์ถ”๊ฐ€ํ•ด ๊ธธ์ด๋ฅผ ์กฐ์ •ํ•ด์•ผ ํ•œ๋‹ค.

05. ์ฐธ๊ณ 

https://portswigger.net/web-security/request-smuggling/advanced

https://portswigger.net/web-security/request-smuggling/advanced/request-tunnelling

https://portswigger.net/web-security/request-smuggling/advanced/http2-exclusive-vectors

https://portswigger.net/web-security/request-smuggling/advanced/response-queue-poisoning

https://portswigger.net/web-security/request-smuggling/advanced/http2-downgrading

https://www.youtube.com/watch?v=w-eJM2Pc0KI

'web hacking ๐Ÿ–ฅ > techniques โŒ principles' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

HTTP Request Smuggling Exploit  (0) 2024.12.10
HTTP Request Smuggling ์ทจ์•ฝ์   (0) 2024.12.08
Race Condition  (0) 2024.04.05
SSTI - RCE(Remote Code Execution) ์—ฐ๊ณ„ ๊ณต๊ฒฉ  (0) 2023.10.13