Hunting For Malware
Hunting For Malware
com
www.virusbulletin.com
HUNTING FOR MALWARE WITH COMMAND LINE LOGGING... SVAJCER
ABSTRACT
Over the years, many detection techniques have been developed, ranging from simple pattern matching to behavioural
detection and machine learning. Unfortunately, none of these methods can guarantee users to be fully protected from all
types of attacks.
This fact is now accepted and many companies, especially medium to large corporations, have established their own
in-house security teams specifically tasked with hunting attacks that may have slipped through the cracks of their protection
layers.
Security operations centres (SOCs) are tasked with collecting, aggregating and analysing large quantities of security data
collected from the most valuable organizational assets as well as external threat intelligence data that is used to enrich the
context and allow team members to identify incidents faster.
When we log Windows events, there are literally hundreds of event types that generate a huge amount of data that can only
be analysed using a data analytic platform. Considering the amount of data, which is too large to be handled manually by
humans, it is crucial for defenders to know what they should look for in order to reduce the set of data to the point where it
can be handled relatively easily by blue team members.
One of the data types that can be collected while hunting for new threats is the command line parameters used to launch
processes. Logging command lines of executed processes can be a useful second line in detection of unknown malicious
attacks as well as in the determination of the root cause of infections during the incident response remediation phase.
In this paper, we focus on analysing command lines and their respective parameters for detecting malware attacks as well
as manual attacks conducted remotely by human attackers. We also look at malicious usage of operating system tools and
command interpreters. We consider process trees as an asset helpful in hunting for all elements of an attack that
successfully breached defences.
Figure 1: Configuration of the group policy to enable logging of process creation events.
In addition to that, if we want to log command lines as well as the process events, we need to change the process creation
event template to include it. The template is changed using the policy path Administrative Templates\System\
Audit Process Creation.
Figure 3: Event ID 4688 showing the data including the process command line.
For more advanced organizations, it is advisable to enrich this information with additional events which can be collected by
tools such as Sysinternals sysmon [1] and a configuration file specifically suited for malware [2] or a commercial EDR
platform.
LoLBins
A LoLBin is any binary supplied by the operating system that is normally used for legitimate purposes but which can also
be abused by malicious actors. Several default system binaries have unexpected side effects, which may allow attackers to
hide their activities post-exploitation. New LoLBins are regularly discovered and readers are advised to actively follow
sites such as the LOLBAS Project [3].
The concept of LoLBins is not new and isn’t specific to Windows. Almost all conventional operating systems, starting from
the early DOS versions and Unix systems, contained executables that attackers could exploit.
Overall, attackers can use LoLBins to:
Hunting for LoLBins abuse in command lines with big data analytics
It is easy to spot malicious PowerShell invocation when we are dealing with tens of computers and hundreds of events.
However, this task becomes increasingly difficult when we are dealing with thousands, let alone millions of computers
which are typically protected by major security vendors. For the sheer size of the data we need a better tool that will allow
us to detect malicious activity over the whole data set.
For this, we used the Hadoop file system and a large cluster of servers to store the telemetry in a structured Parquet format
together with Apache Spark as an analytical framework that allowed us to create and run Spark applications on a regular
basis.
By running analytic jobs, we build a set of approximate rules for detection and provide general guidelines for the defenders
on what to look for when triaging their own logs. For every rule to reduce the amount of log data to investigate we discuss
cases of recent malware discovered by applying them.
Apache Spark [8] abstracts the complexities of running map-reduce jobs into a spreadsheet or database table-like
interface known as Spark Dataframe [9]. Furthermore, the user can create a logical view over a dataframe representation
of the structured data stored in the big data store and use familiar query language such as SQL to define and run Spark
jobs.
In addition to standard SQL functions and operators, Spark SQL allows us to define our user-defined functions (UDFs),
which can be used in a Spark application in the same way as any predefined Spark SQL functions.
The following is an example of an application which allows the analyst to find traces of China Chopper activity. It can
easily scale to billions of records and if the Spark cluster is properly configured the application will complete its task in
minutes. The application assumes that the command line data is stored in the Hadoop file system using the structured
Parquet file format [10]:
def matchsigs(cmdline):
sigs=['&netstat -an | find','&whoami&echo', '&ipconfig /all&echo']
fullcmdline=string.join(cmdline)
for word in sigs:
if fullcmdline.lower().find(word) != -1:
return True
return False
spark = SparkSession.builder.appName('A_Job').getOrCreate()
p = spark.read.parquet("/aggregatedeventlogshadoopfspath/")
p.registerTempTable("cmdlines")
A researcher can create a set of Spark applications that can be run on a daily basis or conduct retro-hunts if the data is
retained for longer periods. The spark-submit script in Spark’s bin directory is used to launch applications on a cluster.
For example:
spark-submit --queue=myownsparkqueue ./findchinachopper.py
Abusing MSBuild
Over time, attackers have also realized the malicious potential of PowerShell, widening the number of executables used as
LoLBins. Msbuild.exe and C# compiler csc.exe are some of the most frequently used by red teams. Both are frequently
used to download, build and load malicious code that is built for that particular system and does not appear on any
executable block list.
MSBuild is part of the Microsoft Build Engine, a software build system that builds applications as specified in its XML
input file. The input file is usually created with Microsoft Visual Studio [11]. However, Visual Studio is not required when
building applications, as some .NET framework and other compilers that are required for compilation are already present
on the system.
The attackers take advantage of MSBuild characteristics that allow them to include malicious source code within the
MSBuild configuration or project file.
We collected malicious MSBuild project configuration files and documented their structure, observed infection vectors and
final payloads.
One of the characteristics of MSBuild input configuration files is that the developer can include a special XML tag that
specifies an inline task [12], containing source code that will be compiled and loaded by MSBuild in memory.
• mshta.exe
• certutil.exe
• bitsadmin.exe
• regsvr32.exe
• powershell.exe
Our relaxed definition of suspicious process invocation means that it will also have a significant false positive rate and will
require significant manual intervention to analyse the data. For example, for a PowerShell invocation with a URL in its
command line, we estimated that only 7 per cent of the initially chosen calls should be checked in depth and are likely to be
malicious.
We obtained the percentage of suspicious calls by dividing the number of detected suspicious calls with the overall number
of calls. Overall, our worst-case scenario shows that at least 99.8 per cent of all LoLBin invocations are not worth further
investigation.
Overall, when hunting for malicious command lines it is important to consider the following:
• PowerShell and other scripting engines command line arguments
- Decode Base64-encoded commands given as argument in PowerShell
- Detect obfuscation applied by modules such as Invoke-Obfuscation [13]
- Invoke-Expression (iex) cmdlet usage
• URLs supplied in the command line, mshta.exe, regsvr32.exe
• Unusual execution paths of files with default Windows process names
• Misspelled names similar to default executables
• Unsigned executables launched using default Windows program names.
z1 - cmd
The tell sign of China Chopper infection is the presence of the string "[S]&cd&echo [E]" at the end of the command
line, which will be visible in the event log. When hunting for specific malware families using the command line it is
important to thoroughly analyse all known IOCs and identify unique patterns which will allow us to identify the activity in
the log without causing a high false positive rate.
Process trees
A process tree is simply a graph where the nodes of the graph are processes and edges describe relationships between the
nodes and can be created, terminated or written_to (for process injection). Nodes can contain meta-data that helps with
establishing the context, such as command lines, contacted IP addresses, contacted URLs, etc.
Process trees can be stored in a graph database which can then easily be queried using a query language.
Figure 8: A simple schema with entities and relations for storing process trees.
Once we implement such a representation of trees, we are able to query and traverse trees from any point we discover while
hunting for new threats using command lines as input.
The discovery of Prometei was prompted by a single discovered PowerShell command line, which was launched by an
svchost.exe process residing in a non standard path (C:\Windows\ vs C:\Windows\System32). Traversing the svchost.exe
process tree led to discovery of the path C:\Windows\Dell, which contains the rest of the Prometei modules.
After traversing the full process tree forward, we were able to find other modules and build a clear picture of the attack,
which used AZORult information stealer, Remcos remote access tool, DarkVNC VNC client, cryptocurrency clipboard
stealer and XmrigCC cryptominer for good measure.
CONCLUSION
Any organization that takes security seriously should consider adding hunting as one of the fundamental activities to fight
threats. None of the existing methods of threat protection are perfect and the organizations should adopt an attitude that
assumes the existence of a breach.
For hunting and as an additional line of defence, command lines collected in a centralized manner from logs or product
telemetry are a valuable asset for both corporations and security vendors. When it comes to large corporations and security
vendors, big data analytics frameworks such as Apache Spark are required to address the large volume of log and telemetry
data influx and processing.
Process trees are an essential addition to assist with analysing command lines. They help with generating additional context
information and discovering other attack components.
The main task faced by hunters is to extract useful signals consisting of real indicators of compromise from noise
consisting of legitimate events. For that, many rules can be defined, some global and some specifically valid only for a
single organization. This has paper provided some considerations and hopes to act as a starting point for conducting threat
hunts with command lines and process trees.
REFERENCES
[1] Russinovich, M.; Garnier, T. Sysmon v11.10. https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon.
[2] sysmon-config | A Sysmon configuration file for everybody to fork. https://github.com/SwiftOnSecurity/sysmon-
config.
[3] Living Off The Land Binaries and Scripts (and also Libraries). https://lolbas-project.github.io/.
[4] Application Control for Windows. https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-
defender-application-control/windows-defender-application-control.
[5] Villarreal, R. PowerShell ExecutionPolicy Bypass. January 2019. https://bestestredteam.com/2019/01/27/
powershell-execution-policy-bypass/.
[6] Chocolatey. https://chocolatey.org/.
[7] https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/.
[8] Apache Spark. https://spark.apache.org/.
[9] Spark SQL, DataFrames and Datasets Guide. https://spark.apache.org/docs/latest/sql-programming-guide.html.
[10] Parquet. https://parquet.apache.org/.
[11] Microsoft Visual Studio. https://visualstudio.microsoft.com/.
IOCS
China Chopper
9065755708be18d538ae1698b98201a63f735e3d8a597419588a16b0a72c249a
c5bbb7644aeaadc69920de9a31042920add12690d3a0a38af15c8c76a90605ef
b84cdf5f8a4ce4492dd743cb473b1efe938e453e43cdd4b4a9c1c15878451d07
58b2590a5c5a7bf19f6f6a3baa6b9a05579be1ece224fccd2bfa61224a1d6abc
Prometei
4ec815b28fe30f61a282c1943885fa81c6e0e98413f5e7f3f89ec6810f3b62a3 - SearchIndexer.exe
a02b532cc9dc257009d7f49382746d9d0bce331a665f4a4c12ae6fc2917df745 - miwalk.exe
a303bc8d4011183780344329445bc6dfbb8417f534f304c956e4f86468d620d5 - nvstub.exe
0970037be8f90c3b2b718858a032e77916969113823895e268c7693dddba1181 - nvsync2.exe
dc2fee73b41d488a1cccd905ecc9030e66ff7c7e5dcf60fc580406c6f8090854 - nvsync4.exe
382c3e80eadd7ca7b224ebe1fe656555fb15227face38fbea40ae4a9515ecb80 - ps.exe
54967e106bb2acfd5b4e69fc385c1c20d5af3bdc79b629a9e3ddb3a2375f0bc1 - rdpcIip.exe
b65aef379e3173ca32b83fd0c54483c2090966910fdda3145af97b5dbff85427 - smcard.exe
0dd1d869b3c7ce4af03ce4db6172b84d66c3779b48493d7e504de9d350195c5b - socks.exe
559d65f11e9143dfb093cabc6a1430438643922035765a445276abd80c15ce4b - svchost.exe
f09679bae1388033b17196f92430678e7b15816648f380bb4de3dd25009011b7 - tasklist.exe
f6eddbabc1d6b05d2bc27077bcb55ff640c5cf8b09a18fc51ed160a851f8be58 - zsvc.exe
AZORULT
SHA256
PE Payloads
bf2f3f1db2724b10e4a561dec10f423d99700fec61acf0adcbb70e23e4908535 - Remcos payload
42525551155fd6f242a62e3202fa3ce8f514a0f9dbe93dff68dcd46c99eaab06 - AZORult payload
2014c4ca543f1cc946f3b72e8b953f6e99fbd3660edb4b66e2658b8428c0866d - 64-bit XMRigCC
bde46cf05034ef3ef392fd36023dff8f1081cfca6f427f6c4894777c090dad81 - DarkVNC main
1c08cf3dcf465a4a90850cd256d29d681c7f618ff7ec94d1d43529ee679f62f3 - DarkVNC 64 bit DLL
a02d761cbc0304d1487386f5662a675df3cc6c3ed199e8ed36f738e9843ccc1b - RunPE loader for AZORult, Remcos and
DarkVNC
2f1668cce3c8778850e2528496a0cc473edc3f060a1a79b2fe6a9404a5689eea - Clipboard cryptocurrency stealer unpacked
9e3a6584c77b67e03965f2ae242009a4c69607ea7b472bec2cba9e6ba9e41352 - 32 bit XMRigCC
29695ca6f5a79a99e5d1159de7c4eb572eb7b442148c98c9b24bdfdbeb89ffc0 - 32 DarkVNC dll
aca587dc233dd67f5f265bfda00aec2d4196fde236edfe52ad2e0969932564ed - Clipboard cryptocurrency stealer
Droppers
598c61da8e0932b910ce686a4ab2fae83fa3f1b2a4292accad33ca91aa9bd256 - Main executable loader
d88ed1679d3741af98e5d2a868e2dcb1fa6fbd7b56b2d479cfa8a33d8c4d8e0b - ISO image distributed in a ZIP file
PowerShell scripts
2548072a77742e2d5b5ee1d6e9e1ff9d67e02e4c96350e05a68e31213193b35a
14e956f0d9a91c916cf4ea8d1d581b812c54ac95709a49e2368bd22e1f0a32ca - XMRigCC loader
cea286c1b346be680abbbabd35273a719d59d5ff8d09a6ef92ecf75689b356c4 - Deobfuscated PowerShell downloader
35b95496b243541d5ad3667f4aabe2ed00066ba8b69b82f10dd1186872ce4be2 - Cleanup script
ef9fc8a7be0075eb9372a2564273b6c1fffdb4b64f261b90fefea1d65f79b34e - Part of XMRigCC support
3dd5fbf31c8489ab02cf3c06a16bca7d4f3e6bbc7c8b30514b5c82b0b7970409 - Main PowerShell loader variant
q5fdc4103c9c73f37b65ac3baa3cceae273899f4e319ded826178a9345f6f4a00 - Main PowerShell loader variant
URLS
hxxp://195[.]123[.]234[.]33/win/checking[.]hta
hxxp://195[.]123[.]234[.]33/win/checking[.]ps1
hxxp://195[.]123[.]234[.]33/win/del[.]ps1
hxxp://195[.]123[.]234[.]33/win/update[.]hta
hxxp://answerstedhctbek[.]onion
hxxp://asq[.]r77vh0[.]pw/win/checking[.]hta
hxxp://jthnx5wyvjvzsxtu[.]onion[.]pet
hxxp://qlqd5zqefmkcr34a[.]onion[.]pet/win/checking[.]hta
hxxps://answerstedhctbek[.]onion
hxxps://answerstedhctbek[.]onion[.]pet
hxxps://asq[.]d6shiiwz[.]pw/win/checking[.]ps1
hxxps://asq[.]d6shiiwz[.]pw/win/hssl/d6[.]hta
hxxps://asq[.]r77vh0[.]pw/win/checking[.]ps1
hxxps://asq[.]r77vh0[.]pw/win/hssl/r7[.]hta
hxxps://darkfailllnkf4vf[.]onion[.]pet
hxxps://dreadditevelidot[.]onion[.]pet
hxxps://fh[.]fhcwk4q[.]xyz/win/checking[.]ps1
hxxps://fh[.]fhcwk4q[.]xyz/win/hssl/fh[.]hta
hxxps://qlqd5zqefmkcr34a[.]onion[.]pet/win/checking[.]hta
hxxps://runionv62ul3roit[.]onion[.]pet
hxxps://rutorc6mqdinc4cz[.]onion[.]pet
hxxps://thehub7xbw4dc5r2[.]onion[.]pet
hxxps://torgatedga35slsu[.]onion
hxxps://torgatedga35slsu[.]onion[.]pet
hxxps://torrentzwealmisr[.]onion[.]pet
hxxps://uj3wazyk5u4hnvtk[.]onion[.]pet
hxxps://vkphotofqgmmu63j[.]onion[.]pet
hxxps://xmh57jrzrnw6insl[.]onion[.]pet
hxxps://zqktlwiuavvvqqt4ybvgvi7tyo4hjl5xgfuvpdf6otjiycgwqbym2qad[.]onion[.]pet
hxxps://zzz[.]onion[.]pet
hxxp://memedarka[.]xyz/ynvs2/index.php
DOMAINS
dfgdgertdvdf[.]online - DarkVNC and Remcos C2
dfgdgertdvdf[.]xyz - Remcos C2
memedarka[.]xyz - AZORult C2