HTTP响应拆分漏洞

HTTP响应拆分漏洞,HTTP响应拆分漏洞也称为CRLF注入漏洞。恶意攻击者将CRLF换行符加入到请求中,从而使一个请求产生两个响应,前一个响应是服务器的响应,而后一个则是攻击者设计的响应。

正常的HTTP请求如下。

> GET /header.php?page=http://www.ptpress.com.cn
> HTTP/1.1
> Host: localhost
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Host: localhost:8080
< Date: Mon, 23 Mar 2020 11:32:31 +0000
< Connection: close
< X-Powered-By: PHP/5.2.0
< Location: http://www.ptpress.com.cn
< Content-type: text/html: charset=UTF-8

在PHP中使用header()函数进行URL重定向可能会被响应拆分利用。以下是一段不安全的跳转代码。



正常情况下访问http://localhost/header.php?page=http://test.ptpress.com.cn时,会跳转到 http://test.ptpress.com.cn页面。如果恶意攻击者构造如下所示的URL,用户访问时会显示伪造的页面,并填写信息,从而恶意攻击者可收集用户信息。

http://localhost:8080/header.php?page=%0d%0aContent-Type:%20text/html%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContentLength:%20158%0d%0a%0d%0a请输入密码:

下面是被注入拆分漏洞的请求。

> GET /header.php?page=%0d%0aContent-Type:%20text/html%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContentLength:%20158%0d%0a%0d%0a请输入密码:
> HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Host: localhost:8080
< Date: Mon, 23 Mar 2020 11:32:31 +0000
< Connection: close
< X-Powered-By: PHP/5.2.0
< Location:  // 这里是多余的CRLF < Content-type: text/html
< HTTP/1.1 200 OK
< Content-type: text/html
< Content-Length: 50
<
< 输入密码:

浏览器接收到两个ResponseHeader,最终显示最后接收到的Body,如图1所示。

在PHP中能引起响应拆分漏洞的函数有header()、setcookie()、session_id()、setrawcookie()等。在PHP5.1.2之后,该漏洞被修复,可以一次性阻止多个报文信息的发送。如果使用的是旧版本的PHP,应该设置字符替换。

"","\n"=>"")));

一旦攻击者能够控制HTTP消息头中的字符,注入一些恶意的换行,就能注入一些会话Cookie或者HTML代码。响应拆分一旦被缓存在CDN或代理缓存服务器上,危害也是极大的。


请使用浏览器的分享功能分享到微信等