Potential DLL Hijack via Directory Spoofing
Description
Identifies attempt to perform DLL hijacking using System32 executables or others in non-user-writable folders by spoofing the the directory from which the application is loaded to an arbitrary user-specified one.
Query · eql
sequence by process.entity_id with maxspan=1m
[process where event.action == "start" and
_arraysearch(process.parent.thread.Ext.call_stack, $entry, $entry.symbol_info: "*RtlCreateUserProcessEx*") and
process.parent.thread.Ext.call_stack_summary : "ntdll.dll*" and
not process.parent.thread.Ext.call_stack_summary : ("*kernel32*", "*kernelbase*", "ntdll.dll|smss.exe|ntdll.dll") and
not _arraysearch(process.parent.thread.Ext.call_stack, $entry, $entry.symbol_info: "*RtlCloneUserProcess*")]
[library where not dll.code_signature.status : "trusted" and not startswith~(dll.name, process.name) and
process.thread.Ext.call_stack_summary : "ntdll.dll|kernel32.dll|ntdll.dll" and
not _arraysearch(process.thread.Ext.call_stack, $entry, $entry.symbol_info: ("*LdrLoadDll*", "*LoadLibrary*")) and
not dll.path :
("?:\\Windows\\System32\\*",
"?:\\Windows\\SysWOW64\\*",
"?:\\Windows\\WinSxS\\*",
"?:\\Windows\\assembly\\*",
"?:\\Windows\\assembly\\NativeImages_v*",
"?:\\Windows\\SoftwareDistribution\\Download\\*",
"?:\\Program Files\\*",
"?:\\Program Files (x86)\\*") and
/* DLL not loaded from the process.executable current directory */
not endswith~(substring(dll.path, 0, length(dll.path) - (length(dll.name) + 1)), substring(process.executable, 0, length(process.executable) - (length(process.name) + 1)))]