Input Injection
This detection identifies adversary attempts to simulate keyboard input to execute commands or manipulate applications on behalf of victims. Input injection manifests through HID (Human Interface Device) emulation via malicious USB devices, programmatic keystroke injection via Win32 APIs (SendInput, keybd_event, PostMessage with WM_KEYDOWN/WM_KEYUP), and monitoring of the Windows message loop to inject input into specific applications such as browsers. Key indicators include PowerShell or command interpreters spawning from interactive desktop processes (explorer.exe) with no visible user session context, rapid automated input sequences following USB device attachment, and browser processes receiving injected console commands characteristic of banking trojans like BackSwap that monitor for financial URLs and inject JavaScript via simulated keystrokes.
let SuspiciousChildProcs = dynamic(["powershell.exe", "cmd.exe", "wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe", "regsvr32.exe", "certutil.exe"]);
let EncodedFlags = dynamic(["-EncodedCommand", "-enc ", "-e ", "IEX", "Invoke-Expression", "DownloadString", "DownloadFile", "FromBase64String", "-WindowStyle Hidden", "-NoProfile", "-NonInteractive"]);
// Detect shell processes spawned via simulated input from desktop/shell parents with obfuscated command lines
let HIDSpawnedShells = DeviceProcessEvents
| where TimeGenerated > ago(1d)
| where InitiatingProcessFileName in~ ("explorer.exe", "winlogon.exe", "userinit.exe", "sihost.exe", "taskhostw.exe")
| where FileName in~ (SuspiciousChildProcs)
| where ProcessCommandLine has_any (EncodedFlags)
| project TimeGenerated, DeviceName, AccountName, InitiatingProcessFileName, InitiatingProcessId,
FileName, ProcessId, ProcessCommandLine, InitiatingProcessCommandLine,
FolderPath, SHA256, ReportId;
// Detect browser developer console or address bar manipulation patterns (BackSwap-style)
let BrowserInjection = DeviceProcessEvents
| where TimeGenerated > ago(1d)
| where InitiatingProcessFileName in~ ("chrome.exe", "firefox.exe", "msedge.exe", "iexplore.exe", "brave.exe")
| where FileName in~ ("powershell.exe", "cmd.exe", "wscript.exe", "cscript.exe")
| project TimeGenerated, DeviceName, AccountName, InitiatingProcessFileName, InitiatingProcessId,
FileName, ProcessId, ProcessCommandLine, FolderPath, SHA256, ReportId;
// Union both patterns
union HIDSpawnedShells, BrowserInjection
| extend InjectionType = iff(InitiatingProcessFileName in~ ("chrome.exe", "firefox.exe", "msedge.exe", "iexplore.exe", "brave.exe"), "BrowserInputInjection", "HIDKeystrokeInjection")
| order by TimeGenerated desc
| project TimeGenerated, DeviceName, AccountName, InjectionType, InitiatingProcessFileName,
InitiatingProcessId, FileName, ProcessId, ProcessCommandLine, SHA256, ReportId Data Sources
Required Tables
False Positives
- Legitimate IT automation tools (AutoHotkey, AutoIt, SikuliX) used for desktop automation workflows that spawn PowerShell from shell processes
- Software deployment systems (SCCM, PDQ Deploy, Ansible) that use explorer.exe as a parent during user-context deployments
- Accessibility software (Dragon NaturallySpeaking, voice control tools) that simulate keystrokes to interact with applications
- Developer tools and IDEs that programmatically open terminal sessions from browser-integrated development environments
- Browser automation frameworks (Selenium, Puppeteer in non-headless mode) during legitimate QA testing that trigger child process creation
References (9)
- https://attack.mitre.org/techniques/T1674/
- https://www.bleepingcomputer.com/news/security/backswap-malware-found-in-pirated-software/
- https://www.welivesecurity.com/2018/05/25/backswap-malware-empty-bank-accounts/
- https://www.bleepingcomputer.com/news/security/fin7-hackers-now-sending-malicious-usb-sticks-via-usps/
- https://www.ic3.gov/Media/News/2020/201210-1.pdf
- https://www.mandiant.com/resources/blog/fin7-shim-databases-persistence
- https://attack.mitre.org/groups/G0046/
- https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput
- https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-postmessagea
Unlock Pro Content
Get the full detection package for T1674 including response playbook, investigation guide, and atomic red team tests.