Detection rules › Elastic
Suspicious Netcat Execution
This rule detects the usage of netcat to connect to a remote host. This behavior may be indicative of a reverse shell connection being established.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Command & Control |
Rule body
[rule]
description = """
This rule detects the usage of netcat to connect to a remote host. This behavior may be indicative of a reverse shell
connection being established.
"""
id = "a60859af-bd25-449d-bdb3-e71cb1725f58"
license = "Elastic License v2"
name = "Suspicious Netcat Execution"
os_list = ["linux"]
version = "1.0.2"
query = '''
process where event.type == "start" and event.action == "exec" and
process.name in ("nc", "ncat", "netcat", "netcat.openbsd", "netcat.traditional", "nc.openbsd", "nc.traditional") and
process.args regex "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}" and
process.args_count >= 3 and
not (
process.args like ("127.0.0.1", "127.0.0.01", "0.0.0.0", "::1", "-*z*", "--help", "8.8.8.8") or
process.args regex """10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}""" or
process.args regex """192\.168\.[0-9]{1,3}\.[0-9]{1,3}""" or
process.args regex """172\.(1[6-9]|2[0-9]|3[0-1])\.[0-9]{1,3}\.[0-9]{1,3}""" or
(process.parent.executable == "/usr/sbin/sshd" and process.args == "22")
)
'''
min_endpoint_version = "7.15.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0
[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"
[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1071"
name = "Application Layer Protocol"
reference = "https://attack.mitre.org/techniques/T1071/"
[threat.tactic]
id = "TA0011"
name = "Command and Control"
reference = "https://attack.mitre.org/tactics/TA0011/"
[internal]
min_endpoint_version = "7.15.0"
Stages and Predicates
Stage 1: process
process where event.type == "start" and event.action == "exec" and
process.name in ("nc", "ncat", "netcat", "netcat.openbsd", "netcat.traditional", "nc.openbsd", "nc.traditional") and
process.args regex "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}" and
process.args_count >= 3 and
not (
process.args like ("127.0.0.1", "127.0.0.01", "0.0.0.0", "::1", "-*z*", "--help", "8.8.8.8") or
process.args regex """10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}""" or
process.args regex """192\.168\.[0-9]{1,3}\.[0-9]{1,3}""" or
process.args regex """172\.(1[6-9]|2[0-9]|3[0-1])\.[0-9]{1,3}\.[0-9]{1,3}""" or
(process.parent.executable == "/usr/sbin/sshd" and process.args == "22")
)
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.args | eq | 22 | excludes:process.args field:"process.args" value:"22" |
process.parent.executable | eq | /usr/sbin/sshd | excludes:process.parent.executable field:"process.parent.executable" value:"/usr/sbin/sshd" |
process.args | regex_match | 10.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3} | excludes:process.args field:"process.args" value:"10.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" |
process.args | regex_match | 172.(1[6-9]|2[0-9]|3[0-1]).[0-9]{1,3}.[0-9]{1,3} | excludes:process.args field:"process.args" value:"172.(1[6-9]|2[0-9]|3[0-1]).[0-9]{1,3}.[0-9]{1,3}" |
process.args | regex_match | 192.168.[0-9]{1,3}.[0-9]{1,3} | excludes:process.args field:"process.args" value:"192.168.[0-9]{1,3}.[0-9]{1,3}" |
process.args | wildcard | 127.0.0.1, 127.0.0.01, 0.0.0.0, ::1, -*z*, --help, 8.8.8.8 | excludes:process.args |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq value:"exec" |
event.type | eq |
| field:"event.type" kind:eq value:"start" |
process.args | regex_match |
| field:"process.args" kind:regex_match value:"[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" |
process.args_count | ge |
| field:"process.args_count" kind:ge value:"3" |
process.name | in |
| field:"process_name" kind:in |