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

来源:互联网 发布:软壳冲锋衣 知乎 编辑:程序博客网 时间:2024/05/22 02:14

http://blog.csdn.net/hitwangpeng/article/details/47042971

首先先来看一个简单的asp实例

[plain] view plain copy
  1. <%  
  2.     username = request("username")  
  3.     Response.write username  
  4. %>  
这段代码从URL处获得参数username的值,然后显示在页面中。

可见%00之后的内容没有保存到变量中。
[html] view plain copy
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Language" content="zh-cn">  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
  5. <title>文件上传</title>  
  6. </head>  
  7.   
  8.   
  9. <body>  
  10. <form method="POST" action="SaveFile.asp">  
  11. 文件上传:<input type="file" name="file" size="42"> <input type="submit" value="提交" name="bb">  
  12. </form>  
  13. </body>  
  14. </html>  

[plain] view plain copy
  1. <%  
  2. dim file,filename,houzui  
  3. file = Request.Form("file")  
  4. response.write "文件名:"&file  
  5. response.write "<br>"  
  6. houzui=mid(file,InStrRev(file, "."))  
  7. response.write "后缀名:"&houzui  
  8. response.write "<br>"  
  9. if houzui=".gif" or houzui=".jpg" or houzui=".bmp" then   
  10.     '允许上传的文件类型  
  11.     response.write "图片上传成功"  
  12. else  
  13.     response.write "不允许上传" & houzui & "的格式"  
  14. end if  
  15. %>  
下面在网站中直接上传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] view plain copy
  1. <html>  
  2. <head>  
  3. <meta http-equiv="Content-Language" content="zh-cn">  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
  5. <title>文件上传</title>  
  6. </head>  
  7.   
  8.   
  9. <body>  
  10. <form   
  11. method="POST" action="SaveFile.php">  
  12. 文件上传:<input type="file" name="file" size="42"> <input type="submit" value="提交" name="submit">  
  13. </form>  
  14. </body>  
  15. </html>  

[php] view plain copy
  1. <?php  
  2.     $WhiteList = array('rar','jpg','png','bmp','gif','jpg','doc');  
  3.     if (isset($_POST["submit"])){  
  4.         $name = $_FILES['file']['name']; //接收文件名  
  5.         echo $name;  
  6.         $extension = substr(strrchr($name,"."),1);//得到扩展名  
  7.         $boo = false;  
  8.           
  9.         foreach ($WhiteList as $key=>$value){  
  10.             if ($value==$extension){//迭代判断是否有命中  
  11.                 $boo=true;  
  12.             }  
  13.         }  
  14.           
  15.         if($boo){//如果有命中,则开始文件上传操作  
  16.             $size=$_FILES['file']['size'];//接收文件大小  
  17.             $tmp=$_FILES['file']['tmp_name'];//临时路径  
  18.             move_uploaded_file($tmp,$name);//移动临时文件到当前文件目录  
  19.             echo "文件上传成功!<br/> path:".$name;  
  20.         }else {  
  21.             echo "文件不合法!!";  
  22.         }  
  23.           
  24.     }  
  25. ?>  
过程和asp的类似
上传ma2.php 1.jpg

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

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

最终显示的结果是

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

综上所述,0x00不是针对所有基于白名单的后缀名检查都能绕过,代码的实现过程中必须存在截断上传漏洞。
0 0