Challenges
Format-string vulnerability: memory leak via %x
PWN
Medium
Format string
Solves: 7
Format-string vulnerability: memory leak via %x
Author: CyberSamSU
Points
35
If the program calls the user-inputted text directly as printf(user_input) (without providing the format string itself!), the attacker can "read" any value on the program's STACK using special characters like %x, %N$x — even without providing any actual arguments.
def printf_sim(pos, reg_args, stack_args):
"""Haqiqiy printf(fmt, ...) ning %N$x semantikasi:
N-argument (1-indeksli) — agar N <= 5 bo'lsa registrdan
(reg_args[N-1]), aks holda stekdan (stack_args[N-6]) olinadi."""
if pos <= 5:
return reg_args[pos - 1]
return stack_args[pos - 6]
In x86-64, the FIRST 5 variadic arguments are placed in registers (N=1..5), and starting from the 6th, they are placed on the stack. Below is the state when this program was called:
| N (1..5) | Value (in register) |
|---|---|
1 | 17533 |
2 | 44976 |
3 | 38226 |
4 | 31624 |
5 | 37594 |
| N (6+i) | stack_args index (i) | Value |
|---|---|---|
6 | 0 | 8452831 |
7 | 1 | 5038768 |
8 | 2 | 5410035 |
9 | 3 | 13821324 |
10 | 4 | 15106394 |
11 | 5 | 7796144 |
12 | 6 | 6237517 |
13 | 7 | 2438921 |
The attacker sent the format string "%12$x". What (hex) value will be output to the screen?
Submit the answer in the format BAYROQ{PWN_LEAK_<hex qiymat, katta harflarda>}.
Theory: learn the topic
To submit a flag, log in.