SlideShare a Scribd company logo
1 of 55
Download to read offline
Windows Offender: Reverse Engineering
Windows Defender's Antivirus Emulator
Alexei Bulazel, BlackHat2018 & DEFCON26
redhung@SQLab, NYCU
>_ Outline
● Introduction
● Tooling & Process
● Reverse Engineering
● Vulnerability Research
● Conclusion
Introduction
>_ Windows Defender Antivirus
● Huge AV market share
● Runs unsandboxed as NT AUTHORITYSYSTEM
○ Exploit = Initial RCE + Privilege Escalation + AV Bypass
● Surprisingly easy for attackers to reach remotely
>_ Target - mpengine.dll
● mpengine.dll
○ “Microsoft Malware Protection Engine”
● MpSigStub.exe
○ “Microsoft Malware Protection Signature Update Stub”
● mpengine.dll provides malware scanning
and detection capabilities,other AV features
and OS integration are handled in Defender’s
other components
32 & 64-bit builds
>_ Introduction to emulation
● Why emulate?
○ Traditional AV model: scan files and look for known malware signatures
(file hashes, sequences of bytes, file traits, etc …)
● Problem: signatures are easily evaded with packed code, novel binaries
● Solution: run unknown binaries in a virtual emulated environment, look for
runtime malicious behavior or known signatures
○ Not a new idea, in use for at least 15 years
>_ Emulation Overview
● Load unknown potentailly malicious binary
● Begin running from entrypoint, and run until termination condition
○ Time, Number of instructions, Number of API calls, memory …
● Collect heuristic observations about runtime behavior, look for
signatures in memory or dropped to disk, etc …
Tooling &
Process
>_ Static Analysis
● ~12MB DLL (Grow up to ~17MB)
● ~30,000 functions
● IDA Pro
○ Patch analysis with BinDiff
● Microsoft publishes PDBs
>_ Dynamic Analysis & Loader
● AV-Specific Challenges:
○ Protected Process, cannot debug even as local admin
● Introspection
● Scanning on demand
● Code reachability may be configuration/
heuristics dependent
● Solution: Custom loaders for AV binaries
>_ Tavis Ormandy’s “loadlibrary”
● PE loader for Linux
○ Shim out implementations for Windows API imports
○ Only implements the bare minimum to get mpengine.dll running, not a
general purpose Windows emulator or Wine
● mpclient tool exposes the main scanning interface
○ The author built ~3k LoC of additional tooling on top of mpclient
>_ mpclient
Reverse Engineering
>_ Getting Emulated
● __rsignal function provides an entry point into
Defender’s scanning, give it a buffer of data
and it returns a malware classification
● Defender uses emulation to analyze executables
it does not recognize with other less expensive
analyses
● Emulation results are cached, a given binary will
only be emulated once, even if scanned multiple
times
>_ Emulator Initialization
● Allocate memory
● Initialize various objects and subsystems used
during emulation
● Load the binary to be analyzed, relocate, resolve
imports, etc
● Initialize virtual DLLs in the process memory space
● Heuristic observations about the binary are
recorded, section alignmentm number of imports,
etc
>_ CPU Emulation
● Support for many architectures
○ This presentation looks at x86 32-bit
● Technically dynamic translation, not “emulation”
○ Lift to IL, JIT compile to sanitized x86
● Architecture-specific software emulation functions handle unique or
difficult lift instructions
● The subsystem is incredibly complicated
>_ *_2_IL Lifting
● Individual architecture to IL lifting
● Grab the bytes of opcode, determine type, then emit IL accordingly
x86_IL_translator::translate
Single-byte x86 push register
opcodes all map to type 0x13
>_ Instrumenting mpengine
● Problem: little visibility into engine
○ Coverage for the big picture, breakpoints for detailed observation
● Only output is malware detection
● Solution: a malware’s eye view
○ mpengine.dll has functions that are invoked when our malware
calls certain Windows APIs
○ Create a binary to explore the AV from inside, hook and reuse
existing functions to share that view with us on the outside
>_ Modified mpclient
Original mpclient Modified mpclient
>_ OutputDebugStringA Hook
● Hook the native function pointer that gets called when
OutputDebugStringA is called in-emulator
● Use existing functions in Defender to interact with function
parameters and virtual memory
>_ OutputDebugStringA Hook
>_ myapp.exe
● I/O communication with outside the emulator by calling
OuputDebugStringA and other hooked functions
mpclient Defender
myapp.exe
Loader
Communicate Detect
>_ Windows Emulation & Environment
● Usermode Environment
● Usermode Code
● User-Kernel Interaction
● Kernel Internals
● AV Instrumentation
>_ Windows Emulation & Environment
● Usermode Environment
● Usermode Code
● User-Kernel Interaction
● Kernel Internals
● AV Instrumentation
>_ Virtual File System Contents
● Dump file system contents with a similar trick
to the OutputDebugStringA hook, just pass
void pointers to arbitrary data
○ 1455 files on the 2/28/18 build
○ Mostly fake executables
○ A handful of fake config files
○ Various text “goat” files
○ Lots of empty files
>_ C:aaa_TouchMeNot_.txt
>_ Fake Config Files
C:Mircmirc.ini
[chanfolder]
n0=#Blabla
n1=#End
C:Mircscript.ini
[script]
; blabla
C:Windowsmsdfmap.ini
[connect default]
Access=NoAccess
[sql default]
Sql=” “
[connect CustomerDatabase]
Access=ReadWrite
Connect=”DSN=AdvWorks”
[sql CustomerById]
Sql=”SELECT * FROM Customers WHERE CustomerID = ?”
[connect AuthorDatabase]
Access=ReadOnly
Connect=”DSN=MyLibraryInfo;UID=MyUserID;PWD=MyPassword”
[userlist AuthorDatabase]
Administrator=ReadWrite
[sql AuthorById]
Sql=”SELECT * FROM Authors WHERE au_id = ?”
>_ Virtual Registry
● Huge virtual registry with thousands of entries
>_ Processes
● Various processes are shown as running on the system
● These are not real running processes, just names returned in order to
present a realistic execution environment to malware
● “myapp.exe” is the name of the process under emulation, PID varies in
different mpengine builds
0 - [System Process] 700 - kav.exe 728 - norton.exe 1268 - spoolsv.exe 1816 - yahoo.exe
4 - System 704 - avpcc.exe 732 - msmpeng.exe 1768 - explorer.exe 1820 - msnmsgr.exe
356 - smss.exe 708 - _avpm.exe 736 - msmpsvc.exe 1796 - iexplore.exe 1824 - far.exe
608 - csrss.exe 712 - avp32.exe 740 - mrt.exe 1800 - outlook.exe 1828 - trillian.exe
624 - winlogon.exe 716 - avp.exe 744 - outpost.exe 1804 - msimn.exe 1832 - skype.exe
676 - services.exe 720 - antivirus.exe 856 - svchost.exe 1808 - firefox.exe 1836 - googletalk.exe
680 - lsass.exe 724 - fsav.exe 1084 - svchost.exe 1812 - icq.exe 3904 - myapp.exe
>_ Windows Emulation & Environment
● Usermode Environment
● Usermode Code
● User-Kernel Interaction
● Kernel Internals
● AV Instrumentation
>_ Windows API Emulation
● Two types of Windows API functions
○ Stay in usermode -> stay in the emulator
○ Resolve to syscall -> trap to native emulation
● Implemented just like the real Windows API - DLLs
○ Symbols indicate they are called “vdlls”
○ Present on disk and in memory in the emulator, like real Windows
○ VDLLs are not present in mpengine.dll, must be dynamically loaded
from VDMs
>_ Reversing VDLLs
>_ In-Emulator VDLL Emulations
● In-emulator emulations stay within the emulator
● Code is run within the dynamic translation system
● Some emulations stub out to hardcoded returns
>_ Stubbed Out Functions
● Complex functions are stubbed out to return hardcoded values or halt emulation
RPCRT4.dll
mspaint.exe
NTOSKRNL.exe
>_ ws2_32.dll
● Winsock library is uniquely full of fingerprints, strings with “Mp” and
German websites
>_ Windows Emulation & Environment
● Usermode Environment
● Usermode Code
● User-Kernel Interaction
● Kernel Internals
● AV Instrumentation
>_ Native Emulation
● Complex functions that cannot be handled in-emulator must be emulated in native code
● Akin to usermode -> kernel, or VM guest -> host transitions
● Emulator to native transition implemented with a custom hypercall instruction - apicall
0x0F 0xFF 0xF0 [4 byte immediate]
● Stubs that apicall to various functions are included in VDLLs
apicall
Emulated VDLL: kernel32!CopyFileWWorker Native code: mpengine!KERNEL32_DLL_CopyFileWWorker
>_ g_syscalls table
● g_syscalls contains over 119 emulation functions
● apicall instruction use triggers dispatch to function pointer in g_syscalls table
● This is the table we modify when hooking OutputDebugStringA
>_ kernel32!OutputDebugStringA
In-emulator VDLL code
Native emulation function
>_ Emulated VDLL Functions
ADVAPI32
RegCreateKeyExW
RegDeleteKeyW
RegDeleteValueW
RegEnumKeyExW
RegEnumValueW
RegOpenKeyExW
RegQueryInfoKeyW
RegQueryValueExW
RegSetValueExW
USER32
MessageBoxA
KERNEL32
CloseHandle
CopyFileWWorker
CreateDirectoryW
CreateFileMappingA
CreateProcessA
CreateToolhelp32Snapshot
ExitProcess
ExitThread
FlushFileBuffers
GetCommandLineA
GetCurrentProcess
GetCurrentProcessId
GetCurrentThread
GetCurrentThreadId
GetModuleFileNameA
GetModuleHandleA
GetProcAddress
GetThreadContext
GetTickCount
LoadLibraryW
MoveFileWWorker
MpAddToScanQueue
MpCreateMemoryAliasing
MpReportEvent
MpReportEventEx
MpReportEventW
MpSetSelectorBase
OpenProcess
OutputDebugStringA
ReadProcessMemory
RemoveDirectoryW
SetFileAttributesA
SetFileTime
Sleep
TerminateProcess
UnimplementedAPIStub
VirtualAlloc
VirtualFree
VirtualProtectEx
VirtualQuery
WinExec
WriteProcessMemory
>_ Emulated ntdll.dll Functions
MpGetSelectorBase
MpUfsMetadataOp
NtCloseWorker
NtContinue
NtControlChannel
NtCreateEventWorker
NtCreateFileWorker
NtCreateMutantWorker
NtCreateSemaphoreWorker
NtCreateThreadWorker
NtDeleteFileWorker
NtDuplicateObjectWorker
NtGetContextThread
NtOpenEventWorker
NtOpenMutantWorker
NtOpenSemaphoreWorker
NtOpenThreadWorker
NtPulseEventWorker
NtQueryInformationFileWorker
NtQueryInformationThreadWorker
NtReadFileWorker
NtReleaseMutantWorker
NtReleaseSemaphoreWorker
NtResetEventWorker
NtResumeThreadWorker
NtSetContextThread
NtSetEventWorker
NtSetInformationFileWorker
NtSetLdtEntries
NtSuspendThreadWorker
NtTerminateThreadWorker
NtWaitForMultipleObjectsWorker_PostBlock
NtWaitForMultipleObjectsWorker_PreBlock
NtWriteFileWorker
ObjMgr_ValidateVFSHandle
ThrdMgr_GetCurrentThreadHandle
ThrdMgr_SaveTEB
ThrdMgr_SwitchThreads
VFS_CopyFile
VFS_DeleteFile
VFS_DeleteFileByHandle
VFS_FileExists
VFS_FindClose
VFS_FindFirstFile
VFS_FindNextFile
VFS_FlushViewOfFile
VFS_GetAttrib
VFS_GetHandle
VFS_GetLength
VFS_MapViewOfFile
VFS_MoveFile
VFS_Open
VFS_Read
VFS_SetAttrib
VFS_SetCurrentDir
VFS_SetLength
VFS_UnmapViewOfFile
VFS_Write
VFS_Read
VFS_SetAttrib
VFS_SetCurrentDir
VFS_SetLength
VFS_UnmapViewOfFile
VFS_Write
>_ Windows Emulation & Environment
● Usermode Environment
● Usermode Code
● User-Kernel Interaction
● Kernel Internals
● AV Instrumentation
>_ Windows Kernel Emulation
● Windows kernel facilities are emulated with native code
● Object Manager
● Process management
● File system
● Registry
● Synchronization primitives
>_ Object Manager
● The Object Manager is an essential part of the Windows Executive, provides
kernel mode resource management, processes, files, registry keys, mutexes, etc
● Defender supports 5 types of objects: File, Thread, Event, Mutant(Mutex),
Semaphore
● Manages system state during emulation that is persistent between native
emulation API calls
● Objects are stored in a map, tracked by pid and handle
Current process handle is emulated as 0x1234
>_ Windows Emulation & Environment
● Usermode Environment
● Usermode Code
● User-Kernel Interaction
● Kernel Internals
● AV Instrumentation
>_ Defender Internal Functions
● Internal administration and configuration functions accessible via apicall
● MpAddToScanQueue
○ Queue up a file (e.g., a dropped binary) for scanning
● MpCreateMemoryAliasing
○ Alias memory in emulator
● MpReportEvent, MpReportEventEx, MpReportEventW
○ Report malware behavior to inform heuristic detections
● MpGetSelectorBase, MpSetSelectorBase
○ Get/set segment registers (CS, DS, ES, etc)
● MpUfsMetadataOp
○ Get/set metadata about the file being scanned
● NtControlChannel
○ IOCTL-like administration for the AV engine
>_ MpReportEvent
● Used to communicate information about malware binary actions with Defender’s
heuristic detection engine
>_ MpReportEvent - AV Processes
● Processes types are grouped by PID, processes for antivirus software has 700 PIDs
● Emulated process information is stored in a data structure in the kernel32.dll
VDLL and presented when enumerated
● Calling TerminateProcess on an AV product triggers and MpReportEvent call
>_ NtControlChannel Options
Vulnerability
Research
>_ Tavis’ apicall Trick
● Build binary with an rwx .text section, generate apicall instruction on the
fly as needed
● apicall instruction triggers native emulation functions from malware .text
section with attacker controlled
>_ Fuzzing Emulated APIs
● Create a binary that goes inside the emulator and repeatedly calls hooked WinExec
function to request new data, then sends that data to functions with native
emulations
● Buffers in memory passed to external hook function to populate with parameters
● Could do fuzzing in-emulator too, but this is easier for logging results
>_ Input Generation
● Borrow OSX syscall fuzzer code from MWR Labs OSXFuzz project
● Nothing fancy, just throw random values at native emulation handlers
● Re-seed rand() at the start of each emulation session, just save off seeds in a log
Conclusion
>_ Antivirus Reverse Engineering
● People constantly talk about what AVs can or can’t do, and how or where
they are vulnerable
● Hope we’ll see more Antivirus research in the future
● More fuzzing methods to the Antivirus or Defender

More Related Content

Similar to Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator

Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbgPractical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbgSam Bowne
 
Windows internals
Windows internalsWindows internals
Windows internalsPiyush Jain
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...Paris Open Source Summit
 
[CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs
[CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs [CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs
[CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs PROIDEA
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsCaptain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsenSilo
 
Piratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPiratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPriyanka Aash
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modulesEddy Reyes
 
COM Hijacking Techniques - Derbycon 2019
COM Hijacking Techniques - Derbycon 2019COM Hijacking Techniques - Derbycon 2019
COM Hijacking Techniques - Derbycon 2019David Tulis
 
Windows内核技术介绍
Windows内核技术介绍Windows内核技术介绍
Windows内核技术介绍jeffz
 
Hacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote AccessHacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote AccessEC-Council
 
.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
 
Black hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slidesBlack hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slidesBakry3
 
Exploiting Llinux Environment
Exploiting Llinux EnvironmentExploiting Llinux Environment
Exploiting Llinux EnvironmentEnrico Scapin
 
Ch 6: The Wild World of Windows
Ch 6: The Wild World of WindowsCh 6: The Wild World of Windows
Ch 6: The Wild World of WindowsSam Bowne
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentAbid Malik
 
Code Signing with CPK
Code Signing with CPKCode Signing with CPK
Code Signing with CPKZhi Guan
 

Similar to Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator (20)

Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbgPractical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
 
Windows internals
Windows internalsWindows internals
Windows internals
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
 
[CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs
[CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs [CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs
[CONFidence 2016] Andrey Plastunov - Simple bugs to pwn the devs
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsCaptain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
 
Piratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPiratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigation
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
I hunt sys admins 2.0
I hunt sys admins 2.0I hunt sys admins 2.0
I hunt sys admins 2.0
 
COM Hijacking Techniques - Derbycon 2019
COM Hijacking Techniques - Derbycon 2019COM Hijacking Techniques - Derbycon 2019
COM Hijacking Techniques - Derbycon 2019
 
Windows内核技术介绍
Windows内核技术介绍Windows内核技术介绍
Windows内核技术介绍
 
Hacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote AccessHacker Halted 2014 - Post-Exploitation After Having Remote Access
Hacker Halted 2014 - Post-Exploitation After Having Remote Access
 
.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
 
Black hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slidesBlack hat dc-2010-egypt-uav-slides
Black hat dc-2010-egypt-uav-slides
 
Exploiting Llinux Environment
Exploiting Llinux EnvironmentExploiting Llinux Environment
Exploiting Llinux Environment
 
Ch 6: The Wild World of Windows
Ch 6: The Wild World of WindowsCh 6: The Wild World of Windows
Ch 6: The Wild World of Windows
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
 
Code Signing with CPK
Code Signing with CPKCode Signing with CPK
Code Signing with CPK
 

More from Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.

More from Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan. (18)

AEG_ Automatic Exploit Generation
AEG_ Automatic Exploit GenerationAEG_ Automatic Exploit Generation
AEG_ Automatic Exploit Generation
 
Unleashing MAYHEM On Binary Code
Unleashing MAYHEM On Binary CodeUnleashing MAYHEM On Binary Code
Unleashing MAYHEM On Binary Code
 
Firmadyne
FirmadyneFirmadyne
Firmadyne
 
Fintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJSFintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJS
 
TA-java-method-109
TA-java-method-109TA-java-method-109
TA-java-method-109
 
TA Lesson Web-109
TA Lesson Web-109TA Lesson Web-109
TA Lesson Web-109
 
TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)
 
Java - TA課 - Array
Java - TA課 - ArrayJava - TA課 - Array
Java - TA課 - Array
 
Reverse Engineering - Assembly & Introduction
Reverse Engineering - Assembly & IntroductionReverse Engineering - Assembly & Introduction
Reverse Engineering - Assembly & Introduction
 
TA Lesson3 - Method
TA Lesson3 - MethodTA Lesson3 - Method
TA Lesson3 - Method
 
Web Introduction
Web IntroductionWeb Introduction
Web Introduction
 
Java - TA課 - Let's Begin
Java - TA課 - Let's BeginJava - TA課 - Let's Begin
Java - TA課 - Let's Begin
 
Java - TA課 - 開發環境
Java - TA課 - 開發環境Java - TA課 - 開發環境
Java - TA課 - 開發環境
 
IoT Penetration Talk
IoT Penetration TalkIoT Penetration Talk
IoT Penetration Talk
 
Introduction to computer network
Introduction to computer networkIntroduction to computer network
Introduction to computer network
 
Assembly Language Redhung ( x86 ) @ TDOH
Assembly Language Redhung ( x86 ) @ TDOHAssembly Language Redhung ( x86 ) @ TDOH
Assembly Language Redhung ( x86 ) @ TDOH
 
TP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attackTP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attack
 
滲透測試入門 Penetration test - white hat hacking introduction
 滲透測試入門 Penetration test - white hat hacking introduction 滲透測試入門 Penetration test - white hat hacking introduction
滲透測試入門 Penetration test - white hat hacking introduction
 

Recently uploaded

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 

Recently uploaded (20)

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator

  • 1. Windows Offender: Reverse Engineering Windows Defender's Antivirus Emulator Alexei Bulazel, BlackHat2018 & DEFCON26 redhung@SQLab, NYCU
  • 2. >_ Outline ● Introduction ● Tooling & Process ● Reverse Engineering ● Vulnerability Research ● Conclusion
  • 4. >_ Windows Defender Antivirus ● Huge AV market share ● Runs unsandboxed as NT AUTHORITYSYSTEM ○ Exploit = Initial RCE + Privilege Escalation + AV Bypass ● Surprisingly easy for attackers to reach remotely
  • 5. >_ Target - mpengine.dll ● mpengine.dll ○ “Microsoft Malware Protection Engine” ● MpSigStub.exe ○ “Microsoft Malware Protection Signature Update Stub” ● mpengine.dll provides malware scanning and detection capabilities,other AV features and OS integration are handled in Defender’s other components 32 & 64-bit builds
  • 6. >_ Introduction to emulation ● Why emulate? ○ Traditional AV model: scan files and look for known malware signatures (file hashes, sequences of bytes, file traits, etc …) ● Problem: signatures are easily evaded with packed code, novel binaries ● Solution: run unknown binaries in a virtual emulated environment, look for runtime malicious behavior or known signatures ○ Not a new idea, in use for at least 15 years
  • 7. >_ Emulation Overview ● Load unknown potentailly malicious binary ● Begin running from entrypoint, and run until termination condition ○ Time, Number of instructions, Number of API calls, memory … ● Collect heuristic observations about runtime behavior, look for signatures in memory or dropped to disk, etc …
  • 9. >_ Static Analysis ● ~12MB DLL (Grow up to ~17MB) ● ~30,000 functions ● IDA Pro ○ Patch analysis with BinDiff ● Microsoft publishes PDBs
  • 10. >_ Dynamic Analysis & Loader ● AV-Specific Challenges: ○ Protected Process, cannot debug even as local admin ● Introspection ● Scanning on demand ● Code reachability may be configuration/ heuristics dependent ● Solution: Custom loaders for AV binaries
  • 11. >_ Tavis Ormandy’s “loadlibrary” ● PE loader for Linux ○ Shim out implementations for Windows API imports ○ Only implements the bare minimum to get mpengine.dll running, not a general purpose Windows emulator or Wine ● mpclient tool exposes the main scanning interface ○ The author built ~3k LoC of additional tooling on top of mpclient
  • 14. >_ Getting Emulated ● __rsignal function provides an entry point into Defender’s scanning, give it a buffer of data and it returns a malware classification ● Defender uses emulation to analyze executables it does not recognize with other less expensive analyses ● Emulation results are cached, a given binary will only be emulated once, even if scanned multiple times
  • 15. >_ Emulator Initialization ● Allocate memory ● Initialize various objects and subsystems used during emulation ● Load the binary to be analyzed, relocate, resolve imports, etc ● Initialize virtual DLLs in the process memory space ● Heuristic observations about the binary are recorded, section alignmentm number of imports, etc
  • 16. >_ CPU Emulation ● Support for many architectures ○ This presentation looks at x86 32-bit ● Technically dynamic translation, not “emulation” ○ Lift to IL, JIT compile to sanitized x86 ● Architecture-specific software emulation functions handle unique or difficult lift instructions ● The subsystem is incredibly complicated
  • 17. >_ *_2_IL Lifting ● Individual architecture to IL lifting ● Grab the bytes of opcode, determine type, then emit IL accordingly x86_IL_translator::translate Single-byte x86 push register opcodes all map to type 0x13
  • 18. >_ Instrumenting mpengine ● Problem: little visibility into engine ○ Coverage for the big picture, breakpoints for detailed observation ● Only output is malware detection ● Solution: a malware’s eye view ○ mpengine.dll has functions that are invoked when our malware calls certain Windows APIs ○ Create a binary to explore the AV from inside, hook and reuse existing functions to share that view with us on the outside
  • 19. >_ Modified mpclient Original mpclient Modified mpclient
  • 20. >_ OutputDebugStringA Hook ● Hook the native function pointer that gets called when OutputDebugStringA is called in-emulator ● Use existing functions in Defender to interact with function parameters and virtual memory
  • 22. >_ myapp.exe ● I/O communication with outside the emulator by calling OuputDebugStringA and other hooked functions mpclient Defender myapp.exe Loader Communicate Detect
  • 23. >_ Windows Emulation & Environment ● Usermode Environment ● Usermode Code ● User-Kernel Interaction ● Kernel Internals ● AV Instrumentation
  • 24. >_ Windows Emulation & Environment ● Usermode Environment ● Usermode Code ● User-Kernel Interaction ● Kernel Internals ● AV Instrumentation
  • 25. >_ Virtual File System Contents ● Dump file system contents with a similar trick to the OutputDebugStringA hook, just pass void pointers to arbitrary data ○ 1455 files on the 2/28/18 build ○ Mostly fake executables ○ A handful of fake config files ○ Various text “goat” files ○ Lots of empty files
  • 27. >_ Fake Config Files C:Mircmirc.ini [chanfolder] n0=#Blabla n1=#End C:Mircscript.ini [script] ; blabla C:Windowsmsdfmap.ini [connect default] Access=NoAccess [sql default] Sql=” “ [connect CustomerDatabase] Access=ReadWrite Connect=”DSN=AdvWorks” [sql CustomerById] Sql=”SELECT * FROM Customers WHERE CustomerID = ?” [connect AuthorDatabase] Access=ReadOnly Connect=”DSN=MyLibraryInfo;UID=MyUserID;PWD=MyPassword” [userlist AuthorDatabase] Administrator=ReadWrite [sql AuthorById] Sql=”SELECT * FROM Authors WHERE au_id = ?”
  • 28. >_ Virtual Registry ● Huge virtual registry with thousands of entries
  • 29. >_ Processes ● Various processes are shown as running on the system ● These are not real running processes, just names returned in order to present a realistic execution environment to malware ● “myapp.exe” is the name of the process under emulation, PID varies in different mpengine builds 0 - [System Process] 700 - kav.exe 728 - norton.exe 1268 - spoolsv.exe 1816 - yahoo.exe 4 - System 704 - avpcc.exe 732 - msmpeng.exe 1768 - explorer.exe 1820 - msnmsgr.exe 356 - smss.exe 708 - _avpm.exe 736 - msmpsvc.exe 1796 - iexplore.exe 1824 - far.exe 608 - csrss.exe 712 - avp32.exe 740 - mrt.exe 1800 - outlook.exe 1828 - trillian.exe 624 - winlogon.exe 716 - avp.exe 744 - outpost.exe 1804 - msimn.exe 1832 - skype.exe 676 - services.exe 720 - antivirus.exe 856 - svchost.exe 1808 - firefox.exe 1836 - googletalk.exe 680 - lsass.exe 724 - fsav.exe 1084 - svchost.exe 1812 - icq.exe 3904 - myapp.exe
  • 30. >_ Windows Emulation & Environment ● Usermode Environment ● Usermode Code ● User-Kernel Interaction ● Kernel Internals ● AV Instrumentation
  • 31. >_ Windows API Emulation ● Two types of Windows API functions ○ Stay in usermode -> stay in the emulator ○ Resolve to syscall -> trap to native emulation ● Implemented just like the real Windows API - DLLs ○ Symbols indicate they are called “vdlls” ○ Present on disk and in memory in the emulator, like real Windows ○ VDLLs are not present in mpengine.dll, must be dynamically loaded from VDMs
  • 33. >_ In-Emulator VDLL Emulations ● In-emulator emulations stay within the emulator ● Code is run within the dynamic translation system ● Some emulations stub out to hardcoded returns
  • 34. >_ Stubbed Out Functions ● Complex functions are stubbed out to return hardcoded values or halt emulation RPCRT4.dll mspaint.exe NTOSKRNL.exe
  • 35. >_ ws2_32.dll ● Winsock library is uniquely full of fingerprints, strings with “Mp” and German websites
  • 36. >_ Windows Emulation & Environment ● Usermode Environment ● Usermode Code ● User-Kernel Interaction ● Kernel Internals ● AV Instrumentation
  • 37. >_ Native Emulation ● Complex functions that cannot be handled in-emulator must be emulated in native code ● Akin to usermode -> kernel, or VM guest -> host transitions ● Emulator to native transition implemented with a custom hypercall instruction - apicall 0x0F 0xFF 0xF0 [4 byte immediate] ● Stubs that apicall to various functions are included in VDLLs apicall Emulated VDLL: kernel32!CopyFileWWorker Native code: mpengine!KERNEL32_DLL_CopyFileWWorker
  • 38. >_ g_syscalls table ● g_syscalls contains over 119 emulation functions ● apicall instruction use triggers dispatch to function pointer in g_syscalls table ● This is the table we modify when hooking OutputDebugStringA
  • 39. >_ kernel32!OutputDebugStringA In-emulator VDLL code Native emulation function
  • 40. >_ Emulated VDLL Functions ADVAPI32 RegCreateKeyExW RegDeleteKeyW RegDeleteValueW RegEnumKeyExW RegEnumValueW RegOpenKeyExW RegQueryInfoKeyW RegQueryValueExW RegSetValueExW USER32 MessageBoxA KERNEL32 CloseHandle CopyFileWWorker CreateDirectoryW CreateFileMappingA CreateProcessA CreateToolhelp32Snapshot ExitProcess ExitThread FlushFileBuffers GetCommandLineA GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetModuleFileNameA GetModuleHandleA GetProcAddress GetThreadContext GetTickCount LoadLibraryW MoveFileWWorker MpAddToScanQueue MpCreateMemoryAliasing MpReportEvent MpReportEventEx MpReportEventW MpSetSelectorBase OpenProcess OutputDebugStringA ReadProcessMemory RemoveDirectoryW SetFileAttributesA SetFileTime Sleep TerminateProcess UnimplementedAPIStub VirtualAlloc VirtualFree VirtualProtectEx VirtualQuery WinExec WriteProcessMemory
  • 41. >_ Emulated ntdll.dll Functions MpGetSelectorBase MpUfsMetadataOp NtCloseWorker NtContinue NtControlChannel NtCreateEventWorker NtCreateFileWorker NtCreateMutantWorker NtCreateSemaphoreWorker NtCreateThreadWorker NtDeleteFileWorker NtDuplicateObjectWorker NtGetContextThread NtOpenEventWorker NtOpenMutantWorker NtOpenSemaphoreWorker NtOpenThreadWorker NtPulseEventWorker NtQueryInformationFileWorker NtQueryInformationThreadWorker NtReadFileWorker NtReleaseMutantWorker NtReleaseSemaphoreWorker NtResetEventWorker NtResumeThreadWorker NtSetContextThread NtSetEventWorker NtSetInformationFileWorker NtSetLdtEntries NtSuspendThreadWorker NtTerminateThreadWorker NtWaitForMultipleObjectsWorker_PostBlock NtWaitForMultipleObjectsWorker_PreBlock NtWriteFileWorker ObjMgr_ValidateVFSHandle ThrdMgr_GetCurrentThreadHandle ThrdMgr_SaveTEB ThrdMgr_SwitchThreads VFS_CopyFile VFS_DeleteFile VFS_DeleteFileByHandle VFS_FileExists VFS_FindClose VFS_FindFirstFile VFS_FindNextFile VFS_FlushViewOfFile VFS_GetAttrib VFS_GetHandle VFS_GetLength VFS_MapViewOfFile VFS_MoveFile VFS_Open VFS_Read VFS_SetAttrib VFS_SetCurrentDir VFS_SetLength VFS_UnmapViewOfFile VFS_Write VFS_Read VFS_SetAttrib VFS_SetCurrentDir VFS_SetLength VFS_UnmapViewOfFile VFS_Write
  • 42. >_ Windows Emulation & Environment ● Usermode Environment ● Usermode Code ● User-Kernel Interaction ● Kernel Internals ● AV Instrumentation
  • 43. >_ Windows Kernel Emulation ● Windows kernel facilities are emulated with native code ● Object Manager ● Process management ● File system ● Registry ● Synchronization primitives
  • 44. >_ Object Manager ● The Object Manager is an essential part of the Windows Executive, provides kernel mode resource management, processes, files, registry keys, mutexes, etc ● Defender supports 5 types of objects: File, Thread, Event, Mutant(Mutex), Semaphore ● Manages system state during emulation that is persistent between native emulation API calls ● Objects are stored in a map, tracked by pid and handle Current process handle is emulated as 0x1234
  • 45. >_ Windows Emulation & Environment ● Usermode Environment ● Usermode Code ● User-Kernel Interaction ● Kernel Internals ● AV Instrumentation
  • 46. >_ Defender Internal Functions ● Internal administration and configuration functions accessible via apicall ● MpAddToScanQueue ○ Queue up a file (e.g., a dropped binary) for scanning ● MpCreateMemoryAliasing ○ Alias memory in emulator ● MpReportEvent, MpReportEventEx, MpReportEventW ○ Report malware behavior to inform heuristic detections ● MpGetSelectorBase, MpSetSelectorBase ○ Get/set segment registers (CS, DS, ES, etc) ● MpUfsMetadataOp ○ Get/set metadata about the file being scanned ● NtControlChannel ○ IOCTL-like administration for the AV engine
  • 47. >_ MpReportEvent ● Used to communicate information about malware binary actions with Defender’s heuristic detection engine
  • 48. >_ MpReportEvent - AV Processes ● Processes types are grouped by PID, processes for antivirus software has 700 PIDs ● Emulated process information is stored in a data structure in the kernel32.dll VDLL and presented when enumerated ● Calling TerminateProcess on an AV product triggers and MpReportEvent call
  • 51. >_ Tavis’ apicall Trick ● Build binary with an rwx .text section, generate apicall instruction on the fly as needed ● apicall instruction triggers native emulation functions from malware .text section with attacker controlled
  • 52. >_ Fuzzing Emulated APIs ● Create a binary that goes inside the emulator and repeatedly calls hooked WinExec function to request new data, then sends that data to functions with native emulations ● Buffers in memory passed to external hook function to populate with parameters ● Could do fuzzing in-emulator too, but this is easier for logging results
  • 53. >_ Input Generation ● Borrow OSX syscall fuzzer code from MWR Labs OSXFuzz project ● Nothing fancy, just throw random values at native emulation handlers ● Re-seed rand() at the start of each emulation session, just save off seeds in a log
  • 55. >_ Antivirus Reverse Engineering ● People constantly talk about what AVs can or can’t do, and how or where they are vulnerable ● Hope we’ll see more Antivirus research in the future ● More fuzzing methods to the Antivirus or Defender