PowerShell Keylogging Script

Last updated 8 days ago on 2026-01-26
Created 4 years ago on 2021-10-15

About

Detects PowerShell script block content that references Win32 keylogging primitives such as key state polling or low-level input hooks. Adversaries use keylogging to capture credentials and other sensitive user input.
Tags
Domain: EndpointOS: WindowsUse Case: Threat DetectionTactic: CollectionData Source: PowerShell LogsLanguage: kuery
Severity
high
Risk Score
73
MITRE ATT&CK™

Collection (TA0009)(external, opens in a new tab or window)

Execution (TA0002)(external, opens in a new tab or window)

License
Elastic License v2(external, opens in a new tab or window)

Definition

Rule Type
Query (Kibana Query Language)
Integration Pack
Prebuilt Security Detection Rules
Index Patterns
winlogbeat-*logs-windows.powershell*
Related Integrations

windows(external, opens in a new tab or window)

Query
text code block:
event.category:process and host.os.type:windows and ( powershell.file.script_block_text : (GetAsyncKeyState or NtUserGetAsyncKeyState or GetKeyboardState or "Get-Keystrokes") or powershell.file.script_block_text : ( (SetWindowsHookEx or SetWindowsHookExA or SetWindowsHookExW or NtUserSetWindowsHookEx) and ( GetForegroundWindow or GetWindowTextA or GetWindowTextW or "WM_KEYBOARD_LL" or "WH_MOUSE_LL" or "WH_KEYBOARD_LL" or "LowLevelKeyboardProc" or "CallNextHookEx" ) ) ) and not user.id : "S-1-5-18" and not powershell.file.script_block_text : ( "sentinelbreakpoints" and "Set-PSBreakpoint" )

Install detection rules in Elastic Security

Detect PowerShell Keylogging Script in the Elastic Security detection engine by installing this rule into your Elastic Stack.

To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).