Hunting .NET Malware (Lab 2)
Hunting .NET Malware (Lab 2)
Scenario
According to https://www.fireeye.com/blog/threat-research/2018/06/bring-your-own-land-novel-red-teaming-technique.html, one of
most significant recent developments in sophisticated offensive operations is the use of "Living off the Land" (LotL) techniques by
attackers. These techniques leverage legitimate tools present on the system, such as the PowerShell scripting language, in order to
execute attacks. In response, defenders have developed detections for the malicious use of legitimate applications. These detections
include suspicious parent/child process relationships, suspicious process command line arguments, and even deobfuscation of malicious
PowerShell scripts through the use of Script Block Logging.
For this reason, attackers came up with an alternative to LotL techniques. Attacker's (and penetration testers) are now executing .NET
assemblies entirely within memory. By developing custom C#-based assemblies, attackers no longer need to rely on the tools present on
the target system; they can instead write and deliver their own tools, a technique fireeye calls Bring Your Own Land (BYOL).
In this lab we will emulate such behavior and show you how you can proactively hook all .NET processes of a system and also perform
an in-line hook of the LoadImage function (that is used under the hood to load the provided assembly.)
Goals
The learning objective of this lab is increase familiarity with .NET attacks by doing a hands-on analysis.
Recommended tools
https://github.com/endgameinc/ClrGuard
Tasks
Task 1. Get familiar with ClrGuard
ClrGuard comes with some testing .bat files. One is benign and one is malicious. Try them out.
First, execute ClrGuard.exe and then run fp.bat. Notice what ClrGuard mentions.
PowerShell has the ability to load .NET assemblies from a specified location or even from a Byte Array (like attackers prefer). See an
example below.
https://powershell.one/tricks/assemblies/load-from-memory
The above capability calls the native LoadImage() function under the hood to load the specified assembly, essentially emulating the
execute-assembly command of Cobalt Strike.
Hint: If you can't create your own PowerShell code, a LoadNETAssembly.ps1 can be found in the Downloads directory of the machine,
that performs what we have described above.
SOLUTIONS
Below, you can find solutions for each task. Remember though, that you can follow your own strategy, which may be different from the
one explained in the following lab.
The module being loaded is whitelisted by ClrGuard. Assembly loading can also be performed for legitimate purposes!
Note: If you receive the above error, Please re-run all the commands again.
The specific .net assembly loading was blocked by ClrGuard. Notice that there is no "whitelisted" string in the second entry.
Click the PowerShell icon that is pinned on the taskbar and execute:
Note that there are execute-assembly variations included in multiple attacking frameworks. The detection method covered
doesn't work only against Cobalt Strike.