文件上传绕过

1.准备upload-labs 靶场(此篇文章仅针对pass-20)

文件上传绕过_第1张图片

2.打开pass-20并查看上传代码

文件上传绕过_第2张图片

3.对上传代码进行分析

$is_upload = false;
$msg = null;
if(!empty($_FILES['upload_file'])){
    //检查MIME
    $allow_type = array('image/jpeg','image/png','image/gif');
    if(!in_array($_FILES['upload_file']['type'],$allow_type)){
        $msg = "禁止上传该类型文件!";
    }else{
        //检查文件名
        $file = empty($_POST['save_name']) ? $_FILES['upload_file']['name'] : $_POST['save_name'];
        if (!is_array($file)) {
            $file = explode('.', strtolower($file));
        }

        $ext = end($file); 
        //end() 函数将数组内部指针指向最后一个元素,并返回该元素的值,所以这个函数可以接受数组的

        $allow_suffix = array('jpg','png','gif');
        if (!in_array($ext, $allow_suffix)) {
            $msg = "禁止上传该后缀文件!";
        }else{

            $file_name = reset($file) . '.' . $file[count($file) - 1];
            //reset() 函数将内部指针指向数组中的第一个元素,并输出,所以这个函数也可以接受数组的,count() 统计数组有多少个元素

            $temp_file = $_FILES['upload_file']['tmp_name'];
            $img_path = UPLOAD_PATH . '/' .$file_name;
            if (move_uploaded_file($temp_file, $img_path)) {
                $msg = "文件上传成功!";
                $is_upload = true;
            } else {
                $msg = "文件上传失败!";
            }
        }
    }
}else{
    $msg = "请选择要上传的文件!";
}

部分代码的分析我已放在上面注释中,由

$file_name = reset($file) . '.' . $file[count($file) - 1];

可以知道文件名字是如何拼接的

4.接着来上传文件并使用bp进行抓包

文件上传绕过_第3张图片文件上传绕过_第4张图片

 5.对抓包数据进行修改文件上传绕过_第5张图片

6.复制上传图像地址访问,出现下面页面即为成功(页面的显示不是一模一样,与自己上传的木马有关)文件上传绕过_第6张图片

注:本文仅为个人学习记录

你可能感兴趣的:(网络安全)