Lab 5 - Confusing Code¶
Table of Contents¶
Overview¶
In this lab, you'll first need to identify which program you can run with root privileges. Use Ghidra to decompile the program and understand the confusing code. Using the information you discover, run the program and answer the questions correctly, revealing the location where the access code is hidden along the way.
Analysis¶
What is the path to the binary you can run as the root user?¶
Matching Defaults entries for kali on halloween-2024-confusing-code:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
use_pty
User kali may run the following commands on halloween-2024-confusing-code:
(root) NOPASSWD: /opt/b-code/a-iamconfused/confusing-code
/opt/b-code/a-iamconfused/confusing-code
Ghidra Tool¶
Analyzing the file above in Ghidra provides details for the execution in the main() function.
Ghidra first disassembles the binary into machine instructions and provides the confusing-code.asm file. In this file, we can see the true representation of the program logic:
- Function entry points
- Registers
- Stack operations
- Jumps and branches
- Calls to other functions
Ghidra also includes a decomplier that reconstructs high-level C code from the assembly under the confusing-code.c file.
- The program continuously calls the
loop()function insidemain(). - Inside
loop(), the program:- Reads a value from user input.
- Depending on the value entered by the user (
local_14), it calls a corresponding function (zero(),one(), etc.). - If no matching value is found, it clears the screen and displays an error message.
- The program checks for stack corruption before returning from the function.
- The valid ride identifiers are as follows:
- Looking at the assembly code, the password is
pge2jand it is saved in thelocal_30variable, which is the one used by all the functions to check for the password. - Looking at all the functions, they all do the same except for input
294(0x126). - This input calls
three(), which asks for the password and callsseven(0)on success. - This actually tries to read a file containing the access code and prints its content.
Solution¶
Let's run the program using the information we just gathered.
Welcome doomed investigator
Where is the AI's access code hidden?
- In the remains of the Python Pit?
- In the jaws of the sharks in their pool?
- In the chaos of the carnival?
- Under the Rusty Rollercoaster?
- Somewhere in Mirror Mayhem?
- In the Cursed Crypt?
Which route do you want to take? - enter the id of the ride (it will be between 0-65535)): 294
What is the passcode to the computer?: pge2j
You go to the correct ride and unlock the computer there with the correct password, it unlocks revealing the access code to you: 3280d4
3280d4.
Navigation¶
| ← Encryption Enigma | Haunted Helpdesk → |