您的位置:首页 > 其它

[基本实验] %00截断攻击的探索

2015-07-24 16:29 369 查看
首先先来看一个简单的asp实例

<%
username = request("username")
Response.write username
%>
这段代码从URL处获得参数username的值,然后显示在页面中。



可见%00之后的内容没有保存到变量中。

<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上传</title>
</head>

<body>
<form method="POST" action="SaveFile.asp">
文件上传:<input type="file" name="file" size="42"> <input type="submit" value="提交" name="bb">
</form>
</body>
</html>


<%
dim file,filename,houzui
file = Request.Form("file")
response.write "文件名:"&file
response.write "<br>"
houzui=mid(file,InStrRev(file, "."))
response.write "后缀名:"&houzui
response.write "<br>"
if houzui=".gif" or houzui=".jpg" or houzui=".bmp" then
'允许上传的文件类型
response.write "图片上传成功"
else
response.write "不允许上传" & houzui & "的格式"
end if
%>
下面在网站中直接上传asp程序



可见网站阻止上传

利用Burp工具来实现0x00的截断,首先上传ma1.asp[空格]1.jpg获取到上传请求,随后点击action,并选择Send to Repeater



在Repeater选项卡中点击要更改的字节,(该网站将空格变为了+),将表示+的0x2b改为0x00,





然后点击Go,返回到proxy中,查看hex可见更改已经起效。



放行此请求,结果显示



通过上面的结果可知当asp代码file = Request.Form("file")得到文件名时,0x00之后的内容已经被删除了。

所以如果想利用0x00来达到攻击的目的,相应的网站代码也必须是存在截断上传漏洞的,而此例中的代码不具有此漏洞。

类似的来看看php中的情况

<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上传</title>
</head>

<body>
<form
method="POST" action="SaveFile.php">
文件上传:<input type="file" name="file" size="42"> <input type="submit" value="提交" name="submit">
</form>
</body>
</html>


<?php
$WhiteList = array('rar','jpg','png','bmp','gif','jpg','doc');
if (isset($_POST["submit"])){
$name = $_FILES['file']['name']; //接收文件名
echo $name;
$extension = substr(strrchr($name,"."),1);//得到扩展名
$boo = false;

foreach ($WhiteList as $key=>$value){
if ($value==$extension){//迭代判断是否有命中
$boo=true;
}
}

if($boo){//如果有命中,则开始文件上传操作
$size=$_FILES['file']['size'];//接收文件大小
$tmp=$_FILES['file']['tmp_name'];//临时路径
move_uploaded_file($tmp,$name);//移动临时文件到当前文件目录
echo "文件上传成功!<br/> path:".$name;
}else {
echo "文件不合法!!";
}

}
?>
过程和asp的类似

上传ma2.php 1.jpg



在repeater中更改相应的字节 0x20->0x00



回头在看proxy中相应的字节已经被更改



最终显示的结果是



可见$_FILES['file']['name']在得到文件名时0x00之后的内容已经不见了,如果在此基础上判断后缀名是否合法,则肯定不能通过。

综上所述,0x00不是针对所有基于白名单的后缀名检查都能绕过,代码的实现过程中必须存在截断上传漏洞。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: