安全矩阵

 找回密码
 立即注册
搜索
查看: 3807|回复: 0

PHP安全:HTTP响应拆分漏洞

[复制链接]

991

主题

1063

帖子

4315

积分

论坛元老

Rank: 8Rank: 8

积分
4315
发表于 2020-9-20 15:36:40 | 显示全部楼层 |阅读模式
原文链接:PHP安全: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重定向可能会被响应拆分利用。以下是一段不安全的跳转代码。

<?php
header("Location: ".$_GET['page']); // 接收参数跳转到相应页面

正常情况下访问http://localhost/header.php?page=http://test.ptpress.com.cn时,会跳转到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请输入密码:<input%20name="pass"%20value=""%20/>

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

> 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请输入密码:<input%20name="pass"%20value=""%20/>
> 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

<
< 输入密码:<input name="pass" value=""/>

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

图1  响应拆分示例

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

<?php
header("Location: ".strtr($_GET['page'],array("\r"=>"","\n"=>"")));

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



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-4-20 16:40 , Processed in 0.017363 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表