EquationGroup has a malware called DoubleFantasy. Sounded interesting, so I decided to go ahead and attack it and find out what it’s all about. Supposedly Kaspersky said about EquationGroup,
The Equation Group is probably one of the most sophisticated cyber
attack groups in the world; and they are the most advanced threat actor
we have seen
So let’s see what it’s all about.
I’m definitely splitting this one up into several posts because a detailed from-scratch analysis will take some time. Due to this, be ready for a more comprehensive explanation in the latter posts as at that point, I can tie it all together and explain what this thing does. Let’s look at the preliminaries:
I ran the malware executable through PE Studio first to get suspicious imports and strings. Of the ones PES identified, this is what caught my eye. Note that some of these may be harmless, but nevertheless, I flagged the below strings:
9h_007AhFLW33abcdefghijklmnopqrstuvwzyz. ABCDEFGHIJKLMNOPQRSTUVWXYZ. 1234567890.
ABOVE 341 bytes^
As we can see, there are a lot of goodies up above, such as thread creation, possible privilege escalation, creating or modifying of some dll file called msvcp5(some number).dll, Common Object Model usage, service creation, file reading and writing, possible shellcode text, and I even found ntoskrnl.exe (Windows Kernel) functions PsDereferencePrimaryToken and PsReferencePrimaryToken, which indicate some sort of driver or low-level code because that is Kernel-Mode code. Last but not least, at the beginning of the giant string with the hex codes, there is Uc32nbspace. This one caught my eye and with a simple Google search, I found something called MicroChip ChipKIT Development Board UC32 1 which is just a speculation at this point, but who knows, maybe this malware targets or looks for an embedded device.
Next on the list was to try and identify any cryptography ahead of time, so I ran this thing through PEiD KANAL and came up with:
BASE64 table :: 0002B8C0 :: 0042C8C0
The reference is above.
RC5 / RC6 [Init, -Delta] :: 00027D07 :: 00428D07
The reference is above.
So we have RC6 encryption and a BASE64 encoding, which I suspected based upon a few of the strings above. Good to know.
Next on the list was checking the resources in ResourceHacker. We have 3 resources in this file named 1,2, and 4. The first two resources appeared to be some sort of encoded binary data and the third resource was, voila, an entire embedded executable file! I extraced this guy to disk, to be analyzed soon. See screenshots:
Opening the main malware executable up into IDA, I found a WinMain, and one of the first things it does is load up resource 1, copy it into a buffer, decrypt it, and then save it into memory decoded. The rest of the post will examine this process:
If the “1” resource is found, the resource is loaded in the below series of API calls:
LocalAlloc is similar to malloc in that it grabs some heap memory. The reason why SizeOfResource above is run is to know how much memory to allocate in this step:
Pictured above, the malware also goes ahead and copies the resource data into the newly allocated heap memory, as shown by the arrow. It’s important to remember that LocalAlloc has returned a handle to the fresh heap memory which is inside of eax, which is then pushed to memcpy. This step is quite easy to miss as its a plain-old memcpy which does the dirty work. If this is all successful, the malware then iterates through the buffer containing the encoded data from the resource and decodes it using the below function. Note that I added some comments to explain the details, but this is just a simple xor decode:
As we see, the function adds the counter variable value to the current byte, xors it with 0x79 or 121 decimal, then moves on to the next byte. After the decode, the decoded message is placed into a buffer and returned back a couple of subroutines.
Stay tuned for more analysis of this and other malware in upcoming posts. I’ve decided to take a multi-part approach to these rather than write one ginormous page.