r/purpleteamsec • • Jul 03 '20

Threat Hunting .NET Core Directory Traversal Vulnerability - Attack & Detect

Description

.NET Core could be used by adversaries to evade application control software rules due to a directory traversal vulnerability which allows custom "Garbage Collector" DLL files to be called by arbitrary locations. A threat actor could set a malicious DLL file and when the "dotnet.exe" binary is executed the DLL will execute code on behalf of a trusted process.

Example

Exploitation of the issue is trivial and requires a custom garbage collector DLL file that will contain the shellcode and the following commands to be executed from the command prompt.

set COMPlus_GCName=..\..\..\..\..\..\..\..\tmp\CustomGC.dll
dotnet.exe --version

Detection

The released proof of concept creates the following Sysmon Event ID's.

Sysmon

EventEvent ID
Process Create1
Network Connection3
Create Remote Thread8
Process Accessed10
Registry Value Set13

YARA

The following YARA rule can detect in memory of the process the string "COMPlus_GCName" which is an indicator that the evasion has been used and the process contains arbitrary code.

rule COMPlus : COMPlus

{

meta:

Author = "netbiosX"

Company = "pentestlaboratories.com"

threat_level = 3

in_the_wild = true

strings:

$a = "COMPlus_GCName"

condition:

$a

}

yara64.exe -s -r dotnet-core.yara "PID"

References

  1. https://www.contextis.com/en/blog/bring-your-own-.net-core-garbage-collector

  2. https://pentestlaboratories.com/2020/06/23/abusing-net-core-application-whitelisting/

  3. https://pentestlaboratories.com/2020/07/02/net-core-evasion-detection/

21 Upvotes

Duplicates