Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Leave your malware @home MALPROXY
Amit Waisel Hila Cohen
USAboutAmit Waisel
Offensive Cyber Security Expert
Technology lead, Security Research @ XM Cyber
Trusted Security Advisor
Favorite bit: 1
Private Pilot , Skipper and cat lover
Hila Cohen
Security Researcher @ XM Cyber
@hilaco10
Passionate about Windows Internals and Malware
Analysis
Love to dance, travel the world and capture
moments with my camera
Endpoint protections introduction
Malproxy - A new technique to bypass endpoint protections
Demo Mitigations
TL;DR
&Organizations heavily rely on endpoint protection solutions in their security stack
Unfair cat-and-mouse game
Security solutions evolved over time, so are the viruses
What do you know about your
endpointprotectionsolutions?
not great, not terrible
Anatoly Dyatlov
”
malicious activity detection mechanisms
Endpoint Protection 101
Static signatures
Behavioral signatures
1 3
Heuristics
2
Static signatures1
Behavioral signatures
Heuristics2
3
//testbin.c int main (){ char *user = "adm.user"; printf("%s\n",user); return 0;}
Static signatures1
Behavioral signatures
Heuristics2
3
rule APT_adm_corp : apt //apt is just a tag, it doesn’t affect the rule.{ meta: //Metadata, they don’t affect the rule author = "xgusix"
strings: $adm = "adm." $corp = "corp." $elf = { 7f 45 4c 46 } //ELF file’s magic numbers
condition: $elf in (0..4) and ($adm or $corp) // If $elf in the first 4 bytes and it matches $adm or $corp}
Static signatures1
Behavioral signatures
Heuristics2
3
# yara -s -m -g rules.yar testbinAPT_adm_corp [apt] [author="xgusix"] testbin0x0:$elf: 7F 45 4C 460x4c0:$adm: adm.
Static signatures1
Behavioral signatures
Heuristics2
3
HackTool:Win32/OurCoolMimikatzSignature:"A La Vie, A L'Amour" - (oe.eo)Benjamin DELPY `gentilkiwi`Vincent LE TOUX## / \ ##sekurlsalogonpasswords
Static signatures1
Heuristics2
Behavioral signatures3
UPX2.data.textProperty
0x000034000x000004000x00000400Raw-address
0x200 bytes0x3000 bytes0x0 bytesRaw-size
0x0040A0000x004070000x00401000Virtual-address
0x1000 bytes0x3000 bytes0x6000 bytesVirtual-size
+-+Executable
-++Writable
Static signatures1
Heuristics2
Behavioral signatures3
Static signatures1
Heuristics2
Behavioral signatures3
Endpointprotectionsolutionsbypass
Endpoint protection solutions bypass
MALPROXY
Looking for my code somewhere?You will neverget this!
Target OS
Process
MA
LPR
OXY
Malicious code interacts with the underlying OS using API function calls
Those actions can be detected and blocked by any security solution
Malicious code
API
MA
LPR
OXY
Proxy the malicious operations over the network
Never deploying the actual malicious code on the target side
Emulating needed API calls
Attacker OS
Stub
Malicious code
Stub
Innocent code
Target OS
API
MA
LPR
OXY
Target & attacker stubs
Load the PE file and hook system API functions
Execution flow – hook, serialize, send, execute, serialize, send, return. Repeat.
Attacker OS
Stub
Malicious code
Target OS
Stub
Innocent code
API
MA
LPR
OXY
Target & attacker stubs
Load the PE file and hook system API functions
Execution flow – hook, serialize, send, execute, serialize, send, return. Repeat.
Attacker OS
Stub
Malicious code
Target OS
Stub
Innocent code
CreateFile(”blah.txt”
)
API
MA
LPR
OXY
Target & attacker stubs
Load the PE file and hook system API functions
Execution flow – hook, serialize, send, execute, serialize, send, return. Repeat.
Attacker OS
Stub
Malicious code
Target OS
Stub
Innocent code
CreateFile(”blah.txt”
)
API
MA
LPR
OXY
Target & attacker stubs
Load the PE file and hook system API functions
Execution flow – hook, serialize, send, execute, serialize, send, return. Repeat.
Attacker OS
Stub
Malicious code
Target OS
Stub
Innocent code
HANDLE blah.txt
API
MA
LPR
OXY
Target & attacker stubs
Load the PE file and hook system API functions
Execution flow – hook, serialize, send, execute, serialize, send, return. Repeat.
Attacker OS
Stub
Malicious code
Target OS
Stub
Innocent code
HANDLE blah.txt
API
Key terms:SYSTEM CALLS OVERVIEW
USER MODE
KERNEL MODE
Kernel32.dll CreateFileCall CreateFile
Call NtCreateFile
SYSENTER\SYSCALLFind relevant function in SSDT and executes it
NtCreateFile
ZwCreateFile
Ntdll.dll
Ntoskrnl
Windows Application
Key terms:SYSTEM CALLS OVERVIEW
USER MODE
KERNEL MODE
Kernel32.dll CreateFileCall CreateFile
Call NtCreateFile
SYSENTER\SYSCALLFind relevant function in SSDT and executes it
NtCreateFile
ZwCreateFile
Ntdll.dll
Ntoskrnl
Windows Application
Key terms:SYSTEM CALLS OVERVIEW
USER MODE
KERNEL MODE
Kernel32.dll CreateFileCall CreateFile
Call NtCreateFile
SYSENTER\SYSCALLFind relevant function in SSDT and executes it
NtCreateFile
ZwCreateFile
Ntdll.dll
Ntoskrnl
Windows Application
Key terms:SYSTEM CALLS OVERVIEW
USER MODE
KERNEL MODE
Kernel32.dll CreateFileCall CreateFile
Call NtCreateFile
SYSENTER\SYSCALLFind relevant function in SSDT and executes it
NtCreateFile
ZwCreateFile
Ntdll.dll
Ntoskrnl
Windows Application
Key terms:SYSTEM CALLS OVERVIEW
USER MODE
KERNEL MODE
Kernel32.dll CreateFileCall CreateFile
Call NtCreateFile
SYSENTER\SYSCALLFind relevant function in SSDT and executes it
NtCreateFile
ZwCreateFile
Ntdll.dll
Ntoskrnl
Windows Application Process
Innocent code
COMPUTER OS
API
Key terms:SYSTEM CALLS OVERVIEW
USER MODE
KERNEL MODE
Kernel32.dll CreateFileCall CreateFile
Call NtCreateFile
SYSENTER\SYSCALLFind relevant function in SSDT and executes it
NtCreateFile
ZwCreateFile
Ntdll.dll
Ntoskrnl
Process
Innocent code
COMPUTER OS
Windows Application
API
Key terms:
HOOKINGRedirect system API calls to our code
Control all arguments & return value
Imported system API function addresses are resolved during PE load process and can be overridden later – IAT hooking
This allows us to separate the code’s logic from its interaction with the OS
IMPORT ADDRESS TABLE
NtQuerySystemInformation Malproxy
OpenProcess Malproxy
ReadProcessMemory Malproxy
BCryptGenerateSymetricKey Bcrypt.dll
ConvertSidToStringSidW Advapi32.dll
… …
RtlAdjustPrivilege Malproxy
NtQueryInformationProcess Malproxy
RtlEqualUnicodeString Ntdll.dll
Key terms:
BOOL stdcall ReadProcessMemory(HANDLE hProcrss, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T *lpNumberOfBytesRead);
Return Type Calling Convention Function arguments
FUNCTIONPROTOTYPE
Dealing with all aspects of different prototypes
ProxyingWin32 API
Calling convention – same for all Win32API and Native API calls
Input Arguments:
Primitives
Pointers to primitives
User-allocated buffers
Output Arguments:
User-allocated output buffer
System-allocated output buffer
Return values
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE
Request Message
ProcessHandle
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE
Request Message
ProcessHandleProcessInformationClass
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE
Request Message
ProcessHandleProcessInformationClass
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE
Request Message
ProcessHandleProcessInformationClass
ProcessInformationLength
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE
Request Message
ProcessHandleProcessInformationClass
ProcessInformationLength
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE TARGET SIDE
Request Message
ProcessHandleProcessInformationClass
ProcessInformationLength
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE TARGET SIDE
Request Message
ProcessHandleProcessInformationClass
ProcessInformationLength
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE TARGET SIDE
Response Message
ReturnLength
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE TARGET SIDE
Response Message
ReturnLength
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE TARGET SIDE
Response Message
ProcessInformationReturnLength
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE TARGET SIDE
Response Message
ProcessInformationReturnLengthReturn value
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
Response Message
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
TARGET SIDEATTACKER SIDE
ProcessInformationReturnLengthReturn value
HandlingARGUMENTS
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
NTSTATUS NtQueryInformationProcess(IN HANDLE ProcessHandle,IN PROCESSINFOCLASS ProcessInformationClass,OUT PVOID ProcessInformation,IN ULONG ProcessInformationLength,OUT PULONG ReturnLength
);
ATTACKER SIDE TARGET SIDE
Response Message
ProcessInformationReturnLengthReturn value
Attacker OS
Process
Malicious code
Target OS
Process
Innocent code
RECAPTarget & attacker stubs
Load the PE file and hook system API functions
Execution flow – hook, serialize, send, execute, serialize, send, return. Repeat.
API
RunningMALPROXY
ATTACKER SIDE TARGET SIDE
RunningMALPROXY
ATTACKER SIDE TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
IMPORT ADDRESS TABLENtQuerySystemInformation Kernel32.dll
OpenProcess Kernel32.dll
ReadProcessMemory Ntdll.dll
BCryptGenerateSymetricKey Bcrypt.dll
ConvertSidToStringSidW Advapi32.dll
… …
RtlAdjustPrivilege Ntdll.dll
NtQueryInformationProcess Ntdll.dll
RtlEqualUnicodeString Ntdll.dll
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
IMPORT ADDRESS TABLENtQuerySystemInformation Malproxy
OpenProcess Malproxy
ReadProcessMemory Malproxy
BCryptGenerateSymetricKey Bcrypt.dll
ConvertSidToStringSidW Advapi32.dll
… …
RtlAdjustPrivilege Malproxy
NtQueryInformationProcess Malproxy
RtlEqualUnicodeString Ntdll.dll
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
RtlAdjustPrivilege
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
RtlAdjustPrivilegeNtQuerySystemInformation
Chrome.exe, explorer.exe Calc.exe, lsass.exe
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
RtlAdjustPrivilegeNtQuerySystemInformation
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
RtlAdjustPrivilegeNtQuerySystemInformation
OpenProcessHandle 0x00000080
PID 1234
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
RtlAdjustPrivilegeNtQuerySystemInformation
OpenProcessNtQueryInformationProcess
Handle 0x00000080
PEB at 0xdeadbeef
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
RtlAdjustPrivilegeNtQuerySystemInformation
OpenProcessNtQueryInformationProcessReadProcessMemory
Read 0xdeadbeef
[0x12, 0x34, 0x56, 0x78]
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
RtlAdjustPrivilegeNtQuerySystemInformation
OpenProcessNtQueryInformationProcessReadProcessMemory
TARGET SIDE
RunningMALPROXY
ATTACKER SIDE
RtlAdjustPrivilegeNtQuerySystemInformation
OpenProcessNtQueryInformationProcessReadProcessMemoryPWNED!
RtlAdjustPrivilegeNtQuerySystemInformationRtlEqualUnicodeStringOpenProcessNtQueryInformationProcessReadProcessMemoryBCryptDecrypt
TopSecretPassword
TARGET SIDE
DEMO
”You came off
as a naive idiot. and naive idiots are not a threat
Endpoint protections
BYPASSBehavioral Signatures
Bypassing Heuristic Rules
Bypassing Static Signatures
Security Solution Mimikatz sekurlsa::logonpasswords
Microsoft Defender Malproxied!
Symantec Norton Security Malproxied!
Kaspersky Internet Security Blocks ReadProcessMemory without a verdict
ESET Smart Security Malproxied!
Avast Free Antivirus Blocks OpenProcess on lsass.exe without a verdict
Bitdefender Total Security Malproxied!
McAfee Total Protection Malproxied!
”Why worry
about something that isn't going
to happen?
MITIGATIONSAny more ideas?Hunt and sign
the target-side proxy stub
Improve the behavioral signature engines to handle their known weaknesses
MITIGATIONSAny more ideas? /dev/nullHunt and sign
the target-side proxy stub
Improve the behavioral signature engines to handle their known weaknesses
CREDITSThe Crazy Ideas Section - Remote Syscalls by Yaron Shani:
http://breaking-the-system.blogspot.com/2016/06/the-crazy-ideas-section-remote-syscalls.html
Syscall Proxying - Simulating remote execution by Maximiliano Caceres:http://www.vodun.org/papers/exploits/SyscallProxying.pdf
Syscall Proxying || Pivoting Systems by Filipe Balestra and Rodrigo Rubira Branco:https://www.kernelhacking.com/rodrigo/docs/H2HCIII.pdf
Questions?