Netcat Listener Established via rlwrap
Monitors for the execution of a netcat listener via rlwrap. rlwrap is a 'readline wrapper', a small utility that uses the GNU Readline library to allow the editing of keyboard input for any command. This utility can be used in conjunction with netcat to gain a more stable reverse shell.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/09/22"
3integration = ["endpoint", "crowdstrike", "sentinel_one_cloud_funnel"]
4maturity = "production"
5min_stack_version = "8.13.0"
6min_stack_comments = "Breaking change at 8.13.0 for SentinelOne Integration."
7updated_date = "2025/01/15"
8
9[rule]
10author = ["Elastic"]
11description = """
12Monitors for the execution of a netcat listener via rlwrap. rlwrap is a 'readline wrapper', a small utility that uses
13the GNU Readline library to allow the editing of keyboard input for any command. This utility can be used in conjunction
14with netcat to gain a more stable reverse shell.
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 = ["logs-endpoint.events.*", "endgame-*", "logs-crowdstrike.fdr*", "logs-sentinel_one_cloud_funnel.*"]
25language = "eql"
26license = "Elastic License v2"
27name = "Netcat Listener Established via rlwrap"
28risk_score = 21
29rule_id = "0f56369f-eb3d-459c-a00b-87c2bf7bdfc5"
30setup = """## Setup
31
32This rule requires data coming in from Elastic Defend.
33
34### Elastic Defend Integration Setup
35Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows
36the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
37
38#### Prerequisite Requirements:
39- Fleet is required for Elastic Defend.
40- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
41
42#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
43- Go to the Kibana home page and click "Add integrations".
44- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
45- Click "Add Elastic Defend".
46- Configure the integration name and optionally add a description.
47- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
48- 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).
49- We suggest to select "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
50- 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.
51For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
52- Click "Save and Continue".
53- 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.
54For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
55"""
56severity = "low"
57tags = [
58 "Domain: Endpoint",
59 "OS: Linux",
60 "Use Case: Threat Detection",
61 "Tactic: Execution",
62 "Data Source: Elastic Defend",
63 "Data Source: Elastic Endgame",
64 "Data Source: Crowdstrike",
65 "Data Source: SentinelOne",
66 "Resources: Investigation Guide",
67]
68timestamp_override = "event.ingested"
69type = "eql"
70
71query = '''
72process where host.os.type == "linux" and event.type == "start" and
73 event.action in ("exec", "exec_event", "start", "ProcessRollup2") and
74 process.name == "rlwrap" and process.args in ("nc", "ncat", "netcat", "nc.openbsd", "socat") and
75 process.args : "*l*" and process.args_count >= 4
76'''
77note = """## Triage and analysis
78
79> **Disclaimer**:
80> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
81
82### Investigating Netcat Listener Established via rlwrap
83
84Netcat, a versatile networking tool, can establish connections for data transfer or remote shell access. When combined with rlwrap, which enhances command-line input, it can create a more stable reverse shell environment. Adversaries exploit this to maintain persistent access. The detection rule identifies such misuse by monitoring rlwrap's execution with netcat-related arguments, signaling potential unauthorized activity.
85
86### Possible investigation steps
87
88- Review the process execution details to confirm the presence of rlwrap with netcat-related arguments by examining the process.name and process.args fields.
89- Check the process start time and correlate it with any known scheduled tasks or user activity to determine if the execution was expected or authorized.
90- Investigate the source IP address and port used in the netcat connection to identify potential external connections or data exfiltration attempts.
91- Analyze the user account associated with the process execution to verify if the account has a history of similar activities or if it has been compromised.
92- Examine any related network traffic logs to identify unusual patterns or connections that coincide with the alert, focusing on the host where the process was executed.
93- Look for any additional processes spawned by the netcat listener to detect further malicious activity or persistence mechanisms.
94
95### False positive analysis
96
97- Development and testing environments may frequently use rlwrap with netcat for legitimate purposes, such as testing network applications or scripts. To manage this, create exceptions for specific user accounts or IP addresses known to be involved in development activities.
98- System administrators might use rlwrap with netcat for troubleshooting or network diagnostics. Identify and exclude these activities by setting up rules that recognize the specific command patterns or user roles associated with administrative tasks.
99- Automated scripts or cron jobs that utilize rlwrap and netcat for routine maintenance or monitoring can trigger false positives. Review and whitelist these scripts by their unique process identifiers or command structures to prevent unnecessary alerts.
100- Educational or training environments where rlwrap and netcat are used for learning purposes can generate alerts. Implement exceptions based on the environment's network segment or user group to reduce noise from these benign activities.
101
102### Response and remediation
103
104- Immediately isolate the affected host from the network to prevent further unauthorized access or data exfiltration.
105- Terminate the rlwrap and netcat processes on the affected host to disrupt the reverse shell connection.
106- Conduct a forensic analysis of the affected system to identify any additional malicious activities or persistence mechanisms.
107- Review and secure any compromised accounts or credentials that may have been used or accessed during the incident.
108- Apply security patches and updates to the affected system to mitigate any exploited vulnerabilities.
109- Enhance monitoring and logging on the affected host and network to detect similar activities in the future.
110- Report the incident to the appropriate internal security team or external authorities if required, following organizational protocols."""
111
112
113[[rule.threat]]
114framework = "MITRE ATT&CK"
115[[rule.threat.technique]]
116id = "T1059"
117name = "Command and Scripting Interpreter"
118reference = "https://attack.mitre.org/techniques/T1059/"
119[[rule.threat.technique.subtechnique]]
120id = "T1059.004"
121name = "Unix Shell"
122reference = "https://attack.mitre.org/techniques/T1059/004/"
123
124
125
126[rule.threat.tactic]
127id = "TA0002"
128name = "Execution"
129reference = "https://attack.mitre.org/tactics/TA0002/"
Triage and analysis
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating Netcat Listener Established via rlwrap
Netcat, a versatile networking tool, can establish connections for data transfer or remote shell access. When combined with rlwrap, which enhances command-line input, it can create a more stable reverse shell environment. Adversaries exploit this to maintain persistent access. The detection rule identifies such misuse by monitoring rlwrap's execution with netcat-related arguments, signaling potential unauthorized activity.
Possible investigation steps
- Review the process execution details to confirm the presence of rlwrap with netcat-related arguments by examining the process.name and process.args fields.
- Check the process start time and correlate it with any known scheduled tasks or user activity to determine if the execution was expected or authorized.
- Investigate the source IP address and port used in the netcat connection to identify potential external connections or data exfiltration attempts.
- Analyze the user account associated with the process execution to verify if the account has a history of similar activities or if it has been compromised.
- Examine any related network traffic logs to identify unusual patterns or connections that coincide with the alert, focusing on the host where the process was executed.
- Look for any additional processes spawned by the netcat listener to detect further malicious activity or persistence mechanisms.
False positive analysis
- Development and testing environments may frequently use rlwrap with netcat for legitimate purposes, such as testing network applications or scripts. To manage this, create exceptions for specific user accounts or IP addresses known to be involved in development activities.
- System administrators might use rlwrap with netcat for troubleshooting or network diagnostics. Identify and exclude these activities by setting up rules that recognize the specific command patterns or user roles associated with administrative tasks.
- Automated scripts or cron jobs that utilize rlwrap and netcat for routine maintenance or monitoring can trigger false positives. Review and whitelist these scripts by their unique process identifiers or command structures to prevent unnecessary alerts.
- Educational or training environments where rlwrap and netcat are used for learning purposes can generate alerts. Implement exceptions based on the environment's network segment or user group to reduce noise from these benign activities.
Response and remediation
- Immediately isolate the affected host from the network to prevent further unauthorized access or data exfiltration.
- Terminate the rlwrap and netcat processes on the affected host to disrupt the reverse shell connection.
- Conduct a forensic analysis of the affected system to identify any additional malicious activities or persistence mechanisms.
- Review and secure any compromised accounts or credentials that may have been used or accessed during the incident.
- Apply security patches and updates to the affected system to mitigate any exploited vulnerabilities.
- Enhance monitoring and logging on the affected host and network to detect similar activities in the future.
- Report the incident to the appropriate internal security team or external authorities if required, following organizational protocols.
Related rules
- Cupsd or Foomatic-rip Shell Execution
- Git Hook Child Process
- Potential Hex Payload Execution
- Potential Linux Hack Tool Launched
- Potential Reverse Shell via Background Process