Snyk Fetch the Flag CTF 2023 writeup: Honey Baked Messages

Escrito por:
snyk-ctf-2023-honey-baked-messages

30 de novembro de 2023

0 minutos de leitura

Thanks for playing Fetch with us! Congrats to the thousands of players who joined us for Fetch the Flag CTF. If you were at Snyk’s 2023 Fetch the Flag and are looking for the answer to the Honey Baked Messages challenge, you’ve come to the right place. Let’s walk through the solution together!

This challenge focuses on the idea of Hamming codes. Hamming codes are a type of error-correcting codes. This challenge uses the (7, 4) version of Hamming codes.

The challenge consists of these parts:

  1. Understand that this is Hamming coding.

  2. Read in each line of the file. 

  3. Determine the needed H matrix for the problem.

  4. Error correct the entire file and get the flag.

Here is the solve.py solution script:

import numpy as np

H = np.array(
        [
            [1, 1, 1, 0, 1, 0, 0],
            [0, 1, 1, 1, 0, 1, 0],
            [1, 1, 0, 1, 0, 0, 1]
        ]
    )
errors = {
    "000":None,
    "001": 6,
    "010": 5,
    "011": 3,
    "100": 4,
    "101": 0,
    "110": 2,
    "111": 1
}

def np2usable(nparr):
    return np.array2string(nparr).replace(" ", "" ).replace("[", "").replace(']', "")

def fixErrs(hamming):
    error = (np.matmul(H, hamming)%2)
    err_idx = errors[np2usable(error)]
    if err_idx != None:
        # print(err_idx)
        hamming[err_idx] +=1
        hamming[err_idx] %= 2

    return hamming[:4]

data = []
with open("message_2.txt", "r") as reader:
    for line in reader:
        code = np.fromstring(" ".join(line.strip("\n")), dtype = int, sep=" ")
        data.append(np2usable(fixErrs(code)))
split_chars = (list(zip(*(iter(data),) * 2)))

[print(chr(int(j+k, 2)), end="") for j,k in split_chars ]

Thanks for making Fetch happen!

A huge thank you to all the teams in Fetch the Flag 2023! It was great seeing all of you there and you can always find me on YouTube.

Here are the writeups for the other 2023 challenges. Dig in!

Publicado em:Ctf

Snyk é uma plataforma de segurança para desenvolvedores. Integrando-se diretamente a ferramentas de desenvolvimento, fluxos de trabalhos e pipelines de automação, a Snyk possibilita que as equipes encontrem, priorizem e corrijam mais facilmente vulnerabilidades em códigos, dependências, contêineres e infraestrutura como código. Com o suporte do melhor aplicativo do setor e inteligência em segurança, a Snyk coloca a experiência em segurança no kit de ferramentas de todo desenvolvedor.

Comece grátisAgende uma demonstração ao vivo

© 2024 Snyk Limited
Registrada na Inglaterra e País de Gales

logo-devseccon