Indirect Command Execution
Adversaries may abuse utilities that allow for command execution to bypass security restrictions that limit the use of command-line interpreters. Various Windows utilities may be used to execute commands, possibly without invoking cmd.exe directly. Tools such as Forfiles, the Program Compatibility Assistant (pcalua.exe), Windows Subsystem for Linux (WSL via wsl.exe or bash.exe), Scriptrunner.exe, and ssh.exe may invoke the execution of programs and commands from a scripting interpreter, Run window, or via scripts. Adversaries use these features for Defense Evasion, specifically to perform arbitrary execution while subverting detections and Group Policy controls that restrict cmd.exe usage or block certain file extensions. Real-world actors including Lazarus Group (forfiles for .htm execution), Revenge RAT (forfiles for command execution), and RedCurl (pcalua.exe for binary obfuscation) have demonstrated operational use of this technique.
let IndirectExecutors = dynamic(["forfiles.exe", "pcalua.exe", "scriptrunner.exe", "wsl.exe", "bash.exe", "wscript.exe"]);
let SuspiciousChildProcesses = dynamic(["cmd.exe", "powershell.exe", "pwsh.exe", "mshta.exe", "wscript.exe", "cscript.exe", "rundll32.exe", "regsvr32.exe", "certutil.exe", "bitsadmin.exe", "msbuild.exe", "csc.exe", "net.exe", "net1.exe", "sc.exe", "reg.exe"]);
// Detection 1: Forfiles used to execute commands indirectly
let ForfilesExec = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "forfiles.exe"
| where ProcessCommandLine has_any ("/c", "/C")
| where ProcessCommandLine has_any ("cmd", "powershell", "pwsh", "mshta", "wscript", "cscript", "rundll32", "regsvr32", "certutil", "bitsadmin", "/c ", "0x", "@path", "@file", "@fdate", "@ftime")
| extend ExecutionMethod = "Forfiles"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine, ExecutionMethod;
// Detection 2: pcalua.exe used for binary execution bypass
let PcaluaExec = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "pcalua.exe"
| where ProcessCommandLine has_any ("-a", "-i")
| extend ExecutionMethod = "PcaluaBypass"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine, ExecutionMethod;
// Detection 3: Scriptrunner.exe proxy execution
let ScriptrunnerExec = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "scriptrunner.exe"
| where ProcessCommandLine has_any ("-appcompat", "/appcompat", "-appcompatpath", ".exe", ".bat", ".ps1", ".cmd")
| extend ExecutionMethod = "Scriptrunner"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine, ExecutionMethod;
// Detection 4: WSL/bash used to execute Windows-facing commands or reach out
let WslExec = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName in~ ("wsl.exe", "bash.exe")
| where ProcessCommandLine has_any ("-e ", "--exec", "-c ", "cmd.exe", "powershell", "net.exe", "curl", "wget", "nc", "ncat", "python", "/mnt/c", "/proc/", "base64")
| extend ExecutionMethod = "WSL"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine, ExecutionMethod;
// Detection 5: ssh.exe ProxyCommand / LocalCommand abuse
let SshExec = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "ssh.exe"
| where ProcessCommandLine has_any ("ProxyCommand", "LocalCommand", "-o ProxyCommand", "-o LocalCommand", "PermitLocalCommand")
| extend ExecutionMethod = "SSH-ProxyCommand"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine, ExecutionMethod;
// Union all detections
union ForfilesExec, PcaluaExec, ScriptrunnerExec, WslExec, SshExec
| sort by Timestamp desc Data Sources
Required Tables
False Positives
- Legitimate administrative use of forfiles.exe for batch file operations, directory traversal, or scheduled maintenance scripts (e.g., deleting files older than N days)
- WSL (wsl.exe/bash.exe) activity from developers who legitimately use Linux tools and access the Windows filesystem via /mnt/c in their daily workflows
- System compatibility infrastructure invoking pcalua.exe when users launch legacy applications that trigger Program Compatibility Assistant automatically
- SSH client usage with ProxyCommand set in ~/.ssh/config for legitimate jump-host configurations or tunneling through bastion hosts
- Scriptrunner.exe invoked by application shims during compatibility testing or software packaging processes
References (13)
- https://attack.mitre.org/techniques/T1202/
- https://community.rsa.com/community/products/netwitness/blog/2017/08/14/are-you-looking-out-for-forfilesexe-if-you-are-watching-for-cmdexe
- https://x.com/vector_sec/status/896049052642533376
- https://x.com/Evi1cg/status/935027922397573120
- https://secureteam.co.uk/2023/01/08/windows-error-reporting-tool-abused-to-load-malware/
- https://www.bleepingcomputer.com/news/security/hackers-abuse-windows-error-reporting-tool-to-deploy-malware/
- https://ss64.com/nt/scriptrunner.html
- https://cyble.com/blog/threat-actor-targets-manufacturing-industry-with-malware/
- https://lolbas-project.github.io/lolbas/Binaries/Forfiles/
- https://lolbas-project.github.io/lolbas/Binaries/Pcalua/
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1202/T1202.md
- https://github.com/SigmaHQ/sigma/blob/master/rules/windows/process_creation/proc_creation_win_lolbin_forfiles.yml
- https://learn.microsoft.com/en-us/defender-endpoint/advanced-hunting-deviceprocessevents-table
Unlock Pro Content
Get the full detection package for T1202 including response playbook, investigation guide, and atomic red team tests.