pwn_template
code: (python)
from pwn import *
def recv(until="\n", after=None):
res = io.recvuntil(until.encode() if type(until) == str else until)
return resres.index(after)+len(after): if after else res
def send(payload, endl=True):
io.send(payload + (b"\n" if endl else b""))
def sendafter(until, payload, endl=True):
io.sendafter(until.encode() if type(until) == str else until, payload + (b"\n" if endl else b""))
def conn():
if args.REMOTE:
io = remote(HOST, PORT)
elif args.GDB:
io = gdb.debug(elf.path, aslr=ASLR, gdbscript=gdb_script)
else:
io = process(elf.path, aslr=ASLR)
return io
context.arch = 'amd64'
context.terminal = 'tmux splitw -v -b -l 40'.split()
context.log_level = 'debug'
HOST = ""
PORT = 0
ASLR = False
elf = ELF("./chall")
# libc = ELF("./libc.so.6")
gdb_script = """
set max-visualize-chunk-size 0x400
# set resolve-heap-via-heuristic force
b main
c
"""
def exploit():
return 0
while True:
io = conn()
if exploit():
print("Failed")
io.close()
if args.GDB: pause()
continue
io.interactive()
break