Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import ssl
- import socket
- import pprint
- import time
- def read(c):
- b = b''
- reading = True
- while reading:
- try:
- b = b + c.recv()
- except socket.error as e:
- pprint.pprint(e)
- pprint.pprint(b)
- if b.endswith(b'> '):
- reading = False
- elif b == b'':
- try:
- b = b + c.recv()
- except socket.error as e:
- pprint.pprint(e)
- pprint.pprint(b)
- reading = False
- return b
- context = ssl.create_default_context()
- conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname="sewers.mctf2019.com")
- conn.connect(("sewers.mctf2019.com", 1337))
- found = False
- moves = 0
- output = b'OK\n> '
- read(conn)
- while not found :
- if output == b'OK\n> ' or output == b'OK\n':
- conn.sendall(b"left\n")
- pprint.pprint("left sent {}".format(moves))
- moves = moves + 1
- read(conn)
- conn.sendall(b"forward\n")
- pprint.pprint("forward sent {}".format(moves))
- moves = moves + 1
- output = read(conn)
- elif output == b'BLOCKED\n> ':
- conn.sendall(b"right\n")
- pprint.pprint("right sent {}".format(moves))
- moves = moves + 1
- read(conn)
- conn.sendall(b"forward\n")
- pprint.pprint("forward sent {}".format(moves))
- moves = moves + 1
- output = read(conn)
- else:
- pprint.pprint("Unknown output received")
- pprint.pprint(str(moves))
- found = True
- # Double check no bytes left to pull
- read(conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement