Post

HackTheBox Crushing Writeup

Explore the basics of cybersecurity in the Crushing Challenge on Hack The Box. This easy-level Challenge introduces encryption reversal and file handling concepts in a clear and accessible way, perfect for beginners.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import struct

def read_serialized_data(filepath):
    char_map = {}
    with open(filepath, 'rb') as f:
        for char_code in range(256):
            list_len_bytes = f.read(8)
            if not list_len_bytes:
                break
            list_len = struct.unpack('Q', list_len_bytes)[0]
            positions = []
            for _ in range(list_len):
                pos_bytes = f.read(8)
                if pos_bytes:
                    pos = struct.unpack('Q', pos_bytes)[0]
                    positions.append(pos)
            if positions:
                char_map[char_code] = positions
    return char_map

def reconstruct_message(char_map):
    max_pos = max(pos for positions in char_map.values() for pos in positions)
    message = ['\x00'] * (max_pos + 1)
    for char_code, positions in char_map.items():
        for pos in positions:
            message[pos] = chr(char_code)
    return ''.join(message)

def main():
    char_map = read_serialized_data('message.txt.cz')
    message = reconstruct_message(char_map)
    print(f"Decoded message:\n{message}")

if __name__ == "__main__":
    main()

Summary

The Crushing Challenge on Hack The Box is an easy-level challenge where you decode a message by reading serialized data from a file, reconstructing a character map, and mapping character codes to positions, offering a beginner-friendly introduction to encryption reversal and file handling.

This post is licensed under CC BY 4.0 by the author.