Lab2 Malware Analysis Incident Response
Lab2 Malware Analysis Incident Response
In this lab you will practice with the analysis of malware from memory dumps with the
Volatility environment. Specifically, we are going to analyze with Volatility version 3 the
memory dump available at https://webdiis.unizar.es/~ricardo/sbc-2023/laboratories/
additional_files/wannacry.elf.tar.gz, which is a dump from a Windows 7 machine infected
with WannaCry (sample MD5 hash: 84c82835a5d21bbcf75a61706d8ab549).
1 Process identification
Once the memory dump is downloaded, the first thing is to identify the processes that appear
in it. To do this, we are going to use the PsList plugin:
python3 vol . py -f ~/ volcados / wannacry . elf windows . pslist . PsList
1 de 7
Distributed under CC BY-NC-SA 4.0 license. (© Ricardo J. Rodrı́guez)
https://creativecommons.org/licenses/by-nc-sa/4.0/
Malware Analysis for Incident Response
Malware Extraction and Analysis
3920 taskhsvc . exe 0 x1090000 0 x2fe000 taskhsvc . exe C :\ Path \ TaskData \ Tor \ taskhsvc . exe N/A
3920 taskhsvc . exe 0 x770c0000 0 x142000 ntdll . dll C :\ Windows \ SYSTEM32 \ ntdll . dll N / A Disabled
3920 taskhsvc . exe 0 x756b0000 0 xd5000 kernel32 . dll C :\ Windows \ system32 \ kernel32 . dll 2021 -07 -
3920 taskhsvc . exe 0 x75250000 0 x4b000 KERNELBASE . dll C :\ Windows \ system32 \ KERNELBASE . dll 2021 -07 -
3920 taskhsvc . exe 0 x62d20000 0 x82000 libevent -2 -0 -5. dll C :\ Path \ TaskData \ Tor \ libevent -2 -0 -5. dll
3920 taskhsvc . exe 0 x6b5d0000 0 x1c000 libssp -0. dll C :\ Path \ TaskData \ Tor \ libssp -0. dll 2021 -07 -
[... omitido ...]
3920 taskhsvc . exe 0 x772d0000 0 x35000 WS2_32 . dll C :\ Windows \ system32 \ WS2_32 . dll 2021 -07 -14 19:22
3920 taskhsvc . exe 0 x76f80000 0 x6000 NSI . dll C :\ Windows \ system32 \ NSI . dll 2021 -07 -14 19:22:05.0000
3920 taskhsvc . exe 0 x622c0000 0 x21c000 LIBEAY32 . dll C :\ Path \ TaskData \ Tor \ LIBEAY32 . dll 2021
3920 taskhsvc . exe 0 x62230000 0 x82000 SSLEAY32 . dll C :\ Users \ IEUser \ Desktop \ e d 0 1 e b f b c 9 e b 5 b b e a 5 4 5
[... omitido ...]
3920 taskhsvc . exe 0 x74b90000 0 x3c000 mswsock . dll C :\ Windows \ system32 \ mswsock . dll 2021 -07 -14 19:22
3920 taskhsvc . exe 0 x746e0000 0 x5000 wshtcpip . dll C :\ Windows \ System32 \ wshtcpip . dll 2021 -07 -
3920 taskhsvc . exe 0 x74750000 0 x1c000 iphlpapi . dll C :\ Windows \ system32 \ iphlpapi . dll 2021 -07 -
3920 taskhsvc . exe 0 x74740000 0 x7000 WINNSI . DLL C :\ Windows \ system32 \ WINNSI . DLL 2021 -07 -14 19:22
3920 taskhsvc . exe 0 x73310000 0 xd000 dhcpcsvc6 . DLL C :\ Windows \ system32 \ dhcpcsvc6 . DLL 2021 -07 -
3920 taskhsvc . exe 0 x746f0000 0 x12000 dhcpcsvc . DLL C :\ Windows \ system32 \ dhcpcsvc . DLL 2021 -07 -
As can be seen, this process effectively has certain libraries used by the Tor server loaded. Also,
these libraries are stored in a folder with the same name. Other libraries related to the manage-
ment of sockets and Windows Internet connectivity are also observed, such as ≪WS 2.32.dll≫,
≪mswsock.dll≫, or ≪dhcpcsvc.dll≫, among others.
If we look at the libraries related to the first process @WanaDecryptor (identifier 816), there
are libraries related to the Microsoft Visual 6.0 development environment, with networking and
socket creation issues, with handling of the Windows Registry (≪ADVAPI32.dll≫), with cryp-
tography (≪CRYPT32.dll≫), among others.
python3 vol . py -f ~/ volcados / wannacry . elf -r json windows . dlllist . DllList -- pid 816 | grep Path
Volatility 3 Framework 1.0.1
" Path ": " C :\\ Users \\ IEUser \\ Desktop \\ e d 0 1 e b f b c 9 e b 5 b b e a 5 4 5 a f 4 d 0 1 b f 5 f 1 0 7 1 6 6 1 8 4 0 4 8 0 4 3 9 c 6 e 5 b a b e 8 e 0 8 0 e 4 1 a
" Path ": " C :\\ Windows \\ SYSTEM32 \\ ntdll . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ kernel32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ KERNELBASE . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ MFC42 . DLL " ,
" Path ": " C :\\ Windows \\ system32 \\ msvcrt . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ USER32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ GDI32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ LPK . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ USP10 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ ole32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ RPCRT4 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ OLEAUT32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ ODBC32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ ADVAPI32 . dll " ,
" Path ": " C :\\ Windows \\ SYSTEM32 \\ sechost . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ SHELL32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ SHLWAPI . dll " ,
" Path ": " C :\\ Windows \\ WinSxS \\ x86_microsoft . windows . common - c o n t r o l s _ 6 5 9 5 b 6 4 1 4 4 c c f 1 d f _ 6 .0.7601.18837 _
" Path ": " C :\\ Windows \\ system32 \\ urlmon . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ XmlLite . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ WININET . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ iertutil . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ CRYPT32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ MSASN1 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ MSVCP60 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ WS2_32 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ NSI . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ IMM32 . DLL " ,
" Path ": " C :\\ Windows \\ system32 \\ MSCTF . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ odbcint . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ RICHED32 . DLL " ,
" Path ": " C :\\ Windows \\ system32 \\ RICHED20 . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ uxtheme . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ dwmapi . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ mswsock . dll " ,
" Path ": " C :\\ Windows \\ System32 \\ wshtcpip . dll " ,
" Path ": " C :\\ Windows \\ system32 \\ apphelp . dll " ,
reinfections is very common with malware, as well as a defense mechanism to prevent infections
from uncompromised machines.
3 Persistence identification
Remember that one of the phases of the malicious code is to perform persistence on infected
systems to ensure that they continue to carry out their malicious activity after a system reboot.
You can find a classification of all the possible persistence methods that a malware can exploit
in “Characteristics and Detectability of Windows Auto-Start Extensibility Points in Memory
Forensics” (https://doi.org/10.1016/j.diin.2019.01.026).
To locate the registry keys that are accessible in the memory dump, you can make use of the
PrintKey plugin, whose operation is similar to the Volatility 2 plugin of the same name:
python3 vol . py -f ~/ volcados / wannacry . elf windows . registry . printkey . PrintKey
Volatility 3 Framework 1.0.1
Progress : 100.00 PDB scanning finished
Last Write Time Hive Offset Type Key Name Data Volatile
3812 832 ed01ebfbc9eb5b 0 x858282a8 10 83 1 False 2021 -07 -14 19:21:30.000000 N / A pid .3812.0 x4
In the same way, if you want to extract the libraries associated with a certain process, you
have to use the DllList plugin with the parameter --dump:
1. Static analysis phase. This phase, also called dead code or cold code analysis phase,
includes the analysis of the binary file without executing it. That is, in this phase the
binary content (the bytes) of the file will be read. In this phase it will help to know in
depth the assembler of the architecture where the binary is executed (this is where the
reverse engineering skills that we saw in the previous section come in). This phase is
divided into three basic aspects:
• MD5/SHA1/SHA256 signature calculation. In this subphase, the signature of the
binary will be calculated using some cryptographic algorithm such as MD5, SHA-1,
or SHA-256. These algorithms allow, given an input, to calculate a number that
“exclusively” identifies the binary. Once the signature has been calculated, it can
be searched on the Internet in order to locate other analyzes of the malware sample
and thus facilitate the analysis work itself. A good tool on Windows for this task is
HashTab (http://implbits.com/products/hashtab/). On macOS or GNU/Linux
systems, you can use the native commands md5sum or sha1sum, to name a few.
• Strings within the file. This second subphase consists of locating all the text strings
that are contained within the binary. The text strings, as variables defined within the
original source code of the program and that it uses during its execution, are found
within the executable file. In fact, if the executable does not have any protection
mechanism (e.g., code obfuscation or encryption), these strings will be found in the
file completely visible. That is, if we viewed the executable file with a word processor,
the text strings would be clearly visible. The presence of certain strings is an indication
of the activity that the malicious sample will be carrying out. For example, if we see
an Internet IP address, or a web domain and parts of strings relating to an HTTP
POST or GET request, we can infer that the malicious sample is surely connecting to
that IP/web address via HTTP POST or GET requests. For this phase, you can use
a tool like strings (native tool on UNIX-based systems, and available for Windows
at https://docs.microsoft.com/en-us/sysinternals/downloads/strings).
• Import functions. Finally, the last subphase of the static analysis consists of analyz-
ing the Windows API functions that the executable file is using. An API function
is a function provided by the operating system that makes it easier for other pro-
grams to interact with it. That is, it allows the application developer to use system
resources such as files, network sockets, registry keys, create processes, etc. For ex-
ample, the presence of file-related functions (for example, FindFirstFileA) will lead
to the conclusion that the malware supposedly performs some action with files. To
learn more about the functions used by the binary, it is recommended that you con-
sult the MSDN website (https://msdn.microsoft.com/en-us/library/ms310241)
for a specific function. Specifically, the MSDN provides information about what a sys-
tem function does, what parameters it uses, and what it returns. On Windows, tools
like CFF Explorer (http://www.ntcore.com/exsuite.php) can be used to check the
import functions.
All these described steps correspond to a basic static analysis of the sample. A more
advanced analysis would use disassembly tools or other techniques based on flow control
graphs or symbolic execution, among others. In any case, one of the biggest limitations of
static analysis is that the code of the binary to be analyzed does not have to be obfuscated
or protected. Furthermore, a static analysis shows us all possible execution paths of
that program. That is, the state space of all these paths can be very large and difficult to
manage.
2. Dynamic analysis phase. This phase, also called live or hot code analysis phase, includes
the study of the program during its execution. Specifically, in this phase the interaction of
the malware sample with its environment is studied. This phase can be divided into two
sub-phases, depending on what is meant by environment:
• Interaction with the Operating System. When we understand by environment the
interaction made with the operating system, we must attend to three particular ex-
tremes: files (what files is the program creating, modifying, or deleting?, Registry keys
(what registry keys is the program creating, modifying, or deleting?), and processes
Figure 1: Analysis of the malicious sample extracted from the dump with Ghidra version 10.01.
(what processes is the program creating, modifying, or deleting?). If the malware sam-
ple is observed to be creating new files, it will be necessary to analyze what type of
files are created and in the case of executable files, carry out a new malware analysis
with them. In the case of Registry keys, it is necessary to check which registry keys
are affected (configuration changes, persistence, etc.).
• Interaction with the outside (Internet). Finally, we must look at the interaction that
the malware performs with the Internet. Specifically, it will be necessary to locate
if the malware sample makes any connection to the Internet (to which IP addresses
or Internet domains is it trying to connect?), and if it does make any connection,
it is necessary to look at what type of information is sending, how it receives data
and what type of information it receives. These servers to which you connect to send
information and possibly receive orders are called command and control servers (C&C
servers).
This dynamic analysis phase that we have just described will help us to answer (almost)
all the questions related to malware that were discussed at the beginning of this section.
More advanced dynamic analysis would require using a debugger to analyze at runtime
how CPU registers are evolving, the values returned by Windows functions called by the
malware, and so on.
Finally, it should be noted that, unlike the static analysis, in the dynamic analysis
only one of the possible execution paths is analyzed, which may also depend on the
current execution conditions.
Once extracted, the process can be taken to analysis tools such as disassemblers or debuggers
for analysis, as is the normal malware analysis process. As an example, Figure 1 shows the
analysis of the process dumped in the tool Ghidra. In particular, the part of the code related to
the creation of the mutex is shown.