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:

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 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", "", 32779, 3),
    ("phase_0", "", 32780, 3),
    ("phase_1", "", 32781, 6)

for t, h, p, s in connections:
    tn = Telnet(h, p)

    tn.read_until(str.encode("give me a name: "))

    tt = time()

    while True:
            d = []
            d_tmp = []

            for _ in range(s):
                    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 += 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"
        except Exception:

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!