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

Description

The final stage of your initialization sequence is mastering cutting-edge technology tools that can be life-changing. One of these tools is quipqiup, an automated tool for frequency analysis and breaking substitution ciphers. This is the ultimate challenge, simulating the use of AES encryption to protect a message. Can you break it?

Exploitation

#!/usr/bin/python3

def get_plaintext(ciphertext_file):
    mappings = {
        "0fbf645baa0ecce12ed52071a4ed0d1d": "F",
        "ce2e2acd1155ac79105dcabcdb4fbbff": "R", 
        "d78843699ad962a2a7c513d193d27ab4": "E",
        "9a2f91dbedaa39d9b53f8146c2301098": "Q",
        "3ea6ab81fee5f5c718f48b86e8680732": "U",
        "b403c6f30eec7075d0643b5d4125de1b": "N",
        "9e520d83ca02f81ab980ed7ff9a16526": "C",
        "9b9233be563be442bf2edf0e3e42848d": "Y",
        "a952cfc1d886d6084113d5f3e13508f0": " ",
        "00273fa04b9b836c553d876502e9a1e2": "A",
        "d3eae0ab73225a3d841241af5d8a0654": "L",
        "4ca1a8b8e8ca22b70d69ca257d79e5ed": "S",
        "98c50ceddda78b850757dc37c1c0814d": "I",
        "cb20a26ba8411b2e0072e7438ed67e54": "B",
        "4065e6b94c150f4137af46b752e25204": "D",
        "495c118c128a67d8a0f022e3f001775e": "O",
        "d395fedae9dca912da1b1b50b0aca161": "T",
        "c98f7e77e918e98833b8fa19de4b1653": "H",
        "e3372f2164f66ea750b5b14f8166b0b9": "G",
        "473a4eb8c699b9141c7d0bb4fa691674": "V",
        "b1119ba67f26c30144e9cea6a6d7059c": "W",
        "a33f02cf75488a76efb91511a0111982": "M",
        "48654fae441fee7cd607d8cb90c1de44": "P",
        "3321154f7ace2161b8cafb37c6307e6b": "K",
        "4fdd58bb71f5f8c882eaa592d51cf647": "X",
        "ddfdaa01baab48baf54067dd3a3de527": "Z",
        "8115f6662bacddd86db1ae8dc533c46c": "J",
        "d4dde50295a8c036709603b3c216e44d": "{",
        "97038e93767664edf41312c98285ba94": "_",
        "25581e56ea570e8f68c9dab82f24f36e": "}"
    }
    with open(ciphertext_file) as f:
        blocks = [line.strip() for line in f if line.strip()]
    plaintext = ""
    for block in blocks:
        if block in mappings:
            plaintext += mappings[block]
        else:
            plaintext += "?"
    return plaintext

try:
    plaintext = get_plaintext("output.txt")
    print("Plaintext message:")
    print("-" * 50)
    print(plaintext)
    flag_start = plaintext.find("HTB{")
    flag_end = plaintext.find("}") + 1
    if flag_start != -1 and flag_end != -1:
        flag = plaintext[flag_start:flag_end]
        print("\nFlag found:", flag)
except FileNotFoundError:
    print("Error: output.txt file not found")
except Exception as e:
    print(f"Error occurred: {e}")

Summary

Perfect Synchronization: recover the Vigenere key from the ciphertext, decrypt the message, and verify the flag.