Ultimate Encryptor
In this challenge, we have an encrypted flag in a file and the binary used to encrypt it. So I used GHidra to decompile and analyze the Assembly and C. After reading the program, I understood the following 3 functions on the program:
read_file()
: get the content of a file and return it as a stringUltimateEncryption()
: encrypt the message and return the textmain():
call
read_file()
passing the first parameter(file with message in clean text);Pass the content of the file to
UltimateEncryption()
Finally, the program salve the content encrypted in a second file passed as a second parameter to binary
After some debugging, renaming variables, and commenting on the main lines I got this code.
To put my code to work I got the main()
and read_file()
raw functions from Ghidra and paste them in my encrypt.c
file with the function below. To understand how the encryption was working I commented the "for" statements one a one to understand how each step works. And I had these conclusions:
Step 0: if the string was odd, appended '0' at the end;
Step 1: switch letter positions two by two. So replace the first letter with a second, the third with the fourth, and so on;
Step 2: XOR each byte with
0x2b
("+" in ASCII)Step 3: Skip in 15 the letter using ASCII table
Step 4: XOR each letter with the next (and use the last with the first)
After testing all statements, I implemented a decode to each and tested all steps encrypting and decrypting one a one. Finally, I got this solution:
Last updated