Introduction
The challenge contains a single Linux executable ELF
file that is not stripped (has debug symbols, which will
make our life easier).
I’ll be using Ghidra for analysing this binary.
Analysis
After opening the file in Ghidra, we can start by searching for the main
function in the left panel. We found it and here it is:
|
|
In Ghidra, there are some types not present in C
like undefined
, but we can
ignore them and just analyze what the program is doing. Here is the basic flow:
- Get input from the user and check that the length of the input is 0x20 (32) characters.
- We do some encryption using
SHUFFLE
andXOR
global arrays. - We check that the result is the same as the input.
- Lastly, check that the characters at
0x1b..0x1e(exclusive)
are equal to"159"
.
Even though in the last
strncmp
it is comparing it with"15963"
, it is using 3 asn
.
So now we need to reverse the encryption.
Solution
First, let’s get the SHUFFLE
and XOR
arrays,
In the encryption process, it loops through all character, shuffle it and XOR it with a value.
We can reverse that by XORing the result, which we have 3
characters of for now,
and re-position the XORed characters in their original location.
I’ll be using Python for programming the decryption logic:
Let’s make an array of None
s to hold the result/decrypted buffer as they are the same,
and fill it with the known 3 characters
Then for reversing the encryption, we will loop until the buffer is full:
In the end we should get decypted
filled:
|
|
|
|
Flag
In the code it prints the flag in "wgmy{%s}"
|
|