CreateWindowExA
IsDebuggerPresent
InternetReadFile
HttpSendRequestA
InternetConnectA
GetCurrentProcess
TerminateProcess
etc
These functions indicate that program connects with remote host and downloads file.It also opens a new GUI window as presence of CreateWindowExA function indicates.
Now that we have some general idea of what malware does, let us now execute it in sandbox environment to validate our findings.
Ensure you have setup a secure private network that is not connected to Internet. This is essential to avoid malware spread across the entire network. Ensure you use Virtual Environment to detonate malware.
Dynamic Analysis
step 5) Detonation
Following are the pre-requisites for the dynamic analysis:
Virtual system to execute malware
Simulated network to ensure malware attempts to connect to C&C server
Network and File monitoring tools [As we did not find any registry modification functions in imported list, we need to monitor registry changes here.]
I am using Windows 10 OS where I have already installed Wireshark, Fakenet and Procmon to carry out detonation.
First start all tools before hand in the following order: Fakenet,Wireshark and then Procmom.
Then rename file from Unknown to Unknown.exe. Then double click on it to execute. Make sure all tools are listening for events before executing the file.
A new popup windows is displayed as shown below:
Unfortunately we do not see any activity at Fakenet window:
Let us look at events captured by Procmon. The Procmon by default captures all the system calls being executed by processes in the system. We need to filter these events to the calls made by process/malware we are analyzing only, to make analysis manageable.
Two system calls are of particular interest here:
Process Create
Apparently, as our static analysis rightly predicted, this malware has dropped second sample at location <User\Home\Directory\Roaming\> with name stage2.exe
It also executed this
stage2.exe using
Process Create system call.
We have so far been able to analyze the malware to the extent of predicting that Dropper will load additional malware and stage2 shall connect to remote host. But when we detonated the malware we did not see any network traffic.
Thus to answer why we need to dive much deeper now and use next step of reviewing disassembled code of malware.
6) Dis-assembled code review
While there are many dis-assembler in the wild to use, we will use most famous one: IDA Pro. Use can use it's community edition which is freely available.
First we shall review original malware sample Original.exe and then stage2.exe
When we open Unknown.exe in IDA we immediately notice that it uses very few functions:
This is expected from a Dropper program since its only job is to unload extra payload, execute it and then exit.
start function is where we shall begin our analysis.
It's a small function. All it does is makes a call to sub_401000 and then displays a message box we saw earlier.
Lets proceed to function sub_401000. A quick scroll through this function makes us evident that here resource payload is being written to file and being executed in new process.
locate and load resource
write it to file
execute the payload
At this point we dont need to analyse any further into this code. Its evident that main functionality of malware lies in stage2.exe
Let us open stage2.exe in IDA.
Again this sample also has very few functions.
start function of this sample is a little bit complex than previous one. We see use of loop and messaging functions here.
We can proceed to analyse function sub_401000 because that seems to be the only non library function being called from start.
This function is tasked with connecting with remote host and downloading a file to buffer. This can be seen from following images:
internet handler being created
make http request through handle
loop to read incoming stream into buffer
Here we can validate our findings by quickly detonating stage2.exe with fakenet running to see malware attempting to make connection to remote domain.
The content of file is loaded into buffer referred to by EDI register which holds pointer to variable var_104 as is evident from image below.
here effective address of var_104 is loaded in EDI before call to function
Code construct after this call is validating the loaded content to ensure that is what it is looking for. As we are not actually going to let malware connect to remote host, we need to pass this validation barrier using debugger.
7) Debugging the code
We need to pass validation construct before we get any further. Here we take help of X32DBG
Open x32dbg and load our binary by drag and drop feature.
We now need to set break point at desired address so that debugger can halt execution there. For this we need to know address of instruction in the file. To know this, first enable line prefixes in IDA by Options > General > Line prefixes.
Once enabled, we see addresses as follows:
Note the address of call instruction 401176. This is where we shall set breakpoint.
Use command bp in x32dbg to set breakpoint as follows:
bp <addr> ie bp 401176
we can see list of bp set
Now begin execution again by pressing F9. X32dbg will execute program till breakpoint is hit. Now we need to step into the function so press F7.
Once inside, we need to set breakpoint at point where httprequest is made. So set breakpoint accordingly. Also start Fakenet to ensure http request is catered to.
We can see the once httpSendRequest function is executed, we receive corresponding event in fakenet:
As can be seen, fakenet delivers configured IP address to DNS query just imitate DNS server response. Malware then proceeded with http request GET.
Now click on Execute till Return so that debugger proceeds with execution till execution returns to start function.
Immediately following function call, we have complex code construct we saw earlier. This is where we need to make changes.
Following are the 4 cmp instructions in the debugger. We need to make changes in the jump instructions highlighted. These instruction make jump based on Zero Flag[ZF].
The jump is taken only if ZF flag is set that is ZF=1. This flag is set based on result of previous instruction. Previous instruction is cmp, each of which compares indexed buffer value with predefined value. If found equal flag is set to 1.
But as we have not read any stream data into buffer, we need to manually alter these ZF flags. This can be done by clicking on flag and hitting space bar which alters its value. So if value is 0 it will be made 1. Following image shows the code:
Once all jump instructions have been dealt with, we can again hit F9 which resumes execution.
We can proceed till code where call to CreateWindow is made. Once call is completed a window is displayed now as shown below:
Based on the code following this function call, it seems some sort of messages are displayed on this window.
Conclusion:
So we have now completed our analysis of a malware. We carried out both Static and Dynamic analysis. Though it was a long post it is necessary to lay down step by step procedure. All of these procedures may not be necessary for malware you are analyzing. None the less it is useful to know broad framework of malware analysis.
This post will act a base on which we shall proceed with analysis of other malware samples. We need not outline all the details henceforth. If you ever have doubt about certain step taken, you can always come back and check it here.
Teel next time, Cheers!
No comments:
Post a Comment