WinAPI Function Calls Via PowerShell Scripts
Description
Detects calls to WinAPI functions from PowerShell scripts. Attackers can often leverage these APIs to avoid detection based on typical PowerShell function calls. Use this rule as a basis to hunt for interesting scripts.
Query · sigma
selection: ScriptBlockText|contains: - AddSecurityPackage - AdjustTokenPrivileges - CloseHandle - CreateProcessWithToken - CreateRemoteThread - CreateThread - CreateUserThread - DangerousGetHandle - DuplicateTokenEx - EnumerateSecurityPackages - FreeLibrary - GetDelegateForFunctionPointer - GetLogonSessionData - GetModuleHandle - GetProcAddress - GetProcessHandle - GetTokenInformation - ImpersonateLoggedOnUser - LoadLibrary - memcpy - MiniDumpWriteDump - OpenDesktop - OpenProcess - OpenProcessToken - OpenThreadToken - OpenWindowStation - QueueUserApc - ReadProcessMemory - RevertToSelf - RtlCreateUserThread - SetThreadToken - VirtualAlloc - VirtualFree - VirtualProtect - WaitForSingleObject - WriteInt32 - WriteProcessMemory - ZeroFreeGlobalAllocUnicode condition: selection
Known false positives
- This rule is mainly used for hunting and will generate quite a lot of false positives when applied in production. It's best combined with other fields such as the path of execution, the parent process, etc.