upload-labs-master-Pass-03

131 阅读1分钟

第三关 依然还是先看源码

$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array('.asp','.aspx','.php','.jsp');
        $file_name = trim($_FILES['upload_file']['name']);
        $file_name = deldot($file_name);//删除文件名末尾的点
        $file_ext = strrchr($file_name, '.');
        $file_ext = strtolower($file_ext); //转换为小写
        $file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
        $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 = '不允许上传.asp,.aspx,.php,.jsp后缀文件!';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    }
}

代码看到有$deny_ext 函数 以asp aspx php jsp结尾的文件都不允许上传

那我们依然有之前两关的方法去上传试试

image.png

image.png 执行后发现不行了 不能使用burp 抓包修改成php上传了,那怎么弄?

php不行 那Php7行不行呢? image.png 居然上传成功了

image.png 但是显示的是代码并没有执行代码内容

image.png

说明代码层开始有意识的加强了验证 但是这里的黑名单只有少数几个 依然还有很多类型的文件可以上传 比如html

<!DOCTYPE html>
<html>
<head>
    <title>PHP Info</title>
</head>
<body>
	<script>
	document.write("Hello World!");
	alert ('弹窗出点东西')
	</script>
</body>
</html>

image.png

image.png 虽然不能做到 webshell 但是也是一个小bug

有人说这题要修改apache 的conf文件 我心想我都能修改apache配置文件了 肯定已经拿到服务器权限了 还需要做文件上传的漏洞渗透? 那不就是脱裤子放屁多此一举 而且添加给配置文件添加文件后缀的方法也只存在低版本的apache里面 我个人觉得完全没有必要去搞