CRLF(Carriage Return Line Feed)란?
CR(Carriage Return: \r): 커서의 위치를 현재 줄의 맨 앞으로 보내는 개행 문자
LF(Line Feed: \n): 커서를 다음 행으로 옮기는 개행 문자
이 둘의 결합으로
쉽게 말해서 키보드의 Enter키와 동일한 기능을 가지고 있다
Char | URL Encode | ASCII Code | |
CR(Carriage Return) | \r | %0D | ASCII 13 |
LF(Line Feed) | \n | %0A | ASCII 10 |
아래와 같이 버프를 통해 요청값의 줄바꿈이 된 문자열 전에 무조건 \r\n이 포함되어 있다는 것을 확인 가능하다.
\n버튼 클릭 전 | \n 버튼 클릭 후 |
![]() |
![]() |
이러한 CRLF 개행문자를 이용하여 공격을 할 수 있는데
CRLF Injection 또는 HTTP 응답 분할 취약점(HTTP Response Splitting Vulnerability)라고 명칭한다.
관련 내용은 CWE-93번과 113번에서도 확인 가능하다.
https://cwe.mitre.org/data/definitions/93.html
CWE - CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection') (4.13)
div.collapseblock { display:inline} CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')Weakness ID: 93Abstraction: BaseStructure: Simple The product uses CRLF (carriage return line feeds) as a special element, e.g. to separate lines or rec
cwe.mitre.org
https://cwe.mitre.org/data/definitions/113.html
CWE - CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Request/Response Splitting') (4.13)
div.collapseblock { display:inline} CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Request/Response Splitting')Weakness ID: 113Abstraction: VariantStructure: Simple The product receives data from an HTTP agent/component (e.g., we
cwe.mitre.org
- HTTP Request에 존재하는 파라미터가 HTTP Response의 헤더로 다시 전달되는 경우 파라미터 내 CRLF 개행문자가 존재하면 HTTP Response가 분리되어 두개의 응답이 생성된다.
- 분리된 응답 중 두 번째는 정상적인 다른 사용자의 응답으로 잘못 해석될 수 있다.
- 분리가 된 Response에 악의적인 코드를 주입함으로써 XSS 및 캐시를 훼손 가능
요약하면 \r이나 \n을 이용해서 줄바꿈을 넣어 공격 가능하다는 것인데
CWE-113에서 말하는 사례로 어떻게 공격이 가능한지 살펴보자.
- 사용자 간 변조 공격(실제 환경에서 수행 어려움)
만약 page라는 파라미터로 값을 받아서 해당 페이지로 이동되게 개발을 했을 경우
page 값에 CRLF를 포함한 공격 구문을 넣어서 요청을 하면
/test.php?page=http://abc.abcdef.com%0d%0aContent-Length:%20%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2019%0d%0a%0d%0a<html>login</html> |
서버는 다음 헤더 두 개로 응답한다.
1
HTTP/1.1 302 Moved Temporarily Date: Wed, ~생략~ Location: http://index.com/test.php?page=http://abc.abcdef.com Content-Length:0 |
2
HTTP/1.1 200 OK Content-Type: text/html Content-Length: 18 <html>login</html> |
이렇게 되면 지정된 웹페이지가 아닌 응답 2를 반환하여 악의적인 페이지로 리다이렉트 될 수 있다.
아래 3개는 다음에 이어서 작성하도록 하겠다.
- 웹 및 브라우저 캐시 중독
- 크로스 사이트 스크립팅(XSS, Cross-Site Scripting)
- 페이지 하이재킹
대응방안
- HTTP Response Header에 입력되는 값을 필터링
- CR(%0D),LF(%0A)를 제거하거나 치환하는 입력값 검증을 실시하여 헤더 분할 방지
JAVA의 경우 아래와 같이 replaceAll함수를 이용하여 개행문자를 필터링하면 될 것 같다.
a = a.replaceAll("\r","");
a = a.replaceAll("\n","");
실제 코드에 적용시켜보지 않았으므로, 본인 코드에 맞게 적당히 바꿔서 쓰시길..
관련 실습은 https://itpop.tistory.com/22 에 정리해 두었다.
[webhacking.kr] old-38번 문제풀이 | CRLF Injection취약점
old-38번 문제를 풀어보겠다. LOG INJECTION이란 문구과 로그인 입력값을 받는 페이지가 나온다. admin을 입력하고 로그인을 시도하면 you are not admin이란 글이 출력된다. 로그인 페이지의 숨겨진 admin.php
itpop.tistory.com
CRLF Injection scanner도 존재한다.
https://github.com/MichaelStott/CRLF-Injection-Scanner
GitHub - MichaelStott/CRLF-Injection-Scanner: Command line tool for testing CRLF injection on a list of domains.
Command line tool for testing CRLF injection on a list of domains. - GitHub - MichaelStott/CRLF-Injection-Scanner: Command line tool for testing CRLF injection on a list of domains.
github.com
https://github.com/rudSarkar/crlf-injector
GitHub - rudSarkar/crlf-injector: A CRLF ( Carriage Return Line Feed ) Injection attack occurs when a user manages to submit a C
A CRLF ( Carriage Return Line Feed ) Injection attack occurs when a user manages to submit a CRLF into an application. This is most commonly done by modifying an HTTP parameter or URL. - GitHub - ...
github.com
OWASP 사이트에서 해당 공격에 대한 내용을 볼 수 있다.
https://owasp.org/www-community/vulnerabilities/CRLF_Injection
CRLF Injection | OWASP Foundation
CRLF Injection on the main website for The OWASP Foundation. OWASP is a nonprofit foundation that works to improve the security of software.
owasp.org