Sigma rule: WinAPI Function Calls Via PowerShell Scripts

A detection rule from the SigmaHQ repository, shown as its author published it. Dataset version ref-cbe0387c43ba, updated 2023-07-21T00:00:00.000Z.

Rule

Title
WinAPI Function Calls Via PowerShell Scripts
Status
test
Level
medium
Author
Nikita Nazarov, oscd.community, Nasreddine Bencherchali (Nextron Systems)
Date
2023-07-21
File
rules-threat-hunting/windows/powershell/powershell_script/posh_ps_win_api_library_access.yml
Commit
ccbb0369507f796db0b0ae6854c8a2be471b9d84

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.

Log source

product
windows
category
ps_script
definition
Requirements: Script Block Logging must be enabled

Detection

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

False positives (as the rule lists them)

  • 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.

Tags

  • attack.execution
  • attack.t1059.001
  • attack.t1106
  • detection.threat-hunting

MITRE ATT&CK ids this rule names

Related rules

References

Read on 2026-11-03T00:58:21.399Z under licence sigma-drl-1.1@d5f4c36a from https://github.com/SigmaHQ/sigma/blob/ccbb0369507f796db0b0ae6854c8a2be471b9d84/rules-threat-hunting/windows/powershell/powershell_script/posh_ps_win_api_library_access.yml

Sources and licences

  • SigmaHQ

    "WinAPI Function Calls Via PowerShell Scripts" by Nikita Nazarov, oscd.community, Nasreddine Bencherchali (Nextron Systems) (SigmaHQ). Rule: https://github.com/SigmaHQ/sigma/blob/ccbb0369507f796db0b0ae6854c8a2be471b9d84/rules-threat-hunting/windows/powershell/powershell_script/posh_ps_win_api_library_access.yml.
    Licensed under the Detection Rule License (DRL) 1.1: https://github.com/SigmaHQ/Detection-Rule-License

    Detection Rule License (DRL) 1.1

Cite this page

Dragons Eye Ransomware Tracker, "Sigma rule: WinAPI Function Calls Via PowerShell Scripts",
entity page, dataset version ref-cbe0387c43ba, updated 2023-07-21T00:00:00.000Z,
https://ransomware-tracker.com/detections/sigma/9f22ccd5-a435-453b-af96-bf99cbb594d4 (accessed 2026-11-03).
Underlying source: SigmaHQ rule 9f22ccd5-a435-453b-af96-bf99cbb594d4, commit ccbb0369507f796db0b0ae6854c8a2be471b9d84.

Pages change. The dataset version identifies the data, but no archive of old versions is kept, so this citation cannot be replayed later.