Post

HackTheBox LunaCrypt Challenge

Explore the basics of cybersecurity in the LunaCrypt 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.

https://app.hackthebox.com/challenges/234

Description

Our astronaut gained access to a key satellite and intercepted an encrypted message. The forensics team also recovered a file that looks like a custom encryption protocol. We are sure that these two elements are linked. Please can you help us reveal the contents of the secret message?

Exploitation

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
#!/usr/bin/env python3

def decrypt_character(char: int, flag: int) -> int:
    flag = flag ^ 0x4A
    if flag & 0b00010000:  # XOR by 0x3E
        char ^= 0b00111110
    if flag & 0b00001000:  # XOR by 0x6B
        char ^= 0b01101011
    if flag & 0b00000010:  # Negate
        char = 255 - char
    if flag & 0b01000000:  # Swap bytes
        THIS_MSB = (char >> 4) & 0b1111
        THIS_LSB = char & 0b1111
        char = ((THIS_LSB << 4) ^ 0b11010000) | (THIS_MSB ^ 0b1011)
    return char

def decrypt(ciphertext: str) -> str:
    pairs = [int(x) for x in ciphertext.split()]
    plaintext = ''
    for i in range(0, len(pairs), 2):
        char = pairs[i]
        flag = pairs[i + 1]
        decrypted = decrypt_character(char, flag)
        plaintext += chr(decrypted)
    return plaintext

if __name__ == "__main__":
    encrypted = "108 182 82 176 167 158 69 222 39 102 234 14 241 16 10 218 160 108 76 234 225 224 1 12 97 122 114 90 10 90 250 14 155 80 101 186 97 218 115 218 207 76 190 174 196 84 192 144"
    print(decrypt(encrypted))

Summary

The LunaCrypt Challenge on Hack The Box involves decrypting a message encoded with a custom encryption protocol. Participants must analyze the encryption logic, which includes bitwise operations, XOR manipulations, and byte swaps based on specific flags. By reversing these operations, the original plaintext message can be reconstructed. This challenge highlights the importance of understanding custom cryptographic implementations and provides a hands-on approach to decrypting non-standard encryption schemes.

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