PowerShell Scripts Calling WinAPI DLLs on Windows

Detects PowerShell script blocks that reference WinAPI-related Windows DLLs such as kernel32.dll and ntdll.dll.

FreeReviewedSigma · Medium · v5
Product
windows
Category
ps_script
Author
Nikita Nazarov, oscd.community, Nasreddine Bencherchali (Nextron Systems) (SigmaHQ), DRL 1.1
Published
2023-07-21
Updated
2026-07-31
title: PowerShell Scripts Calling WinAPI DLLs on Windows
id: 05dcf360-2100-40cf-862e-5d06d39e86c0
related:
  - id: ba3f5c1b-6272-4119-9dbd-0bc8d21c2702
    type: similar
  - id: 03d83090-8cba-44a0-b02f-0b756a050306
    type: similar
  - id: 9f22ccd5-a435-453b-af96-bf99cbb594d4
    type: similar
  - id: 19d65a1c-8540-4140-8062-8eb00db0bba5
    type: derived
status: test
description: This rule flags PowerShell script block content that includes references to common Windows system DLLs such as Advapi32.dll, kernel32.dll, KernelBase.dll, ntdll.dll, secur32.dll, and user32.dll. Attackers may invoke WinAPI functionality directly from scripts to blend in or bypass detections focused on standard PowerShell activity. It relies on PowerShell Script Block Logging telemetry that records script block text for these DLL name matches.
references:
  - https://speakerdeck.com/heirhabarov/hunting-for-powershell-abuse
  - https://github.com/SigmaHQ/sigma/blob/master/rules-threat-hunting/windows/powershell/powershell_script/posh_ps_win_api_functions_access.yml
author: Nikita Nazarov, oscd.community, Nasreddine Bencherchali (Nextron Systems), Huntrule Team
date: 2023-07-21
tags:
  - attack.execution
  - attack.t1059.001
  - attack.t1106
  - detection.threat-hunting
logsource:
  product: windows
  category: ps_script
  definition: "Requirements: Script Block Logging must be enabled"
detection:
  selection:
    ScriptBlockText|contains:
      - Advapi32.dll
      - kernel32.dll
      - KernelBase.dll
      - ntdll.dll
      - secur32.dll
      - user32.dll
  condition: selection
falsepositives:
  - Carbon PowerShell Module (https://github.com/webmd-health-services/Carbon)
  - Chocolatey scripts
level: medium
license: DRL-1.1