Command and Control (TA0011)(external, opens in a new tab or window)
text code block:process where event.type == "start" and event.action == "exec" and ( ( // Tunneling and/or Port Forwarding via process args (process.args regex """.*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,5}:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,5}.*""") or // gost (process.name == "gost" and process.args : ("-L*", "-C*", "-R*")) or // ssh (process.name == "ssh" and (process.args like ("-*R*", "-*L*", "-*D*", "-*w*") and not (process.args == "chmod" or process.args like "*rungencmd*"))) or // ssh Tunneling and/or Port Forwarding via SSH option (process.name == "ssh" and process.args == "-o" and process.args like~( "*ProxyCommand*", "*LocalForward*", "*RemoteForward*", "*DynamicForward*", "*Tunnel*", "*GatewayPorts*", "*ExitOnForwardFailure*", "*ProxyCommand*", "*ProxyJump*" )) or // sshuttle (process.name == "sshuttle" and process.args in ("-r", "--remote", "-l", "--listen")) or // earthworm (process.args == "-s" and process.args == "-d" and process.args == "rssocks") or // socat (process.name == "socat" and process.args : ("TCP4-LISTEN:*", "SOCKS*")) or // chisel (process.name : "chisel*" and process.args in ("client", "server")) or // iodine(d), dnscat, hans, ptunnel-ng, ssf, 3proxy & ngrok (process.name in ("iodine", "iodined", "dnscat", "hans", "hans-ubuntu", "ptunnel-ng", "ssf", "3proxy", "ngrok", "wstunnel", "pivotnacci", "frps", "proxychains")) ) ) and container.id like "?*"
Install detection rules in Elastic Security
Detect Tunneling and/or Port Forwarding Detected via Defend for Containers in the Elastic Security detection engine by installing this rule into your Elastic Stack.
To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).