Practical Malware Analysis (3)
1: What is the address of DllMain?

2: In the Imports window, navigate to gethostbyname. What address does the imported function resolve to?

3: How many functions call gethostbyname?

4: Focus on the call to gethostbyname at 0x10001757. Can you determine which DNS request will be triggered?

At the DNS call, a string is pushed onto the stack beforehand. Following that reference leads to the requested name.



This is the address to query. The push is preceded by add eax,0dh, so it points to pics.praticalmalwareanalysis.com.
5: How many local variables does IDA Pro identify in the subroutine at 0x10001656?

IDA identifies 23 local variables in this subroutine.
6: How many parameters does IDA Pro identify in the subroutine at 0x10001656?
It identifies one parameter: IpThreadParameter=dword ptr 4.
7: Use the Strings window to locate the string \cmd.exe /c in the disassembly. Where is it?

8: What happens in the region of code referencing \cmd.exe /c?

The first part of this region looks like it prepares a command-line operation.

The code starts a process, uses GetSystemDirectoryA to find the system directory, and executes cmd.exe or command.exe from that directory.
9: In the same region at 0x100101C8, dword_1008E5C4 appears to be a global variable that helps decide which path to take. How does the malware set it? (Hint: use cross-references to dword_1008E5C4.)

I have already renamed the item at this location in my IDA database.
The preceding condition uses the GetVersionExA API to inspect the Windows version.

Looking up this API shows that it checks for windows 2000: before Windows 2000, the command interpreter was command.exe, which explains the check above.
10: Among the hundreds of instructions in the subroutine at 0x1000FF58 are several string comparisons using memecmp. What happens if the comparison with robotwork succeeds (memcmp returns 0)?
First, I looked at the code before the comparisons:


This string is displayed on screen, preceded by code that displays the time. The last line is interesting: it mentions an encryption magic number and dword_1009E5D0. We will reverse it later; first examine memcmp as requested.

The value passed as s is a command received from the remote socket.

These memcmp calls look like the virtual machines often seen in CTFs. They check remote commands and use different functions to execute them.
I located the branch for the RobotWork command:

I followed the call and began reversing the function; its name has been changed in this screenshot.

It gets the Worktime value from HKEY_LOCAL_MACHIME\SOFTWARE\Microsoft\Windows\CurrentVersion and passes it to sub_100038EE.
Following the next call shows what happens to that value:

The function adds an offset to the worktime value and sends the result to the remote socket.

The earlier dword_1008E5D0 is related to encryption of the magic number; we will decipher it later.
11: What does the PSLIST export do?
I found PSLIST in IDA’s exports window:

Following it leads to the function body:

This is a function we encountered earlier. Its result indicates whether Windows is 32-bit and whether its version is later than Windows Server 2003.
A branch follows. Since the function call is not yet clear, follow the branch for a matching result, starting with sub_1000664C().

After following the code, I concluded that it gets the current process list, sends it to the remote socket, and writes it to a file named Xinstall.dll. It returns 0 on success and 1 on failure. Rename it getProcessList.
The other branch calls sub_10006518().

This function also gets the process list, but only writes Xinstall.dll; it does not send the list to the socket. Rename it getProcessListNoSend().
That completes the analysis of the PSLIST export.

First it gets the operating system version. If it is too old or too new, it returns false. For windows 2000-windows 8.1 x32, it enumerates processes and uses the process name passed as str to decide which one to send.
12: Use graph mode to draw cross-references to sub_10004E79. Which API might be called on entering this function? Based only on the APIs, what would you name it?

Graph mode would not open for me, but the cross-reference view provides the same information:

After renaming the functions, it is clear that this function gets the system language and sends it to the socket. Rename it sendLanguageInfo().
13: How many Windows APIs does DllMain call directly? How many are called at depth 2?

Since I could not open the graph, I used one from the solution:

14: At 0x10001358 there is a call to Sleep, an API taking a delay in milliseconds. Looking backward through the code, how long will the program sleep if this code executes?

I opened the pseudocode to trace the sleep duration:

The delay is 1000 × v14 milliseconds. To determine the duration, we need v14, which the code derives from a character using atoi.

The ASCII value of [ is 91; adding 13 gives a total sleep of 104 seconds.
15: At 0x10001701 there is a call to socket. What are its three arguments?

The three arguments are pushed onto the stack in reverse order. I looked up the function prototype to interpret them.
Official documentation:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-socket
1 |
|
af = 2 = AF_INET
type = 1 = SOCK_STREAM
protocol = 6 = IPPROTO_TCP
Thus, it creates a TCP stream connection.
16: Using the MSDN socket page and IDA Pro symbolic constants, can you make the arguments more meaningful? What are they after the changes?

Applying IDA’s Symbolic Constant names makes those arguments much easier to read:
17: Search for uses of the in instruction (opcode 0xED). This instruction and the magic string VMXh can detect VMware. Are they used here? Do cross-references to the function executing in provide further evidence of VMware detection?
Search for in with alt+t and find the vmxh magic value:


The cross-references show three places that call the VMware-detection function:

When the check finds VMware, the program writes a message to its log:

This confirms the VMware detection.
18: Jump to 0x1001D988. What do you find?

The bytes look like garbled text at first.
I wrote a small script to XOR the bytes and see what they contain:
1 | a = [0x2D,0x31,0x3A,0x3A,0x27,0x75,0x3C,0x26,0x75,0x21, |
The decoded result:

Extra
We still need to reverse and decipher the earlier magicNumberWaitiongForCrack.

The variable appears in sendtoSocket(), a function called in many places.
I inspected the variable’s cross-references:

I found the last function that assigns it and followed the call:

It is a random number: get the CPU cycle count, take the low five bits, add 1, and use the result as an offset.

Combined with the earlier function, this shows that when remote Enmagic is received, it displays this random number. Rename the variable randomMagicNumber.
When the program sends data, it adds this number as part of its encryption.


