SSH Reverse or Dynamic Tunnel on macOS
Detects SSH or autossh on macOS establishing a reverse (-R) or dynamic SOCKS (-D) tunnel. Attackers use SSH tunneling from compromised macOS hosts to expose local services to attacker infrastructure, proxy command and control traffic or pivot into internal networks through outbound connections. Reverse and dynamic tunnels are uncommon on most macOS endpoints, so alerts are suppressed per host and user to surface each new tunnel owner for review.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2026/11/03"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2026/11/03"
6
7[rule]
8author = ["Elastic"]
9description = """
10Detects SSH or autossh on macOS establishing a reverse (-R) or dynamic SOCKS (-D) tunnel. Attackers use SSH tunneling
11from compromised macOS hosts to expose local services to attacker infrastructure, proxy command and control traffic or
12pivot into internal networks through outbound connections. Reverse and dynamic tunnels are uncommon on most macOS
13endpoints, so alerts are suppressed per host and user to surface each new tunnel owner for review.
14"""
15from = "now-9m"
16index = ["logs-endpoint.events.process-*"]
17language = "eql"
18license = "Elastic License v2"
19name = "SSH Reverse or Dynamic Tunnel on macOS"
20note = """## Triage and analysis
21
22### Investigating SSH Reverse or Dynamic Tunnel on macOS
23
24SSH reverse (`-R`) and dynamic (`-D`) forwarding let a host expose local services to a remote server, or proxy traffic
25through it. Attackers abuse these options to keep remote access to a compromised Mac, for example by forwarding the
26local SSH port to attacker infrastructure, often from a persistence loop or LaunchAgent. This rule matches the
27forwarding flag only when it is directly followed by a forwarding specification, so flags passed to a remote command
28(for example `rsync --server -D` or `chown -R`) do not trigger it. Alerts are suppressed per host and user for 24 hours.
29
30### Possible investigation steps
31
32- Review `process.command_line` for the forwarding specification. Reverse forwards of remote access ports such as 22
33 (SSH), 5900 (Screen Sharing), 3283 (Apple Remote Desktop) or 3389 (RDP), and reverse SOCKS proxies (`-R <port>`
34 without a target), are higher risk than forwards of application or development ports.
35- Check for options that indicate unattended use, such as `StrictHostKeyChecking=no`, `UserKnownHostsFile=/dev/null`,
36 `BatchMode=yes`, `ExitOnForwardFailure=yes` or `-N`.
37- Check the private key passed with `-i`. Keys stored in hidden files or temporary directories such as `/var/folders`,
38 `/tmp` or `/Users/Shared` are suspicious.
39- Examine the parent process and `process.Ext.effective_parent`. Shell loops (`while true; do ... ssh ...; done`),
40 LaunchAgents, LaunchDaemons or unsigned binaries starting SSH are suspicious.
41- Investigate the destination host or IP address and its reputation, and whether the connection is expected for the user.
42 Public destinations are more suspicious than hosts on the local network.
43- Look for related persistence (LaunchAgents, shell profile modifications) and changes to `~/.ssh/authorized_keys`
44 around the same time.
45
46### False positive analysis
47
48- Developers and administrators may use reverse (`-R`) or dynamic (`-D`) forwarding to share local development
49 servers, reach lab machines or run SOCKS proxies. These commonly forward application ports to hosts on the local
50 network using keys stored in `~/.ssh`. Validate the activity with the user, and add exceptions for known destination
51 hosts or parent processes.
52- Remote development and container tooling may start SSH tunnels on behalf of the user. Exclude known tooling by
53 parent executable once validated.
54- Persistent tunnels managed by a LaunchAgent with `KeepAlive` restart frequently and alert once per suppression window. Once validated, exclude them by the key path passed with `-i` or the destination host.
55
56### Response and remediation
57
58- If the tunnel is unauthorized, terminate the SSH process and any parent loop or script that restarts it.
59- Remove associated persistence such as LaunchAgents, LaunchDaemons or shell profile entries, and delete the private key
60 used for the tunnel.
61- Block the remote host or IP address at the network perimeter.
62- Review `~/.ssh/authorized_keys` and rotate credentials that may have been exposed through the tunnel.
63"""
64references = [
65 "https://man.openbsd.org/ssh",
66]
67risk_score = 21
68rule_id = "85339249-73ac-485a-aaa3-218cca00c1df"
69setup = """## Setup
70
71This rule requires data coming in from Elastic Defend.
72
73### Elastic Defend Integration Setup
74Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
75
76#### Prerequisite Requirements:
77- Fleet is required for Elastic Defend.
78- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
79
80#### The following steps should be executed in order to add the Elastic Defend integration on a macOS System:
81- Go to the Kibana home page and click "Add integrations".
82- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
83- Click "Add Elastic Defend".
84- Configure the integration name and optionally add a description.
85- Select the type of environment you want to protect, for MacOS it is recommended to select "Traditional Endpoints".
86- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
87- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
88- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
89For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/current/agent-policy.html).
90- Click "Save and Continue".
91- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
92For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
93"""
94severity = "low"
95tags = [
96 "Domain: Endpoint",
97 "OS: macOS",
98 "Use Case: Threat Detection",
99 "Tactic: Command and Control",
100 "Data Source: Elastic Defend",
101 "Resources: Investigation Guide",
102 "Threat: Protocol Tunneling",
103 "Platform: macOS",
104]
105timestamp_override = "event.ingested"
106type = "eql"
107query = '''
108process where host.os.type == "macos" and event.type == "start" and event.action == "exec" and
109 process.name in ("ssh", "autossh") and
110 (
111 process.command_line regex """.* -[A-NP-Za-np-z]*R ?([^ ]+:)?[0-9]{1,5}:(([^ :]+|\[[^ ]+\]):[0-9]{1,5}|/[^ ]+)( .*)?""" or
112 process.command_line regex """.* -[A-NP-Za-np-z]*R ?(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|localhost|\*|\[[^ ]+\]):)?[0-9]{1,5}( .*)?""" or
113 process.command_line regex """.* -[A-NP-Za-np-z]*D ?([^ ]+:)?[0-9]{1,5}( .*)?""" or
114 (process.args == "-o" and process.args : ("RemoteForward*", "DynamicForward*")) or
115 process.args : ("-oRemoteForward*", "-oDynamicForward*")
116 ) and
117 not process.parent.name == "autossh"
118'''
119
120[[rule.threat]]
121framework = "MITRE ATT&CK"
122
123[[rule.threat.technique]]
124id = "T1090"
125name = "Proxy"
126reference = "https://attack.mitre.org/techniques/T1090/"
127
128[[rule.threat.technique]]
129id = "T1572"
130name = "Protocol Tunneling"
131reference = "https://attack.mitre.org/techniques/T1572/"
132
133[rule.threat.tactic]
134id = "TA0011"
135name = "Command and Control"
136reference = "https://attack.mitre.org/tactics/TA0011/"
137
138[rule.alert_suppression]
139group_by = ["host.id", "user.name"]
140duration = {value = 24, unit = "h"}
141missing_fields_strategy = "suppress"
Triage and analysis
Investigating SSH Reverse or Dynamic Tunnel on macOS
SSH reverse (-R) and dynamic (-D) forwarding let a host expose local services to a remote server, or proxy traffic
through it. Attackers abuse these options to keep remote access to a compromised Mac, for example by forwarding the
local SSH port to attacker infrastructure, often from a persistence loop or LaunchAgent. This rule matches the
forwarding flag only when it is directly followed by a forwarding specification, so flags passed to a remote command
(for example rsync --server -D or chown -R) do not trigger it. Alerts are suppressed per host and user for 24 hours.
Possible investigation steps
- Review
process.command_linefor the forwarding specification. Reverse forwards of remote access ports such as 22 (SSH), 5900 (Screen Sharing), 3283 (Apple Remote Desktop) or 3389 (RDP), and reverse SOCKS proxies (-R <port>without a target), are higher risk than forwards of application or development ports. - Check for options that indicate unattended use, such as
StrictHostKeyChecking=no,UserKnownHostsFile=/dev/null,BatchMode=yes,ExitOnForwardFailure=yesor-N. - Check the private key passed with
-i. Keys stored in hidden files or temporary directories such as/var/folders,/tmpor/Users/Sharedare suspicious. - Examine the parent process and
process.Ext.effective_parent. Shell loops (while true; do ... ssh ...; done), LaunchAgents, LaunchDaemons or unsigned binaries starting SSH are suspicious. - Investigate the destination host or IP address and its reputation, and whether the connection is expected for the user. Public destinations are more suspicious than hosts on the local network.
- Look for related persistence (LaunchAgents, shell profile modifications) and changes to
~/.ssh/authorized_keysaround the same time.
False positive analysis
- Developers and administrators may use reverse (
-R) or dynamic (-D) forwarding to share local development servers, reach lab machines or run SOCKS proxies. These commonly forward application ports to hosts on the local network using keys stored in~/.ssh. Validate the activity with the user, and add exceptions for known destination hosts or parent processes. - Remote development and container tooling may start SSH tunnels on behalf of the user. Exclude known tooling by parent executable once validated.
- Persistent tunnels managed by a LaunchAgent with
KeepAliverestart frequently and alert once per suppression window. Once validated, exclude them by the key path passed with-ior the destination host.
Response and remediation
- If the tunnel is unauthorized, terminate the SSH process and any parent loop or script that restarts it.
- Remove associated persistence such as LaunchAgents, LaunchDaemons or shell profile entries, and delete the private key used for the tunnel.
- Block the remote host or IP address at the network perimeter.
- Review
~/.ssh/authorized_keysand rotate credentials that may have been exposed through the tunnel.
References
Related rules
- Potential Traffic Tunneling using QEMU
- Potential Tunneling via Tailscaled
- Attempt to Establish Microsoft Dev Tunnel
- DNS Query with Padded Encoded Label
- Kubectl Network Configuration Modification