HTTP Response Splitting攻击探究

本文深入探讨了HTTP Response Splitting攻击,解释了其原理、成因和实施条件,涉及服务器安全漏洞、缓存中毒等问题。攻击者通过注入HTTP请求,使服务器返回两个HTTP响应,从而实现多种恶意目的,如Web缓存中毒、跨用户页面篡改等。

 

第一小节: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

### HTTP 响应拆分攻击HTTP Response Splitting Attack)的原理 HTTP 响应拆分攻击是一种利用 HTTP 协议中头字段分隔符 `CRLF`(即 `\r\n`)未被正确处理而引发的安全漏洞。在 HTTP 协议中,HTTP 头字段之间通过单个 `CRLF` 分隔,两个连续的 `CRLF` 表示头字段的结束和消息体的开始[^3]。 当 Web 应用程序将用户输入直接插入到 HTTP 响应头中时,如果未对输入中的 `CRLF` 字符进行过滤或转义,攻击者可以注入额外的头字段或伪造整个响应内容。例如,攻击者可以在请求中包含类似 `%0d%0a`(URL 编码形式的 `CRLF`)的数据,从而构造出恶意的响应头和响应体。这种技术可以导致多个恶意响应被发送给客户端,从而实现多种攻击目标,如跨站脚本攻击(XSS)、缓存污染(Cache Poisoning)等[^2]。 ### 攻击示例 假设一个 Web 应用程序将用户的输入直接写入到 `Location` 响应头中用于重定向,攻击者可以通过构造特殊的输入来插入额外的响应头和响应体。例如: ``` HTTP/1.1 302 Found Location: http://example.com%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2047%0d%0a%0d%0a<html>Hacked</html> ``` 在这个例子中,攻击者成功地注入了一个新的响应头和响应体,使得服务器返回了一个恶意的 HTML 页面[^5]。 ### 防御措施 为了防止 HTTP 响应拆分攻击,开发人员需要采取以下几种主要的防御策略: 1. **输入验证与过滤**:对所有用户输入进行严格的验证和过滤,特别是要检查并移除或转义输入中的 `CRLF` 字符。任何可能被插入到 HTTP 响应头中的数据都应经过处理,确保不会引入非法字符[^3]。 2. **使用安全的编码库**:在处理用户输入时,使用经过验证的安全编码库来自动处理特殊字符的转义工作。这些库通常已经内置了针对常见安全漏洞的有效防护机制。 3. **避免将用户输入直接插入到 HTTP 响应头中**:尽可能减少甚至完全避免将用户提供的数据直接插入到 HTTP 响应头中。如果确实需要这样做,则必须确保数据已经过适当的清理和验证过程。 4. **设置合适的 Content-Security-Policy (CSP)**:虽然 CSP 主要用于防范 XSS 攻击,但它也可以作为额外的一层保护,限制页面只能加载来自指定来源的资源,从而降低因响应拆分导致的 XSS 攻击的风险[^4]。 5. **使用现代 Web 框架**:许多现代 Web 开发框架已经内置了对各种安全威胁的防护机制,包括但不限于 HTTP 响应拆分攻击。选择并使用这些框架可以帮助开发者更容易地构建更加安全的应用程序。 综上所述,HTTP 响应拆分攻击利用了 HTTP 协议解析中的一个特定弱点,通过对用户输入的不当处理来实现攻击目的。然而,通过实施上述提到的各种防御措施,可以有效地减轻此类攻击带来的风险。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值