SSH Tunneling Detected: Warning Signs, Sigma Rules and Elastic Queries

SSH Tunneling Detected: Warning Signs, Sigma Rules and Elastic Queries

This is Part 3 of a three-part series. Part 1 explains how SSH tunneling works, and Part 2 walks through real attacks that used it.

The usual objection to hunting SSH tunnels is “it’s encrypted, so what can we even see?” More than you’d think. The traffic inside the tunnel is hidden, but someone has to start the tunnel, it has to run somewhere, it has to connect to something, and it usually has to survive a reboot. Each of those leaves a trace.

In this post we’ll go through those traces, look at what the public rule sets already cover, and then write our own rules for the gaps, including the exact tricks from the CISA case in Part 2.

Diagram showing endpoint, network and SSH server logs feeding a SIEM to detect SSH tunneling.
Three sources of evidence. Each one alone is noisy; together they make tunnels stand out.

The warning signs

On the endpoint

  • Forwarding flags on the command line. -L, -R, -D and -w for OpenSSH and plink, often with -N, -f or plink’s -batch. Watch for combined flags like -fNR too.
  • SSH clients where they don’t belong. ssh.exe or plink.exe on a domain controller or file server, or ssh started by a web server, a Java application or a database.
  • Renamed binaries. A file whose PE metadata says it’s PuTTY’s plink but whose name says ShellExperienceHost.exe is lying to you.
  • Persistence wrapped around SSH. New scheduled tasks (Windows event 4698), services, cron entries or systemd units that launch an SSH client.
  • Unexpected listening ports. A server that suddenly listens on 8100, 1080 or 39999. Local forwarding and SOCKS proxies have to bind somewhere.
  • Related pivot tricks. netsh interface portproxy rules on Windows, or tools like chisel, socat and ngrok, which attackers often use alongside or instead of SSH.

On the network

  • Servers dialing out over SSH. Most servers accept SSH; very few should start SSH connections to the Internet.
  • SSH on the “wrong” port. Zeek and most NGFWs identify SSH by its handshake, not its port. SSH on 443, 80 or 53 is almost always someone trying to blend in.
  • Long-lived sessions. Interactive SSH sessions come and go. A tunnel can stay up for days, or reconnect at the same time every day.
  • Odd byte ratios. A normal admin session sends small keystrokes and gets back modest output. Large uploads from an internal host to an external SSH server deserve a look.

In SSH server and host logs

  • Who logged in, from where, with which key. Set LogLevel VERBOSE in sshd_config so OpenSSH records the key fingerprint for each login. Logging each forwarded connection generally needs debug-level logging, which is too noisy for most production servers, so lean on the other sources for that.
  • Configuration drift. Changes to AllowTcpForwarding, GatewayPorts or PermitTunnel, and new entries in authorized_keys.
  • ESXi hosts. As Sygnia’s research showed, /var/log/shell.log records the commands run in the ESXi shell (including the tunnel command), hostd.log and vobd.log show SSH being enabled and firewall changes, and auth.log shows the logins. None of it helps if it stays on the host, so forward it with syslog.

Make sure you’re collecting the right data

Rules are only as good as the telemetry behind them. At a minimum:

  • Windows: process creation with full command lines (Sysmon event 1, or Security event 4688 with command-line auditing turned on), Sysmon event 3 for network connections, and event 4698 for scheduled task creation.
  • Linux: an EDR agent, or auditd watching executions of the SSH client:
# /etc/audit/rules.d/ssh-client.rules
-a always,exit -F arch=b64 -S execve -F exe=/usr/bin/ssh -k ssh_client
  • Network: Zeek conn.log and ssh.log, or flow data from your firewall with application identification.
  • ESXi: remote syslog. Sygnia suggests esxcli system syslog config set --loghost=..., then esxcli system syslog reload, and enabling the syslog firewall rule set with esxcli network firewall ruleset set --ruleset-id=syslog --enabled=true.

What already exists in SigmaHQ

Before writing anything new, check the public SigmaHQ repository. These rules already cover the most common patterns:

RuleWhat it looks forLevel
Port Forwarding Activity Via SSH.EXE
327f48c1-a6db-4eb8-875a-f6981f1b0183
ssh.exe with -R on the command linemedium
Suspicious Plink Port Forwarding
48a61b29-389f-4032-b317-b30de6b95314
Any binary with plink’s PE description and -Rhigh
Potential RDP Tunneling Via SSH
f7d7ebd5-a016-46e2-9c54-f9932f2d386d
ssh.exe with :3389 in the command linehigh
RDP to HTTP or HTTPS Target Ports
b1e5da3b-ca8e-4adf-915c-9921f3d85481
RDP (source port 3389) talking to remote ports 80/443, a sign of RDP inside a tunnelhigh

Here’s the plink rule, which is a nice example of matching on PE metadata rather than the file name:

# SigmaHQ: rules/windows/process_creation/proc_creation_win_plink_port_forwarding.yml
# Author: Florian Roth (Nextron Systems). Licensed under the Detection Rule License (DRL) 1.1
title: Suspicious Plink Port Forwarding
id: 48a61b29-389f-4032-b317-b30de6b95314
status: test
description: Detects suspicious Plink tunnel port forwarding to a local port
logsource:
    category: process_creation
    product: windows
detection:
    selection:
        Description: 'Command-line SSH, Telnet, and Rlogin client'
        CommandLine|contains: ' -R '
    condition: selection
falsepositives:
    - Administrative activity using a remote port forwarding to a local port
level: high

These are a good start, but they leave gaps: no coverage for -L or -D, combined flags like -NR slip through a ' -R ' match, nothing on Linux tunnels started by suspicious parents, and nothing on the network side. Let’s fill those in.

Custom Sigma rules

The rules below are a starting point, not drop-in production rules. Test them against your own data, convert them with pySigma / sigma-cli for your SIEM, and tune the false positives before you turn on alerting.

Rule 1: Any SSH forwarding on Windows, including combined flags

title: SSH Port Forwarding or SOCKS Proxy via ssh.exe or plink.exe
id: 9b64a94d-cf0a-466a-b74b-f4da480f66cf
status: experimental
description: |
    Detects ssh.exe or plink.exe (including renamed plink) started with local (-L),
    remote (-R) or dynamic (-D) port forwarding, including combined flags such as -NR.
references:
    - https://www.cisa.gov/news-events/analysis-reports/ar20-268a
    - https://attack.mitre.org/techniques/T1572/
author: Netsec101
date: 2026-11-11
tags:
    - attack.command-and-control
    - attack.t1572
    - attack.t1090
logsource:
    category: process_creation
    product: windows
detection:
    selection_ssh:
        Image|endswith: '\ssh.exe'
    selection_plink:
        - Image|endswith: '\plink.exe'
        - Description: 'Command-line SSH, Telnet, and Rlogin client'
    selection_flags:
        CommandLine|re: '\s-[A-Za-z]*[LRD](\s|$)'
    condition: (selection_ssh or selection_plink) and selection_flags
falsepositives:
    - Admins using approved tunnels from jump boxes (filter by host or user)
level: medium

Rule 2: Renamed plink (the CISA AR20-268A trick)

title: Renamed Plink Execution
id: 4fae8443-5e52-412f-804d-7920c1b73456
status: experimental
description: |
    Detects PuTTY's plink running under a different file name, as seen in CISA AR20-268A
    where plink.exe was renamed to ShellExperienceHost.exe.
references:
    - https://www.cisa.gov/news-events/analysis-reports/ar20-268a
author: Netsec101
date: 2026-11-11
tags:
    - attack.defense-evasion
    - attack.t1036.003
    - attack.command-and-control
    - attack.t1572
logsource:
    category: process_creation
    product: windows
detection:
    selection:
        Description: 'Command-line SSH, Telnet, and Rlogin client'
    filter_main_plink:
        Image|endswith: '\plink.exe'
    condition: selection and not filter_main_plink
falsepositives:
    - Software that bundles plink under its own name (rare; add an allowlist by path)
level: high

Rule 3: SSH tunnel spawned by a web server or interpreter (Linux)

If a web shell or an exploited Java app is used to open a reverse tunnel, the SSH client’s parent process gives it away.

title: SSH Tunnel Spawned by a Web Server or Script Interpreter
id: 12f427c8-4fe3-4fa7-89eb-7b7ffc91e080
status: experimental
description: |
    Detects the OpenSSH client started with forwarding flags (-L, -R, -D, -w) by a web
    server, application runtime or script interpreter, a common pattern after web shell
    or application exploitation.
references:
    - https://attack.mitre.org/techniques/T1572/
author: Netsec101
date: 2026-11-11
tags:
    - attack.command-and-control
    - attack.t1572
    - attack.t1090
logsource:
    category: process_creation
    product: linux
detection:
    selection_img:
        Image|endswith: '/ssh'
    selection_flags:
        CommandLine|re: '\s-[A-Za-z]*[LRDw](\s|$)'
    selection_parent:
        - ParentImage|endswith:
              - '/httpd'
              - '/apache2'
              - '/nginx'
              - '/java'
              - '/node'
        - ParentImage|contains:
              - 'php-fpm'
              - '/python'
              - '/perl'
              - '/ruby'
    condition: all of selection_*
falsepositives:
    - Deployment or automation scripts written in Python, Perl or Ruby that open tunnels
level: high

Rule 4: SSH client talking to the Internet on a non-standard port (Windows)

title: SSH Client Outbound Connection to Public IP on Non-Standard Port
id: c4815e28-cdfb-448e-a0d6-0e085d983262
status: experimental
description: |
    Detects ssh.exe or plink.exe connecting to a public IP address on a port other than 22.
    Attackers often run SSH over 443 or other allowed ports to blend in.
references:
    - https://attack.mitre.org/techniques/T1571/
author: Netsec101
date: 2026-11-11
tags:
    - attack.command-and-control
    - attack.t1572
    - attack.t1571
logsource:
    category: network_connection
    product: windows
detection:
    selection:
        Image|endswith:
            - '\ssh.exe'
            - '\plink.exe'
        Initiated: 'true'
    filter_main_port_22:
        DestinationPort: 22
    filter_main_private:
        DestinationIp|cidr:
            - '10.0.0.0/8'
            - '172.16.0.0/12'
            - '192.168.0.0/16'
            - '127.0.0.0/8'
    condition: selection and not 1 of filter_main_*
falsepositives:
    - Git over SSH to services that use port 443 (for example ssh.github.com:443)
level: medium

Rule 5: SSH protocol on web or DNS ports (Zeek)

title: SSH Protocol Detected on Web or DNS Ports
id: cf5b3d45-84a5-47e3-908c-5305de4ee02b
status: experimental
description: |
    Zeek identifies SSH by its handshake, regardless of port. SSH on ports normally used
    for web or DNS traffic is a strong sign of an attempt to evade egress filtering.
references:
    - https://attack.mitre.org/techniques/T1571/
author: Netsec101
date: 2026-11-11
tags:
    - attack.command-and-control
    - attack.t1572
    - attack.t1571
logsource:
    product: zeek
    service: ssh
detection:
    selection:
        id.resp_p:
            - 53
            - 80
            - 443
            - 8080
            - 8443
    condition: selection
falsepositives:
    - Git over SSH on 443, or deliberately configured bastions on 443
level: medium

Elastic: prebuilt rules to turn on first

If you run Elastic Security, several relevant rules ship with the prebuilt rule set. Enable these before writing your own:

RuleWhat it coversSeverity
Potential Linux Tunneling and/or Port Forwarding
6ee947e9-de7e-4281-a55d-09289bdf947e
ssh with -R/-L/-D/-w or -J started from a shell, plus sshuttle, socat, chisel, ngrok and other tunneling toolsmedium (47)
Potential Remote Desktop Tunneling Detected
76fd43b7-3480-4dd9-8ad7-8bd36bfad92f
Any Windows process with -L or -R and an argument ending in :3389high (73)
Port Forwarding Rule Addition
3535c8bb-3bd5-40f4-ae32-b7cd589d5372
New netsh portproxy entries in the registrymedium (47)
Linux SSH X11 Forwarding
29f0cf93-d17c-4b12-b4f3-a433800539fa
ssh with -X/-Y started from a shelllow (21)

Elastic: custom queries

These use ECS field names, so they work with Elastic Defend and with Sysmon data shipped through the Windows integration or Winlogbeat. Adjust index patterns and field names to match your environment.

EQL: SSH or plink forwarding on Windows

process where host.os.type == "windows" and event.type == "start" and
  (
    process.name : ("ssh.exe", "plink.exe") or
    process.pe.description == "Command-line SSH, Telnet, and Rlogin client"
  ) and
  process.args regex "-[A-Za-z]*[LRD]"

EQL’s regex must match the whole argument and is case-sensitive, so this catches -L, -NR and -fND without tripping on plink’s lowercase -load.

EQL: renamed plink

process where host.os.type == "windows" and event.type == "start" and
  process.pe.description == "Command-line SSH, Telnet, and Rlogin client" and
  not process.name : "plink.exe"

EQL: SSH tunnel from a web server or interpreter (Linux)

process where host.os.type == "linux" and event.type == "start" and
  process.name == "ssh" and
  process.args regex "-[A-Za-z]*[LRDw]" and
  process.parent.name : ("httpd", "apache2", "nginx", "php-fpm*", "java", "node",
                         "python*", "perl", "ruby")

KQL: SSH on unexpected ports and very long sessions

For network data (Zeek, Packetbeat or firewall logs that set network.protocol), these are handy in Discover or as custom query rules:

// SSH that isn't on port 22
network.protocol : "ssh" and not destination.port : 22

// SSH sessions lasting more than one hour (event.duration is in nanoseconds)
network.protocol : "ssh" and event.duration >= 3600000000000

ES|QL: which internal hosts push the most data out over SSH?

FROM logs-*
| WHERE network.protocol == "ssh"
    AND NOT CIDR_MATCH(destination.ip, "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16")
| STATS sessions = COUNT(*), bytes_out = SUM(source.bytes) BY source.ip, destination.ip
| WHERE bytes_out > 500000000
| SORT bytes_out DESC
| LIMIT 50

This is a hunting query rather than an alert. Run it weekly, and the hosts that show up should either be on your list of approved tunnels or get a closer look.

KQL: ESXi tunnel activity

Once ESXi logs reach Elastic over syslog, you can search the raw messages for the events Sygnia highlighted. Field names depend on how you ingest syslog, so treat this as a template:

message : "ssh -fN -R" or message : "SSH access has been enabled"

When an alert fires: a quick triage checklist

  1. Who started it? Check the user, the parent process and the full process tree. An admin’s terminal is one thing; a scheduled task running as SYSTEM or a web server process is another.
  2. Where does it go? Look up the destination IP and port. Is it your own bastion, a cloud VPS nobody has heard of, or a residential IP?
  3. Is it expected? Compare against your list of approved tunnels and change tickets. If nobody can explain it within an hour, treat it as an incident.
  4. How does it come back? Look for scheduled tasks, services, cron jobs, systemd units and authorized_keys changes that recreate the tunnel.
  5. What went through it? You can’t decrypt it, but you can check the volume of data, the timing, and which internal hosts the tunnel endpoint talked to while it was up.

Tuning tips

  • Allowlist by context, not by binary. Exclude specific jump hosts, service accounts or destination IPs. Never exclude ssh.exe entirely.
  • Tier by asset. SSH forwarding on a developer laptop might be medium; the same thing on a domain controller, file server or hypervisor should be high or critical.
  • Correlate. A new scheduled task plus an SSH client with -R plus a new listening port on the same host within an hour is a far stronger signal than any one of them alone.
  • Test it. Run a harmless ssh -N -R to a lab box and make sure every rule you expect to fire actually does.

Wrapping up the series

Over these three posts we’ve gone from how SSH tunnels work, to how attackers turned them into hidden backdoors, to how to catch them. If there’s one idea to take away, it’s this: you don’t need to see inside the tunnel to spot it. You need to know who opened it, where it goes, and whether it should exist at all. Get those three answers into your SIEM, and SSH tunneling stops being a blind spot.

References

2 thoughts on “SSH Tunneling Detected: Warning Signs, Sigma Rules and Elastic Queries”

Leave a Reply