Potential Reverse Shell via Suspicious Binary

This detection rule detects the creation of a shell through a chain consisting of the execution of a suspicious binary (located in a commonly abused location or executed manually) followed by a network event and ending with a shell being spawned. Stageless reverse tcp shells display this behaviour. Attackers may spawn reverse shells to establish persistence onto a target system.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/07/05"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/01/15"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This detection rule detects the creation of a shell through a chain consisting of the execution of a suspicious binary
 11(located in a commonly abused location or executed manually) followed by a network event and ending with a shell being
 12spawned. Stageless reverse tcp shells display this behaviour. Attackers may spawn reverse shells to establish
 13persistence onto a target system.
 14"""
 15from = "now-9m"
 16index = ["logs-endpoint.events.*"]
 17language = "eql"
 18license = "Elastic License v2"
 19name = "Potential Reverse Shell via Suspicious Binary"
 20references = [
 21    "https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md",
 22]
 23risk_score = 47
 24rule_id = "fa3a59dc-33c3-43bf-80a9-e8437a922c7f"
 25setup = """## Setup
 26
 27This rule requires data coming in from Elastic Defend.
 28
 29### Elastic Defend Integration Setup
 30Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
 31
 32#### Prerequisite Requirements:
 33- Fleet is required for Elastic Defend.
 34- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 35
 36#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 37- Go to the Kibana home page and click "Add integrations".
 38- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 39- Click "Add Elastic Defend".
 40- Configure the integration name and optionally add a description.
 41- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 42- 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).
 43- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 44- 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.
 45For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 46- Click "Save and Continue".
 47- 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.
 48For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 49"""
 50severity = "medium"
 51tags = [
 52    "Domain: Endpoint",
 53    "OS: Linux",
 54    "Use Case: Threat Detection",
 55    "Tactic: Execution",
 56    "Data Source: Elastic Defend",
 57    "Resources: Investigation Guide",
 58]
 59type = "eql"
 60
 61query = '''
 62sequence by host.id, process.entity_id with maxspan=1s
 63[ process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
 64  process.executable : (
 65  "./*", "/tmp/*", "/var/tmp/*", "/var/www/*", "/dev/shm/*", "/etc/init.d/*", "/etc/rc*.d/*",
 66  "/etc/crontab", "/etc/cron.*", "/etc/update-motd.d/*", "/usr/lib/update-notifier/*",
 67  "/boot/*", "/srv/*", "/run/*", "/root/*", "/etc/rc.local"
 68   ) and
 69  process.parent.name : ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and not
 70  process.name : ("curl", "wget", "ping", "apt", "dpkg", "yum", "rpm", "dnf", "dockerd") ]
 71[ network where host.os.type == "linux" and event.type == "start" and event.action in ("connection_attempted", "connection_accepted") and
 72  process.executable : (
 73  "./*", "/tmp/*", "/var/tmp/*", "/var/www/*", "/dev/shm/*", "/etc/init.d/*", "/etc/rc*.d/*",
 74  "/etc/crontab", "/etc/cron.*", "/etc/update-motd.d/*", "/usr/lib/update-notifier/*",
 75  "/boot/*", "/srv/*", "/run/*", "/root/*", "/etc/rc.local"
 76   ) and destination.ip != null and destination.ip != "127.0.0.1" and destination.ip != "::1" ]
 77[ process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and
 78  process.name : ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and
 79  process.parent.name : ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") ]
 80'''
 81note = """## Triage and analysis
 82
 83> **Disclaimer**:
 84> 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.
 85
 86### Investigating Potential Reverse Shell via Suspicious Binary
 87
 88Reverse shells are a common technique used by attackers to gain persistent access to a compromised system. They exploit legitimate shell environments to execute commands remotely. Adversaries often deploy binaries in unusual directories to evade detection. The detection rule identifies suspicious binaries executed in these locations, followed by network activity and shell spawning, indicating potential reverse shell activity. This approach helps in identifying unauthorized access attempts on Linux systems.
 89
 90### Possible investigation steps
 91
 92- Review the process execution details to identify the suspicious binary's path and name, focusing on the directories specified in the query such as /tmp, /var/tmp, and /dev/shm.
 93- Examine the parent process of the suspicious binary to determine if it was spawned by a legitimate shell process like bash or sh, as indicated in the query.
 94- Analyze the network activity associated with the suspicious binary, paying attention to the destination IP address to identify any external connections that are not local (i.e., not 127.0.0.1 or ::1).
 95- Check the process tree to see if a new shell was spawned following the network activity, which could indicate a reverse shell attempt.
 96- Investigate the user account under which the suspicious process was executed to assess if it aligns with expected behavior or if it might be compromised.
 97- Correlate the event timestamps to understand the sequence of actions and verify if they align with typical reverse shell behavior patterns.
 98
 99### False positive analysis
100
101- Legitimate administrative scripts or binaries may be executed from directories like /tmp or /var/tmp during maintenance tasks. To handle this, create exceptions for known scripts or binaries used by trusted administrators.
102- Automated deployment tools might temporarily use directories such as /dev/shm or /run for staging files. Identify these tools and exclude their processes from triggering the rule.
103- Custom monitoring or backup scripts could initiate network connections from non-standard directories. Review these scripts and whitelist their activities if they are verified as safe.
104- Development or testing environments might involve executing binaries from unusual locations. Ensure these environments are well-documented and exclude their processes from the detection rule.
105- Some legitimate applications may spawn shells as part of their normal operation. Identify these applications and add them to an exception list to prevent false alerts.
106
107### Response and remediation
108
109- Isolate the affected system from the network immediately to prevent further unauthorized access or data exfiltration.
110- Terminate any suspicious processes identified by the detection rule, especially those originating from unusual directories or involving shell spawning.
111- Conduct a thorough review of the system's scheduled tasks, startup scripts, and cron jobs to identify and remove any unauthorized entries that may have been added by the attacker.
112- Analyze network logs to identify any external IP addresses involved in the suspicious network activity and block these IPs at the firewall to prevent further connections.
113- Restore the affected system from a known good backup to ensure that any malicious changes are reverted.
114- Update and patch the system to the latest security standards to close any vulnerabilities that may have been exploited.
115- Escalate the incident to the security operations team for further investigation and to assess the potential impact on other systems within the network."""
116
117
118[[rule.threat]]
119framework = "MITRE ATT&CK"
120[[rule.threat.technique]]
121id = "T1059"
122name = "Command and Scripting Interpreter"
123reference = "https://attack.mitre.org/techniques/T1059/"
124[[rule.threat.technique.subtechnique]]
125id = "T1059.004"
126name = "Unix Shell"
127reference = "https://attack.mitre.org/techniques/T1059/004/"
128
129
130
131[rule.threat.tactic]
132id = "TA0002"
133name = "Execution"
134reference = "https://attack.mitre.org/tactics/TA0002/"
135[[rule.threat]]
136framework = "MITRE ATT&CK"
137[[rule.threat.technique]]
138id = "T1071"
139name = "Application Layer Protocol"
140reference = "https://attack.mitre.org/techniques/T1071/"
141
142
143[rule.threat.tactic]
144id = "TA0011"
145name = "Command and Control"
146reference = "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 Reverse Shell via Suspicious Binary

Reverse shells are a common technique used by attackers to gain persistent access to a compromised system. They exploit legitimate shell environments to execute commands remotely. Adversaries often deploy binaries in unusual directories to evade detection. The detection rule identifies suspicious binaries executed in these locations, followed by network activity and shell spawning, indicating potential reverse shell activity. This approach helps in identifying unauthorized access attempts on Linux systems.

Possible investigation steps

  • Review the process execution details to identify the suspicious binary's path and name, focusing on the directories specified in the query such as /tmp, /var/tmp, and /dev/shm.
  • Examine the parent process of the suspicious binary to determine if it was spawned by a legitimate shell process like bash or sh, as indicated in the query.
  • Analyze the network activity associated with the suspicious binary, paying attention to the destination IP address to identify any external connections that are not local (i.e., not 127.0.0.1 or ::1).
  • Check the process tree to see if a new shell was spawned following the network activity, which could indicate a reverse shell attempt.
  • Investigate the user account under which the suspicious process was executed to assess if it aligns with expected behavior or if it might be compromised.
  • Correlate the event timestamps to understand the sequence of actions and verify if they align with typical reverse shell behavior patterns.

False positive analysis

  • Legitimate administrative scripts or binaries may be executed from directories like /tmp or /var/tmp during maintenance tasks. To handle this, create exceptions for known scripts or binaries used by trusted administrators.
  • Automated deployment tools might temporarily use directories such as /dev/shm or /run for staging files. Identify these tools and exclude their processes from triggering the rule.
  • Custom monitoring or backup scripts could initiate network connections from non-standard directories. Review these scripts and whitelist their activities if they are verified as safe.
  • Development or testing environments might involve executing binaries from unusual locations. Ensure these environments are well-documented and exclude their processes from the detection rule.
  • Some legitimate applications may spawn shells as part of their normal operation. Identify these applications and add them to an exception list to prevent false alerts.

Response and remediation

  • Isolate the affected system from the network immediately to prevent further unauthorized access or data exfiltration.
  • Terminate any suspicious processes identified by the detection rule, especially those originating from unusual directories or involving shell spawning.
  • Conduct a thorough review of the system's scheduled tasks, startup scripts, and cron jobs to identify and remove any unauthorized entries that may have been added by the attacker.
  • Analyze network logs to identify any external IP addresses involved in the suspicious network activity and block these IPs at the firewall to prevent further connections.
  • Restore the affected system from a known good backup to ensure that any malicious changes are reverted.
  • Update and patch the system to the latest security standards to close any vulnerabilities that may have been exploited.
  • Escalate the incident to the security operations team for further investigation and to assess the potential impact on other systems within the network.

References

Related rules

to-top