【文件上传绕过】八、::$DATA上传绕过

文章目录

        • 一、利用Windows特性
        • 二、源码
        • 三、使用burpsuite抓包在文件后缀加::$DATA绕过


一、利用Windows特性

在window的时候如果文件名+"::$DATA"会把::$DATA之后的数据当成文件流处理,不会检测后缀名,且保持::$DATA之前的文件名,他的目的就是不检查后缀名

例如:"phpinfo.php::$DATA"Windows会自动去掉末尾的::$DATA变成"phpinfo.php"

二、源码

源码中未过滤::$DATA

$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
     
    if (file_exists(UPLOAD_PATH)) {
     
        $deny_ext = array(".php",".php5",".php4",".php3",".php2",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".htaccess");
        $file_name = trim($_FILES['upload_file']['name']);
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = trim($file_ext); //首尾去空
        
        if (!in_array($file_ext, $deny_ext)) {
     
            $temp_file = $_FILES['upload_file']['tmp_name'];
            $img_path = UPLOAD_PATH.'/'.date("YmdHis").rand(1000,9999).$file_ext;
            if (move_uploaded_file($temp_file, $img_path)) {
     
                $is_upload = true;
            } else {
     
                $msg = '上传出错!';
            }
        } else {
     
            $msg = '此文件类型不允许上传!';
        }
    } else {
     
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    }
}

代码中没有对::$DATA进行处理

三、使用burpsuite抓包在文件后缀加::$DATA绕过

1、抓包

【文件上传绕过】八、::$DATA上传绕过_第1张图片
2、上传文件

【文件上传绕过】八、::$DATA上传绕过_第2张图片
3、访问文件

【文件上传绕过】八、::$DATA上传绕过_第3张图片

上传到服务器的文件在Windows中会自动去掉::$DATA

【文件上传绕过】八、::$DATA上传绕过_第4张图片

你可能感兴趣的:(文件上传绕过,php,web,wenshell,文件上传漏洞)