Rev Rev Rev
Problem
rev_rev_rev
Lets first disassemble the main function of the binary:
Ignoring the MK_FP
function which is related to the stack canaries protection on the executable we can see the program is reading from the STDIN
into s
and then modifies 4 modifications on the string using 4 functions:
sub_80486B9(&s);
sub_80486DB(&s);
sub_8048738(&s);
sub_80487B2(&s);
Sub_80486B9 is just removing the new line in the end of the string by inserting a nullbyte on it (note that 10 or 0x0A in hex represents the \n):
1 | char *__cdecl sub_80486B9(char *s) |
sub_80486DB is just reversing the string:
1 | char *__cdecl sub_80486DB(char *s) |
sub_8048738 is performing a bunch of operation on the characters of the string some AND, OR and shifts
1 | int __cdecl sub_8048738(char *a1) |
sub_80487B2 is flipping the bits of each byte using ~ operator
1 | int __cdecl sub_80487B2(_BYTE *a1) |
We could rewrite this functions in python and apply it into the cipher string to get the real flag back! but thats too much work why don’t we insert the ciphertext to the binary and check if it spits the flag? lets do this with radare2:
And we got the flag!!! Additionally I did a python script that interacts with radare2 using r2pipe which is a really cool python package, this script will automate what I did manually above doing a dynamic analysis:
1 | import r2pipe |
Running it
1 | $ python revrevrev.py 2>/dev/null |