Detect ssh.exe -R Reverse Tunnels (KQL and ES|QL)
Detects: ssh.exe launched with a remote forward (-R), alone or inside a flag cluster.
ATT&CK: T1572 Protocol Tunneling, T1090.002 External Proxy
Works on: Microsoft Defender for Endpoint, KQL (DeviceProcessEvents); Elastic with Sysmon Event ID 1, ES|QL
Tested on: my lab, five ssh.exe starts from one Windows host, three plain -R and two flag clusters (-fNR, -NR), on both stacks
Full write-up: Detecting Reverse SSH SOCKS Tunnels: Separating Benign -R From Akira Pivoting
Why a destination-less -R matters
Since OpenSSH 7.6, giving -R a bind and a port but no target opens that remote port as a SOCKS 4/5 proxy: reverse dynamic forwarding. A remote client asks for host:port and SSH dials the connection from the compromised host. In an Akira intrusion documented by The DFIR Report, the operators did this with ssh root@<host> -R *:10400, ran a renamed scanner through it, and deployed ransomware in under 44 hours.
The published Sigma rule, Port Forwarding Activity Via SSH.EXE, checks for ssh.exe plus -R and ships with a false-positive note about admin port forwarding. These queries are that logic as a hunt on each stack.
The queries
Published verbatim from the newsletter issue.
KQL (Microsoft Defender for Endpoint):
DeviceProcessEvents
| where Timestamp > ago(1h)
| where FileName =~ "ssh.exe"
| where ProcessCommandLine matches regex @"\s-\w*R"
| project Timestamp, DeviceName, ActionType, FileName, ProcessCommandLine,
InitiatingProcessFileName, InitiatingProcessCommandLine, InitiatingProcessParentFileName,
InitiatingProcessVersionInfoProductVersion, InitiatingProcessIntegrityLevel
| order by Timestamp asc

ES|QL (Elastic, Sysmon Event ID 1):
FROM logs-windows.sysmon_operational-default
| WHERE @timestamp > NOW() - 1 hours
| WHERE event.code == "1"
| WHERE process.name == "ssh.exe"
| WHERE process.command_line RLIKE """.*\s-[A-Za-z]*R.*"""
| KEEP @timestamp, host.name, process.name, process.command_line,
process.parent.name, process.parent.command_line,
user.name, winlog.event_data.IntegrityLevel
| SORT @timestamp ASC
| LIMIT 1000

What it catches
Every ssh.exe start with a capital -R in its arguments, with the parent process and integrity level next to it. That is intent: someone opened a reverse tunnel.
Get the next detection in your inbox
One lab-proven detection per issue: the attacker command, the telemetry it leaves, and the KQL / ES|QL that catches it.
You confirm on Substack in one tap.
No spam. Unsubscribe anytime.
Tuning note
This is the trigger, not the verdict.
Whatever the attacker runs next, NetExec, nmap or lateral movement, executes inside the encrypted tunnel and never surfaces in a command line; the initiating process reads ssh.exe for every move.
Proving the pivot takes the network side: the connections ssh.exe opens for the proxy, and their shape.
Did this query fire in your environment, or miss something? Email me what you saw: ayush@securityinbits.com (open in Gmail). I read every reply, and it decides what I test next.
Questions
Is every ssh.exe -R malicious?
No. The same -R mechanism shows up in benign admin work and in attacks. The process event proves a tunnel is present, not that it is a pivot.
Why a regex instead of contains "-R"?
Attackers bundle the flag into a cluster like -NR, -fNR or -fNTR to background the tunnel. The regex still catches the -R inside those, and it is capital-R only, case-sensitive on purpose.