HackThisSite - Basic Mission 8

Challenge

Sam remains confident that an obscured password file is still the best idea, but he screwed up with the calendar program. Sam has saved the unencrypted password file in /var/www/hackthissite.org/html/missions/basic/8/

Sam 仍然认为把密码文件藏起来是个好办法。密码文件保存在 /missions/basic/8/ 目录下。

Sam 的女儿 Stephanie 刚学了 PHP,她写了一个脚本来展示保存文件的能力。

页面有一个"Enter your name"输入框,还有一个密码输入框。

Solution

Stephanie 的脚本会保存用户输入的名字到一个 .shtml 文件中。.shtml 是 Server-Side Includes (SSI) 文件,服务器会解析其中的 SSI 指令。

尝试输入 SSI exec 指令来执行 shell 命令:

1
<!--#exec cmd="ls ../" -->

提交后,页面返回一个链接指向生成的 .shtml 文件(如 tmp/fyrvqqak.shtml)。访问这个链接,服务器会解析 SSI 指令并执行 ls ../,输出 /missions/basic/8/ 目录的内容:

1
2
3
4
au12ha39vc.php    ← 密码文件
index.php
level8.php
tmp/

然后访问 https://www.hackthissite.org/missions/basic/8/au12ha39vc.php 获取密码。

注意:服务器限制了可执行的命令范围(只允许与查找密码文件相关的命令),但 ls 是被允许的。

核心知识点:SSI Injection(服务器端包含注入)。当用户输入被保存到 .shtml 文件并由服务器解析时,SSI 指令中的 exec 可以执行任意 shell 命令。防御方法:不要将用户输入存储在会被服务器解析的文件中,或严格过滤 SSI 特殊字符。

4046427a