File Transfer or Listener Established via Netcat
A netcat process is engaging in network activity on a Linux host. Netcat is often used as a persistence mechanism by exporting a reverse shell or by serving a shell on a listening port. Netcat is also sometimes used for data exfiltration.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2020/02/18"
3integration = ["endpoint"]
4maturity = "production"
5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
6min_stack_version = "8.3.0"
7updated_date = "2023/02/22"
8
9[rule]
10author = ["Elastic"]
11description = """
12A netcat process is engaging in network activity on a Linux host. Netcat is often used as a persistence mechanism by
13exporting a reverse shell or by serving a shell on a listening port. Netcat is also sometimes used for data
14exfiltration.
15"""
16false_positives = [
17 """
18 Netcat is a dual-use tool that can be used for benign or malicious activity. Netcat is included in some Linux
19 distributions so its presence is not necessarily suspicious. Some normal use of this program, while uncommon, may
20 originate from scripts, automation tools, and frameworks.
21 """,
22]
23from = "now-9m"
24index = ["auditbeat-*", "logs-endpoint.events.*"]
25language = "eql"
26license = "Elastic License v2"
27name = "File Transfer or Listener Established via Netcat"
28note = """## Triage and analysis
29
30### Investigating Netcat Network Activity
31
32Netcat is a dual-use command line tool that can be used for various purposes, such as port scanning, file transfers, and connection tests. Attackers can abuse its functionality for malicious purposes such creating bind shells or reverse shells to gain access to the target system.
33
34A reverse shell is a mechanism that's abused to connect back to an attacker-controlled system. It effectively redirects the system's input and output and delivers a fully functional remote shell to the attacker. Even private systems are vulnerable since the connection is outgoing.
35
36A bind shell is a type of backdoor that attackers set up on the target host and binds to a specific port to listen for an incoming connection from the attacker.
37
38This rule identifies potential reverse shell or bind shell activity using Netcat by checking for the execution of Netcat followed by a network connection.
39
40#### Possible investigation steps
41
42- Examine the command line to identify if the command is suspicious.
43- Extract and examine the target domain or IP address.
44 - Check if the domain is newly registered or unexpected.
45 - Check the reputation of the domain or IP address.
46 - Scope other potentially compromised hosts in your environment by mapping hosts that also communicated with the domain or IP address.
47- Investigate other alerts associated with the user/host during the past 48 hours.
48- Investigate any abnormal account behavior, such as command executions, file creations or modifications, and network connections.
49- Investigate any abnormal behavior by the subject process such as network connections, file modifications, and any spawned child processes.
50
51### False positive analysis
52
53- Netcat is a dual-use tool that can be used for benign or malicious activity. It is included in some Linux distributions, so its presence is not necessarily suspicious. Some normal use of this program, while uncommon, may originate from scripts, automation tools, and frameworks.
54
55### Response and remediation
56
57- Initiate the incident response process based on the outcome of the triage.
58- Isolate the involved host to prevent further post-compromise behavior.
59- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
60- Block the identified indicators of compromise (IoCs).
61- Take actions to terminate processes and connections used by the attacker.
62- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
63- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
64- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
65"""
66references = [
67 "http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet",
68 "https://www.sans.org/security-resources/sec560/netcat_cheat_sheet_v1.pdf",
69 "https://en.wikipedia.org/wiki/Netcat",
70 "https://www.hackers-arise.com/hacking-fundamentals",
71 "https://null-byte.wonderhowto.com/how-to/hack-like-pro-use-netcat-swiss-army-knife-hacking-tools-0148657/",
72 "https://levelup.gitconnected.com/ethical-hacking-part-15-netcat-nc-and-netcat-f6a8f7df43fd",
73]
74risk_score = 47
75rule_id = "adb961e0-cb74-42a0-af9e-29fc41f88f5f"
76severity = "medium"
77tags = ["Elastic", "Host", "Linux", "Threat Detection", "Execution", "Investigation Guide"]
78type = "eql"
79
80query = '''
81sequence by process.entity_id
82 [process where host.os.type == "linux" and event.type == "start" and
83 process.name:("nc","ncat","netcat","netcat.openbsd","netcat.traditional") and (
84 /* bind shell to echo for command execution */
85 (process.args:("-l","-p") and process.args:("-c","echo","$*"))
86 /* bind shell to specific port */
87 or process.args:("-l","-p","-lp")
88 /* reverse shell to command-line interpreter used for command execution */
89 or (process.args:("-e") and process.args:("/bin/bash","/bin/sh"))
90 /* file transfer via stdout */
91 or process.args:(">","<")
92 /* file transfer via pipe */
93 or (process.args:("|") and process.args:("nc","ncat"))
94 )]
95 [network where host.os.type == "linux" and (process.name == "nc" or process.name == "ncat" or process.name == "netcat" or
96 process.name == "netcat.openbsd" or process.name == "netcat.traditional")]
97'''
98
99
100[[rule.threat]]
101framework = "MITRE ATT&CK"
102[[rule.threat.technique]]
103id = "T1059"
104name = "Command and Scripting Interpreter"
105reference = "https://attack.mitre.org/techniques/T1059/"
106[[rule.threat.technique.subtechnique]]
107id = "T1059.004"
108name = "Unix Shell"
109reference = "https://attack.mitre.org/techniques/T1059/004/"
110
111
112
113[rule.threat.tactic]
114id = "TA0002"
115name = "Execution"
116reference = "https://attack.mitre.org/tactics/TA0002/"
Triage and analysis
Investigating Netcat Network Activity
Netcat is a dual-use command line tool that can be used for various purposes, such as port scanning, file transfers, and connection tests. Attackers can abuse its functionality for malicious purposes such creating bind shells or reverse shells to gain access to the target system.
A reverse shell is a mechanism that's abused to connect back to an attacker-controlled system. It effectively redirects the system's input and output and delivers a fully functional remote shell to the attacker. Even private systems are vulnerable since the connection is outgoing.
A bind shell is a type of backdoor that attackers set up on the target host and binds to a specific port to listen for an incoming connection from the attacker.
This rule identifies potential reverse shell or bind shell activity using Netcat by checking for the execution of Netcat followed by a network connection.
Possible investigation steps
- Examine the command line to identify if the command is suspicious.
- Extract and examine the target domain or IP address.
- Check if the domain is newly registered or unexpected.
- Check the reputation of the domain or IP address.
- Scope other potentially compromised hosts in your environment by mapping hosts that also communicated with the domain or IP address.
- Investigate other alerts associated with the user/host during the past 48 hours.
- Investigate any abnormal account behavior, such as command executions, file creations or modifications, and network connections.
- Investigate any abnormal behavior by the subject process such as network connections, file modifications, and any spawned child processes.
False positive analysis
- Netcat is a dual-use tool that can be used for benign or malicious activity. It is included in some Linux distributions, so its presence is not necessarily suspicious. Some normal use of this program, while uncommon, may originate from scripts, automation tools, and frameworks.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved host to prevent further post-compromise behavior.
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
- Block the identified indicators of compromise (IoCs).
- Take actions to terminate processes and connections used by the attacker.
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).