Upload-labs_Pass-10_for_Linux
我们利用 Windows 的特性来做 Pass-10 的漏洞,那么在 Linux 下怎么做呢?
Pass-10
环境: Dokcer {Debian8 Apache2.4/Nginx1.18+PHP5.4}
题目
$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 . '文件夹不存在,请手工创建!';
}
}
在Windos
下,这里可以轻松使用 xxx.php. .
绕过黑名单,并且利用 Windows
把后缀的点和空格自动去除的特性,轻松 getshell
。
Linux
下,尝试用此方法,会出现什么情况呢?
cat 一下
很明显,空格被转义了,虽然可以访问 webshell.php.%20 ,但是并不解析。
那怎么办 呢,那就先从源码入手
寻找函数的漏洞
- trim函数过滤不全,但是这个并不能利用
复现 ,但是很遗憾,没有能突破这个pass。
换个思路,找中间件的漏洞
Apache 2.4.0-2.4.29存在解析漏洞CVE-2017-15715,上传一个后缀末尾包含换行符的文件,来绕过FilesMatch。但绕过FilesMatch不一定能被PHP解析。但是这个题目换行符被过滤了。
那切换一下环境 (Apache2.2+php5.3)
使用Apache的多后缀名解析漏洞绕过
利用成功
除此之外,暂时没有想到其他的突破方式。