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

Description

Your initialization sequence requires loading various programs to gain the necessary knowledge and skills for your journey. Your first task is to learn the ancient encodings used by the aliens in their communication.

Source

source.py

from Crypto.Util.number import bytes_to_long
from base64 import b64encode
from secret import FLAG

def encode(message):
    return hex(bytes_to_long(b64encode(message)))

def main():
    encoded_flag = encode(FLAG)
    with open("output.txt", "w") as f:
        f.write(encoded_flag)

if __name__ == "__main__":
    main()

output.txt

0x53465243657a51784d56383361444e664d32356a4d475178626a6c664e44497a5832677a4d6a4e664e7a42664e5463306558303d

Exploitation

#!/usr/bin/python3
from Crypto.Util.number import long_to_bytes
from base64 import b64decode

def decode(encoded_hex):
    encoded_int = int(encoded_hex, 16)
    encoded_base64 = long_to_bytes(encoded_int)
    return b64decode(encoded_base64)

def main():
    with open("output.txt", "r") as f:
        encoded_hex = f.read().strip()
    flag = decode(encoded_hex)
    print(f"Recovered FLAG: {flag.decode()}")

if __name__ == "__main__":
    main()

Summary

Ancient Encodings: model the crypto leak, recover the missing secret, and decrypt the flag.