十、利用 windows 环境的叠加特征绕过
1、简介
在 windwos 中如果上传文件名 phpinfo.php:.jpg 的时候,会在目录下生产空白的文件名 phpinfp.php,再利用 php 和 windows
环境的叠加属性。
以下符号在正则匹配时相等:
双引号" 等于 点号.
大于符号> 等于 问号?
小于符号< 等于 星号*
文件名.< 或 文件名.<<< 或 文件名.>>> 或 文件名.>><空文件名
2、代码分析
$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");
$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 . '文件夹不存在,请手工创建!';
}
}
同样是黑名单匹配,把.去掉,把空格过滤了,::$data 也过滤了。
3、绕过上传
首先抓包上传 a.php:.jpg 上传会在目录里生成 a.php 空白文件,接着再次提交把a.php 改成 a.>>>
十一、双写后缀名绕过
1、简介
在上传模块,有的代码会把黑名单的后缀名替换成空,例如 a.php 会把 php 替换成空,但是可以使用双写绕过例如 asaspp,pphphp,即可绕过上传。
2、代码分析
同样是黑名单过滤。str_ireplace 对上传的后缀名是黑名单内的字符串转换成空。
3、绕过攻击
抓包上传,把后缀名改成 pphphp 即可绕过上传