Deep Dive 01 · Detection Engineering

Abusing Windows OpenSSH and Closing First-Match-Wins Bypasses in KQL & Sigma

Native C:\Windows\System32\OpenSSH\ssh.exe ships on modern Windows endpoints as a Microsoft-signed binary capable of executing arbitrary local payloads before user authentication completes (KnownHostsCommand) or immediately after session establishment (PermitLocalCommand). This write-up documents the complete LOLBAS → Sigma → Microsoft Sentinel KQL engineering cycle, including a pure-RE2 automaton that defeats OpenSSH's first-match-wins option override trick.

MITRE ATT&CK: T1202 · T1059 Telemetry: DeviceProcessEvents · Sysmon EID 1 Published: 2026-11-20 9 min read

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.
Key Design Constraint: Renamed Binaries & Config Indirection

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:

Evasion Payload · OpenSSH First-Match-Wins
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:

Pure RE2 · Per-Occurrence Non-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 literally none followed by whitespace, quote, or end-of-string fails every branch of the alternation.
  • Preserves commands starting with n/no/non/none: A payload named net.exe, notepad.exe, nonexistent.bat, or none_evil.exe matches via the n[^o], no[^n], non[^e], or none[^\s"'] branches—without false negatives or ReDoS backtracking.
  • Evaluates each -o token independently: In the bypass command above, the first -o KnownHostsCommand="cmd /c calc.exe" matches immediately regardless of how many =none overrides 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:

KQL · SshIndirectCommandExecution.yaml (MITRE T1202 / T1059)
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):

YAML · proc_creation_win_ssh_proxy_execution.yml (Diff Highlight)
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 / 11
True Positives Detected
0 / 8
False Positives (TN 8/8)
2.382 s
ADX Execution Runtime
24 / 24
Sentinel CI Checks Passed
  • 11 True Positives verified: Star Blizzard RedFlick pattern (PermitLocalCommand=yes + LocalCommand), pre-auth KnownHostsCommand, compact -oKnownHostsCommand=..., renamed ssh.exe caught via ProcessVersionInfoOriginalFileName, OpenSSH first-match-wins bypass attempts with trailing =none / =no overrides, ProxyCommand invoking PowerShell, -F config child-process spawning, and n/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), legitimate cloudflared ProxyCommand wrapper, benign ssh-askpass.exe child process, whitespace around =, and empty quoted directives.
  • Repo CI validations: Passed KqlValidations (Microsoft.Azure.Kusto.Language against DeviceProcessEvents.json schema), 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 verified InitiatingProcessCommandLine patterns or dedicated jump-host automation accounts rather than relaxing KnownHostsCommand or PermitLocalCommand checks.
  • Pre-auth hardening: Where remote SSH access from workstations is unneeded or standardized, enforce explicit client policy or WDAC/AppLocker rules auditing ssh.exe execution alongside %USERPROFILE%\.ssh\config integrity monitoring.

8. Verified References