[upload-labs] 学习
2019-01-19 本文已影响92人
2mpossible
一个帮你总结所有类型的上传漏洞的靶场
Pass-01
- 在js中发现校验文件后缀的函数,我们添加php类型后在控制台更改然后上传shell



- 上传shell之后在返回的数据中发现了shell的路径,然后用蚁剑连接即可


Pass-02
- 这关是服务器验证,首先试了php后缀,当然是不行的,然后继续试了1.php.jpg是可以上传的,1.php.asd是不可以上传的,所以可以知道是白名单绕过,然后没思路看了提示和源码发现是检验了数据包的content-type,所以上传php的时候抓包修改content-type为image/jpeg来绕过上传即可


Pass-03
- 上传php的时候有个很明显的黑名单限制提示,尝试使用php3,phtml绕过,最后phtml成功绕过并解析


Pass-04
-
不能上传php,但能上传php.jpg,php.asd,说明是黑名单限制,但是php3,phtml都被限制了,查看提示几乎所有可以绕过的后缀名都被限制了,但是唯独没有.htaccess,可以先上传一个.htaccess让所有文件解析为php,然后再上传一个图片马
-
htaccess文件是Apache服务器中的一个配置文件,它负责相关目录下的网页配置。通过htaccess文件,可以帮我们实现:网页301重定向、自定义404错误页面、改变文件扩展名、允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能。
//.htaccess
SetHandler application/x-httpd-php


Pass-05
- 不能上传php,.htaccess但能上传php.jpg,php.asd,说明是黑名单限制,查看源码发现与上一关少了统一大小写,所以用大小写绕过,上传phP文件绕过即可

Pass-06
- 可以上传php.asd,黑名单限制,源码中没有去除空格所以可以上传.php 文件进行绕过


Pass-07
- 可以上传php.asd,黑名单限制,源码没有去除文件名最后的.号,windows特性会自动去掉后缀名中最后".",于是可以构造.php.来绕过上传

Pass-08
- 可以上传php.asd,黑名单限制,没有去除文件名后缀的::$DATA, 同样可以利用 windows 特性, 在后缀添加::$DATA即可绕过


Pass-09
- 黑名单限制,咋一看好像可以绕过的都被限制了,但是仔细看最后拼接的文件名是处理后的文件名,所以可以上传"1.php. .",经过处理后的文件名就变成"1.php.",最后由于windows特性会将.自动去除来绕过



Pass-10
- 黑名单过滤,上传时会去除php等字样,所以用双写绕过,构造.pphphp去除php后就变成.php


Pass-11
- 白名单校验,但是图片路径是拼接的,所以可以用%00截断
//%00截断适用条件
PHP 版本 < 5.3.4
php.ini 中 magic_quotes_gpc=off



Pass-12
- 这题跟上一题的不同就是保存路径从 GET方法变成了POST方法,此时不能再使用%00截断, 因为%00截断在 GET 中被 url 解码之后是空字符,但是在 POST 中%00不会被 url 解码, 所以只能通过burpsuite修改hex值为00进行截断




Pass-13
- 题目要求上传图片马,源码是根据文件的前2个字节来判断文件类型,于是构造个图片马

- 可以看到上传成功,后续利用就要配合文件包含了

Pass-14
- 这里用了getimagesize()函数来检查图片,但是getimagesize也是根据文件头判断,所以跟上关一样就可以绕过了

Pass-15
- 虽然换了exif_imagetype()检查,但是跟前两关一样就能绕过

Pass-16
-
发现上传即使没通过也会将图片存在upload目录下,后面发现是作者一开始的逻辑没写好,即使没通过if循环也会因为move_uploaded_file函数将图片马上传到upload目录,所以我又重新下载了一份作者修改后的版本
-
具体针对二次渲染的上传绕过可以看这篇文章upload-labs之pass 16详细分析,我试了下gif文件的绕过
-
修改没有二次渲染后没有变动的地方

- 利用文件包含成功执行php语句

- jpg文件我试了好几次发现都会将php语句破坏一点
Pass-17
- 查看源码发现存在条件竞争,在if判读不通过unlink文件之前已经用move_uploaded_file函数将文件上传到upload目录下,所以通过bp不断的上传weshell,然后在浏览器中不断的访问总能访问到未被unlink的webshell文件


Pass-18
- 上传图片马时也存在条件竞争,有可能会未重命名

Pass-19
- move_uploaded_file()函数中的img_path是由post参数save_name控制的,因此可以在save_name利用00截断绕过


- 上传成功


Pass-20
$is_upload = false;
$msg = null;
if(!empty($_FILES['upload_file'])){
//检查MIME
$allow_type = array('image/jpeg','image/png','image/gif');
if(!in_array($_FILES['upload_file']['type'],$allow_type)){
$msg = "禁止上传该类型文件!";
}else{
//检查文件名
$file = empty($_POST['save_name']) ? $_FILES['upload_file']['name'] : $_POST['save_name'];
if (!is_array($file)) {
$file = explode('.', strtolower($file));
}
$ext = end($file);
$allow_suffix = array('jpg','png','gif');
if (!in_array($ext, $allow_suffix)) {
$msg = "禁止上传该后缀文件!";
}else{
$file_name = reset($file) . '.' . $file[count($file) - 1];
$temp_file = $_FILES['upload_file']['tmp_name'];
$img_path = UPLOAD_PATH . '/' .$file_name;
if (move_uploaded_file($temp_file, $img_path)) {
$msg = "文件上传成功!";
$is_upload = true;
} else {
$msg = "文件上传失败!";
}
}
}
}else{
$msg = "请选择要上传的文件!";
}
- 这里smi1e师傅教我如何绕过(我要做smi1e师傅的舔狗),首先end函数取所post参数数组中的最后一个值,$file_name = reset($file) . '.' . $file[count($file) - 1]我们可以post一个参数名为一个[0]一个[2],然后$file[count($file) - 1]就为空,$file_name最终就为reset($file)即$file[0],就可以绕过判断


- 然后自动过滤.
