Practical Malware Analysis - Lab 12

Lab 12-1

Analyze the malware found in the file Lab12-01.exe and Lab12-01.dll. Make sure that these files are in the same directory when performing the analysis.

Q1: What happens when you run the malware executable?

On procmon we don’t get much but noticed a lot of file mapping into memory maybe it will modify some process in memory

../_images/1q22.png

Q2: What process is being injected?

lets pull the exe into ida, in imports we see CreateRemoteThread and the required functions for it, we could say it uses dll injection into remote thread

../_images/1q32.png

Look at the functions list we find only one function then the main function in sub_401000 we see all its doing is converting PID to a process name then comparing it to explorer.exe to return 1 so we can say its injecting explorer (Almost same PrintProcessNameAndID function in (MSDN)[https://learn.microsoft.com/en-us/windows/win32/psapi/enumerating-all-processes] )

../_images/1q51.png

Q3: How can you make the malware stop the pop-ups?

By restarting explorer.exe like cmd command wmic process where name="explorer.exe" call terminate

Q4: How does this malware operate?

lets go over the exe, in first part its importing psapi.dll functions:EnumProcessModules, EnumProcesses,GetModuleBaseNameA (they do as their name suggests) then it sets Buffer to Lab12-01.dll location

../_images/1q61.png

Second part enumerating-all-processes then saving list of process identifiers in dwprocessid, and saving number of processes in v7 (v14 >>>2->v14 / 2^2 where 4 bytes is size of DWORD ,its calculating all bytes returns over size of single process) then it is passing all process identifiers (pid) to 40100 function we said above to check if there is explorer, when found it gets a handle to explorer

../_images/1q71.png

Now the overhead is done, the main part here, first it allocates space in explorer process memory then writing Lab12-01.dll to it then calling CreateRemoteThread with all prepared parameters (handle to loadlibrary +handle to explorer +the base address where Lab12-01.dll where written to ,to load it )

../_images/1q81.png

in the dll simple program in a loop to create a thread with open messagebox

../_images/1q9.png ../_images/1q10.png

Lab 12-2

Analyze the malware found in the file Lab12-02.exe.

Q1: What is the purpose of this program?

In the imports we see it is importing to write something to another process memory

../_images/2q22.png

then we see it loading resource maybe it is hiding something in its resources

../_images/2q110.png

at main we see it first passes ApplicationName and string containing \\svchost.exe and calls 40149D Then pass a handle to the calling (exe) process and calls 40132C

../_images/2q31.png
we will first check 40149D routine
Looks like it just concatenates the systemdirectory to \svchost output to -> ApplicationName
../_images/2q41.png
going to the second call 40132C

It loads something from resource with name LOCALIZATION and type UNICODE then allocates place in memory copies the resource to it and checks if first character or second character doesnt equal to MZ (which is start of exe file) then calls 401000 routine maybe it will decode what is in the resource

Yup it xors the resource file with 65

../_images/2q61.png

then all the routine returns pointer to the start of allocated memory which contains the decoded resource

../_images/2q71.png

It then calls 4010EA with parameters decoded resource (lpBuffer) and svchost (lpApplicationName) | after the call it zeroes the ApplicationName and virtualfrees the decoded resource

../_images/2q81.png

into 4010EA, it does some checks then starts process with name of module to be executed svchost.exe

../_images/2q91.png

notice it created the process in suspended state with creationflag set to 0x4 means it used to load a process into memory and suspend it at the entrypoint.

../_images/9q9.png

with similar overhead discussed in Lab12-01 to allocate space for the decoded resource and using ZwUnmapViewOfSection to release all memory pointed to by a section passed as a parameter (the svchost)

../_images/2q101.png

then Once the process is created, the next step is to replace the victim process’s memory with the malicious executable and uses WriteProcessMemory to write each of the malware sections to the victim process space

../_images/2q111.png

In the final step, the malware restores the victim process environment so that the malicious code can run by calling SetThreadContext to set the entry point to point to the malicious code. Finally, ResumeThread is called to initiate the malware, which has now replaced the victim process.

../_images/2q121.png

We can gather now it is process replacement (hollowing) malware

the docoded malware is Lab12-03.exe in next section

Q2: How does the launcher program hide execution?

answered above by process hollowing

Q3: Where is the malicious payload stored?

answered above in .rsrc

Q4: How is the malicious payload protected?

answered above by encoding routine

Q5: How are strings protected?

answered above by encoding routine

Lab 12-3

Analyze the malware extracted during the analysis of Lab 12-2, or use the file Lab12-03.exe.

Q1: What is the purpose of this malicious payload?

it creates a hidden console as cmdshow set to 0

../_images/3q19.png

It creates a hook (so this maybe dll injection by hooking) with threadid set to 0 (meaning all threads are hooked) and idhook set to 13 and procedure at fn and hmod set to the calling process (as getmodulehandle had parameter 0)

../_images/3q21.png

idhook 13 in MSDN

For WH_KEYBOARD_LL , the events are sent directly to the process that installed the hook, so the hook will be running in the context of the process that created it.

../_images/3q41.png

In fn the hook procedure, it calls a function then calls CallNextHookExA which ensures that the next hook procedure in the call chain gets the message and that the system continues to run properly. (also so victim doesnt get no keyboard input is registered)

../_images/3q31.png

in 4010C7 routine it creates file practicalmalwareanalysis.log

../_images/3q51.png

Then logs the keys pressed into the file while keeping in mind which window and special keys like capslock

../_images/3q61.png ../_images/3q7.png

Q2: How does the malicious payload inject itself?

answered above by dll injection with SetWindowsHookExA

Q3: What filesystem residue does this program create?

practicalmalwareanalysis.log

../_images/3q111.png

Lab 12-4

Analyze the malware found in the file Lab12-04.exe.

Q1: What does the code at 0x401000 accomplish?

It get parameter PID, it opens process associated with that pid then calls two functions (global variable ) 40312C and 403128

../_images/4q1.png

the two functions global variables doesnt contain anything going to their cross refrences where they are set likely and they got resolved automatically by ida So it searches the modules for specified PID and gets the modules name So it searches for winlogon.exe within the pid process if found return 1

../_images/4q2.png

Q2: Which process has code injected?

Going to cross refrences for 401000. We see it is inside a loop which checks all PIDs so lets follow the branch where winlogon is found

../_images/4q4.png ../_images/4q3.png

it calls 401174 with pid passed, we see it open the process associated with the pid then call the CreateRemoteThread to inject code there

../_images/4q5.png

winlogon is process being injected

Q3: What DLL is loaded using LoadLibraryA?

sfc_os.dll https://www.file.net/process/sfc_os.dll.html

Q4: What is the fourth argument passed to the CreateRemoteThread call?

address to sfc_os.dll

../_images/4q7.png

notice it gets the second function from sfc_os.dll we see example here https://ntcore.com/files/wfp.htm that used it for disabling Windows File Protection

../_images/4q6.png

Q5: What malware is dropped by the main executable?

Following the flow of main after the above, it create a backup of \system32\wupdmgr.exe then calls another routine

../_images/5q1.png

into 4011FC, it loads exe file from .rsrc named #101 type BIN

../_images/5q2.png

and writes it into \system32\wupdmgr.exe

../_images/5q3.png

then executes and hides it (with cmdshow set 0)

../_images/5q4.png

Q6: What is the purpose of this and the dropped malware?

replacing legit update manager with malicious one it executes first the legit one then the malicious one

../_images/5q5.png ../_images/5q6.png