PowerShell Keylogging via Get-Keystrokes and Win32 API Calls (GetAsyncKeyState, GetForegroundWindow)

Flags PowerShell script blocks containing Get-Keystrokes with GetAsyncKeyState/GetForegroundWindow for potential keylogging.

FreeReviewedSigma · Medium · v2
Product
windows
Category
ps_script
Author
frack113 (SigmaHQ), DRL 1.1
Published
2021-07-30
Updated
2026-07-31

ATT&CK techniques

Cred Access → Collection
  1. Recon

  2. Resource Dev

  3. Initial Access

  4. Execution

  5. Persistence

  6. Priv Esc

  7. Defense Evasion

  8. Discovery

  9. Lateral Movement

  10. C2

  11. Exfiltration

  12. Impact

What it detects

This rule identifies PowerShell scripts that include the Get-Keystrokes function and use Win32 API calls commonly associated with monitoring keyboard state and foreground window context. Such activity can enable attackers to capture user input and potentially intercept credentials as they are typed. Detection relies on Script Block Logging telemetry containing the relevant PowerShell text patterns and API call strings within the executed script block.

Related detections9 linkedT1056.001 — drag to rearrange
Suspicious Keylog and Screenshot Files in windows-cache Directory (OtterCookie)
Suspicious WezRat Keylog File in Temp Directory
Suspicious Larva-24009 Keylogger Log Staging in OneDrive Path (via file_event)
Suspicious Kimsuky AlphaSeed Artifacts in edge Hidden Directory (via file_event)
In-Memory Remcos RAT Keylog Store Created Under ProgramData rema (via file_event)
Possible Andariel Keylogger Output Archive Staged in Temp (via file_event)
Suspicious Parallax RAT Keylogger Output File Creation via File System (via file_event)
Malicious VenomRAT Offline Keylog File Creation via file_event
Suspicious BunnyLoader Keylog Capture File in AppData Temp (via file_event)
PowerShell Keylogging via Get-Keystrokes and Win32 API Calls (GetAsyncKeyState, GetForegroundWindow)
Pivot detection · T1056.001 · 9 related

Changelog

v2
  1. v2
    Candidate ingested via manual entry.2026-07-31
  2. v1
    No changelog recorded for this version.2026-07-30

Detection content is published as a reviewed draft. Tune thresholds and exclusions against your own telemetry before enabling this rule for alerting.