Ransomware - 464 Points
WARNING! DON’T EXECUTE THIS SAMPLE IN YOUR OWN PERSONAL MACHINE!!!
We have a malware to analyse, right at the beginning(_start function) I found an encrypted string with xor, reversing it wasn’t very hard as you can see bellow:
The actual function in the ida was this one:
Rewriting this function into python we ended up with this:
1 | import struct |
By running the script we can see that the encrypted string was the name of the file we received from the challenge which was encrypted:
1 | $ python writeup_mocoh.py |
One good thing to do while reversing is to rename the function and string names to a more readable names, so if they are reused we can immediately recognize them :
Now continuing analysing the contents of sub_40023B
we have more strings to decrypt:
Updating this python script with this:
1 | import struct |
By running we can see it’s some words in Portuguese and they don’t look really useful at all:
1 | $ python mocoh.py |
After renaming the variable names in IDA ended up in this final part of the program:
As you can see above every string we decrypted is being concatenated into a place in memory at dword_4012c0, and at the end in sub_4005DA the flag file name is being pushed in to the stack since this will be a argument to that function so this may be the one that was used to encrypted the flag.mocoh file!
Now by checking this function I found it too hard to reverse sub_400684, without running the malware itself (Couldn’t do it since it executable wasn’t compatible with my Windows 10 VM), so after failing to infect myself and debugging it with IDA, I checked that sub_4006D8 of them was using xor again to encrypt that file:
Now you may be asking if I didn’t reverse sub_400684 how the hell I did get the keys to decrypt the flag file? well I wasn’t really expecting this to happen but at some point I knew I could know the first 4 bytes of the key because we know the first 4 bytes of the plaintext which is part of the flag format 3DS{, I wanted to check before reversing the rest, the first 4 bytes of the key, I did this by brute-forcing byte by byte:
1 | flag_cipher = open('flag.mocoh', 'r').read() |
And surprisingly to me the first 4 bytes of the keys was always 175
1 | $ python test.py |
And then I asked myself what if the key is always the same? this couldn’t be a coincidence:
1 | flag_cipher = open('flag.mocoh', 'r').read() |
Running it we could see that this was the case…1
2$ python test.py
3DS{4sS3mbly_r0cks!!}
And in the end I realized that I lost a lot of time reversing the binary, we didn’t even needed to reverse anything, if we made a guess that it was xor we could just tried and check that it was using always the same 1 byte key to encrypt…