MalwareTech Beginner Malware Reversing Challenges shellcode1 Writeup
16 Feb 2019Environment
- Host OS: Kali linux 2018.4
- Guest OS: Windows 7 Home Basic
- Virtualization: Virtualbox 5.2.22
- Debugger: IDA Pro 7.0
Explanation
We have several malware reversing challenges this page on MalwareTech
This is a write-up of “shellcode1”.
Solution
1. Opening the shellcode1.exe
Let’s open the shellcode1.exe.
As we can see on a following picture, it shows a MD5 encrypted flag.
Just like strings challenges, we have to “decrypt” this MD5 hash and get original text.
2. Analyzing assembly code
Same as last challenge, to encrypt the original text, a function MD5:digestString is used.
It’s argument is in an offset “Str” and it must be a text which we’re looking for.
However, it is already encrypted and sounds like does not mean anything.
In this assembly code, we can find the “offset Str” one more time.
As we can see, it’s getting the length of Str and storing it into [ecx+4].
Then, figure out what it ecx.
Sounds like the value of ecx is return value of HeapAlloc.
And the return value is a pointer to the allocated momory block.
This means, after these instructions below, values of ecx and ecx+4 are
Then we still have 3 functions which we have to analyze.
Sounds like return value of VirtualAlloc is set in [ebp+Dst]. According to the official document, the arguments of VirtualAlloc are
and in this case, VirtualAlloc is called like
Next, look at memcpy.
This means, in this case, memcpy is called like
We can find that the unknown function [ebp+Dst] is from offset unk_404068. Looks like just some encrypted codes. However, we can convert the data to code with C key.
Sounds like this doing followning things.
At this time, the value of esi is [ebp+var_4]. This means it is heap space allocated.
Now, we have offset Str in the heapspace.
In summerize, the value which Str is modified by this function above is the original text.
3. decryption
Now we know what we have to do.
After selecting the data we need, we can export it with “Edit->Export data” (or Shift+E) and choose C hex for python code.
Then, what we have to do is writing a code for decryption.
By executing this code, we can obtain the original text.