SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Downloaden Sie, um offline zu lesen
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
1
AMANDA ROUSSEAU
.NET HIJACKING to
DEFEND POWERSHELL
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
2
AMANDA ROUSSEAU
MALWARE UNICORN
Senior Malware Researcher @ Endgame, Inc.
Works as a Malware Researcher at Endgame who
focuses on attacker technique application to
dynamic behavior detection both on Windows and
OSX platforms.
@malwareunicorn
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
3
GOALS
Allow PowerShell to be run in a normal environment
Analyze de-obfuscated commands
Remain stealthy in the environment to avoid bypasses
Allows run-time analysis and blocking
Supports PowerShell v2-5
STEALTHY,
RUN-TIME
MONITORING.
What Do We Need?
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
4
CLR PROFILING
JIT COMPILER
HOOKING
IL BINARY
MODIFCATION
C-BASED
METHOD HOOKING
CONTENT OVERVIEW
SOLUTIONS:
.NET OVERVIEW
POWERSHELL
OVERVIEW
ATTACK HISTORY C# DLL INJECTION
FOUNDATIONS:
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
5
TIMELINE
Offensive PowerShell and .NET Attacks
ATTACK HISTORY
2012
2013
2014
2015
2016
Plotus (10/2013)
Power Worm (3/2014)
Syrian Malware (8/2014)
PoweLiks (8/2014)
CoinVault Rasnomware (11/ 2014)
PowerDuke Backdoor (11/2016)
PowerSniff (3/2016) Trojan.Laziok (4/2016)
PowerShell Ransomware (5/2016)
Fileless Backdoor (8/2015)
PS>Attack (12/2015)
Hunter EK (8/2015)
PowerShell Empire (2014)
ConfuserEx (5/2014)
Nishang (8/2012)
PowerSploit (2012)
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
6
PHISHING CAMPAIGNS
Utilizing scripting for
transitioning from the
1st stage of the attack to the
2nd stage payload
PoweLiks
PowerSniff
PowerDuke
Hunter Exploit Kit
Diagram of PoweLiks
1
2
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
7
BAD MALWARE PICKUP LINES
Hey girl, do you like PowerShell?
Because I'd like to stay persistent in
your memory ;)
“
”
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
8
OBFUSCATION
ANALYSIS EVASION
Script Obfuscation
Code Protection Applications:
ConfuserEx
.NET Reactor:
string encryption
anti-decompilation
control flow obfuscation
anti-tampering
Invoke-Obfuscation
CoinVault obfuscated C# Code
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
9
POWERSHELL
EMPIRE
PS>ATTACK
NISHANGPOWERSPLOIT
OFFENSIVE FRAMEWORKS
PowerShell Offensive Frameworks
Useful for automating attacks and post-
exploitation routines
Collection of scripts to automate tasks such as:
• analysis evasion
• remote execution
• privilege escalation
• lateral movement
• exfiltration
Command to reflectively load and execute a PE
binary into memory
Improve and propagate these PowerShell
offensive techniques
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
10
FOUNDATIONS of .NET
C O M M O N L A N G U A G E R U N T I M E ( C L R )
J U S T - I N - T I M E ( J I T )
“ S T R O N G N A M E D ” A S S E M B L I E S
N G E N A S S E M B L I E S
D E C O M P I L I N G . N E T B I N A R I E S
I N T E R M E D I A T E L A N G A G E ( I L )
.NET Framework
Compiler
C#
Code
Managed Assembly
Metadata & IL
codes
CLR
clr.dll / mscorwks.dll
JIT
getJit()
compileMethod()
clrjit.dll/mscorjit.dll
Native/Machine
Code
Referenced
Assemblies
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
11
COMMON LANGUAGE RUNTIME (CLR)
UNMANAGED Vs MANAGED
Handler that manages:
Dependencies
Memory
Exceptions
Synchronization
Managed Assemblies
Metadata & IL Code
No additional information is required
Agnostic across architectures
C# vs IL Code PowerShell ScriptBlock Create
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
12
JUST-IN-TIME COMPILER (JIT)
IL CODE -> NATIVE CODE
Convert and optimize the IL code into
native CPU instructions which is then
stored in dynamic memory
getJit()
compileMethod()
JIT Order of Operations
JITCompiler 1) Metadata Lookup Table
Index of MethodInfo
Memory Block
3) Convert IL to CPU
Instructions & Store in
Memory Block
4) Update Method’s entry
point in the table
5) Jump to memory &
execute
Return Back to Compiler
2) Allocate
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
13
JUST-IN-TIME COMPILER (JIT)
METADATA LOOKUPS
Assembly contains metadata tables
Lists of objects with names, offsets
Method Tokens are unique per module
Assembly Metadata
Metadata Table Description
ModuleDef (0x00) Identity of the module
TypeDef (0x01)
List of class Types and the indexes to the
methods that each class owns
MethodDef (0x02)
Each method entry contains the name,
offset location, flags, and signature.
Assembly (0x20)
Contains information about the current
assembly.
AssemblyRef (0x23)
Contains information about the referenced
assemblies.
MemberRef (0x0A)
Contains each member including methods
referenced by the module.
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
14
JUST-IN-TIME COMPILER (JIT)
TRAVERSING THE METADATA
Download JIT .PDB
Identify function offsets for hooking
Need to traverse the MethodDesc Tables to
update the information for methods
JIT Compiler Function Offsets
D971C845B82D877107906335EFF1824C#32_2_0_50727_8670
2621605;MethodDesc::s_pfnReset
55606;MethodDesc::s_pfnIsGenericMethodDefinition
60512;MethodDesc::s_pfnGetNumGenericMethodArgs
762227;MethodDesc::s_pfnStripMethodInstantiation
60894;MethodDesc::s_pfnHasClassOrMethodInstantiation
160213;MethodDesc::s_pfnContainsGenericVariables
1179150;MethodDesc::s_pfnGetWrappedMethodDesc
56056;MethodDesc::s_pfnGetDomain
1020785;MethodDesc::s_pfnGetLoaderModule
4801122;LoadedMethodDescIterator::s_pfnConstructor
0;LoadedMethodDescIterator::s_pfnConstructor_v45
0;LoadedMethodDescIterator::s_pfnConstructor_v46
4950262;LoadedMethodDescIterator::s_pfnStart
0;LoadedMethodDescIterator::s_pfnNext_v4
4950393;LoadedMethodDescIterator::s_pfnNext_v2
4950297;LoadedMethodDescIterator::s_pfnCurrent_F43F7
0AF86B02890FCF95ED91EA373BB#32_4_0_30319_17929
_1BC333D76444B51B01A74B7447ADBC9E#64_2_0_50727_4963
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
15
MICROSOFT INTERMEDIATE LANGUAGE (MSIL)
CPU agnostic machine language that
operates on a slightly higher level
CLI instruction set
standard from ECMA-335
Address is a 4-byte value called a token
Relevant only to assembly
JIT Optimizes the IL instructions
Extraneous instructions such as NOP codes will be
removed to improve performance
IL Instructions
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
16
MICROSOFT INTERMEDIATE LANGUAGE (MSIL)
CPU agnostic machine language that
operates on a slightly higher level
Pushed and popped on the stack
.maxstack refers the stack slot size needed for arguments
and local variables
After JIT
Can acquire the virtual memory address of the method.
Using GetFunctionPointer.
.method /*06002149*/ public hidebysig static
class
System.Management.Automation.ScriptBlock/*02000316*/
Create(string script) cil managed
// SIG: 00 01 12 8C 58 0E
{
// Method begins at RVA 0xa9499
// Code size 12 (0xc)
.maxstack 8
IL_0000: /*73|(06)001FDA*/ newobj instance
void
System.Management.Automation.Parser/*020002F7*/::.ctor
() /*06001FDA*/
IL_0005: /*02|*/ ldarg.0
IL_0006: /*28|(06)00214A*/ call class
System.Management.Automation.ScriptBlock/*02000316*/
System.Management.Automation.ScriptBlock/*02000316*/::
Create(class
System.Management.Automation.Parser/*020002F7*/,
string) /*0600214A*/
IL_000b: /*2A|*/ ret
} // end of method ScriptBlock::Create
PowerShell ScriptBlock IL Instructions
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
17
DECOMPILING .NET BINARIES
Can easily be
decompiled & disassembled
Tools rely on disassembling the IL code
and reconstructing the C# code based on
the metadata definition
original function names
function offsets
membership to parent classes
Tools
dotPeek
dnSpy
ILspy
De4dot
ILAsm.exe & ILDasm.exe
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
18
DECOMPILING .NET BINARIES
DotPeek
https://www.jetbrains.com/decompiler/
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
19
STRONG NAMED ASSEMBLIES
Fixes version dependency
from DLL Hell
Uniquely identified assemblies signed with
a publisher’s public/private key pair
Public key is embedded into the header of the assembly
Intended to tamper-resistant
Global assembly cache (GAC)
.NET tool gacutil.exe to install assembly
Weak assemblies searched by its file name and
executable extension with in the containing folder.
Public Key Token Reference for Mscorlib
GAC Locations
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
20
STRONG NAMED ASSEMBLIES
BYPASSING ANTI-TAMPERING
.NET Framework version 3.5 Service Pack 1
Strong-name signatures are not
validated when an assembly is loaded
DISABLING STRONG NAME SIGNATURE VERIFICATION
Arch
Windows Registry Key to Disable for All
Applications
32
HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFra
meworkAllowStrongNameBypass
64
HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFra
meworkAllowStrongNameBypass
HKEY_LOCAL_MACHINESOFTWAREWow6432NodeM
icrosoft.NETFrameworkAllowStrongNameBypass
C# Application Configuration for One Application
<configuration>
<runtime>
<bypassTrustedAppStrongNames enabled="false" />
</runtime>
</configuration>
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
21
NGEN ASSEMBLIES
BYPASSES JIT COMPILATION
Native Images are precompiled native
code PE binaries
Install & Uninstall
Ngen.exe
Contains both IL & Machine Code
Code will load native images before IL
assemblies
Native Images
C:WindowsassemblyNativeImages_v2.0.50727_32
C:WindowsassemblyNativeImages_v2.0.50727_64
C:WindowsassemblyNativeImages_v4.0.30319_32
C:WindowsassemblyNativeImages_v4.0.30319_64
System.Management.Automation.ni.dll
System.Management.Automation.dll
IL Assembly
Native Image
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
22
C# Programs
POWERSHELL
A POWERFUL SCRIPTING
LANGUAGE
Directly access globally cached .NET
assemblies
Reflectively load .NET assemblies which
can load C-based Windows libraries
Run unsigned scripts locally
Run scripts that are interpreted and
executed as base64 strings.
System.Management.Automation.dll
PowerShell.exe
.NET FRAMEWORK
CLRJIT
Machine Code
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
23
POWERSHELL
All string or stream based scripts are
parsed and compiled within a ScriptBlock.
PowerShell source code differs in each
version
PowerShell ScriptBlock Create
public static ScriptBlock Create(string script)
{
return ScriptBlock.Create(new Parser(), script);
}
PS Version Released Default Windows Versions .NET CLR Versions
1.0 2006 WinServer 2008 2.0.50727
2.0 2009
Win7
WinServer 2008 R2
2.0.50727
3.0 2012
Win8
WinServer 2012
4.0.30319
4.5+
4.0 2013
Wuin8.1
WinServer 2012 R2
4.0.30319
4.5+
5.0 2014 Win10 4.5+
SCRIPTBLOCKS
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
24
BAD MALWARE PICKUP LINES
Hey girl, do you like PowerShell?
I can tell you do by the
invoked expression I gave you ;)
“
”
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
25
POWERSHELL
Runspaces allows C# code to invoke
PowerShell commands
PowerSploit SharpPick ->
Invoke-Expression and Invoke-
Command that will execute piped
string input or a ScriptBlock in the
local or remote shell contexts
RUNSPACES, INVOKE, WIN API
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
26
POWERSHELL
.NET assemblies and can
reflectively load C-based
Windows DLL
RUNSPACES, INVOKE, WIN API
# Get a reference to System.dll in the GAC
$SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object { $_.GlobalAssemblyCache -And
$_.Location.Split('')[-1].Equals('System.dll') }
$UnsafeNativeMethods =
$SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods')
# Get a reference to the GetModuleHandle and GetProcAddress
methods
$GetModuleHandle =
$UnsafeNativeMethods.GetMethod('GetModuleHandle')
$GetProcAddress =
$UnsafeNativeMethods.GetMethod('GetProcAddress')
# Get a handle to the module specified
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))
$tmpPtr = New-Object IntPtr
$HandleRef = New-Object
System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle)
PowerSploit: Invoke-Shellcode
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
27
AMSI
PowerShell v5 Anti-Malware
Scan Interface
Windows 10
Allows Windows Defender and third
party Anti-virus solutions access the
script code
Provides:
Memory and Stream scanning
De-obfuscated plain code
Detect C# .NET usage of the PowerShell assembly
PowerShell.exe
System.Management.Automation.dll
GetCodeToInvoke()
Compile()
PerformSecurityCheck()
ScanContent()
AMSI.dll
AmsiScanString()
COM API Interface
RPC
Windows Defender
MPCLIENT.dll
Anti Malware Scan Interface
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
28
AMSI
SUSPICIOUS METHODS GetMethod
GetMethods
GetNestedType
GetNestedTypes
GetProperties
GetProperty
InvokeMember
GetDelegateForFunctionPointer
kernel32
…
Anti Malware Scan Interface
System.Management.
Automation.ScriptBlock.
CheckSuspiciousContent
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
29
AMSI BYPASSES
SIGNATURE BYPASS
Windows Defender relies on known
variable names to block a malicious script
String obfuscation on the variable name
$code = @" Sv ('R9'+'HYt') ( " )
)93]rahC[]gnirtS[,'UCS'(ecalpeR.)63]rahC[]gnirtS[,'aEm'(ecalpe
R.)')eurt'+'aEm,llun'+'aEm(eulaVt'+'eS'+'.)UCScit'+'atS,ci'+'l
buPnoNUCS'+',U'+'CSdeli'+'aFt'+'inI'+'is'+'maUCS('+'dle'+'iF'+
'teG'+'.'+')'+'UCSslitU'+'is'+'mA.noitamotu'+'A.tn'+'em'+'egan
aM.'+'m'+'e'+'t'+'sySUCS(epy'+'TteG.ylbmessA'+'.]'+'feR['(
(noisserpxE-ekovnI" ); Invoke-Expression( -Join ( VaRIAbLe
('R9'+'hyT') -val )[ - 1..- (( VaRIAbLe ('R9'+'hyT') -val
).Length)])"@
NISHANG AMSI BYPASS
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
30
AMSI BYPASSES
DISABLING AMSI
AMSI provides a command to disable the
real-time monitoring for Windows
Defender
DLL Load Hijacking to replace ASMI.dll
p0wnshell was trying to load the AMSI.dll in the
local executing directory
Place a fake copy of the ASMI.dll in this local
directory
Disable AMSI using Set-MpPreference
PS C:> Set-MpPreference -DisableRealtimeMonitoring
$true
Fake AMSI.DLL
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
31
AMSI BYPASSES
ASSEMBLY FIELD MODIFICATION
Using .NET reflection, a user can modify
values within a class.
When the AmsiUtils class is loaded, the
class initialization result can be modified
to appear as failed by setting it to True.
PowerShell to Disable AMSI by Setting AmsiInitFailed
AMSI Integration code
[Ref].Assembly.GetType(‘System.Management.Automation.AmsiUtils
').GetField('amsiInitFailed','NonPublic,Static').SetValue($nul
l,$true)
int AMSIIntegration()
{
HAMSICONTEXT amsiContext;
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
hres = AmsiInitialize(L"Win32Project2", &amsiContext);
if (FAILED(hres))
{
std::cout << "AmsiInitialize fails" << std::endl;
CoUninitialize();
return -1; // Program has failed.
}
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
32
C# DLL INJECTION
.NET ROOTKITS BINARY MODIFICATION
CLR PROFILING
JIT COMPILER HOOKING
C-BASED METHOD HOOKING
METHODS AND SOLUTIONS
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
33
C# DLL INJECTION
To run an injected C# assembly DLL, it
must be first wrapped in a C-based
wrapper DLL
C# DLL does not have a DllMain()
Determine the version of CLR
Host process will use the environment’s .NET version
unless forced to an older version
Will need to be a payload compiled for different major
version of .NET (2.0,3.5,4.0,4.5, and 4.6).
Target Host Process
C#DLL
Wrapper DLL
JIT Compiler
Injected
DLL Injector or Filter Driver
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
34
C# DLL INJECTION
Load mscoree.dll CLR library
Load the C# payload into the host process’s
C# AppDomain
Using a precompiled C# payload and adding it as an
embedded resource in the parent C-based DLL
CoCreateInstance to access the CLR runtime
environment of the host process
Grab the AppDomain and load the assembly as a
bytearray stored in the resource section
CoInitializeEx(0, COINIT_MULTITHREADED);
ICorRuntimeHost* pICorRuntimeHost = 0;
HRESULT st = CoCreateInstance(CLSID_CorRuntimeHost, 0,
CLSCTX_ALL, IID_ICorRuntimeHost,
(void**)&pICorRuntimeHost);
if (!pICorRuntimeHost) {
return 1;
}
HDOMAINENUM hEnum = NULL;
pICorRuntimeHost->EnumDomains(&hEnum);
if (!hEnum) {
return 1;
}
IUnknown* pUunk = 0;
st = pICorRuntimeHost->NextDomain(hEnum, &pUunk);
if (!pUunk) {
return 1;
}
CComPtr<mscorlib::_AppDomain> pAppDomain = NULL;
st = pUunk->QueryInterface( __uuidof(
CComPtr<mscorlib::_AppDomain>), (VOID**)&pAppDomain);
if (!pAppDomain) {
return 1;
}
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
35
NET ROOTKITS BINARY MODIFICATION
MODIFYING GAC ASSEMBLY
Metula’s BlackHat talk about developing
.NET framework rootkits
1. Targeting a GAC assembly to decompile
into its IL code
2. Modify the IL code by injecting functions
3. Recompiling the IL
4. Force the framework to use the modified
DLL
IL Codes
Disassembles using
ILDasm
Insert Loader
Function
Reassemble using
ILAsm
C# Compiled
Assembly DLL
%SystemRoot%Microsoft.NETAssemblyGAC_MSILSystem.M
anagement.Automation<version>System.Management.Auto
mation.dll
Overwrite Original DLL
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
36
NET ROOTKITS BINARY MODIFICATION
Avoid Human Error
.NET-Sploit
dotNetHookLibrary
Mono.Cecil
Load existing assemblies statically or dynamically
to modify the IL code to insert new code for you
Used by both developers and gaming hackers
AssemblyDef
ModuleDefModuleDef
FieldDefTypeDef
PropertyDefMethodDef
SetMethod GetMethod
Methods
Constructors
Properties
Fields
Modules
MainModule
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
37
CLR PROFILING
CLR DYNAMIC HOOK INJECTION
.NET framework provides its own CLR
performance monitoring API to evaluate
the runtime performance of JITed IL code
Allows tighter control over the CLR
JIT environment monitors the execution
Any time a module, assembly, or method loads it will
track that event
Environment
Controller
& Event receiver
EXE
EXE
DLL
Register CLR Profiler
C#DLL
Target Host
Process
Insert & Control the
CLR environment
Hooking
Class
Reflective
Loading
CLR Profiler
CLR
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
38
SETTING IL HOOK
Target, Hooked, and Trampoline
Target Method
Hooked Method
Trampoline Method
Entry Point
Return Value
struct injectorTranpoline {
BYTE methodHeader; // TINY format header
BYTE ilCall01;
DWORD refTranpoline;
BYTE ilRet;
injectorTranpoline(mdMethodDef tkClrHook)
{
ilCall01 = 0x28;
refTranpoline = tkClrHook;
ilRet = 0x2A;
methodHeader =
CorILMethod_TinyFormat|((sizeof(injectorTranpoline)-
1)<<(CorILMethod_FormatShift-1));
}
};
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
39
JIT COMPILER HOOKING
DLL INJECTION & HOOKING
Modify methods on the fly so that a
developer can test inputs for methods
without being invasive
1. An injector process will inject the unmanaged wrapper DLL
into the target process.
2. The wrapper DLL will determine the version of CLR and JIT to
acquire the method offsets for hooking.
3. Using a C-based hooking library called EasyHook the JIT’s
compileMethod functions installs a hook to a prototype of
compileMethod.
4. Now load the C# hooking library into the AppDomain of the
target process.
5. Update the IL code to install the trampoline method to the C#
hooked prototype method.
Target Host Process
C#DLL
DLL
Wrapper DLL
EasyHook
Safe Hooking Library
JIT Compiler
Injected
DLL Injector or Filter Driver
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
40
JIT COMPILER HOOKING
Hooking JIT from
compileMethod()
//Set Jit
p_getJit = (ULONG_PTR *(__stdcall *)()) GetProcAddress(g_hJitModule, "getJit");
if (p_getJit)
{
ICorJitCompiler::Instance = (ICorJitCompiler *)*((ULONG_PTR *)p_getJit());
if (ICorJitCompiler::Instance)
{
DWORD OldProtect;
VirtualProtect(ICorJitCompiler::Instance, sizeof(ULONG_PTR), PAGE_READWRITE,
&OldProtect);
compileMethodcache = ICorJitCompiler::Instance->compileMethodintercept;
ICorJitCompiler::Instance->compileMethodintercept =
&ICorJitCompiler::compileMethod;
VirtualProtect(ICorJitCompiler::Instance, sizeof(ULONG_PTR), OldProtect,
&OldProtect);
//Set Hook
ICorJitCompiler::PFN_compileMethod pfnCompileMethod =
&ICorJitCompiler::compileMethod;
LPVOID * pAddr = (LPVOID*)&pfnCompileMethod;
NTSTATUS ntStatus = LhInstallHook(
(PVOID&)ICorJitCompiler::Instance->compileMethodintercept,
*pAddr,
NULL,
&s_hHookCompileMethod);
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
41
JIT COMPILER HOOKING
0.13164930[2888] Microsoft.PowerShell.ToStringCodeMethods
0.13168100[2888] Microsoft.PowerShell.AdapterCodeMethods
0.13171920[2888] System.Management.Automation.SettingValueExceptionEventArgs
0.13174960[2888] System.Management.Automation.GettingValueExceptionEventArgs
0.13178501[2888] System.Management.Automation.PSObjectPropertyDescriptor
0.13181540[2888] System.Management.Automation.PSObjectTypeDescriptor
0.13184530[2888] System.Management.Automation.PSObjectTypeDescriptionProvider
0.13187569[2888] System.Management.Automation.Runspaces.ConsolidatedString
0.13192080[2888] System.Management.Automation.Runspaces.NodeCardinality
0.13196360[2888] System.Management.Automation.Runspaces.Node
0.13201410[2888] System.Management.Automation.Runspaces.Node+NodeMethod
0.13204980[2888] System.Management.Automation.Runspaces.LoadContext
0.13213710[2888] System.Management.Automation.Runspaces.TypeTableLoadException
0.13217470[2888] System.Management.Automation.Runspaces.TypeData
0.13226460[2888] System.Management.Automation.Runspaces.TypeMemberData
0.13230330[2888] System.Management.Automation.Runspaces.NotePropertyData
0.13233720[2888] System.Management.Automation.Runspaces.AliasPropertyData
0.13237029[2888] System.Management.Automation.Runspaces.ScriptPropertyData
0.13240279[2888] System.Management.Automation.Runspaces.CodePropertyData
0.13243540[2888] System.Management.Automation.Runspaces.ScriptMethodData
0.13246840[2888] System.Management.Automation.Runspaces.CodeMethodData
0.13250659[2888] System.Management.Automation.Runspaces.PropertySetData
0.13254040[2888] System.Management.Automation.Runspaces.TypeTable
0.13258070[2888] System.Management.Automation.ExtendedTypeSystemException
0.13261370[2888] System.Management.Automation.MethodException
PowerShell Eventing From Hooking JIT
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
42
C-BASED METHOD HOOKING
Machine Code Manipulation
Topher’s DEFCON talk illustrated the
manipulation of .NET machine code in
memory locations that were R-W-X after
IL JITed
Tool GreyStorm used to inject shellcode
into memory blocks of methods
.NET Framework
Managed Assembly
Metadata & IL
codes
CLR
clr.dll /
mscorwks.dll
JIT
getJit()
compileMethod()
clrjit.dll/mscorjit.dll
Native/Machine
Code
Hook is Placed
on this Level
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
43
C-BASED METHOD HOOKING
Machine Code Manipulation
Use pointer reflection
Create your traditional ASM trampoline
code in a byte array and overwrite the
method
Need to keep the original method code
Tricky to handle method arguments
Prototype method needs to be accessible
MethodInfo commandCtor =
targetType.GetMethod("ParseScriptBlock");
System.Runtime.CompilerServices.RuntimeHelpers
.PrepareMethod(commandCtor.MethodHandle);
IntPtr commandCtorPtr =
commandCtor.MethodHandle.GetFunctionPointer();
PrepareMethod & GetFunctionPointer
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
44
RESULTS
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
45
SOLUTION RESULTS COMPARISON
Requirements
IL Binary
Modification
CLR Profiler
Hooking
JIT Hooking
Machine Code
Manipulation
Runtime Analysis YES YES YES YES
Run on PowerShell v2+ YES YES YES YES
Stealth vs AMSI YES YES YES YES
Any System Artifacts? YES YES NO NO
NGEN to Be Uninstalled YES YES YES YES
Requires Signature
Validation
YES NO NO NO
Difficulty
High
(If Manual)
Low Medium High
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
46
SOLUTION RESULTS COMPARISON
Requirements
IL Binary
Modification
CLR Profiler
Hooking
JIT Hooking
Machine Code
Manipulation
Runtime Analysis YES YES YES YES
Run on PowerShell v2+ YES YES YES YES
Stealth vs AMSI YES YES YES YES
Any System Artifacts? YES YES NO NO
NGEN to Be Uninstalled YES YES YES YES
Requires Signature
Validation
YES NO NO NO
Difficulty
High
(If Manual)
Low Medium High
3 12
CanSecWest 2017 | .NET Hijacking to Defend PowerShell
47
TAKE AWAYS
INTERCEPT THE ACTUAL POWERSHELL METHOD
STAY STEALTHY
DO IT RIGHT, DON’T CRASH POWERSHELL
WELCOME TO .NET HELL
amanda.secured.org

Weitere ähnliche Inhalte

Was ist angesagt?

Killing any security product … using a Mimikatz undocumented feature
Killing any security product … using a Mimikatz undocumented featureKilling any security product … using a Mimikatz undocumented feature
Killing any security product … using a Mimikatz undocumented featureCyber Security Alliance
 
The origin: Init (compact version)
The origin: Init (compact version)The origin: Init (compact version)
The origin: Init (compact version)Tzung-Bi Shih
 
BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...
BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...
BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...BlueHat Security Conference
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Gavin Guo
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...Cyber Security Alliance
 
syzbot and the tale of million kernel bugs
syzbot and the tale of million kernel bugssyzbot and the tale of million kernel bugs
syzbot and the tale of million kernel bugsDmitry Vyukov
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programmingkozossakai
 
Ищем уязвимости нулевого дня в ядре Linux
Ищем уязвимости нулевого дня в ядре LinuxИщем уязвимости нулевого дня в ядре Linux
Ищем уязвимости нулевого дня в ядре LinuxPositive Hack Days
 
Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!Anne Nicolas
 
Csw2016 tang virtualization_device emulator testing technology
Csw2016 tang virtualization_device emulator testing technologyCsw2016 tang virtualization_device emulator testing technology
Csw2016 tang virtualization_device emulator testing technologyCanSecWest
 
Статический анализ кода в контексте SSDL
Статический анализ кода в контексте SSDLСтатический анализ кода в контексте SSDL
Статический анализ кода в контексте SSDLPositive Hack Days
 
How to Root 10 Million Phones with One Exploit
How to Root 10 Million Phones with One ExploitHow to Root 10 Million Phones with One Exploit
How to Root 10 Million Phones with One ExploitJiahong Fang
 
Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?inaz2
 
Davide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruptionDavide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruptionlinuxlab_conf
 
Awesome_fuzzing_for _pentester_red-pill_2017
Awesome_fuzzing_for _pentester_red-pill_2017Awesome_fuzzing_for _pentester_red-pill_2017
Awesome_fuzzing_for _pentester_red-pill_2017Manich Koomsusi
 
syzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzersyzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzerDmitry Vyukov
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon chinaPeter Hlavaty
 
BlueHat v18 || Hardening hyper-v through offensive security research
BlueHat v18 || Hardening hyper-v through offensive security researchBlueHat v18 || Hardening hyper-v through offensive security research
BlueHat v18 || Hardening hyper-v through offensive security researchBlueHat Security Conference
 
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...CODE BLUE
 
[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes
[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes
[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik OpcodesCODE BLUE
 

Was ist angesagt? (20)

Killing any security product … using a Mimikatz undocumented feature
Killing any security product … using a Mimikatz undocumented featureKilling any security product … using a Mimikatz undocumented feature
Killing any security product … using a Mimikatz undocumented feature
 
The origin: Init (compact version)
The origin: Init (compact version)The origin: Init (compact version)
The origin: Init (compact version)
 
BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...
BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...
BlueHat v18 || Straight outta v mware - modern exploitation of the svga devic...
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
 
syzbot and the tale of million kernel bugs
syzbot and the tale of million kernel bugssyzbot and the tale of million kernel bugs
syzbot and the tale of million kernel bugs
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programming
 
Ищем уязвимости нулевого дня в ядре Linux
Ищем уязвимости нулевого дня в ядре LinuxИщем уязвимости нулевого дня в ядре Linux
Ищем уязвимости нулевого дня в ядре Linux
 
Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!Kernel Recipes 2019 - CVEs are dead, long live the CVE!
Kernel Recipes 2019 - CVEs are dead, long live the CVE!
 
Csw2016 tang virtualization_device emulator testing technology
Csw2016 tang virtualization_device emulator testing technologyCsw2016 tang virtualization_device emulator testing technology
Csw2016 tang virtualization_device emulator testing technology
 
Статический анализ кода в контексте SSDL
Статический анализ кода в контексте SSDLСтатический анализ кода в контексте SSDL
Статический анализ кода в контексте SSDL
 
How to Root 10 Million Phones with One Exploit
How to Root 10 Million Phones with One ExploitHow to Root 10 Million Phones with One Exploit
How to Root 10 Million Phones with One Exploit
 
Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?
 
Davide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruptionDavide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruption
 
Awesome_fuzzing_for _pentester_red-pill_2017
Awesome_fuzzing_for _pentester_red-pill_2017Awesome_fuzzing_for _pentester_red-pill_2017
Awesome_fuzzing_for _pentester_red-pill_2017
 
syzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzersyzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzer
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon china
 
BlueHat v18 || Hardening hyper-v through offensive security research
BlueHat v18 || Hardening hyper-v through offensive security researchBlueHat v18 || Hardening hyper-v through offensive security research
BlueHat v18 || Hardening hyper-v through offensive security research
 
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
 
[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes
[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes
[CB17] Trueseeing: Effective Dataflow Analysis over Dalvik Opcodes
 

Andere mochten auch

CSW2017 Harri hursti csw17 final
CSW2017 Harri hursti csw17 finalCSW2017 Harri hursti csw17 final
CSW2017 Harri hursti csw17 finalCanSecWest
 
CSW2017 Kyle ehmke lots of squats- ap-ts never miss leg day
CSW2017 Kyle ehmke lots of squats- ap-ts never miss leg dayCSW2017 Kyle ehmke lots of squats- ap-ts never miss leg day
CSW2017 Kyle ehmke lots of squats- ap-ts never miss leg dayCanSecWest
 
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoTCSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoTCanSecWest
 
CSW2017 Scott kelly secureboot-csw2017-v1
CSW2017 Scott kelly secureboot-csw2017-v1CSW2017 Scott kelly secureboot-csw2017-v1
CSW2017 Scott kelly secureboot-csw2017-v1CanSecWest
 
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu security
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu securityCSW2017 Qiang li zhibinhu_meiwang_dig into qemu security
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu securityCanSecWest
 
Csw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelistingCsw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelistingCanSecWest
 
CSW2017 Qinghao tang+Xinlei ying vmware_escape_final
CSW2017 Qinghao tang+Xinlei ying vmware_escape_finalCSW2017 Qinghao tang+Xinlei ying vmware_escape_final
CSW2017 Qinghao tang+Xinlei ying vmware_escape_finalCanSecWest
 
CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017CanSecWest
 
CSW2017 Privilege escalation on high-end servers due to implementation gaps i...
CSW2017 Privilege escalation on high-end servers due to implementation gaps i...CSW2017 Privilege escalation on high-end servers due to implementation gaps i...
CSW2017 Privilege escalation on high-end servers due to implementation gaps i...CanSecWest
 
CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...
CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...
CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...CanSecWest
 
CSW2017 Saumil shah stegosploit_internals_cansecwest_2017
CSW2017 Saumil shah stegosploit_internals_cansecwest_2017CSW2017 Saumil shah stegosploit_internals_cansecwest_2017
CSW2017 Saumil shah stegosploit_internals_cansecwest_2017CanSecWest
 
CSW2017 Weston miller csw17_mitigating_native_remote_code_execution
CSW2017 Weston miller csw17_mitigating_native_remote_code_executionCSW2017 Weston miller csw17_mitigating_native_remote_code_execution
CSW2017 Weston miller csw17_mitigating_native_remote_code_executionCanSecWest
 
CSW2017 Mickey+maggie low cost radio attacks on modern platforms
CSW2017 Mickey+maggie low cost radio attacks on modern platformsCSW2017 Mickey+maggie low cost radio attacks on modern platforms
CSW2017 Mickey+maggie low cost radio attacks on modern platformsCanSecWest
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CanSecWest
 
CSW2017 Enrico branca What if encrypted communications are not as secure as w...
CSW2017 Enrico branca What if encrypted communications are not as secure as w...CSW2017 Enrico branca What if encrypted communications are not as secure as w...
CSW2017 Enrico branca What if encrypted communications are not as secure as w...CanSecWest
 
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_markCSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_markCanSecWest
 
Csw2016 song li-smart_wars
Csw2016 song li-smart_warsCsw2016 song li-smart_wars
Csw2016 song li-smart_warsCanSecWest
 
CSW2017 jun li_car anomaly detection
CSW2017  jun li_car anomaly detectionCSW2017  jun li_car anomaly detection
CSW2017 jun li_car anomaly detectionCanSecWest
 
Csw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooksCsw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooksCanSecWest
 
Csw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgenerationCsw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgenerationCanSecWest
 

Andere mochten auch (20)

CSW2017 Harri hursti csw17 final
CSW2017 Harri hursti csw17 finalCSW2017 Harri hursti csw17 final
CSW2017 Harri hursti csw17 final
 
CSW2017 Kyle ehmke lots of squats- ap-ts never miss leg day
CSW2017 Kyle ehmke lots of squats- ap-ts never miss leg dayCSW2017 Kyle ehmke lots of squats- ap-ts never miss leg day
CSW2017 Kyle ehmke lots of squats- ap-ts never miss leg day
 
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoTCSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
 
CSW2017 Scott kelly secureboot-csw2017-v1
CSW2017 Scott kelly secureboot-csw2017-v1CSW2017 Scott kelly secureboot-csw2017-v1
CSW2017 Scott kelly secureboot-csw2017-v1
 
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu security
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu securityCSW2017 Qiang li zhibinhu_meiwang_dig into qemu security
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu security
 
Csw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelistingCsw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelisting
 
CSW2017 Qinghao tang+Xinlei ying vmware_escape_final
CSW2017 Qinghao tang+Xinlei ying vmware_escape_finalCSW2017 Qinghao tang+Xinlei ying vmware_escape_final
CSW2017 Qinghao tang+Xinlei ying vmware_escape_final
 
CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017
 
CSW2017 Privilege escalation on high-end servers due to implementation gaps i...
CSW2017 Privilege escalation on high-end servers due to implementation gaps i...CSW2017 Privilege escalation on high-end servers due to implementation gaps i...
CSW2017 Privilege escalation on high-end servers due to implementation gaps i...
 
CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...
CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...
CSW2017 Minrui yan+Jianhao-liu a visualization tool for evaluating can-bus cy...
 
CSW2017 Saumil shah stegosploit_internals_cansecwest_2017
CSW2017 Saumil shah stegosploit_internals_cansecwest_2017CSW2017 Saumil shah stegosploit_internals_cansecwest_2017
CSW2017 Saumil shah stegosploit_internals_cansecwest_2017
 
CSW2017 Weston miller csw17_mitigating_native_remote_code_execution
CSW2017 Weston miller csw17_mitigating_native_remote_code_executionCSW2017 Weston miller csw17_mitigating_native_remote_code_execution
CSW2017 Weston miller csw17_mitigating_native_remote_code_execution
 
CSW2017 Mickey+maggie low cost radio attacks on modern platforms
CSW2017 Mickey+maggie low cost radio attacks on modern platformsCSW2017 Mickey+maggie low cost radio attacks on modern platforms
CSW2017 Mickey+maggie low cost radio attacks on modern platforms
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
CSW2017 Enrico branca What if encrypted communications are not as secure as w...
CSW2017 Enrico branca What if encrypted communications are not as secure as w...CSW2017 Enrico branca What if encrypted communications are not as secure as w...
CSW2017 Enrico branca What if encrypted communications are not as secure as w...
 
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_markCSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
 
Csw2016 song li-smart_wars
Csw2016 song li-smart_warsCsw2016 song li-smart_wars
Csw2016 song li-smart_wars
 
CSW2017 jun li_car anomaly detection
CSW2017  jun li_car anomaly detectionCSW2017  jun li_car anomaly detection
CSW2017 jun li_car anomaly detection
 
Csw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooksCsw2016 macaulay eh_trace-rop_hooks
Csw2016 macaulay eh_trace-rop_hooks
 
Csw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgenerationCsw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgeneration
 

Ähnlich wie CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell

.Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 .Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 Amanda Rousseau
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet IntroductionWei Sun
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonnettitude_labs
 
Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Wei Sun
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법GangSeok Lee
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 
Introdot Netc Sharp En
Introdot Netc Sharp EnIntrodot Netc Sharp En
Introdot Netc Sharp EnGregory Renard
 
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
 
Top 20 Asp.net interview Question and answers
Top 20 Asp.net interview Question and answersTop 20 Asp.net interview Question and answers
Top 20 Asp.net interview Question and answersw3asp dotnet
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging TechniquesBala Subra
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and TechniquesBala Subra
 
150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrind150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrindRaghu Palakodety
 
Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)
Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)
Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)WE-IT TUTORIALS
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack webhostingguy
 
Linux Assignment 3
Linux Assignment 3Linux Assignment 3
Linux Assignment 3Diane Allen
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerunidsecconf
 

Ähnlich wie CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell (20)

.Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017 .Net Hijacking to Defend PowerShell BSidesSF2017
.Net Hijacking to Defend PowerShell BSidesSF2017
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet Introduction
 
powershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-londonpowershell-is-dead-epic-learnings-london
powershell-is-dead-epic-learnings-london
 
Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
Introduction to Visual Studio.NET
Introduction to Visual Studio.NETIntroduction to Visual Studio.NET
Introduction to Visual Studio.NET
 
Introdot Netc Sharp En
Introdot Netc Sharp EnIntrodot Netc Sharp En
Introdot Netc Sharp En
 
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)
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
Top 20 Asp.net interview Question and answers
Top 20 Asp.net interview Question and answersTop 20 Asp.net interview Question and answers
Top 20 Asp.net interview Question and answers
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
 
150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrind150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrind
 
Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)
Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)
Tycs sem 5 asp.net notes unit 1 2 3 4 (2017)
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack
 
Linux Assignment 3
Linux Assignment 3Linux Assignment 3
Linux Assignment 3
 
Technology to Stop Hackers
Technology to Stop Hackers Technology to Stop Hackers
Technology to Stop Hackers
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerun
 

Mehr von CanSecWest

Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updatedCsw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updatedCanSecWest
 
CSW2017 Geshev+Miller logic bug hunting in chrome on android
CSW2017 Geshev+Miller logic bug hunting in chrome on androidCSW2017 Geshev+Miller logic bug hunting in chrome on android
CSW2017 Geshev+Miller logic bug hunting in chrome on androidCanSecWest
 
CSW2017 chuanda ding_state of windows application security
CSW2017 chuanda ding_state of windows application securityCSW2017 chuanda ding_state of windows application security
CSW2017 chuanda ding_state of windows application securityCanSecWest
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCanSecWest
 
Csw2016 wang docker_escapetechnology
Csw2016 wang docker_escapetechnologyCsw2016 wang docker_escapetechnology
Csw2016 wang docker_escapetechnologyCanSecWest
 
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerabilityCsw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerabilityCanSecWest
 

Mehr von CanSecWest (6)

Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updatedCsw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
 
CSW2017 Geshev+Miller logic bug hunting in chrome on android
CSW2017 Geshev+Miller logic bug hunting in chrome on androidCSW2017 Geshev+Miller logic bug hunting in chrome on android
CSW2017 Geshev+Miller logic bug hunting in chrome on android
 
CSW2017 chuanda ding_state of windows application security
CSW2017 chuanda ding_state of windows application securityCSW2017 chuanda ding_state of windows application security
CSW2017 chuanda ding_state of windows application security
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
 
Csw2016 wang docker_escapetechnology
Csw2016 wang docker_escapetechnologyCsw2016 wang docker_escapetechnology
Csw2016 wang docker_escapetechnology
 
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerabilityCsw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
 

Kürzlich hochgeladen

(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge GraphsEleniIlkou
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...SUHANI PANDEY
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...SUHANI PANDEY
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls DubaiEscorts Call Girls
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...SUHANI PANDEY
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...SUHANI PANDEY
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...SUHANI PANDEY
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...roncy bisnoi
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceEscorts Call Girls
 

Kürzlich hochgeladen (20)

(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 

CSW2017 Amanda rousseau cansecwest2017_net_hijacking_powershell

  • 1. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 1 AMANDA ROUSSEAU .NET HIJACKING to DEFEND POWERSHELL
  • 2. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 2 AMANDA ROUSSEAU MALWARE UNICORN Senior Malware Researcher @ Endgame, Inc. Works as a Malware Researcher at Endgame who focuses on attacker technique application to dynamic behavior detection both on Windows and OSX platforms. @malwareunicorn
  • 3. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 3 GOALS Allow PowerShell to be run in a normal environment Analyze de-obfuscated commands Remain stealthy in the environment to avoid bypasses Allows run-time analysis and blocking Supports PowerShell v2-5 STEALTHY, RUN-TIME MONITORING. What Do We Need?
  • 4. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 4 CLR PROFILING JIT COMPILER HOOKING IL BINARY MODIFCATION C-BASED METHOD HOOKING CONTENT OVERVIEW SOLUTIONS: .NET OVERVIEW POWERSHELL OVERVIEW ATTACK HISTORY C# DLL INJECTION FOUNDATIONS:
  • 5. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 5 TIMELINE Offensive PowerShell and .NET Attacks ATTACK HISTORY 2012 2013 2014 2015 2016 Plotus (10/2013) Power Worm (3/2014) Syrian Malware (8/2014) PoweLiks (8/2014) CoinVault Rasnomware (11/ 2014) PowerDuke Backdoor (11/2016) PowerSniff (3/2016) Trojan.Laziok (4/2016) PowerShell Ransomware (5/2016) Fileless Backdoor (8/2015) PS>Attack (12/2015) Hunter EK (8/2015) PowerShell Empire (2014) ConfuserEx (5/2014) Nishang (8/2012) PowerSploit (2012)
  • 6. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 6 PHISHING CAMPAIGNS Utilizing scripting for transitioning from the 1st stage of the attack to the 2nd stage payload PoweLiks PowerSniff PowerDuke Hunter Exploit Kit Diagram of PoweLiks 1 2
  • 7. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 7 BAD MALWARE PICKUP LINES Hey girl, do you like PowerShell? Because I'd like to stay persistent in your memory ;) “ ”
  • 8. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 8 OBFUSCATION ANALYSIS EVASION Script Obfuscation Code Protection Applications: ConfuserEx .NET Reactor: string encryption anti-decompilation control flow obfuscation anti-tampering Invoke-Obfuscation CoinVault obfuscated C# Code
  • 9. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 9 POWERSHELL EMPIRE PS>ATTACK NISHANGPOWERSPLOIT OFFENSIVE FRAMEWORKS PowerShell Offensive Frameworks Useful for automating attacks and post- exploitation routines Collection of scripts to automate tasks such as: • analysis evasion • remote execution • privilege escalation • lateral movement • exfiltration Command to reflectively load and execute a PE binary into memory Improve and propagate these PowerShell offensive techniques
  • 10. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 10 FOUNDATIONS of .NET C O M M O N L A N G U A G E R U N T I M E ( C L R ) J U S T - I N - T I M E ( J I T ) “ S T R O N G N A M E D ” A S S E M B L I E S N G E N A S S E M B L I E S D E C O M P I L I N G . N E T B I N A R I E S I N T E R M E D I A T E L A N G A G E ( I L ) .NET Framework Compiler C# Code Managed Assembly Metadata & IL codes CLR clr.dll / mscorwks.dll JIT getJit() compileMethod() clrjit.dll/mscorjit.dll Native/Machine Code Referenced Assemblies
  • 11. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 11 COMMON LANGUAGE RUNTIME (CLR) UNMANAGED Vs MANAGED Handler that manages: Dependencies Memory Exceptions Synchronization Managed Assemblies Metadata & IL Code No additional information is required Agnostic across architectures C# vs IL Code PowerShell ScriptBlock Create
  • 12. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 12 JUST-IN-TIME COMPILER (JIT) IL CODE -> NATIVE CODE Convert and optimize the IL code into native CPU instructions which is then stored in dynamic memory getJit() compileMethod() JIT Order of Operations JITCompiler 1) Metadata Lookup Table Index of MethodInfo Memory Block 3) Convert IL to CPU Instructions & Store in Memory Block 4) Update Method’s entry point in the table 5) Jump to memory & execute Return Back to Compiler 2) Allocate
  • 13. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 13 JUST-IN-TIME COMPILER (JIT) METADATA LOOKUPS Assembly contains metadata tables Lists of objects with names, offsets Method Tokens are unique per module Assembly Metadata Metadata Table Description ModuleDef (0x00) Identity of the module TypeDef (0x01) List of class Types and the indexes to the methods that each class owns MethodDef (0x02) Each method entry contains the name, offset location, flags, and signature. Assembly (0x20) Contains information about the current assembly. AssemblyRef (0x23) Contains information about the referenced assemblies. MemberRef (0x0A) Contains each member including methods referenced by the module.
  • 14. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 14 JUST-IN-TIME COMPILER (JIT) TRAVERSING THE METADATA Download JIT .PDB Identify function offsets for hooking Need to traverse the MethodDesc Tables to update the information for methods JIT Compiler Function Offsets D971C845B82D877107906335EFF1824C#32_2_0_50727_8670 2621605;MethodDesc::s_pfnReset 55606;MethodDesc::s_pfnIsGenericMethodDefinition 60512;MethodDesc::s_pfnGetNumGenericMethodArgs 762227;MethodDesc::s_pfnStripMethodInstantiation 60894;MethodDesc::s_pfnHasClassOrMethodInstantiation 160213;MethodDesc::s_pfnContainsGenericVariables 1179150;MethodDesc::s_pfnGetWrappedMethodDesc 56056;MethodDesc::s_pfnGetDomain 1020785;MethodDesc::s_pfnGetLoaderModule 4801122;LoadedMethodDescIterator::s_pfnConstructor 0;LoadedMethodDescIterator::s_pfnConstructor_v45 0;LoadedMethodDescIterator::s_pfnConstructor_v46 4950262;LoadedMethodDescIterator::s_pfnStart 0;LoadedMethodDescIterator::s_pfnNext_v4 4950393;LoadedMethodDescIterator::s_pfnNext_v2 4950297;LoadedMethodDescIterator::s_pfnCurrent_F43F7 0AF86B02890FCF95ED91EA373BB#32_4_0_30319_17929 _1BC333D76444B51B01A74B7447ADBC9E#64_2_0_50727_4963
  • 15. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 15 MICROSOFT INTERMEDIATE LANGUAGE (MSIL) CPU agnostic machine language that operates on a slightly higher level CLI instruction set standard from ECMA-335 Address is a 4-byte value called a token Relevant only to assembly JIT Optimizes the IL instructions Extraneous instructions such as NOP codes will be removed to improve performance IL Instructions
  • 16. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 16 MICROSOFT INTERMEDIATE LANGUAGE (MSIL) CPU agnostic machine language that operates on a slightly higher level Pushed and popped on the stack .maxstack refers the stack slot size needed for arguments and local variables After JIT Can acquire the virtual memory address of the method. Using GetFunctionPointer. .method /*06002149*/ public hidebysig static class System.Management.Automation.ScriptBlock/*02000316*/ Create(string script) cil managed // SIG: 00 01 12 8C 58 0E { // Method begins at RVA 0xa9499 // Code size 12 (0xc) .maxstack 8 IL_0000: /*73|(06)001FDA*/ newobj instance void System.Management.Automation.Parser/*020002F7*/::.ctor () /*06001FDA*/ IL_0005: /*02|*/ ldarg.0 IL_0006: /*28|(06)00214A*/ call class System.Management.Automation.ScriptBlock/*02000316*/ System.Management.Automation.ScriptBlock/*02000316*/:: Create(class System.Management.Automation.Parser/*020002F7*/, string) /*0600214A*/ IL_000b: /*2A|*/ ret } // end of method ScriptBlock::Create PowerShell ScriptBlock IL Instructions
  • 17. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 17 DECOMPILING .NET BINARIES Can easily be decompiled & disassembled Tools rely on disassembling the IL code and reconstructing the C# code based on the metadata definition original function names function offsets membership to parent classes Tools dotPeek dnSpy ILspy De4dot ILAsm.exe & ILDasm.exe
  • 18. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 18 DECOMPILING .NET BINARIES DotPeek https://www.jetbrains.com/decompiler/
  • 19. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 19 STRONG NAMED ASSEMBLIES Fixes version dependency from DLL Hell Uniquely identified assemblies signed with a publisher’s public/private key pair Public key is embedded into the header of the assembly Intended to tamper-resistant Global assembly cache (GAC) .NET tool gacutil.exe to install assembly Weak assemblies searched by its file name and executable extension with in the containing folder. Public Key Token Reference for Mscorlib GAC Locations
  • 20. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 20 STRONG NAMED ASSEMBLIES BYPASSING ANTI-TAMPERING .NET Framework version 3.5 Service Pack 1 Strong-name signatures are not validated when an assembly is loaded DISABLING STRONG NAME SIGNATURE VERIFICATION Arch Windows Registry Key to Disable for All Applications 32 HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFra meworkAllowStrongNameBypass 64 HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFra meworkAllowStrongNameBypass HKEY_LOCAL_MACHINESOFTWAREWow6432NodeM icrosoft.NETFrameworkAllowStrongNameBypass C# Application Configuration for One Application <configuration> <runtime> <bypassTrustedAppStrongNames enabled="false" /> </runtime> </configuration>
  • 21. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 21 NGEN ASSEMBLIES BYPASSES JIT COMPILATION Native Images are precompiled native code PE binaries Install & Uninstall Ngen.exe Contains both IL & Machine Code Code will load native images before IL assemblies Native Images C:WindowsassemblyNativeImages_v2.0.50727_32 C:WindowsassemblyNativeImages_v2.0.50727_64 C:WindowsassemblyNativeImages_v4.0.30319_32 C:WindowsassemblyNativeImages_v4.0.30319_64 System.Management.Automation.ni.dll System.Management.Automation.dll IL Assembly Native Image
  • 22. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 22 C# Programs POWERSHELL A POWERFUL SCRIPTING LANGUAGE Directly access globally cached .NET assemblies Reflectively load .NET assemblies which can load C-based Windows libraries Run unsigned scripts locally Run scripts that are interpreted and executed as base64 strings. System.Management.Automation.dll PowerShell.exe .NET FRAMEWORK CLRJIT Machine Code
  • 23. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 23 POWERSHELL All string or stream based scripts are parsed and compiled within a ScriptBlock. PowerShell source code differs in each version PowerShell ScriptBlock Create public static ScriptBlock Create(string script) { return ScriptBlock.Create(new Parser(), script); } PS Version Released Default Windows Versions .NET CLR Versions 1.0 2006 WinServer 2008 2.0.50727 2.0 2009 Win7 WinServer 2008 R2 2.0.50727 3.0 2012 Win8 WinServer 2012 4.0.30319 4.5+ 4.0 2013 Wuin8.1 WinServer 2012 R2 4.0.30319 4.5+ 5.0 2014 Win10 4.5+ SCRIPTBLOCKS
  • 24. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 24 BAD MALWARE PICKUP LINES Hey girl, do you like PowerShell? I can tell you do by the invoked expression I gave you ;) “ ”
  • 25. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 25 POWERSHELL Runspaces allows C# code to invoke PowerShell commands PowerSploit SharpPick -> Invoke-Expression and Invoke- Command that will execute piped string input or a ScriptBlock in the local or remote shell contexts RUNSPACES, INVOKE, WIN API
  • 26. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 26 POWERSHELL .NET assemblies and can reflectively load C-based Windows DLL RUNSPACES, INVOKE, WIN API # Get a reference to System.dll in the GAC $SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('')[-1].Equals('System.dll') } $UnsafeNativeMethods = $SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods') # Get a reference to the GetModuleHandle and GetProcAddress methods $GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle') $GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress') # Get a handle to the module specified $Kern32Handle = $GetModuleHandle.Invoke($null, @($Module)) $tmpPtr = New-Object IntPtr $HandleRef = New-Object System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle) PowerSploit: Invoke-Shellcode
  • 27. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 27 AMSI PowerShell v5 Anti-Malware Scan Interface Windows 10 Allows Windows Defender and third party Anti-virus solutions access the script code Provides: Memory and Stream scanning De-obfuscated plain code Detect C# .NET usage of the PowerShell assembly PowerShell.exe System.Management.Automation.dll GetCodeToInvoke() Compile() PerformSecurityCheck() ScanContent() AMSI.dll AmsiScanString() COM API Interface RPC Windows Defender MPCLIENT.dll Anti Malware Scan Interface
  • 28. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 28 AMSI SUSPICIOUS METHODS GetMethod GetMethods GetNestedType GetNestedTypes GetProperties GetProperty InvokeMember GetDelegateForFunctionPointer kernel32 … Anti Malware Scan Interface System.Management. Automation.ScriptBlock. CheckSuspiciousContent
  • 29. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 29 AMSI BYPASSES SIGNATURE BYPASS Windows Defender relies on known variable names to block a malicious script String obfuscation on the variable name $code = @" Sv ('R9'+'HYt') ( " ) )93]rahC[]gnirtS[,'UCS'(ecalpeR.)63]rahC[]gnirtS[,'aEm'(ecalpe R.)')eurt'+'aEm,llun'+'aEm(eulaVt'+'eS'+'.)UCScit'+'atS,ci'+'l buPnoNUCS'+',U'+'CSdeli'+'aFt'+'inI'+'is'+'maUCS('+'dle'+'iF'+ 'teG'+'.'+')'+'UCSslitU'+'is'+'mA.noitamotu'+'A.tn'+'em'+'egan aM.'+'m'+'e'+'t'+'sySUCS(epy'+'TteG.ylbmessA'+'.]'+'feR['( (noisserpxE-ekovnI" ); Invoke-Expression( -Join ( VaRIAbLe ('R9'+'hyT') -val )[ - 1..- (( VaRIAbLe ('R9'+'hyT') -val ).Length)])"@ NISHANG AMSI BYPASS
  • 30. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 30 AMSI BYPASSES DISABLING AMSI AMSI provides a command to disable the real-time monitoring for Windows Defender DLL Load Hijacking to replace ASMI.dll p0wnshell was trying to load the AMSI.dll in the local executing directory Place a fake copy of the ASMI.dll in this local directory Disable AMSI using Set-MpPreference PS C:> Set-MpPreference -DisableRealtimeMonitoring $true Fake AMSI.DLL
  • 31. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 31 AMSI BYPASSES ASSEMBLY FIELD MODIFICATION Using .NET reflection, a user can modify values within a class. When the AmsiUtils class is loaded, the class initialization result can be modified to appear as failed by setting it to True. PowerShell to Disable AMSI by Setting AmsiInitFailed AMSI Integration code [Ref].Assembly.GetType(‘System.Management.Automation.AmsiUtils ').GetField('amsiInitFailed','NonPublic,Static').SetValue($nul l,$true) int AMSIIntegration() { HAMSICONTEXT amsiContext; HRESULT hres; hres = CoInitializeEx(0, COINIT_MULTITHREADED); hres = AmsiInitialize(L"Win32Project2", &amsiContext); if (FAILED(hres)) { std::cout << "AmsiInitialize fails" << std::endl; CoUninitialize(); return -1; // Program has failed. }
  • 32. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 32 C# DLL INJECTION .NET ROOTKITS BINARY MODIFICATION CLR PROFILING JIT COMPILER HOOKING C-BASED METHOD HOOKING METHODS AND SOLUTIONS
  • 33. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 33 C# DLL INJECTION To run an injected C# assembly DLL, it must be first wrapped in a C-based wrapper DLL C# DLL does not have a DllMain() Determine the version of CLR Host process will use the environment’s .NET version unless forced to an older version Will need to be a payload compiled for different major version of .NET (2.0,3.5,4.0,4.5, and 4.6). Target Host Process C#DLL Wrapper DLL JIT Compiler Injected DLL Injector or Filter Driver
  • 34. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 34 C# DLL INJECTION Load mscoree.dll CLR library Load the C# payload into the host process’s C# AppDomain Using a precompiled C# payload and adding it as an embedded resource in the parent C-based DLL CoCreateInstance to access the CLR runtime environment of the host process Grab the AppDomain and load the assembly as a bytearray stored in the resource section CoInitializeEx(0, COINIT_MULTITHREADED); ICorRuntimeHost* pICorRuntimeHost = 0; HRESULT st = CoCreateInstance(CLSID_CorRuntimeHost, 0, CLSCTX_ALL, IID_ICorRuntimeHost, (void**)&pICorRuntimeHost); if (!pICorRuntimeHost) { return 1; } HDOMAINENUM hEnum = NULL; pICorRuntimeHost->EnumDomains(&hEnum); if (!hEnum) { return 1; } IUnknown* pUunk = 0; st = pICorRuntimeHost->NextDomain(hEnum, &pUunk); if (!pUunk) { return 1; } CComPtr<mscorlib::_AppDomain> pAppDomain = NULL; st = pUunk->QueryInterface( __uuidof( CComPtr<mscorlib::_AppDomain>), (VOID**)&pAppDomain); if (!pAppDomain) { return 1; }
  • 35. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 35 NET ROOTKITS BINARY MODIFICATION MODIFYING GAC ASSEMBLY Metula’s BlackHat talk about developing .NET framework rootkits 1. Targeting a GAC assembly to decompile into its IL code 2. Modify the IL code by injecting functions 3. Recompiling the IL 4. Force the framework to use the modified DLL IL Codes Disassembles using ILDasm Insert Loader Function Reassemble using ILAsm C# Compiled Assembly DLL %SystemRoot%Microsoft.NETAssemblyGAC_MSILSystem.M anagement.Automation<version>System.Management.Auto mation.dll Overwrite Original DLL
  • 36. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 36 NET ROOTKITS BINARY MODIFICATION Avoid Human Error .NET-Sploit dotNetHookLibrary Mono.Cecil Load existing assemblies statically or dynamically to modify the IL code to insert new code for you Used by both developers and gaming hackers AssemblyDef ModuleDefModuleDef FieldDefTypeDef PropertyDefMethodDef SetMethod GetMethod Methods Constructors Properties Fields Modules MainModule
  • 37. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 37 CLR PROFILING CLR DYNAMIC HOOK INJECTION .NET framework provides its own CLR performance monitoring API to evaluate the runtime performance of JITed IL code Allows tighter control over the CLR JIT environment monitors the execution Any time a module, assembly, or method loads it will track that event Environment Controller & Event receiver EXE EXE DLL Register CLR Profiler C#DLL Target Host Process Insert & Control the CLR environment Hooking Class Reflective Loading CLR Profiler CLR
  • 38. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 38 SETTING IL HOOK Target, Hooked, and Trampoline Target Method Hooked Method Trampoline Method Entry Point Return Value struct injectorTranpoline { BYTE methodHeader; // TINY format header BYTE ilCall01; DWORD refTranpoline; BYTE ilRet; injectorTranpoline(mdMethodDef tkClrHook) { ilCall01 = 0x28; refTranpoline = tkClrHook; ilRet = 0x2A; methodHeader = CorILMethod_TinyFormat|((sizeof(injectorTranpoline)- 1)<<(CorILMethod_FormatShift-1)); } };
  • 39. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 39 JIT COMPILER HOOKING DLL INJECTION & HOOKING Modify methods on the fly so that a developer can test inputs for methods without being invasive 1. An injector process will inject the unmanaged wrapper DLL into the target process. 2. The wrapper DLL will determine the version of CLR and JIT to acquire the method offsets for hooking. 3. Using a C-based hooking library called EasyHook the JIT’s compileMethod functions installs a hook to a prototype of compileMethod. 4. Now load the C# hooking library into the AppDomain of the target process. 5. Update the IL code to install the trampoline method to the C# hooked prototype method. Target Host Process C#DLL DLL Wrapper DLL EasyHook Safe Hooking Library JIT Compiler Injected DLL Injector or Filter Driver
  • 40. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 40 JIT COMPILER HOOKING Hooking JIT from compileMethod() //Set Jit p_getJit = (ULONG_PTR *(__stdcall *)()) GetProcAddress(g_hJitModule, "getJit"); if (p_getJit) { ICorJitCompiler::Instance = (ICorJitCompiler *)*((ULONG_PTR *)p_getJit()); if (ICorJitCompiler::Instance) { DWORD OldProtect; VirtualProtect(ICorJitCompiler::Instance, sizeof(ULONG_PTR), PAGE_READWRITE, &OldProtect); compileMethodcache = ICorJitCompiler::Instance->compileMethodintercept; ICorJitCompiler::Instance->compileMethodintercept = &ICorJitCompiler::compileMethod; VirtualProtect(ICorJitCompiler::Instance, sizeof(ULONG_PTR), OldProtect, &OldProtect); //Set Hook ICorJitCompiler::PFN_compileMethod pfnCompileMethod = &ICorJitCompiler::compileMethod; LPVOID * pAddr = (LPVOID*)&pfnCompileMethod; NTSTATUS ntStatus = LhInstallHook( (PVOID&)ICorJitCompiler::Instance->compileMethodintercept, *pAddr, NULL, &s_hHookCompileMethod);
  • 41. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 41 JIT COMPILER HOOKING 0.13164930[2888] Microsoft.PowerShell.ToStringCodeMethods 0.13168100[2888] Microsoft.PowerShell.AdapterCodeMethods 0.13171920[2888] System.Management.Automation.SettingValueExceptionEventArgs 0.13174960[2888] System.Management.Automation.GettingValueExceptionEventArgs 0.13178501[2888] System.Management.Automation.PSObjectPropertyDescriptor 0.13181540[2888] System.Management.Automation.PSObjectTypeDescriptor 0.13184530[2888] System.Management.Automation.PSObjectTypeDescriptionProvider 0.13187569[2888] System.Management.Automation.Runspaces.ConsolidatedString 0.13192080[2888] System.Management.Automation.Runspaces.NodeCardinality 0.13196360[2888] System.Management.Automation.Runspaces.Node 0.13201410[2888] System.Management.Automation.Runspaces.Node+NodeMethod 0.13204980[2888] System.Management.Automation.Runspaces.LoadContext 0.13213710[2888] System.Management.Automation.Runspaces.TypeTableLoadException 0.13217470[2888] System.Management.Automation.Runspaces.TypeData 0.13226460[2888] System.Management.Automation.Runspaces.TypeMemberData 0.13230330[2888] System.Management.Automation.Runspaces.NotePropertyData 0.13233720[2888] System.Management.Automation.Runspaces.AliasPropertyData 0.13237029[2888] System.Management.Automation.Runspaces.ScriptPropertyData 0.13240279[2888] System.Management.Automation.Runspaces.CodePropertyData 0.13243540[2888] System.Management.Automation.Runspaces.ScriptMethodData 0.13246840[2888] System.Management.Automation.Runspaces.CodeMethodData 0.13250659[2888] System.Management.Automation.Runspaces.PropertySetData 0.13254040[2888] System.Management.Automation.Runspaces.TypeTable 0.13258070[2888] System.Management.Automation.ExtendedTypeSystemException 0.13261370[2888] System.Management.Automation.MethodException PowerShell Eventing From Hooking JIT
  • 42. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 42 C-BASED METHOD HOOKING Machine Code Manipulation Topher’s DEFCON talk illustrated the manipulation of .NET machine code in memory locations that were R-W-X after IL JITed Tool GreyStorm used to inject shellcode into memory blocks of methods .NET Framework Managed Assembly Metadata & IL codes CLR clr.dll / mscorwks.dll JIT getJit() compileMethod() clrjit.dll/mscorjit.dll Native/Machine Code Hook is Placed on this Level
  • 43. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 43 C-BASED METHOD HOOKING Machine Code Manipulation Use pointer reflection Create your traditional ASM trampoline code in a byte array and overwrite the method Need to keep the original method code Tricky to handle method arguments Prototype method needs to be accessible MethodInfo commandCtor = targetType.GetMethod("ParseScriptBlock"); System.Runtime.CompilerServices.RuntimeHelpers .PrepareMethod(commandCtor.MethodHandle); IntPtr commandCtorPtr = commandCtor.MethodHandle.GetFunctionPointer(); PrepareMethod & GetFunctionPointer
  • 44. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 44 RESULTS
  • 45. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 45 SOLUTION RESULTS COMPARISON Requirements IL Binary Modification CLR Profiler Hooking JIT Hooking Machine Code Manipulation Runtime Analysis YES YES YES YES Run on PowerShell v2+ YES YES YES YES Stealth vs AMSI YES YES YES YES Any System Artifacts? YES YES NO NO NGEN to Be Uninstalled YES YES YES YES Requires Signature Validation YES NO NO NO Difficulty High (If Manual) Low Medium High
  • 46. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 46 SOLUTION RESULTS COMPARISON Requirements IL Binary Modification CLR Profiler Hooking JIT Hooking Machine Code Manipulation Runtime Analysis YES YES YES YES Run on PowerShell v2+ YES YES YES YES Stealth vs AMSI YES YES YES YES Any System Artifacts? YES YES NO NO NGEN to Be Uninstalled YES YES YES YES Requires Signature Validation YES NO NO NO Difficulty High (If Manual) Low Medium High 3 12
  • 47. CanSecWest 2017 | .NET Hijacking to Defend PowerShell 47 TAKE AWAYS INTERCEPT THE ACTUAL POWERSHELL METHOD STAY STEALTHY DO IT RIGHT, DON’T CRASH POWERSHELL WELCOME TO .NET HELL amanda.secured.org