Shimbles the E-L-F

Reverse Engineering · BearcatCTF 2025 · Nyla

Problem

Description

Utilizing Ghidra allows us to see functions effectively.

Main function

Two_layer_decrypt function

Explanation

undefined8 main(void)

The main function simulates a decryption challenge from Schimbles the gnome:

  1. Introduction: Prints an ASCII art gnome and taunts the user.

  2. User Input: Prompts the user for a decryption key, reads input, and compares it with an encrypted key.

  3. Key Validation:

    • Decrypts the encrypted key using two_layer_decrypt with parameters (local_e1, key_length, 0xaa, 3, 0x5f, 2).

    • If the input matches, it decrypts and displays the flag with parameters (local_d8, flag_length, 0x77, 4, 0x3c, 3).

    • If incorrect, it decrypts and shows a taunt with parameters (local_b8, taunt_length, 0x6d, 2, 0x33, 5).

  4. Stack Integrity: Checks for stack corruption at the end.


void two_layer_decrypt(long param_1, ulong param_2, byte param_3, undefined4 param_4, byte param_5, undefined4 param_6)

This function decrypts a byte array using two XOR and rotation layers:

  1. First Layer: XORs each byte with param_5, then rotates by param_6.

  2. Second Layer: XORs the result with param_3, then rotates by param_4.

  3. Stores Decrypted Byte: Updates the byte array with the final decrypted value.

This function is used to decrypt keys, flags, and taunts in the main function.

Finding the key

  • The x command in GDB is used for examining memory.

  • 8b specifies that you want to view 8 bytes (the b stands for byte) of memory.

  • x/8bx tells GDB to show the bytes in hexadecimal format.

  • 0x4010 is the memory address you are examining. You provided the address 0x4010 to GDB to inspect the contents at that specific location in memory.

gef➤ info address encrypted_key

Symbol "encrypted_key" is at 0x4010 in a file compiled without debugging.

GDB

Solution

Run the binary file and enter the key.

Last updated