%00截断攻击的探索
首先先来看一个简单的asp实例
[plain] view plain copy

可见%00之后的内容没有保存到变量中。
[html] view plain copy
[plain] view plain copy

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

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

通过上面的结果可知当asp代码file = Request.Form("file")得到文件名时,0x00之后的内容已经被删除了。
所以如果想利用0x00来达到攻击的目的,相应的网站代码也必须是存在截断上传漏洞的,而此例中的代码不具有此漏洞。
类似的来看看php中的情况
[html] view plain copy
[php] view plain copy
上传ma2.php 1.jpg

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

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

最终显示的结果是

可见$_FILES["file"]["name"]在得到文件名时0x00之后的内容已经不见了,如果在此基础上判断后缀名是否合法,则肯定不能通过。
php的
[plain] view plain copy
- <%
- username = request("username")
- Response.write username
- %>
可见%00之后的内容没有保存到变量中。
[html] view plain copy
- <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>
[plain] view plain copy
- <%
- 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
- %>
可见网站阻止上传
利用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
- <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] view plain copy
- <?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 "文件不合法!!";
- }
- }
- ?>
上传ma2.php 1.jpg
在repeater中更改相应的字节 0x20->0x00
回头在看proxy中相应的字节已经被更改
最终显示的结果是
可见$_FILES["file"]["name"]在得到文件名时0x00之后的内容已经不见了,如果在此基础上判断后缀名是否合法,则肯定不能通过。
综上所述,0x00不是针对所有基于白名单的后缀名检查都能绕过,代码的实现过程中必须存在截断上传漏洞。
转自 http://blog.csdn.net/hitwangpeng/article/details/47042971
截断大概可以在以下情况适用
include(require)
file_get_contents
file_exists
所有url中参数可以用%00控制
0x01. 本地文件包含
1.1 截断类型:php %00截断
截断条件:
php版本小于5.3.4 详情关注CVE-2006-7243
php的
magic_quotes_gpc
为OFF状态
漏洞文件lfi.php
<?php $temp = $_REQUEST["action"].".php"; include $temp; // include造成了LFI和php的%00截断 ?>
要include的password文件
Password <?php phpinfo(); ?>
利用代码:lfi.php?action=password%00
注意:url正宗%00是被会url解码成0x00,所以可能导致截断。
password文件被成功包含并且执行phpinfo()函数。
如果没有截断条件,lfi.php就只能包含php扩展名的文件。
相反,如果有截断条件,lfi.php可以包含任意文件的扩展名。
当把magic_quotes_gpc
打开,php版本依然是5.2.9时,再测试,结果%00被转义成了