Vampires Checker (Reverse)
Vampires Checker solution (medium).
Last updated
Vampires Checker solution (medium).
Last updated
We have a single ELF file, and when we run it we get:
It is basically a flag checker, we need to enter the flag to get the correct message, let's start disassembling.
Seeing main function, it takes our input, then pass it to a function called "func" then checks if it's equal to an array called "arr" which is the encrypted flag.
Let's check the "func" function:
We see some sort of encryption happening, with an array key (local_38), let's start organizing the code and renaming variables using 'L' button.
We will first go to "arr" array and get all the hex values from there, then in CyberChef we will use two options to convert them to decimal so we use them in our solver script:
NOTE: be careful extracting the flag, because one of the values is 00. After renaming the variables to have a better understanding, here is what we have:
So the function first XOR's with one of the key elements, and then multiply by 8, then an OR operation is done with 5 bits shifted to the right.
Now we can trace that and just rewrite the code in python to solve it, or we can use chatGPT, when i tried that it gave me wrong answers and wasn't able to solve it, so let's do it manually, we will first write some code to set the flag, and then make an empty list that we will modify to have the final flag.
Next we will loop over the encrypted flag, and start doing the encryption operation backwards:
What we are doing here basically is:
Masking the number (so it doesn't exceed 8 bits, can be done using '% 8' or '& 0x7').
Reverse the 5 bits right shift, by a left shift.
OR operation with 3 bits right shift to reverse the 8, since dividing by 8 wont give good results (due to floats and integers).
Finally XOR-ing with the key.
Let's now assemble the whole code and print the characters of the result numbers, here is the final code:
Running it results in:
And done!