SlideShare a Scribd company logo
1 of 71
Download to read offline
1
.NET MALWARE THREATS
BHACK CONFERENCE 2019
BHACK CONFERENCE 2019
by Alexandre Borges
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
2
 Security Researcher
 Speaker at DEF CON USA 2019
 Speaker at DEF CON USA 2018
 Speaker at DEF CON CHINA 2019
 Speaker at NO HAT 2019 (Italy)
 Speaker at HITB 2019 (Amsterdam)
 Speaker at CONFidence 2019 (Poland)
 Speaker at DevOpsDays BH 2019
 Speaker at BSIDES
2019/2018/2017/2016
 Speaker at H2HC 2016/2015
 Speaker at BHACK 2018
 Researcher on Android/iOS Reversing,
Rootkits and Digital Forensics.
 Referee on Digital Investigation: The
International Journal of Digital
Forensics & Incident Response
Agenda:
 Introduction
.NET Details
Analysis
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
3
 Last lectures in conferences:
 DEVOPSDAYS BH 2019 (Belo Horizonte/Brazil):
 slides: http://www.blackstormsecurity.com/docs/DEVOPSDAYS_BH_2019.pdf
 NO HAT Conference 2019 (Bergamo/Italy)
 slides: http://www.blackstormsecurity.com/docs/NO_HAT_2019.pdf
 DEF CON USA 2019 (Las Vegas / USA):
 slides: http://www.blackstormsecurity.com/docs/ALEXANDREBORGES_DEFCON_2019.pdf
 CONFidence Conference 2019 (Krakow / Poland):
 slides: http://www.blackstormsecurity.com/CONFIDENCE_2019_ALEXANDRE.pdf
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
4
 DEF CON China 2019 (Beijing / China):
 slides: http://www.blackstormsecurity.com/docs/DEFCON_CHINA_ALEXANDRE.pdf
 HITB Security Conference 2019 (Amsterdam):
 slides: http://www.blackstormsecurity.com/docs/HITB_AMS_2019.pdf
 BSIDES Sao Paulo 2019 (workshop):
 slides: http://www.blackstormsecurity.com/docs/BSIDES_SP_2019.pdf
 DEF CON USA 2018 (Las Vegas / USA):
 slides: http://www.blackstormsecurity.com/docs/DEFCON2018.pdf
Malwoverview Tool: https://github.com/alexandreborges/malwoverview
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
INTRODUCTION
BHACK CONFERENCE 2019
5
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
6
Motivations to this talk about .NET reversing and internals:
Most of the time, professionals are interested in unpacking embedded
resources from a .NET sample.
In another moment, the concern is dumping the unpacked binary from
memory.
Sometimes, we have looked for any unpacking routine to dynamically unpack
the encrypted content.
All of these actions are correct and recommended.
Many people don’t understand .NET metadata components.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
7
Most people based their analysis on the decompiled code, but never on IL.
Malware’s authors have manipulated the IL to attack the system and even the .NET
runtime.
NET Trojan bankers have used Extension Methods to aggregate new
"functionalities“ to existing malware. It’s clever because:
1. No changes in the current malicious class (without breaking existing
malware)
2. The original class can be kept sealed. (no need to subclassing)
3. Extension method:
it must be static and within a static class (of course)
first parameter marked with "this“.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
8
 There are many available methods to infect a system using .NET malware. Most
of the time, a .NET code decrypts and loads a native code (or injects a code into
a target process).
Infection can starts from an user action (as usual) or forced by an attacker
because security vulnerabilities in the system environment:
The attacker finds a XXE (XML External Entity) vulnerability.
The XXE injection occurs by injecting a malicious .dtd file.
The injected first payload connects to remote host controlled by the attacker.
A second payload is downloaded from the remote host.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
9
This payload is a dropper, which downloads a third and encrypted
payload.
The third payload is composed by two parts: a native code payload and a
managed code payload.
The native payload (DLL) is injected into a remote process.
The injected native payload decrypts and execute the managed payload.
The managed payload downloads and executes the real malware.
The infection starts: a rootkit followed by a total BIOS/UEFI infection.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
10
Web
vulnerability
Injection
Download a
payload
Dropper
Native
payload
Remote
injection
Managed
payload is
loaded
Download
the real
payload
Composed
Threat
Ring 0
code
Ring 3
code
UEFI/BIOS
CODE
APC injection
Encrypted
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
11
 We should remember that a typical native application can also load the .NET runtime and
execute a managed code:
 CLRCreateInstance( ): provides the ICLRMetaHost interface.
 ICLRMetaHost::GetRunTime( ): gets the ICLRRuntimeInfo.
 ICLRRuntimeInfo::GetInterface( ): Loads the CLR into the current process and returns
runtime interface pointers.
 ICLRRuntimeHost::ExecuteApplication( ): specifies the application to be activated in a
new domain.
 ICLRRuntimeHost::Start( ): starts the the runtime.
 ICLRRuntimeHost::ExecuteInDefaultAppDomain( ): invokes a method in the .NET
managed assembly (this steps does not work for all .NET assembly’s method). Thus, in
this case, starts the managed assembly. 
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
12
Interesting methods during .NET threat analysis:
 System.Reflection.Assembly.Load( )
 System.Reflection.Assembly.LoadFile()
 System.Reflection.MethodInfo.Invoke( )
GetType ( )  GetMethod( )  Invoke( ) (this is a typical Reflection approach)
GetAssemblyName( ) + GetType( ) + GetMethod( ) + Invoke( )
 FindResource( ) + SizeOfResource( ) + LoadResource( ) + LockResource( )
 Resources.ResourceManager.GetObject( )
 AssemblyLoader.Attach( ) + AssemblyLoader.ResolveAssembly( ) (resolves external
assemblies in runtime)
 GetExecutingAssembly( ) (used during reflection)
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
13
 Another possible approach would be:
 GetAssemblyName( ) + GetType( ) + GetMethod( ) + Invoke( )
 Some “encrypted content” is loaded from as a resource, so it is usual finding the following
sequence:
 FindResource( ) + SizeOfResource( ) + LoadResource( ) + LockResource( )
 Resources.ResourceManager.GetObject( )
 Additionally, we’ve seen techniques using embedded references such as DLLs as resources
through a sequence of calls using:
 AssemblyLoader.Attach( ) + AssemblyLoader.ResolveAssembly( ).
 As you’ve guessed, AssemblyLoader.ResolveAssembly( ) is used to resolving assemblies
that are not available at the exact time of calling other methods, which are external
references to the binary itself.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
14
 The .NET framework is composed by:
 CLR (Common Language Runtime), which is the .NET engine.
 Libraries (System.IO, System.Reflection, System.Collections, ...).
 Basically:
 source code is written in C#, F#, VB.NET and Powershell.
 compiled to CLI (Common Language Infrastruture Code).
 executed by the CLR.
 There are many obfuscators, which perform:
 Control flow obfuscation and dead/junk code insertion.
 Renaming: methods signatures, fields, methods implementation, namespaces, metadata and
external references.
 Re-encoding: changing printable to unprintable characters
 Simple encryption of methods and strings.
 Cross reference obfuscation.
I’ve already talked about
de-obfuscation in DEF CON
China 2019. 
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
15
 Tools are excellent to help us, but most .NET malware threats have deployed the same
tricks from native code to make our job harder: packers, obfuscation and anti-
reversing techniques.
 .NET Reactor
 Salamander .NET Obfuscator
 Dotfuscator
 Smart Assembly
 CryptoObfuscator for .NET
 Agile
 ArmDot
 babelfor.NET
 Eazfuscator.NET
 Spice.Net
 Skater.NET
 VM Protect 3.40
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
16
 Tools used to reverse and analyze .NET malware threats are completely different
than ones used to reverse native language:
 dnSpy (excellent)
 ILSpy (excellent)
 RedGate .NET Reflector
 De4dot (deobfuscator)
 Microsoft Visual Studio
 WinDbg (including SOS and MEX extensions)
 DotPeek
 IDA Pro
 Microsoft ILASM/ILDASM (Intermediate Language Assembly/Disassembler)
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
17
Check the Entry Point: clicking on
the function take us to next step.
Follow each function, one by one.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
18
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
19
managed code
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
20
 Therefore, we can extract these resources (DLLs, for example) by using either dnSpy or ILSpy ,
decrypt and load them again into the managed code.
 Of course, in this case, we’ll be able to see all “hidden” references, finally. 
 To load the “decrypted” resources into the managed code, we can use ILSpy + Reflexil plugin
(http://reflexil.net/).
 Finally, it is necessary to remove the “old” references to the embedded resources (performed
by AssemblyLoader.Attach( )) from the initializer (or removing the whole initializer) because, at
this time, they are “decrypted”.
 By the way, Reflexil is able to handle different obfuscators such as Babel NET, CodeFort, Skater
NET, SmartAssembly, Spices Net, Xenocode, Eazfuscator NET, Goliath NET, ILProtector,
MaxtoCode, MPRESS, Rummage, CodeVeil,CodeWall, CryptoObfuscator, DeepSea, Dotfuscator,
dotNET Reactor, CliSecure and so on.
 At end, gaining knowledge in .NET internals and metadata can be interesting.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
21
 Most time, there are module/type initializers (similar to TLS in native code) executing before
classes and entry point methods.
 .NET protectors hardly change the entry point and, usually, the trick is in the initializer.
 .cctor( ) method is a static class constructor:
 called before the Main( ) method (usually set as entry point), for example.
 when the module has a .cctor (<Module>::.cctor( )), so it is run before executing any
other class initializers or even an entry point.
 It is common finding unpackers, decrypters and hooks in the .cctor( ) method.
 Hijacking the ICorJitCompiler::compileMethod( ) is an interesting and useful way to take the
control of the JIT engine because this method is used to create a native code, so we find
managed and native code together. 
 In this case: .cctor( )  hooking compileMethod( )  hiding/encryting user code.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
.NET DETAILS
BHACK CONFERENCE 2019
22
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
23
 Metadata works as descriptors for each structure component of the application:
classes, attributes, members, and so on.
 Remember that a .NET application is composed by:
 managed executable files, which each one contains metadata
 managed code (optionally)
 .NET Assembly: managed .NET application (modules) + class libraries + resources files
(more information later)
 CLR runtime environment: loaders + JIT compiler.
 .NET source code  .NET compiler  module (IL + metadata)  CLR ( loaders + JIT
compiler)  native instruction  Execution Engine
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
24
 Managed module is composed by:
 PE header: If the module contains only IL code, so most of information of header is
ignored. However, if the module also contains native code, so things are different. 
 CLR header: contains the version of the CLR, token of Main( ) (natural entry poiint),
resources and so on.
 Metadata: describe types and members. Additionally, it helps the GC to track the life time
of objects. 
 IL (Intermediate Language) code: the managed code.
Managed Modules
Resource Files
Compiler (C#, VB, F#)
+ Linker
Managed Modules
Resource Files
Manifest
.NET Assembly
(.exe or .dll)
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
25
PE Header
Native Code /
Data
CLR Header
CLR Data
(ILcode, metadata,
managed resources)
DOS Header
PE Header
Data Directories
(size and location of CLR header)
Section Headers
.text
(includes MSIL and metadata)
.idata
.data
Remaining sections
 Managed resources in contained into .text section (and not .rsrc section).
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
26
 Metadata is composed by tables such as:
 Definition tables: ModuleDef, TypeDef, MethodDef, FieldDef, ParamDef,
PropertyDef and EventDef
 Reference tables: AssemblyRef, ModuleRef, TypeRef and MemberRef.
 Manifest tables: AssemblyDef, FileDef, ManifestResourceDef and
ExportedTypesDef.
 Most malicious .NET malware samples have:
 Used code manipulation (encryption/decryption) in .ctor( )/.cctor( )/Finalize( )
 Called unmanaged functions from DLLs using P/Invoke.
 Used COM components (very usual).
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
27
 Metadata describes all declared or referenced data in a module such as classes, members,
attributes, properties and relationships.
 Metadata is organized as a relational database using cross-references and making possible to
find what class each method comes from.
 Metadata are represented by named streams, which are classified as metadata heaps and
metadata tables.
slot 1: Class A -- methods at slot 1
slot 2: Class B -- methods at slot 3
slot 3: Class C -- methods at slot 5
slot 4: Class D -- methods at slot 6
slot 5: Class E -- methods at slot 8
slot 1: Method 1 - Classe A
slot 2: Method 2 - Classe A
slot 3: Method 1 - Classe B
slot 4: Method 2 - Classe B
slot 5: Method 1 - Classe C
slot 6: Method 1 - Classe D
slot 7: Method 2 - Classe D
slot 8: Method 1 - Classe E
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
28
 Metadata heaps:
 GUID heap: contains objects of size equal to 16 bytes.
 String heap: contains strings.
 Blog heap: contains arbitrary binary objects aligned on 4-byte boundary.
 There can be 6 named streams:
 #GUID: contains global unique identifiers.
 #Strings: contains names of classes, methods, and so on.
 #US: contains user defined strings.
 #~: contains compressed metadata stream.
 #-: contains uncompressed metadata stream.
 Blob: contains metadata from binary objects.
 An important note: compressed and uncompressed named streams are mutually exclusive.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
29
 Check the installed .NET version:
 Subdirectories under C:WindowsMicrosoft.NET
 clrver.exe
 clrver.exe -all
 Programming directly in IL (Intermediate Language) can be interesting because:
 IL is stack based, so we don’t find any instruction related to register manipulation. 
 Ngen.exe can be used to compile IL instructions to native code.
 Eventually, malware threats have attacked the .NET runtime to subvert the system. 
 Assemblies can be classified as:
 private: it is specific of an application and deployed at same directory.
 shared: it is shared and used by other applications
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
30
 In .NET applications:
 .NET Assembly:
 In malware samples, we usually find that resources are encrypted binaries and
DLLs. 
 Remember that the application can download assembly files from a URL
(codeBase element).
 .NET malware have used multi-file assemblies, partitioning types over different
files. Unfortunately, it is only possible to create multfile assembly in the
command line. 
 Few malware authors have create .NET malware containing different types such
as C# and VB in the same assembly.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
31
 Compile multi-file .NET malware is pretty easy:
 csc.exe /t:module hooking.cs
 csc.exe /t:module injection.cs
 csc.exe /out:malwarelib.dll /t:library /addmodule:hooking.netmodule
/addmodule:injection.netmodule BHack.cs
 In this case, we have a multi-file assembly:
 includes a managed module named hooking.netmodule and injection.netmodule. The
output file is a DLL named malwarelib.dll.
 a manifest file wrapping everything.
 This compiling command add the hooking.mod file to the FileDef manifest metadata table
and the its exported types to the ExportedTypeDef manifest metadata table.
 To check: ILDasm  View  MetaInfo  Show! and look for the FileDef and
ExportedTypeDef tables.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
32
 Of course, we could have a “big malware module” to use in projects:
 al.exe /out: BigMalwareLib.dll /t:library hooking. netmodule injection. netmodule
 csc.exe /t:module /r:BigMalwareLib.dll BHack.cs
 al /out:BHack.exe /t:exe /main:BHack.Main BHack.netmodule
 In this case, the __EntryPoint() global function will contain the BHack::Main( ) function call
(check the IL code to confirm it).
 It is not necessary to mention that malware’s authors usually don’t write strong assemblies,
which as signed with the private/public key pair from the publisher. Unless that this key pair
has been stolen... 
 csc.exe /out:TestProgram.exe /t:exe Program.cs
 sn.exe -k AlexandreBorges.snk
 sn.exe -p AlexandreBorges.snk AlexandreBorges.PublicKey sha256
 Sn.exe -tp AlexandreBorges.PublicKey
 csc.exe /out:TestProgram.exe /t:exe /keyfile:AlexandreBorges.snk Program.cs
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
33
Public key generated can be
viewed by:
sn.exe -p AlexandreBorges.snk
AlexandreBorges.PublicKey
sha256
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
34
 Once the system is compromised through a native malware and we have access to the system
as administrator, so it is possible to copy our .NET assembly to the Global Assembly Cache
(GAC). The Registry is not changed.
 Once a malicious .NET assembly (first stage, as a resource library) is copied to GAC, so it can be
accessed by other assemblies.
 Thus, other malicious .NET malware samples (second stage) can access methods and types
from the first stage.
 Only strong assemblies (signed) can be copied to the GAC (located at
C:WindowsMicrosoft.NETassembly) by using GACUtil.exe /i command.
 Futhermore, including /r option integrates the assembly with the Windows install engine.
 Unfortunately, the GACUtil.exe is not available in home-user systems, but it is possible to use
the MSI to install the malware threat into the GAC. 
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
35
 At end, it is still feasible to using delay signing, which is a partial signing only using the public
key. Therefore, private key is not used (and there isn’t real protection).
 The delay signing allows that the malicious assembly to be installed into the GAC and, worse,
other assemblies can make reference to it. 
 csc.exe /out:malware.dll /t:exe Program.cs
 sn.exe -k AlexandreBorges.snk
 sn.exe -p AlexandreBorges.snk AlexandreBorges.PublicKey sha256
 sn.exe -tp AlexandreBorges.PublicKey
 csc.exe /out:malware.dll /t:exe /keyfile:AlexandreBorges.PublicKey /delaysign Program.cs
 sn.exe -Vr malware.dll (CLR trust in the assembly without using the hash).
 Using csc.exe /resource makes simple to add resources (generated by resgen.exe , for
example).
 It updates the the ManifestResourceDef table.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
36
 DLL loaded from the Global Assembly Cache can and need to be monitored to detect strange
behavior. Tools to log the DLL loading such as Fuslogvw.exe (Assembly Bind Log Viewer) and
common applications such as Process Monitor can help us.
 Of course, .NET malware threats can try to compromise the .NET runtime class libraries and
JIT, which would cause a deep infection in the system and demand a detailed investigation
because:
 changing the runtime library (at IL code) can be lethal to many applications.
 it is feasible to change (hooking)/replace a runtime library.
 Changing JIT cause same problems, but it is harder.
 Remember about basics:
 copy DLL from GAC  dnSpy/Reflector + Reflexil  ildasm  change  ilasm  Ngen
 copy back to GAC (malware dropper can accomplish this task) 
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
37
 Of course, nothing is so simple:
 If the malware’s target is a DLL from .NET runtime, so it is digitally signed and it would be
necessary to have the private key to sign it. Unfortunately, we don’t have.
 Another option would be to generate a new pair of keys and re-sign all the DLL
Framework. Unfortunately, it is so much work.
 Copying a modified runtime DLL over the existing one can be difficult or almost impossible
because other programs can be using it. Thus, we should stop programs and services to
accomplish this task.
 Eventually, it is necessary to reboot the machine (urgh!) to perform this copy from a
script.
 Using the new and modified DLL can be tricky: uninstall the existing native library (ngen
uninstall <dll>) and remove it from its respective directory under NativeImages_<version>
directory.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
38
 There are other many tricks such as dropping an assembly into C:WindowsSystem32 or
Syswow64)TasksTasks.dll (hint from Casey Smith)
 An alternative would be change the Registry. In this case, the GAC continue being associated
to the original (and untouched) assembly, while its associated native image is changed to the
modified version. In this case:
 HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionNativeImagesIndexv2.0.5072
7_64IL key holds information (name + signature key) about the original assembly.
 HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionNativeImagesIndexv2.0.5072
7_64NI key would hold information (name + MVID) about the modified native image.
 Using the MVID from NI key makes simple to locate the native image.
 Thus, we can either override the native image with a modified version or change the
MVID entry to point to another native image.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
39
 GAC (old .NET assemblies) / GAC_32 (IL and x86) / GAC_64 (IL and x64) / GAC_MSIL (IL code)
directories are under C:WindowsAssembly directory
 Most of the time, .NET malwares attacking the .NET libraries try either to remove some
check or introduce hooking points at entry or exit of a method. In this case,
System.Reflection is commonly used.
 Additionally, there are cases of .NET malware threats attacking applications and the service
management offered by System.ServiceProcess.ServiceBase class and their associated
method such as OnStart( ), OnStop( ), Run( ), ServiceMain( ) and so on.
 Modifying a target code for changing the execution flow demands inserting references
(.assembly extern directive) to signed libraries (version + public key) to be able to access
member and call methods.
 Of course, we should remember to increase the stack (.maxstack).
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
ANALYSIS
BHACK CONFERENCE 2019
40
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
41
Entry point
Is there COM object? 
Is a recent malware?
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 42
Is there any clue?
What does this method do?
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 43
maybe it is using native functions? 
malware written in Visual Basic, unfortunately (C# fanboy)
External assemblies, which are
referred by the managed
assembly
(AssemblyRef table)
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 44
Assembly name
Instance Constructors
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
45
Managed Resources
referred by the assembly
(ManifestResource
metadata table)
MVID is used in the Registry to
locate assocuiated native image.
Runs in 32-bit, only
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 46
Copies data from unmanaged
memory pointer to managed
memory (a byte array in this case)
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 47
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 48
Set two breakpoints, one for each
runtime
Loads the SOS extension and
examines PEB information
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 49
Listing domains of the CLR process.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 50
COM Threading Model:
 STA: Single Thread Apartment
 MTA: Multi Thread Apartment
Threat state: (0x0) Newly initialized thread. / (0x020)
It can enter a Join / (0x200) background thread.
List the managed stack trace for this thread.
Get a list of managed threads. Of course, we could
used the -special option to get additional information.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 51
Displays information about the EEClass structure associated with a type
Check if the instruction pointer address belongs to the JIT code.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
52
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 53
PreJIT: pre-compiled code
JIT: compiled Code
NONE: the code hasn’t been compiled by the JIT.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 54
Verify the unmanaged
stack trace for this thread.
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
55
v
Dump information about a specific module
v
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 56
Methods from classes
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 57
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
58
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 59
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 60
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
61
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 62
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
63
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 64
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 65
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 66
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 67
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 68
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019 69
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
BHACK CONFERENCE 2019
70
try: python malwoverview.py -r <domain> 
BHACK CONFERENCE 2019
71
 Security Researcher
 Speaker at DEF CON USA 2019
 Speaker at DEF CON USA 2018
 Speaker at DEF CON CHINA 2019
 Speaker at NO HAT 2019 (Italy)
 Speaker at HITB 2019 (Amsterdam)
 Speaker at CONFidence 2019 (Poland)
 Speaker at DevOpsDays BH 2019
 Speaker at BSIDES
2019/2018/2017/2016
 Speaker at H2HC 2016/2015
 Speaker at BHACK 2018
 Researcher on Android/iOS Reversing,
Rootkits and Digital Forensics.
 Referee on Digital Investigation: The
International Journal of Digital
Forensics & Incident Response
THANK YOU FOR
ATTENDING MY TALK. 
 Twitter:
@ale_sp_brazil
@blackstormsecbr
 Website: http://www.blackstormsecurity.com
 LinkedIn: http://www.linkedin.com/in/aleborges
 E-mail: alexandreborges@blackstormsecurity.com
ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER

More Related Content

What's hot

Hacking ble smartwatch
Hacking ble smartwatch Hacking ble smartwatch
Hacking ble smartwatch idsecconf
 
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...Hackito Ergo Sum
 
Wtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_publicWtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_publicJaime Blasco
 
Addressing New Challenges in Software Protection for .NET
Addressing New Challenges in Software Protection for .NETAddressing New Challenges in Software Protection for .NET
Addressing New Challenges in Software Protection for .NETLicensingLive! - SafeNet
 
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...Felipe Prado
 
Automating Security Response with Serverless
Automating Security Response with ServerlessAutomating Security Response with Serverless
Automating Security Response with ServerlessMichael Ducy
 
Tracking vulnerable JARs
Tracking vulnerable JARsTracking vulnerable JARs
Tracking vulnerable JARsDavid Jorm
 
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Theo Jungeblut
 
Building world-class security response and secure development processes
Building world-class security response and secure development processesBuilding world-class security response and secure development processes
Building world-class security response and secure development processesDavid Jorm
 
Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -Theo Jungeblut
 

What's hot (11)

Hacking ble smartwatch
Hacking ble smartwatch Hacking ble smartwatch
Hacking ble smartwatch
 
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
 
Breaking iOS Apps using Cycript
Breaking iOS Apps using CycriptBreaking iOS Apps using Cycript
Breaking iOS Apps using Cycript
 
Wtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_publicWtf is happening_inside_my_android_phone_public
Wtf is happening_inside_my_android_phone_public
 
Addressing New Challenges in Software Protection for .NET
Addressing New Challenges in Software Protection for .NETAddressing New Challenges in Software Protection for .NET
Addressing New Challenges in Software Protection for .NET
 
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
 
Automating Security Response with Serverless
Automating Security Response with ServerlessAutomating Security Response with Serverless
Automating Security Response with Serverless
 
Tracking vulnerable JARs
Tracking vulnerable JARsTracking vulnerable JARs
Tracking vulnerable JARs
 
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
 
Building world-class security response and secure development processes
Building world-class security response and secure development processesBuilding world-class security response and secure development processes
Building world-class security response and secure development processes
 
Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -Clean Code Part i - Design Patterns and Best Practices -
Clean Code Part i - Design Patterns and Best Practices -
 

Similar to .NET MALWARE THREATS -- BHACK CONFERENCE 2019

ADVANCED MALWARE THREATS -- NO HAT 2019 (BERGAMO / ITALY)
ADVANCED MALWARE THREATS --  NO HAT 2019 (BERGAMO / ITALY)ADVANCED MALWARE THREATS --  NO HAT 2019 (BERGAMO / ITALY)
ADVANCED MALWARE THREATS -- NO HAT 2019 (BERGAMO / ITALY)Alexandre Borges
 
MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)
MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)
MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)Alexandre Borges
 
MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)
MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)
MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)Alexandre Borges
 
ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)
ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)
ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)Alexandre Borges
 
MODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAM
MODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAMMODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAM
MODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAMAlexandre Borges
 
The Log4Shell Vulnerability – explained: how to stay secure
The Log4Shell Vulnerability – explained: how to stay secureThe Log4Shell Vulnerability – explained: how to stay secure
The Log4Shell Vulnerability – explained: how to stay secureKaspersky
 
Crisis. advanced malware
Crisis. advanced malwareCrisis. advanced malware
Crisis. advanced malwareYury Chemerkin
 
Building Custom Android Malware BruCON 2013
Building Custom Android Malware BruCON 2013Building Custom Android Malware BruCON 2013
Building Custom Android Malware BruCON 2013Stephan Chenette
 
The EternalBlue Exploit: how it works and affects systems
The EternalBlue Exploit: how it works and affects systemsThe EternalBlue Exploit: how it works and affects systems
The EternalBlue Exploit: how it works and affects systemsAndrea Bissoli
 
The Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming NextThe Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming NextPriyanka Aash
 
The Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming NextThe Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming NextPriyanka Aash
 
Application Security Guide for Beginners
Application Security Guide for Beginners Application Security Guide for Beginners
Application Security Guide for Beginners Checkmarx
 
Two-For-One Talk: Malware Analysis for Everyone
Two-For-One Talk: Malware Analysis for EveryoneTwo-For-One Talk: Malware Analysis for Everyone
Two-For-One Talk: Malware Analysis for EveryonePaul Melson
 
Situational Awareness, Botnet and Malware Detection in the Modern Era - Davi...
Situational Awareness, Botnet and Malware Detection in the Modern Era  - Davi...Situational Awareness, Botnet and Malware Detection in the Modern Era  - Davi...
Situational Awareness, Botnet and Malware Detection in the Modern Era - Davi...Codemotion
 
Lab-10 Malware Creation and Denial of Service (DoS) In t.docx
Lab-10 Malware Creation and Denial of Service (DoS)        In t.docxLab-10 Malware Creation and Denial of Service (DoS)        In t.docx
Lab-10 Malware Creation and Denial of Service (DoS) In t.docxpauline234567
 
Formbook - In-depth malware analysis (Botconf 2018)
Formbook - In-depth malware analysis (Botconf 2018)Formbook - In-depth malware analysis (Botconf 2018)
Formbook - In-depth malware analysis (Botconf 2018)Rémi Jullian
 
Analysis Of Adverarial Code - The Role of Malware Kits
Analysis Of Adverarial Code - The Role of Malware KitsAnalysis Of Adverarial Code - The Role of Malware Kits
Analysis Of Adverarial Code - The Role of Malware KitsRahul Mohandas
 

Similar to .NET MALWARE THREATS -- BHACK CONFERENCE 2019 (20)

ADVANCED MALWARE THREATS -- NO HAT 2019 (BERGAMO / ITALY)
ADVANCED MALWARE THREATS --  NO HAT 2019 (BERGAMO / ITALY)ADVANCED MALWARE THREATS --  NO HAT 2019 (BERGAMO / ITALY)
ADVANCED MALWARE THREATS -- NO HAT 2019 (BERGAMO / ITALY)
 
MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)
MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)
MODERN MALWARE THREAT: HANDLING OBFUSCATED CODE -- CONFIDENCE CONFERENCE (2019)
 
MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)
MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)
MODERN MALWARE: OBFUSCATION AND EMULATION DEF CON CHINA 1.0 (2019)
 
ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)
ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)
ADVANCED MALWARE THREATS -- DC2711 2019 (JOHANNESBURG)
 
MODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAM
MODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAMMODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAM
MODERN TECHNIQUES TO DEOBFUSCATE AND UEFI/BIOS MALWARE -- HITB 2019 AMSTERDAM
 
The Log4Shell Vulnerability – explained: how to stay secure
The Log4Shell Vulnerability – explained: how to stay secureThe Log4Shell Vulnerability – explained: how to stay secure
The Log4Shell Vulnerability – explained: how to stay secure
 
1780 1783
1780 17831780 1783
1780 1783
 
1780 1783
1780 17831780 1783
1780 1783
 
Crisis. advanced malware
Crisis. advanced malwareCrisis. advanced malware
Crisis. advanced malware
 
Building Custom Android Malware BruCON 2013
Building Custom Android Malware BruCON 2013Building Custom Android Malware BruCON 2013
Building Custom Android Malware BruCON 2013
 
News bytes Oct-2011
News bytes  Oct-2011News bytes  Oct-2011
News bytes Oct-2011
 
The EternalBlue Exploit: how it works and affects systems
The EternalBlue Exploit: how it works and affects systemsThe EternalBlue Exploit: how it works and affects systems
The EternalBlue Exploit: how it works and affects systems
 
The Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming NextThe Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming Next
 
The Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming NextThe Seven Most Dangerous New Attack Techniques, and What's Coming Next
The Seven Most Dangerous New Attack Techniques, and What's Coming Next
 
Application Security Guide for Beginners
Application Security Guide for Beginners Application Security Guide for Beginners
Application Security Guide for Beginners
 
Two-For-One Talk: Malware Analysis for Everyone
Two-For-One Talk: Malware Analysis for EveryoneTwo-For-One Talk: Malware Analysis for Everyone
Two-For-One Talk: Malware Analysis for Everyone
 
Situational Awareness, Botnet and Malware Detection in the Modern Era - Davi...
Situational Awareness, Botnet and Malware Detection in the Modern Era  - Davi...Situational Awareness, Botnet and Malware Detection in the Modern Era  - Davi...
Situational Awareness, Botnet and Malware Detection in the Modern Era - Davi...
 
Lab-10 Malware Creation and Denial of Service (DoS) In t.docx
Lab-10 Malware Creation and Denial of Service (DoS)        In t.docxLab-10 Malware Creation and Denial of Service (DoS)        In t.docx
Lab-10 Malware Creation and Denial of Service (DoS) In t.docx
 
Formbook - In-depth malware analysis (Botconf 2018)
Formbook - In-depth malware analysis (Botconf 2018)Formbook - In-depth malware analysis (Botconf 2018)
Formbook - In-depth malware analysis (Botconf 2018)
 
Analysis Of Adverarial Code - The Role of Malware Kits
Analysis Of Adverarial Code - The Role of Malware KitsAnalysis Of Adverarial Code - The Role of Malware Kits
Analysis Of Adverarial Code - The Role of Malware Kits
 

Recently uploaded

Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfakankshagupta7348026
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptxBasil Achie
 
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation TrackSBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation TrackSebastiano Panichella
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 

Recently uploaded (20)

Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdf
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
 
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation TrackSBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
SBFT Tool Competition 2024 - CPS-UAV Test Case Generation Track
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 

.NET MALWARE THREATS -- BHACK CONFERENCE 2019

  • 1. 1 .NET MALWARE THREATS BHACK CONFERENCE 2019 BHACK CONFERENCE 2019 by Alexandre Borges ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
  • 2. BHACK CONFERENCE 2019 2  Security Researcher  Speaker at DEF CON USA 2019  Speaker at DEF CON USA 2018  Speaker at DEF CON CHINA 2019  Speaker at NO HAT 2019 (Italy)  Speaker at HITB 2019 (Amsterdam)  Speaker at CONFidence 2019 (Poland)  Speaker at DevOpsDays BH 2019  Speaker at BSIDES 2019/2018/2017/2016  Speaker at H2HC 2016/2015  Speaker at BHACK 2018  Researcher on Android/iOS Reversing, Rootkits and Digital Forensics.  Referee on Digital Investigation: The International Journal of Digital Forensics & Incident Response Agenda:  Introduction .NET Details Analysis ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER
  • 3. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 3  Last lectures in conferences:  DEVOPSDAYS BH 2019 (Belo Horizonte/Brazil):  slides: http://www.blackstormsecurity.com/docs/DEVOPSDAYS_BH_2019.pdf  NO HAT Conference 2019 (Bergamo/Italy)  slides: http://www.blackstormsecurity.com/docs/NO_HAT_2019.pdf  DEF CON USA 2019 (Las Vegas / USA):  slides: http://www.blackstormsecurity.com/docs/ALEXANDREBORGES_DEFCON_2019.pdf  CONFidence Conference 2019 (Krakow / Poland):  slides: http://www.blackstormsecurity.com/CONFIDENCE_2019_ALEXANDRE.pdf
  • 4. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 4  DEF CON China 2019 (Beijing / China):  slides: http://www.blackstormsecurity.com/docs/DEFCON_CHINA_ALEXANDRE.pdf  HITB Security Conference 2019 (Amsterdam):  slides: http://www.blackstormsecurity.com/docs/HITB_AMS_2019.pdf  BSIDES Sao Paulo 2019 (workshop):  slides: http://www.blackstormsecurity.com/docs/BSIDES_SP_2019.pdf  DEF CON USA 2018 (Las Vegas / USA):  slides: http://www.blackstormsecurity.com/docs/DEFCON2018.pdf Malwoverview Tool: https://github.com/alexandreborges/malwoverview
  • 6. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 6 Motivations to this talk about .NET reversing and internals: Most of the time, professionals are interested in unpacking embedded resources from a .NET sample. In another moment, the concern is dumping the unpacked binary from memory. Sometimes, we have looked for any unpacking routine to dynamically unpack the encrypted content. All of these actions are correct and recommended. Many people don’t understand .NET metadata components.
  • 7. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 7 Most people based their analysis on the decompiled code, but never on IL. Malware’s authors have manipulated the IL to attack the system and even the .NET runtime. NET Trojan bankers have used Extension Methods to aggregate new "functionalities“ to existing malware. It’s clever because: 1. No changes in the current malicious class (without breaking existing malware) 2. The original class can be kept sealed. (no need to subclassing) 3. Extension method: it must be static and within a static class (of course) first parameter marked with "this“.
  • 8. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 8  There are many available methods to infect a system using .NET malware. Most of the time, a .NET code decrypts and loads a native code (or injects a code into a target process). Infection can starts from an user action (as usual) or forced by an attacker because security vulnerabilities in the system environment: The attacker finds a XXE (XML External Entity) vulnerability. The XXE injection occurs by injecting a malicious .dtd file. The injected first payload connects to remote host controlled by the attacker. A second payload is downloaded from the remote host.
  • 9. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 9 This payload is a dropper, which downloads a third and encrypted payload. The third payload is composed by two parts: a native code payload and a managed code payload. The native payload (DLL) is injected into a remote process. The injected native payload decrypts and execute the managed payload. The managed payload downloads and executes the real malware. The infection starts: a rootkit followed by a total BIOS/UEFI infection.
  • 10. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 10 Web vulnerability Injection Download a payload Dropper Native payload Remote injection Managed payload is loaded Download the real payload Composed Threat Ring 0 code Ring 3 code UEFI/BIOS CODE APC injection Encrypted
  • 11. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 11  We should remember that a typical native application can also load the .NET runtime and execute a managed code:  CLRCreateInstance( ): provides the ICLRMetaHost interface.  ICLRMetaHost::GetRunTime( ): gets the ICLRRuntimeInfo.  ICLRRuntimeInfo::GetInterface( ): Loads the CLR into the current process and returns runtime interface pointers.  ICLRRuntimeHost::ExecuteApplication( ): specifies the application to be activated in a new domain.  ICLRRuntimeHost::Start( ): starts the the runtime.  ICLRRuntimeHost::ExecuteInDefaultAppDomain( ): invokes a method in the .NET managed assembly (this steps does not work for all .NET assembly’s method). Thus, in this case, starts the managed assembly. 
  • 12. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 12 Interesting methods during .NET threat analysis:  System.Reflection.Assembly.Load( )  System.Reflection.Assembly.LoadFile()  System.Reflection.MethodInfo.Invoke( ) GetType ( )  GetMethod( )  Invoke( ) (this is a typical Reflection approach) GetAssemblyName( ) + GetType( ) + GetMethod( ) + Invoke( )  FindResource( ) + SizeOfResource( ) + LoadResource( ) + LockResource( )  Resources.ResourceManager.GetObject( )  AssemblyLoader.Attach( ) + AssemblyLoader.ResolveAssembly( ) (resolves external assemblies in runtime)  GetExecutingAssembly( ) (used during reflection)
  • 13. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 13  Another possible approach would be:  GetAssemblyName( ) + GetType( ) + GetMethod( ) + Invoke( )  Some “encrypted content” is loaded from as a resource, so it is usual finding the following sequence:  FindResource( ) + SizeOfResource( ) + LoadResource( ) + LockResource( )  Resources.ResourceManager.GetObject( )  Additionally, we’ve seen techniques using embedded references such as DLLs as resources through a sequence of calls using:  AssemblyLoader.Attach( ) + AssemblyLoader.ResolveAssembly( ).  As you’ve guessed, AssemblyLoader.ResolveAssembly( ) is used to resolving assemblies that are not available at the exact time of calling other methods, which are external references to the binary itself.
  • 14. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 14  The .NET framework is composed by:  CLR (Common Language Runtime), which is the .NET engine.  Libraries (System.IO, System.Reflection, System.Collections, ...).  Basically:  source code is written in C#, F#, VB.NET and Powershell.  compiled to CLI (Common Language Infrastruture Code).  executed by the CLR.  There are many obfuscators, which perform:  Control flow obfuscation and dead/junk code insertion.  Renaming: methods signatures, fields, methods implementation, namespaces, metadata and external references.  Re-encoding: changing printable to unprintable characters  Simple encryption of methods and strings.  Cross reference obfuscation. I’ve already talked about de-obfuscation in DEF CON China 2019. 
  • 15. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 15  Tools are excellent to help us, but most .NET malware threats have deployed the same tricks from native code to make our job harder: packers, obfuscation and anti- reversing techniques.  .NET Reactor  Salamander .NET Obfuscator  Dotfuscator  Smart Assembly  CryptoObfuscator for .NET  Agile  ArmDot  babelfor.NET  Eazfuscator.NET  Spice.Net  Skater.NET  VM Protect 3.40
  • 16. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 16  Tools used to reverse and analyze .NET malware threats are completely different than ones used to reverse native language:  dnSpy (excellent)  ILSpy (excellent)  RedGate .NET Reflector  De4dot (deobfuscator)  Microsoft Visual Studio  WinDbg (including SOS and MEX extensions)  DotPeek  IDA Pro  Microsoft ILASM/ILDASM (Intermediate Language Assembly/Disassembler)
  • 17. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 17 Check the Entry Point: clicking on the function take us to next step. Follow each function, one by one.
  • 20. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 20  Therefore, we can extract these resources (DLLs, for example) by using either dnSpy or ILSpy , decrypt and load them again into the managed code.  Of course, in this case, we’ll be able to see all “hidden” references, finally.   To load the “decrypted” resources into the managed code, we can use ILSpy + Reflexil plugin (http://reflexil.net/).  Finally, it is necessary to remove the “old” references to the embedded resources (performed by AssemblyLoader.Attach( )) from the initializer (or removing the whole initializer) because, at this time, they are “decrypted”.  By the way, Reflexil is able to handle different obfuscators such as Babel NET, CodeFort, Skater NET, SmartAssembly, Spices Net, Xenocode, Eazfuscator NET, Goliath NET, ILProtector, MaxtoCode, MPRESS, Rummage, CodeVeil,CodeWall, CryptoObfuscator, DeepSea, Dotfuscator, dotNET Reactor, CliSecure and so on.  At end, gaining knowledge in .NET internals and metadata can be interesting.
  • 21. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 21  Most time, there are module/type initializers (similar to TLS in native code) executing before classes and entry point methods.  .NET protectors hardly change the entry point and, usually, the trick is in the initializer.  .cctor( ) method is a static class constructor:  called before the Main( ) method (usually set as entry point), for example.  when the module has a .cctor (<Module>::.cctor( )), so it is run before executing any other class initializers or even an entry point.  It is common finding unpackers, decrypters and hooks in the .cctor( ) method.  Hijacking the ICorJitCompiler::compileMethod( ) is an interesting and useful way to take the control of the JIT engine because this method is used to create a native code, so we find managed and native code together.   In this case: .cctor( )  hooking compileMethod( )  hiding/encryting user code.
  • 23. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 23  Metadata works as descriptors for each structure component of the application: classes, attributes, members, and so on.  Remember that a .NET application is composed by:  managed executable files, which each one contains metadata  managed code (optionally)  .NET Assembly: managed .NET application (modules) + class libraries + resources files (more information later)  CLR runtime environment: loaders + JIT compiler.  .NET source code  .NET compiler  module (IL + metadata)  CLR ( loaders + JIT compiler)  native instruction  Execution Engine
  • 24. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 24  Managed module is composed by:  PE header: If the module contains only IL code, so most of information of header is ignored. However, if the module also contains native code, so things are different.   CLR header: contains the version of the CLR, token of Main( ) (natural entry poiint), resources and so on.  Metadata: describe types and members. Additionally, it helps the GC to track the life time of objects.   IL (Intermediate Language) code: the managed code. Managed Modules Resource Files Compiler (C#, VB, F#) + Linker Managed Modules Resource Files Manifest .NET Assembly (.exe or .dll)
  • 25. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 25 PE Header Native Code / Data CLR Header CLR Data (ILcode, metadata, managed resources) DOS Header PE Header Data Directories (size and location of CLR header) Section Headers .text (includes MSIL and metadata) .idata .data Remaining sections  Managed resources in contained into .text section (and not .rsrc section).
  • 26. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 26  Metadata is composed by tables such as:  Definition tables: ModuleDef, TypeDef, MethodDef, FieldDef, ParamDef, PropertyDef and EventDef  Reference tables: AssemblyRef, ModuleRef, TypeRef and MemberRef.  Manifest tables: AssemblyDef, FileDef, ManifestResourceDef and ExportedTypesDef.  Most malicious .NET malware samples have:  Used code manipulation (encryption/decryption) in .ctor( )/.cctor( )/Finalize( )  Called unmanaged functions from DLLs using P/Invoke.  Used COM components (very usual).
  • 27. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 27  Metadata describes all declared or referenced data in a module such as classes, members, attributes, properties and relationships.  Metadata is organized as a relational database using cross-references and making possible to find what class each method comes from.  Metadata are represented by named streams, which are classified as metadata heaps and metadata tables. slot 1: Class A -- methods at slot 1 slot 2: Class B -- methods at slot 3 slot 3: Class C -- methods at slot 5 slot 4: Class D -- methods at slot 6 slot 5: Class E -- methods at slot 8 slot 1: Method 1 - Classe A slot 2: Method 2 - Classe A slot 3: Method 1 - Classe B slot 4: Method 2 - Classe B slot 5: Method 1 - Classe C slot 6: Method 1 - Classe D slot 7: Method 2 - Classe D slot 8: Method 1 - Classe E
  • 28. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 28  Metadata heaps:  GUID heap: contains objects of size equal to 16 bytes.  String heap: contains strings.  Blog heap: contains arbitrary binary objects aligned on 4-byte boundary.  There can be 6 named streams:  #GUID: contains global unique identifiers.  #Strings: contains names of classes, methods, and so on.  #US: contains user defined strings.  #~: contains compressed metadata stream.  #-: contains uncompressed metadata stream.  Blob: contains metadata from binary objects.  An important note: compressed and uncompressed named streams are mutually exclusive.
  • 29. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 29  Check the installed .NET version:  Subdirectories under C:WindowsMicrosoft.NET  clrver.exe  clrver.exe -all  Programming directly in IL (Intermediate Language) can be interesting because:  IL is stack based, so we don’t find any instruction related to register manipulation.   Ngen.exe can be used to compile IL instructions to native code.  Eventually, malware threats have attacked the .NET runtime to subvert the system.   Assemblies can be classified as:  private: it is specific of an application and deployed at same directory.  shared: it is shared and used by other applications
  • 30. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 30  In .NET applications:  .NET Assembly:  In malware samples, we usually find that resources are encrypted binaries and DLLs.   Remember that the application can download assembly files from a URL (codeBase element).  .NET malware have used multi-file assemblies, partitioning types over different files. Unfortunately, it is only possible to create multfile assembly in the command line.   Few malware authors have create .NET malware containing different types such as C# and VB in the same assembly.
  • 31. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 31  Compile multi-file .NET malware is pretty easy:  csc.exe /t:module hooking.cs  csc.exe /t:module injection.cs  csc.exe /out:malwarelib.dll /t:library /addmodule:hooking.netmodule /addmodule:injection.netmodule BHack.cs  In this case, we have a multi-file assembly:  includes a managed module named hooking.netmodule and injection.netmodule. The output file is a DLL named malwarelib.dll.  a manifest file wrapping everything.  This compiling command add the hooking.mod file to the FileDef manifest metadata table and the its exported types to the ExportedTypeDef manifest metadata table.  To check: ILDasm  View  MetaInfo  Show! and look for the FileDef and ExportedTypeDef tables.
  • 32. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 32  Of course, we could have a “big malware module” to use in projects:  al.exe /out: BigMalwareLib.dll /t:library hooking. netmodule injection. netmodule  csc.exe /t:module /r:BigMalwareLib.dll BHack.cs  al /out:BHack.exe /t:exe /main:BHack.Main BHack.netmodule  In this case, the __EntryPoint() global function will contain the BHack::Main( ) function call (check the IL code to confirm it).  It is not necessary to mention that malware’s authors usually don’t write strong assemblies, which as signed with the private/public key pair from the publisher. Unless that this key pair has been stolen...   csc.exe /out:TestProgram.exe /t:exe Program.cs  sn.exe -k AlexandreBorges.snk  sn.exe -p AlexandreBorges.snk AlexandreBorges.PublicKey sha256  Sn.exe -tp AlexandreBorges.PublicKey  csc.exe /out:TestProgram.exe /t:exe /keyfile:AlexandreBorges.snk Program.cs
  • 33. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 33 Public key generated can be viewed by: sn.exe -p AlexandreBorges.snk AlexandreBorges.PublicKey sha256
  • 34. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 34  Once the system is compromised through a native malware and we have access to the system as administrator, so it is possible to copy our .NET assembly to the Global Assembly Cache (GAC). The Registry is not changed.  Once a malicious .NET assembly (first stage, as a resource library) is copied to GAC, so it can be accessed by other assemblies.  Thus, other malicious .NET malware samples (second stage) can access methods and types from the first stage.  Only strong assemblies (signed) can be copied to the GAC (located at C:WindowsMicrosoft.NETassembly) by using GACUtil.exe /i command.  Futhermore, including /r option integrates the assembly with the Windows install engine.  Unfortunately, the GACUtil.exe is not available in home-user systems, but it is possible to use the MSI to install the malware threat into the GAC. 
  • 35. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 35  At end, it is still feasible to using delay signing, which is a partial signing only using the public key. Therefore, private key is not used (and there isn’t real protection).  The delay signing allows that the malicious assembly to be installed into the GAC and, worse, other assemblies can make reference to it.   csc.exe /out:malware.dll /t:exe Program.cs  sn.exe -k AlexandreBorges.snk  sn.exe -p AlexandreBorges.snk AlexandreBorges.PublicKey sha256  sn.exe -tp AlexandreBorges.PublicKey  csc.exe /out:malware.dll /t:exe /keyfile:AlexandreBorges.PublicKey /delaysign Program.cs  sn.exe -Vr malware.dll (CLR trust in the assembly without using the hash).  Using csc.exe /resource makes simple to add resources (generated by resgen.exe , for example).  It updates the the ManifestResourceDef table.
  • 36. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 36  DLL loaded from the Global Assembly Cache can and need to be monitored to detect strange behavior. Tools to log the DLL loading such as Fuslogvw.exe (Assembly Bind Log Viewer) and common applications such as Process Monitor can help us.  Of course, .NET malware threats can try to compromise the .NET runtime class libraries and JIT, which would cause a deep infection in the system and demand a detailed investigation because:  changing the runtime library (at IL code) can be lethal to many applications.  it is feasible to change (hooking)/replace a runtime library.  Changing JIT cause same problems, but it is harder.  Remember about basics:  copy DLL from GAC  dnSpy/Reflector + Reflexil  ildasm  change  ilasm  Ngen  copy back to GAC (malware dropper can accomplish this task) 
  • 37. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 37  Of course, nothing is so simple:  If the malware’s target is a DLL from .NET runtime, so it is digitally signed and it would be necessary to have the private key to sign it. Unfortunately, we don’t have.  Another option would be to generate a new pair of keys and re-sign all the DLL Framework. Unfortunately, it is so much work.  Copying a modified runtime DLL over the existing one can be difficult or almost impossible because other programs can be using it. Thus, we should stop programs and services to accomplish this task.  Eventually, it is necessary to reboot the machine (urgh!) to perform this copy from a script.  Using the new and modified DLL can be tricky: uninstall the existing native library (ngen uninstall <dll>) and remove it from its respective directory under NativeImages_<version> directory.
  • 38. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 38  There are other many tricks such as dropping an assembly into C:WindowsSystem32 or Syswow64)TasksTasks.dll (hint from Casey Smith)  An alternative would be change the Registry. In this case, the GAC continue being associated to the original (and untouched) assembly, while its associated native image is changed to the modified version. In this case:  HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionNativeImagesIndexv2.0.5072 7_64IL key holds information (name + signature key) about the original assembly.  HKEY_LOCAL_MACHINESOFTWAREMicrosoftFusionNativeImagesIndexv2.0.5072 7_64NI key would hold information (name + MVID) about the modified native image.  Using the MVID from NI key makes simple to locate the native image.  Thus, we can either override the native image with a modified version or change the MVID entry to point to another native image.
  • 39. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 39  GAC (old .NET assemblies) / GAC_32 (IL and x86) / GAC_64 (IL and x64) / GAC_MSIL (IL code) directories are under C:WindowsAssembly directory  Most of the time, .NET malwares attacking the .NET libraries try either to remove some check or introduce hooking points at entry or exit of a method. In this case, System.Reflection is commonly used.  Additionally, there are cases of .NET malware threats attacking applications and the service management offered by System.ServiceProcess.ServiceBase class and their associated method such as OnStart( ), OnStop( ), Run( ), ServiceMain( ) and so on.  Modifying a target code for changing the execution flow demands inserting references (.assembly extern directive) to signed libraries (version + public key) to be able to access member and call methods.  Of course, we should remember to increase the stack (.maxstack).
  • 41. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 41 Entry point Is there COM object?  Is a recent malware?
  • 42. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 42 Is there any clue? What does this method do?
  • 43. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 43 maybe it is using native functions?  malware written in Visual Basic, unfortunately (C# fanboy) External assemblies, which are referred by the managed assembly (AssemblyRef table)
  • 45. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 45 Managed Resources referred by the assembly (ManifestResource metadata table) MVID is used in the Registry to locate assocuiated native image. Runs in 32-bit, only
  • 46. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 46 Copies data from unmanaged memory pointer to managed memory (a byte array in this case)
  • 48. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 48 Set two breakpoints, one for each runtime Loads the SOS extension and examines PEB information
  • 50. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 50 COM Threading Model:  STA: Single Thread Apartment  MTA: Multi Thread Apartment Threat state: (0x0) Newly initialized thread. / (0x020) It can enter a Join / (0x200) background thread. List the managed stack trace for this thread. Get a list of managed threads. Of course, we could used the -special option to get additional information.
  • 51. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 51 Displays information about the EEClass structure associated with a type Check if the instruction pointer address belongs to the JIT code.
  • 53. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 53 PreJIT: pre-compiled code JIT: compiled Code NONE: the code hasn’t been compiled by the JIT.
  • 54. ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER BHACK CONFERENCE 2019 54 Verify the unmanaged stack trace for this thread.
  • 71. BHACK CONFERENCE 2019 71  Security Researcher  Speaker at DEF CON USA 2019  Speaker at DEF CON USA 2018  Speaker at DEF CON CHINA 2019  Speaker at NO HAT 2019 (Italy)  Speaker at HITB 2019 (Amsterdam)  Speaker at CONFidence 2019 (Poland)  Speaker at DevOpsDays BH 2019  Speaker at BSIDES 2019/2018/2017/2016  Speaker at H2HC 2016/2015  Speaker at BHACK 2018  Researcher on Android/iOS Reversing, Rootkits and Digital Forensics.  Referee on Digital Investigation: The International Journal of Digital Forensics & Incident Response THANK YOU FOR ATTENDING MY TALK.   Twitter: @ale_sp_brazil @blackstormsecbr  Website: http://www.blackstormsecurity.com  LinkedIn: http://www.linkedin.com/in/aleborges  E-mail: alexandreborges@blackstormsecurity.com ALEXANDREBORGES–MALWAREANDSECURITYRESEARCHER