Dynastic - Cyber Apocalypse 2024: Hacker Royale CTF Writeup

Dynastic - Cyber Apocalypse 2024: Hacker Royale CTF Writeup

In the heart of the Cyber Apocalypse 2024: Hacker Royale CTF by HackTheBox, participants were thrust into a life-or-death scenario with the “Dynastic” challenge. With time ticking away and a lethal gas threatening to fill the chamber, the players had to decrypt a mysterious message to unlock their way to safety. Let’s dive into the eerie world of “Dynastic” and unravel its secrets.

Challenge Description:

Upon entering the challenge, participants found themselves trapped in a sealed gas chamber. A foreboding message revealed that within minutes, the chamber would be filled with deadly hydrogen cyanide. To escape this grim fate, they needed to unlock both the handcuffs restraining them and the exit door, using the same elusive passcode. The only clue: cryptic letters etched into the walls and a disturbing image of a Roman emperor.

The Journey Begins:

To decrypt the passcode, participants were provided with a Python script named source.py and an output file output.txt. The script revealed a custom encryption method based on an identity mapping scheme, encrypting the flag provided in FLAG variable.

from secret import FLAG
from random import randint

def to_identity_map(a):
    return ord(a) - 0x41

def from_identity_map(a):
    return chr(a % 26 + 0x41)

def encrypt(m):
    c = ''
    for i in range(len(m)):
        ch = m[i]
        if not ch.isalpha():
            ech = ch
        else:
            chi = to_identity_map(ch)
            ech = from_identity_map(chi + i)
        c += ech
    return c

with open('output.txt', 'w') as f:
    f.write('Make sure you wrap the decrypted text with the HTB flag format :-]\n')
    f.write(encrypt(FLAG))

The output file output.txt contained the encrypted message, hinting at the form of the final flag.

Make sure you wrap the decrypted text with the HTB flag format :-]
DJF_CTA_SWYH_NPDKK_MBZ_QPHTIGPMZY_KRZSQE?!_ZL_CN_PGLIMCU_YU_KJODME_RYGZXL

Cracking the Code:

To decipher the encrypted message and obtain the flag, participants needed to reverse engineer the encryption process. Armed with the provided to_identity_map and from_identity_map functions, they could decrypt the ciphertext.

def to_identity_map(a):
    return ord(a) - 0x41

def from_identity_map(a):
    return chr(a % 26 + 0x41)

def decrypt(ciphertext):
    m = ''
    for i in range(len(ciphertext)):
        ch = ciphertext[i]
        if not ch.isalpha():
            dch = ch
        else:
            dchi = from_identity_map(to_identity_map(ch) - i)
            dch = dchi
        m += dch
    return m

ciphertext = "DJF_CTA_SWYH_NPDKK_MBZ_QPHTIGPMZY_KRZSQE?!_ZL_CN_PGLIMCU_YU_KJODME_RYGZXL"
plaintext = decrypt(ciphertext)
print(plaintext)

Celebrating Victory:

With the decryption script in hand, participants ran it to reveal the hidden message and claim their well-deserved victory.

HTB{DID_YOU_KNOW_ABOUT_THE_TRITHEMIUS_CIPHER?!_IT_IS_SIMILAR_TO_CAESAR_CIPHER}

Conclusion:

The “Dynastic” challenge provided an exhilarating experience, combining cryptography and problem-solving skills under intense pressure. Participants emerged victorious by unraveling the mysteries within the encrypted message, ultimately escaping the grim fate of the gas chamber. As the Cyber Apocalypse 2024: Hacker Royale continued, participants braced themselves for even more thrilling challenges that lay ahead.

Stay tuned for more exciting CTF adventures!

Comments