Welcome to another new write-up.
This is a reverse engineering challenge from Flaghunt-2022 organized by CTFBD.
The challenge is very easy. Let’s dive in and solve the challenge.
Firstly, let’s see what the given program does. So let’s execute the binary.
After executing, we can see it asks for a pin number. Let’s put a random number and press enter.
After pressing enter it prompts for something else. So, let’s put a random number again.
And again it asks for something more.
Actually, it asks for 5 pins.
We can try with some random numbers and as expected, it returns us an error message.
Now, we need to open the given executable in a reverse engineering tool or frameworks like cutter, IDA Pro, or Ghidra. I’m using Ghidra for now, but you can use whatever you want.
After opening the executable with Ghidra, we need to analyze the binary. After analyzing, we need to look for all the functions of that program.
We can find some functions here as you can see below.
Here we can see we have the main function. Let’s disassemble that function.
In Ghidra, we can see the decompiled source code of the main function.
Here we can see, we have five variables in the function and all of them are set to ZERO initially.
Then the program takes 5 input for these 5 variables and set their value accordingly. And then the program passes these variables as argument in the prize function.
Here we get some unusual naming of the variables. So for convenience, I named them simply like a, b, c, d, and e.
Now, let’s hop in the prize function.
So, here is the decompiled source code of the prize function of the program, where we can find some mathematical equations, we need to solve these equations and find such values of a, b, c, d, and e which will satisfy the equations for getting the flag.
And again for convenience, I’m naming the parameters simply according to the variable names of the main function.
Here the numbers of the equations are in Hexadecimal form. Let’s convert them to decimals.
And after conversion, the equations looks like that.
Now, we can solve these equations by hand. But I’m lazy, so I am using an online calculator and here are the values of the variables that we get after solving all the equations.
Let’s try inputting these values as pin after executing the given binary.
Viola! We got the flag.