Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import ssl
  4. import socket
  5. import pprint
  6. import time
  7.  
  8.  
  9. def read(c):
  10. b = b''
  11. reading = True
  12. while reading:
  13. try:
  14. b = b + c.recv()
  15. except socket.error as e:
  16. pprint.pprint(e)
  17. pprint.pprint(b)
  18. if b.endswith(b'> '):
  19. reading = False
  20. elif b == b'':
  21. try:
  22. b = b + c.recv()
  23. except socket.error as e:
  24. pprint.pprint(e)
  25. pprint.pprint(b)
  26. reading = False
  27.  
  28. return b
  29.  
  30.  
  31. context = ssl.create_default_context()
  32. conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname="sewers.mctf2019.com")
  33. conn.connect(("sewers.mctf2019.com", 1337))
  34.  
  35. found = False
  36. moves = 0
  37. output = b'OK\n> '
  38.  
  39. read(conn)
  40. while not found :
  41. if output == b'OK\n> ' or output == b'OK\n':
  42. conn.sendall(b"left\n")
  43. pprint.pprint("left sent {}".format(moves))
  44. moves = moves + 1
  45.  
  46. read(conn)
  47.  
  48. conn.sendall(b"forward\n")
  49. pprint.pprint("forward sent {}".format(moves))
  50. moves = moves + 1
  51.  
  52. output = read(conn)
  53. elif output == b'BLOCKED\n> ':
  54. conn.sendall(b"right\n")
  55. pprint.pprint("right sent {}".format(moves))
  56. moves = moves + 1
  57.  
  58. read(conn)
  59.  
  60. conn.sendall(b"forward\n")
  61. pprint.pprint("forward sent {}".format(moves))
  62. moves = moves + 1
  63.  
  64. output = read(conn)
  65. else:
  66. pprint.pprint("Unknown output received")
  67. pprint.pprint(str(moves))
  68. found = True
  69. # Double check no bytes left to pull
  70. read(conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement