Skip to content

Add BadUSB PowerShell Run dialog hunting query (HID injection)#14336

Open
descambiado wants to merge 1 commit into
Azure:masterfrom
descambiado:add-badusb-hid-injection-hunting-query
Open

Add BadUSB PowerShell Run dialog hunting query (HID injection)#14336
descambiado wants to merge 1 commit into
Azure:masterfrom
descambiado:add-badusb-hid-injection-hunting-query

Conversation

@descambiado
Copy link
Copy Markdown
Contributor

Description

Adds a hunting query that detects PowerShell spawned by explorer.exe with a hidden window and remote execution or evasion flags, consistent with BadUSB / HID injection payloads that open the Windows Run dialog via WIN+R.

When a hardware keystroke injector (Flipper Zero, Rubber Ducky, etc.) uses WIN+R to launch a command, the resulting process has explorer.exe as its parent. Pairing -WindowStyle Hidden with any cradle flag is a reliable indicator of automated injection rather than interactive user activity.

Detection logic

  • Data source: DeviceProcessEvents (Microsoft Defender for Endpoint)
  • Parent process: explorer.exe
  • Child process: powershell.exe or pwsh.exe
  • CommandLine: has_all("-WindowStyle", "Hidden") AND has_any of 9 evasion/cradle flags
  • Lookback: 1 day (adjustable via timeframe variable)

MITRE ATT&CK

  • T1059.001 - Command and Scripting Interpreter: PowerShell
  • T1564.003 - Hide Artifacts: Hidden Window
  • T1200 - Hardware Additions

Files changed

  • Hunting Queries/MultipleDataSources/BadUSBPowerShellRunDialog.yaml

Testing

Rule validated end-to-end against a Flipper Zero BadUSB payload. Companion SIGMA rule contributed to SigmaHQ (PR #6028). Source payload and forensic breakdown: https://github.com/descambiado/flipper-purple-team/tree/main/badusb/01-windows-powershell-run-dialog

Adds a DeviceProcessEvents hunting query that detects PowerShell spawned
by explorer.exe with -WindowStyle Hidden and any remote execution or
evasion flag, consistent with HID injection payloads using WIN+R.

MITRE ATT&CK: T1059.001, T1564.003, T1200
@descambiado descambiado requested review from a team as code owners May 23, 2026 18:23
@v-maheshbh v-maheshbh added the Hunting Hunting specialty review needed label May 25, 2026
@v-atulyadav v-atulyadav requested a review from Copilot May 26, 2026 08:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new Microsoft Sentinel hunting query to identify likely BadUSB/HID keystroke-injection activity that launches PowerShell via the Windows Run dialog, focusing on explorer.exe parentage plus hidden window + cradle/evasion flags.

Changes:

  • Introduces a new hunting query YAML targeting DeviceProcessEvents (MDE).
  • Adds MITRE ATT&CK tactics/techniques, entity mappings, and solution metadata fields for the query.

Comment on lines +4 to +8
Identifies PowerShell spawned by explorer.exe with a hidden window and remote
execution or evasion flags, consistent with BadUSB HID injection payloads that
open the Windows Run dialog via WIN+R. Keystroke injection via hardware sets
explorer.exe as the parent; pairing -WindowStyle Hidden with any cradle flag is
a reliable indicator of automated injection rather than interactive user activity.
@@ -0,0 +1,70 @@
id: 683b2baa-39c3-457d-b64e-2e57c8fc83ba
name: BadUSB PowerShell execution via Windows Run dialog (HID injection)
Comment on lines +23 to +33
let EvasionFlags = dynamic([
"-NoProfile",
"-NonInteractive",
"-EncodedCommand",
"-ExecutionPolicy Bypass",
"DownloadString",
"IEX",
"Invoke-Expression",
"WebClient",
"Start-Process"
]);
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where InitiatingProcessFileName =~ "explorer.exe"
| where ProcessCommandLine has_all ("-WindowStyle", "Hidden")
| where ProcessCommandLine has_any (EvasionFlags)
support:
tier: Community
categories:
domains: [ "Security - Threat Protection", "Endpoints" ]
"WebClient",
"Start-Process"
]);
DeviceProcessEvents
Comment on lines +49 to +60
| sort by TimeGenerated desc
entityMappings:
- entityType: Account
fieldMappings:
- identifier: Name
columnName: AccountName
- identifier: NTDomain
columnName: AccountDomain
- entityType: Host
fieldMappings:
- identifier: HostName
columnName: DeviceName
@v-atulyadav
Copy link
Copy Markdown
Collaborator

Hi @descambiado,
Please check Copilot’s suggestions and act accordingly. Once done, click the “Resolve conversation” button.
Also, please pull the latest changes from the master branch and push again to rerun the stuck validation. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hunting Hunting specialty review needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants