Level 2 - XIPHEREHPIX's Reckless Mistake

Domain(s): Crypto

Our sources told us that one of PALINDROME's lieutenants, XIPHEREHPIX, wrote a special computer program for certain members of PALINDROME. We have somehow managed to get a copy of the source code and the compiled binary. The intention of the program is unclear, but we think encrypted blob inside the program could contain a valuable secret.

file-download
9KB
file-download
17KB

We are given 2 files, the source code and the compiled binary.

The source code defines some helper functions:

  • getch() -> to get bytes from the terminal

  • input_password() -> to parse the bytes and output the password string

  • calculate_sha256() -> to calculate the sha256 of a given string

  • verify_password() -> to check if the password hash matches the hardcoded hash

The code also defines the function accumulate_xor, which xors each of the 4 items of 2 arrays, and a gcm_decrypt for decryption with AES GCM.

void accumulate_xor(uint256_t *result, uint256_t *arr_entry) {
    result->a0 ^= arr_entry->a0;
    result->a1 ^= arr_entry->a1;
    result->a2 ^= arr_entry->a2;
    result->a3 ^= arr_entry->a3;
}

The flag is expected to be displayed in the show_welcome_msg function, where AES GCM decryption is executed with some hardcoded arguments.

We can view the execution flow of the code in the main() function.

We can see that the program asks for an over 40 byte long password, which it passes into the initialise_key function.

Upon inspection of this function, we see that the password is not actually used in creating the key. This means that we can skip the password verification altogether.

The initialise_key function uses a hardcoded seed to generate the array of 20 SHA256 hashes. This means that the array of hashes used in the key generation is constant.

Moving on to the for loop, we can see that the password is only used for determining which of the arrays are XOR-ed to generate the key.

This means that the final key is generated solely from the same 20 SHA256 hashes, no matter what password is entered. Therefore we could bruteforce all combinations of all lengths of the SHA256 hashes until we find the flag.

Flag: TISC{K3ysP4ce_1s_t00_smol_d2g7d97agsd8yhr}

Last updated