1. Threat Context & Why Auth Boundaries Matter
In September 2026, Microsoft Threat Intelligence reported that Star Blizzard refined its malware delivery with the RedFlick technique, abusing native Windows OpenSSH (C:\Windows\System32\OpenSSH\ssh.exe) with PermitLocalCommand=yes and LocalCommand to spawn secondary payloads through a trusted, OS-bundled binary (LOLBAS #526 / PR #532).
However, focusing detections solely on PermitLocalCommand leaves a faster, less-noisy execution path unmonitored: KnownHostsCommand (LOLBAS PR #539). Whereas LocalCommand fires only after SSH authentication succeeds, OpenSSH invokes KnownHostsCommand during key exchange before authentication completes and without requiring PermitLocalCommand=yes. An operator can point ssh.exe at any reachable SSH banner (such as [email protected] or an attacker-controlled server), trigger local payload execution during key verification, and never complete a login.
2. Execution Vectors & Telemetry Blind Spots
To cover both LOLBAS-documented vectors and config-based execution in Windows environments, detections must account for four distinct invocation patterns:
| Directive / Variant | Auth Stage | LOLBAS / Observed Syntax | Primary Blind Spot |
|---|---|---|---|
KnownHostsCommand |
Pre-Auth (Key Exchange) | ssh.exe -o "StrictHostKeyChecking=no" -o "KnownHostsCommand=C:\Windows\System32\cmd.exe /c {CMD}" user@host |
Does not require PermitLocalCommand; missed by legacy Sigma rules checking only ProxyCommand/LocalCommand. |
PermitLocalCommand + LocalCommand |
Post-Auth (Session Established) | ssh.exe -o "StrictHostKeyChecking=no" -o "PermitLocalCommand=yes" -o "LocalCommand={CMD}" user@host |
LocalCommand executes via cmd.exe; easily masked if a naive query filters out strings containing =none or =no anywhere on the line. |
ProxyCommand |
Pre-Auth (Transport Setup) | ssh.exe -o "ProxyCommand=powershell -NoP -Command ..." user@host |
Legitimate dev tools (e.g., cloudflared access ssh) use ProxyCommand heavily; requires LOLBin/shell scoping. |
-F <file> or %USERPROFILE%\.ssh\config |
Pre- or Post-Auth | ssh.exe -F C:\Users\Public\cfg host |
Zero directive flags appear on the ssh.exe command line. Only parent-child process lineage (ssh.exe → cmd.exe / powershell.exe / mshta.exe ...) catches it. |
Checking only FileName =~ "ssh.exe" breaks if an adversary copies ssh.exe to svchost_helper.exe, and checking only ProcessCommandLine misses -F or .ssh/config. Therefore, the Sentinel query normalizes both process and parent identity with ProcessVersionInfoOriginalFileName =~ "ssh.exe" (and the same for child LOLBins) and pairs CLI matching with unexpected child-process detection.
3. Closing OpenSSH First-Match-Wins Evasion in Pure RE2
A subtle bug appears when rule authors try to exclude benign hardening flags like -o KnownHostsCommand=none or -o PermitLocalCommand=no using a naive global clause such as and not (ProcessCommandLine has "=none").
Per ssh_config(5), OpenSSH evaluates options strictly on a first-match-wins basis:
ssh.exe -o "StrictHostKeyChecking=no" -o KnownHostsCommand="cmd /c calc.exe" -o KnownHostsCommand=none user@host
OpenSSH binds KnownHostsCommand to "cmd /c calc.exe" and ignores the trailing -o KnownHostsCommand=none, so the payload still runs—yet any detection using a global exclusion like not ProcessCommandLine contains "KnownHostsCommand=none" silently drops the alert.
Fixing this cleanly in Microsoft Sentinel requires per-occurrence negation inside the regex itself. The catch is that Kusto's RE2 engine does not support negative lookaheads like (?!none). Instead, we compile the negation into a deterministic pure-RE2 character-prefix automaton:
none Matcher
(?i)(?:^|\s)-o\s{0,}["']{0,1}KnownHostsCommand(?:\s{0,}=\s{0,}|\s+)["']{0,1}(?:[^n=\s"']|n(?:[^o\s"']|["'\s]|$)|no(?:[^n\s"']|["'\s]|$)|non(?:[^e\s"']|["'\s]|$)|none[^\s"'])
- Handles compact & spaced forms:
-oKnownHostsCommand=...,-o "KnownHostsCommand = cmd.exe ...", and space-separated OpenSSH syntax (-o KnownHostsCommand ...). - Rejects exact
=none(and empty quotes): Any directive whose value is literallynonefollowed by whitespace, quote, or end-of-string fails every branch of the alternation. - Preserves commands starting with
n/no/non/none: A payload namednet.exe,notepad.exe,nonexistent.bat, ornone_evil.exematches via then[^o],no[^n],non[^e], ornone[^\s"']branches—without false negatives or ReDoS backtracking. - Evaluates each
-otoken independently: In the bypass command above, the first-o KnownHostsCommand="cmd /c calc.exe"matches immediately regardless of how many=noneoverrides follow it.
4. Full Sentinel KQL Hunting Query (Azure/Azure-Sentinel #15693)
Submitted in Azure/Azure-Sentinel #15693 (Hunting Queries/Microsoft 365 Defender/Execution/SshIndirectCommandExecution.yaml), the production query combines all four CLI detectors with child-process lineage and emits a normalized DetectionSignal summary for analyst triage:
let lookback = 7d;
DeviceProcessEvents
| where TimeGenerated >= ago(lookback)
| where ActionType == "ProcessCreated" or isempty(ActionType)
| extend
IsSshProcess = (FileName =~ "ssh.exe" or ProcessVersionInfoOriginalFileName =~ "ssh.exe"),
IsSshParent = (InitiatingProcessFileName =~ "ssh.exe" or InitiatingProcessVersionInfoOriginalFileName =~ "ssh.exe")
| where IsSshProcess or IsSshParent
| extend
HasKnownHostsCli = IsSshProcess
and ProcessCommandLine matches regex @"(?i)(?:^|\s)-o\s{0,}[""']{0,1}KnownHostsCommand(?:\s{0,}=\s{0,}|\s+)[""']{0,1}(?:[^n=\s""']|n(?:[^o\s""']|[""'\s]|$)|no(?:[^n\s""']|[""'\s]|$)|non(?:[^e\s""']|[""'\s]|$)|none[^\s""'])",
HasLocalCommandCli = IsSshProcess
and ProcessCommandLine matches regex @"(?i)(?:^|\s)-o\s{0,}[""']{0,1}LocalCommand(?:\s{0,}=\s{0,}|\s+)[""']{0,1}(?:[^n=\s""']|n(?:[^o\s""']|[""'\s]|$)|no(?:[^n\s""']|[""'\s]|$)|non(?:[^e\s""']|[""'\s]|$)|none[^\s""'])",
HasPermitLocalCli = IsSshProcess
and ProcessCommandLine matches regex @"(?i)(?:^|\s)-o\s{0,}[""']{0,1}PermitLocalCommand(?:\s{0,}=\s{0,}|\s+)[""']{0,1}(?:yes|true)(?:[""'\s]|$)",
HasSuspiciousProxyCli = IsSshProcess
and ProcessCommandLine matches regex @"(?i)(?:^|\s)-o\s{0,}[""']{0,1}ProxyCommand(?:\s{0,}=\s{0,}|\s+)[""']{0,1}(?:[^n=\s""']|n(?:[^o\s""']|[""'\s]|$)|no(?:[^n\s""']|[""'\s]|$)|non(?:[^e\s""']|[""'\s]|$)|none[^\s""'])"
and ProcessCommandLine has_any ("cmd", "powershell", "pwsh", "mshta", "wscript", "cscript", "rundll32", "regsvr32", "msiexec", "certutil", "bitsadmin"),
HasSuspiciousChild = IsSshParent
and (FileName in~ ("cmd.exe", "powershell.exe", "pwsh.exe", "mshta.exe", "wscript.exe", "cscript.exe", "rundll32.exe", "regsvr32.exe", "msiexec.exe", "certutil.exe", "bitsadmin.exe", "bash.exe", "wsl.exe")
or ProcessVersionInfoOriginalFileName in~ ("cmd.exe", "powershell.exe", "pwsh.exe", "mshta.exe", "wscript.exe", "cscript.exe", "rundll32.exe", "regsvr32.exe", "msiexec.exe", "certutil.exe", "bitsadmin.exe", "bash.exe", "wsl.exe"))
| where HasKnownHostsCli or HasLocalCommandCli or HasPermitLocalCli or HasSuspiciousProxyCli or HasSuspiciousChild
| extend DetectionSignal = strcat_array(pack_array(
iff(HasKnownHostsCli, "CLI:KnownHostsCommand", ""),
iff(HasLocalCommandCli, "CLI:LocalCommand", ""),
iff(HasPermitLocalCli, "CLI:PermitLocalCommand=yes", ""),
iff(HasSuspiciousProxyCli, "CLI:ProxyCommand", ""),
iff(HasSuspiciousChild, "ChildProcess:SpawnedBySsh", "")
), ";")
| extend DetectionSignal = trim(@";+", replace_regex(DetectionSignal, @";{2,}", ";"))
| extend ProcessIdStr = tostring(ProcessId)
| project
TimeGenerated,
DeviceName,
AccountDomain,
AccountName,
AccountSid,
FileName,
ProcessIdStr,
ProcessCommandLine,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
DetectionSignal
| sort by TimeGenerated desc
5. Portable Sigma Coverage (SigmaHQ/sigma #6585)
While the existing Sigma rule proc_creation_win_ssh_proxy_execution.yml covered ProxyCommand and PermitLocalCommand=yes/LocalCommand, it lacked KnownHostsCommand and ATT&CK T1202 tagging. SigmaHQ/sigma #6585 enriches the upstream rule while aligning with ATT&CK v18 tag taxonomy (attack.execution, attack.stealth, attack.t1202, attack.t1218), verified locally with sigma check --fail-on-error --fail-on-issues (0 issues):
title: Program Executed Using Proxy/Local/KnownHosts Command Via SSH.EXE
tags:
- attack.execution
- attack.stealth
- attack.t1202
- attack.t1218
detection:
selection_cli_args:
- CommandLine|contains: 'ProxyCommand'
- CommandLine|contains|all:
- 'PermitLocalCommand=yes'
- ' LocalCommand'
- CommandLine|contains: 'KnownHostsCommand'
condition: selection_parent or all of selection_cli_*
6. Empirical Validation in Azure Data Explorer (19-Case Harness)
Static syntax parsing is never proof that an RE2 automaton handles real quoting and boundary edge cases. The Sentinel query was executed live against an Azure Data Explorer cluster (help/Samples) using a self-contained 19-row synthetic DeviceProcessEvents datatable covering adversarial edge cases and realistic benign telemetry:
- 11 True Positives verified: Star Blizzard RedFlick pattern (
PermitLocalCommand=yes+LocalCommand), pre-authKnownHostsCommand, compact-oKnownHostsCommand=..., renamedssh.execaught viaProcessVersionInfoOriginalFileName, OpenSSH first-match-wins bypass attempts with trailing=none/=nooverrides,ProxyCommandinvoking PowerShell,-Fconfig child-process spawning, andn/no/non/none_command prefix boundary tests (e.g.,notepad.exe,none_tool.exe). - 8 True Negatives verified: Standard interactive SSH login, explicit hardening flags (
-o KnownHostsCommand=none,-o LocalCommand=none,-o PermitLocalCommand=no), legitimatecloudflaredProxyCommandwrapper, benignssh-askpass.exechild process, whitespace around=, and empty quoted directives. - Repo CI validations: Passed
KqlValidations(Microsoft.Azure.Kusto.LanguageagainstDeviceProcessEvents.jsonschema),YamlDotNet,js-yaml,NonAsciiValidationsTests,DocumentsLinkValidation, and CodeQL (24/24 checks completed, 0 failures).
7. Tuning, False Positives & Endpoint Hardening
- Administrative jump hosts & IDE tunnels: Developer tools (VS Code Remote-SSH, Git automation, bastion wrappers) may spawn shells or helpers under
ssh.exe. Tune by excluding verifiedInitiatingProcessCommandLinepatterns or dedicated jump-host automation accounts rather than relaxingKnownHostsCommandorPermitLocalCommandchecks. - Pre-auth hardening: Where remote SSH access from workstations is unneeded or standardized, enforce explicit client policy or WDAC/AppLocker rules auditing
ssh.exeexecution alongside%USERPROFILE%\.ssh\configintegrity monitoring.
8. Verified References
- LOLBAS Project — Official
Ssh.exeDocumentation (PR #539 & PR #532, Merged) - Microsoft Threat Intelligence — Star Blizzard refines phishing and malware delivery with the RedFlick technique (Sep 2026)
- SigmaHQ/sigma #6585 —
proc_creation_win_ssh_proxy_execution.ymlenhancement - Azure/Azure-Sentinel #15693 —
SshIndirectCommandExecution.yamlHunting Query - MITRE ATT&CK T1202 — Indirect Command Execution