Potential Meterpreter Reverse Shell
This detection rule identifies a sample of suspicious Linux system file reads used for system fingerprinting, leveraged by the Metasploit Meterpreter shell to gather information about the target that it is executing its shell on. Detecting this pattern is indicative of a successful meterpreter shell connection.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/08/10"
3integration = ["auditd_manager"]
4maturity = "production"
5updated_date = "2025/01/15"
6
7[rule]
8author = ["Elastic"]
9description = """
10This detection rule identifies a sample of suspicious Linux system file reads used for system fingerprinting, leveraged
11by the Metasploit Meterpreter shell to gather information about the target that it is executing its shell on. Detecting
12this pattern is indicative of a successful meterpreter shell connection.
13"""
14from = "now-9m"
15index = ["auditbeat-*", "logs-auditd_manager.auditd-*"]
16language = "eql"
17license = "Elastic License v2"
18name = "Potential Meterpreter Reverse Shell"
19references = [
20 "https://www.elastic.co/security-labs/primer-on-persistence-mechanisms",
21 "https://www.elastic.co/security-labs/linux-detection-engineering-with-auditd",
22]
23risk_score = 47
24rule_id = "5c895b4f-9133-4e68-9e23-59902175355c"
25setup = """## Setup
26
27This rule requires data coming in from one of the following integrations:
28- Auditbeat
29- Auditd Manager
30
31### Auditbeat Setup
32Auditbeat is a lightweight shipper that you can install on your servers to audit the activities of users and processes on your systems. For example, you can use Auditbeat to collect and centralize audit events from the Linux Audit Framework. You can also use Auditbeat to detect changes to critical files, like binaries and configuration files, and identify potential security policy violations.
33
34#### The following steps should be executed in order to add the Auditbeat on a Linux System:
35- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
36- To install the APT and YUM repositories follow the setup instructions in this [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setup-repositories.html).
37- To run Auditbeat on Docker follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-docker.html).
38- To run Auditbeat on Kubernetes follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-kubernetes.html).
39- For complete “Setup and Run Auditbeat” information refer to the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setting-up-and-running.html).
40
41### Auditd Manager Integration Setup
42The Auditd Manager Integration receives audit events from the Linux Audit Framework which is a part of the Linux kernel.
43Auditd Manager provides a user-friendly interface and automation capabilities for configuring and monitoring system auditing through the auditd daemon. With `auditd_manager`, administrators can easily define audit rules, track system events, and generate comprehensive audit reports, improving overall security and compliance in the system.
44
45#### The following steps should be executed in order to add the Elastic Agent System integration "auditd_manager" on a Linux System:
46- Go to the Kibana home page and click “Add integrations”.
47- In the query bar, search for “Auditd Manager” and select the integration to see more details about it.
48- Click “Add Auditd Manager”.
49- Configure the integration name and optionally add a description.
50- Review optional and advanced settings accordingly.
51- Add the newly installed “auditd manager” to an existing or a new agent policy, and deploy the agent on a Linux system from which auditd log files are desirable.
52- Click “Save and Continue”.
53- For more details on the integration refer to the [helper guide](https://docs.elastic.co/integrations/auditd_manager).
54
55#### Rule Specific Setup Note
56Auditd Manager subscribes to the kernel and receives events as they occur without any additional configuration.
57However, if more advanced configuration is required to detect specific behavior, audit rules can be added to the integration in either the "audit rules" configuration box or the "auditd rule files" box by specifying a file to read the audit rules from.
58- For this detection rule the following additional audit rules are required to be added to the integration:
59 -w /proc/net/ -p r -k audit_proc
60 -w /etc/machine-id -p wa -k machineid
61 -w /etc/passwd -p wa -k passwd
62"""
63severity = "medium"
64tags = [
65 "Data Source: Auditd Manager",
66 "Domain: Endpoint",
67 "OS: Linux",
68 "Use Case: Threat Detection",
69 "Tactic: Execution",
70 "Resources: Investigation Guide",
71]
72timestamp_override = "event.ingested"
73type = "eql"
74
75query = '''
76sample by host.id, process.pid, user.id
77 [file where host.os.type == "linux" and auditd.data.syscall == "open" and auditd.data.a2 == "1b6" and file.path == "/etc/machine-id"]
78 [file where host.os.type == "linux" and auditd.data.syscall == "open" and auditd.data.a2 == "1b6" and file.path == "/etc/passwd"]
79 [file where host.os.type == "linux" and auditd.data.syscall == "open" and auditd.data.a2 == "1b6" and file.path == "/proc/net/route"]
80 [file where host.os.type == "linux" and auditd.data.syscall == "open" and auditd.data.a2 == "1b6" and file.path == "/proc/net/ipv6_route"]
81 [file where host.os.type == "linux" and auditd.data.syscall == "open" and auditd.data.a2 == "1b6" and file.path == "/proc/net/if_inet6"]
82'''
83note = """## Triage and analysis
84
85> **Disclaimer**:
86> 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.
87
88### Investigating Potential Meterpreter Reverse Shell
89
90Meterpreter is a sophisticated payload within the Metasploit framework, enabling attackers to execute commands and scripts on compromised systems. Adversaries exploit it to perform system reconnaissance and data exfiltration. The detection rule identifies suspicious file access patterns typical of Meterpreter's system fingerprinting activities, such as reading key system files, indicating a potential reverse shell connection.
91
92### Possible investigation steps
93
94- Review the process associated with the alert by examining the process ID (process.pid) and user ID (user.id) to determine if the process is legitimate or potentially malicious.
95- Check the host ID (host.id) to identify the specific system where the suspicious activity was detected and assess if it is a high-value target or has been previously compromised.
96- Investigate the command history and running processes on the affected host to identify any unusual or unauthorized activities that may indicate a Meterpreter session.
97- Analyze network connections from the host to detect any suspicious outbound connections that could suggest a reverse shell communication.
98- Examine the file access patterns, particularly the access to files like /etc/machine-id, /etc/passwd, /proc/net/route, /proc/net/ipv6_route, and /proc/net/if_inet6, to understand the context and purpose of these reads and whether they align with normal system operations.
99- Correlate the alert with other security events or logs from the same timeframe to identify any additional indicators of compromise or related malicious activities.
100
101### False positive analysis
102
103- System administration scripts or tools that perform regular checks on system files like /etc/machine-id or /etc/passwd may trigger this rule. To manage this, identify and whitelist these legitimate processes by their process ID or user ID.
104- Backup or monitoring software that accesses network configuration files such as /proc/net/route or /proc/net/ipv6_route can cause false positives. Exclude these applications by adding exceptions for their specific file access patterns.
105- Security tools that perform network diagnostics or inventory checks might read files like /proc/net/if_inet6. Review these tools and exclude their known benign activities from triggering the rule.
106- Custom scripts used for system health checks or inventory management that access the flagged files should be reviewed. If deemed safe, add them to an exception list based on their host ID or user ID.
107
108### Response and remediation
109
110- Isolate the affected system from the network immediately to prevent further data exfiltration or lateral movement by the attacker.
111- Terminate any suspicious processes identified by the detection rule, particularly those associated with the process IDs flagged in the alert.
112- Conduct a thorough review of the affected system's logs and file access history to identify any additional unauthorized access or data exfiltration attempts.
113- Change all credentials and keys that may have been exposed or compromised on the affected system, especially those related to user accounts identified in the alert.
114- Restore the affected system from a known good backup to ensure any malicious changes are removed, and verify the integrity of the restored system.
115- Implement network segmentation to limit the potential impact of future attacks and enhance monitoring of critical systems for similar suspicious activities.
116- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if additional systems are affected."""
117
118
119[[rule.threat]]
120framework = "MITRE ATT&CK"
121[[rule.threat.technique]]
122id = "T1059"
123name = "Command and Scripting Interpreter"
124reference = "https://attack.mitre.org/techniques/T1059/"
125[[rule.threat.technique.subtechnique]]
126id = "T1059.004"
127name = "Unix Shell"
128reference = "https://attack.mitre.org/techniques/T1059/004/"
129
130
131
132[rule.threat.tactic]
133id = "TA0002"
134name = "Execution"
135reference = "https://attack.mitre.org/tactics/TA0002/"
136[[rule.threat]]
137framework = "MITRE ATT&CK"
138[[rule.threat.technique]]
139id = "T1071"
140name = "Application Layer Protocol"
141reference = "https://attack.mitre.org/techniques/T1071/"
142
143
144[rule.threat.tactic]
145id = "TA0011"
146name = "Command and Control"
147reference = "https://attack.mitre.org/tactics/TA0011/"
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 Potential Meterpreter Reverse Shell
Meterpreter is a sophisticated payload within the Metasploit framework, enabling attackers to execute commands and scripts on compromised systems. Adversaries exploit it to perform system reconnaissance and data exfiltration. The detection rule identifies suspicious file access patterns typical of Meterpreter's system fingerprinting activities, such as reading key system files, indicating a potential reverse shell connection.
Possible investigation steps
- Review the process associated with the alert by examining the process ID (process.pid) and user ID (user.id) to determine if the process is legitimate or potentially malicious.
- Check the host ID (host.id) to identify the specific system where the suspicious activity was detected and assess if it is a high-value target or has been previously compromised.
- Investigate the command history and running processes on the affected host to identify any unusual or unauthorized activities that may indicate a Meterpreter session.
- Analyze network connections from the host to detect any suspicious outbound connections that could suggest a reverse shell communication.
- Examine the file access patterns, particularly the access to files like /etc/machine-id, /etc/passwd, /proc/net/route, /proc/net/ipv6_route, and /proc/net/if_inet6, to understand the context and purpose of these reads and whether they align with normal system operations.
- Correlate the alert with other security events or logs from the same timeframe to identify any additional indicators of compromise or related malicious activities.
False positive analysis
- System administration scripts or tools that perform regular checks on system files like /etc/machine-id or /etc/passwd may trigger this rule. To manage this, identify and whitelist these legitimate processes by their process ID or user ID.
- Backup or monitoring software that accesses network configuration files such as /proc/net/route or /proc/net/ipv6_route can cause false positives. Exclude these applications by adding exceptions for their specific file access patterns.
- Security tools that perform network diagnostics or inventory checks might read files like /proc/net/if_inet6. Review these tools and exclude their known benign activities from triggering the rule.
- Custom scripts used for system health checks or inventory management that access the flagged files should be reviewed. If deemed safe, add them to an exception list based on their host ID or user ID.
Response and remediation
- Isolate the affected system from the network immediately to prevent further data exfiltration or lateral movement by the attacker.
- Terminate any suspicious processes identified by the detection rule, particularly those associated with the process IDs flagged in the alert.
- Conduct a thorough review of the affected system's logs and file access history to identify any additional unauthorized access or data exfiltration attempts.
- Change all credentials and keys that may have been exposed or compromised on the affected system, especially those related to user accounts identified in the alert.
- Restore the affected system from a known good backup to ensure any malicious changes are removed, and verify the integrity of the restored system.
- Implement network segmentation to limit the potential impact of future attacks and enhance monitoring of critical systems for similar suspicious activities.
- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if additional systems are affected.
References
Related rules
- AWS SSM `SendCommand` with Run Shell Command Parameters
- Network Connection from Binary with RWX Memory Region
- Potential Linux Hack Tool Launched
- Potential Reverse Shell via UDP
- Process Started from Process ID (PID) File