Preface
This week we have discussed deobfuscating initial stagers and how to unpack their executable payloads. And what I’ve decided to do, to practice this week lesson is to find actual malware on any.run and unpack its entire initial stage.
Setting up goals:
- I’ll choose an infected document from any.run, then I’ll deobfuscate it and extract its payload
- I’ll take the payload and unpack it from memory, showcasing how to unmap a dumped PE
- I’ll attempt to practice the first lesson by finding identifying encryption schemes or known algorithms within the payload.
Required background:
- Knowledge in reversing VBA code
- Knowledge in reversing PowerShell code
- Knowledge in various analysis utilities (Process Hacker, PEBear, PEStudio, PEId)
- Knowledge in IDA Pro
- Knowledge in x64dbg
- Basic understanding of stack overflow exploits and how to debug shellcode ***
Choosing a Target:
I decide to go on any.run to find an interesting sample – I have experience in macro deobfuscation so I decide to look for a infected document hosting an exploit which delivers a payload.
I decide to filter MS Office files with an exploit tag, and quickly find a huge batch of files:
Its valuable to mention that CVE-2017-11882(you can read about it here) is the same exploit used in the Zero2Auto lesson and it seems as it’s the most used exploit when delivering malicious docs. I’ve also observed that the exploit is sometimes leveraged that attacks the Outlook app directly when I filtered for email message file types:
I have chosen the following sample:
https://app.any.run/tasks/fce8f628-52cf-4f5d-968c-ab59ddeaabda/ and the reason for that mainly is because the infection chain is long, contains a wsf script, a vbs script and finally an EXE payload thus it could give me a lot of room to practice my knowledge.
From an email lure to an exploit:
I decide to extract the excel document and inspect it(SHA-256 97CC9023C114013326A97E946B0CA71BB641952208B5BA04463F1DAF15E1A5B5).
Method 1 – Examining the document by opening it
The first method is rather, not very safe to say the least but you should be fine if you have macros disabled by default, so I open up the Excel document and I’m met with the following:
I’m definitely not going to enable macros but before I review the macros I decided to check out the rest of the sheets. Sheet number 2 has a very interesting object within it:
And if you double click it:
This is an equation editor object that was embedded within the document, as I’m running on a fairly new MS Office version and this exploit was long ago mitigated on new versions I would expect I’d run into problems in performing this exploit but I bet I can do some stuff with the shellcode itself if we find it. Let’s continue to Sheet3:
An observant person like myself (flex much danus?) noticed this two little square and if we double click them, we’ll see that they are actually objects embedded within this document
These can also be seen being launched in the any.run view:
What was interesting that if we decide to the view the locations of these embedded objects
They are located within the Temp folder, but I never downloaded them.
To be honest, at this point we can stop the analyzes and simply dump these objects but I would like to review the actual shellcode of the exploit itself just to analyze it. So, I decided to enter the macro editor, and would you like at what I’ve found:
Auto_Open is great news for us!
I’ve decided to remove the macro deobfuscation from the scope of this blog because it’s pretty straight forward, so I’ll summarize it. This first stage macro contains another macro within itself, it copies this macro inside C:/Programdata/asc.txt and then it runs the newly written macro.
The second script is odd to say the least, it includes a lot of documentation for some reason and a lot of nonsense comments and text. I found one valuable text though:
Jokes aside this new macro is extremely obfuscated to the point where I could not use Daniels method of manual deobfuscation, so I decided to look for any valuable info.
One of the functions had Http function references and direct calls to some variable called myURL. The final function which I renamed to **DownloadFile **contains these references to the myURL Variable. Alas tho, this concluded with more confusing VBS code that I could not debug, for two reasons – being that this xlsm file is completely broken and I cant save it which doesn’t allow me to edit and debug the code properly and this method is also extremely dangerous as I couldn’t edit the malicious macro I kept executing the malware each time I opened the excel file. I had two more tools in my arsenal, one was to extract the two VBS files I’ve located within the excel and this can be done by manually opening the excel or using OLETools and honestly it’s a lot more safer to use OLETools so I set off to do just that.
Method 2 – Using OLETools to examine the excel
We know that there are embedded objects with the excel because we saw them and we know they are automatically saved inside the Temp folder as we opened the excel even if Macros are disabled and indeed it was true I found the files in the temp folder but if we want to extract the files safely we should use OLETools for that. I decided to use OLEVba first on the macro itself to see if it can extract anything meaningful from the macro, we located
Thankfully OLEVba did a lot of the work for us! By detecting the location of the exe payload. I also noticed that there are 4 OLE objects embedded within the xlsm. As we recall we found the Equation Editor, xx, mm so let’s try extracting them.
Let’s use OLEDump to view the files embedded with in the script:
:
F3112BD51886FB705F33BEA0DDFA708AE6BABAB6F93162ABFDB931095EC6D116
Unpacked UPX SHA-256:
09A21333C61AA0DE5148E97AA238B8F8295E100891AA6A4F1F1108B27752FAD3
Unpacked Resource SHA-256:
c9b206aeded0795594a450b5717e65ba934c0dfab6005a8c696bd991ba96db15
Article Link: https://danusminimus.github.io/Zero2Auto-From-an-Email-To-a-Trojan/