HackTheBox LunaCrypt Challenge
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
#!/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
LunaCrypt: derive the XOR key stream, invert the transform, and recover the flag.