on
Advent Of Corona: Day 8
This post is about the day 8 problem of the Advent Of Corona challenge.
The problem
You are given 3 TCP
connections:
- A test one:
68.183.210.250:32779
- Phase 1:
68.183.210.250:32780
- Phase 2:
68.183.210.250:32781
Your goal is to get a flag, but… Which flag?
The solution
Disclaimer: I won’t give the flags here. Try to solve it by your own, or run the solution script after understanding it if you want to get the flags. It’s up to you in the end…
If you play with the test connection, for example running it via telnet
:
$ telnet 68.183.210.250 32779
You see a tic-tao-toe game. If you win the bot you will get a flag in the format flag{xxx}
.
As the problem states, there’s a timeout of 2s and 3s for the first and second phase, respectively.
My approach is to try to solve it via a random algorithm, i.e. just pick a random empty cell every time.
Here is the code:
from telnetlib import Telnet
from time import time
connections = [
("test", "68.183.210.250", 32779, 3),
("phase_0", "68.183.210.250", 32780, 3),
("phase_1", "68.183.210.250", 32781, 6)
]
for t, h, p, s in connections:
tn = Telnet(h, p)
tn.read_until(str.encode("give me a name: "))
tn.write(str.encode("taras"))
tn.read_until(str.encode("\n"))
tt = time()
while True:
try:
d = []
d_tmp = []
for _ in range(s):
try:
tmp = tn.read_until(str.encode("\n"))
except Exception:
flag = bytes.decode(d_tmp[0]).replace("\n", "")
print(f"{t}: {flag} - {time()-tt:2.4f} s.")
raise Exception("end")
d_tmp.append(tmp)
d += bytes.decode(tmp).replace("\n", "").split("|")[1:-1]
d = [ dd.replace(" ", "") for dd in d ]
tn.read_until(str.encode("give me a position (comma separated): "))
for i in range(len(d)):
if d[i] == "":
ss = f"{i//s},{i%s}\n"
tn.write(str.encode(ss))
break
except Exception:
break
You may have to run it a few times if it does not solve it in the first run.
The actual code
It was written in Go and deployed via Docker :3
If you are interested in how I created this challenge here you can have a look!