Potential Reverse Shell via Suspicious Child Process

This detection rule detects the creation of a shell through a suspicious process chain. Any reverse shells spawned by the specified utilities that are initialized from a single process followed by a network connection attempt will be captured through this rule. Attackers may spawn reverse shells to establish persistence onto a target system.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/07/04"
  3integration = ["endpoint"]
  4maturity = "production"
  5min_stack_comments = "New fields added: required_fields, related_integrations, setup"
  6min_stack_version = "8.3.0"
  7updated_date = "2023/12/13"
  8
  9[rule]
 10author = ["Elastic"]
 11description = """
 12This detection rule detects the creation of a shell through a suspicious process chain. Any reverse shells spawned by 
 13the specified utilities that are initialized from a single process followed by a network connection attempt will be 
 14captured through this rule. Attackers may spawn reverse shells to establish persistence onto a target system.
 15"""
 16from = "now-9m"
 17index = ["logs-endpoint.events.*"]
 18language = "eql"
 19license = "Elastic License v2"
 20name = "Potential Reverse Shell via Suspicious Child Process"
 21references = [
 22    "https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md"
 23]
 24risk_score = 47
 25rule_id = "76e4d92b-61c1-4a95-ab61-5fd94179a1ee"
 26setup = """## Setup
 27
 28This rule requires data coming in from Elastic Defend.
 29
 30### Elastic Defend Integration Setup
 31Elastic 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.
 32
 33#### Prerequisite Requirements:
 34- Fleet is required for Elastic Defend.
 35- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 36
 37#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 38- Go to the Kibana home page and click "Add integrations".
 39- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 40- Click "Add Elastic Defend".
 41- Configure the integration name and optionally add a description.
 42- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 43- 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).
 44- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 45- 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.
 46For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 47- Click "Save and Continue".
 48- 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.
 49For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 50"""
 51severity = "medium"
 52tags = [
 53        "Domain: Endpoint",
 54        "OS: Linux",
 55        "Use Case: Threat Detection",
 56        "Tactic: Execution",
 57        "Data Source: Elastic Defend"
 58        ]
 59type = "eql"
 60query = '''
 61sequence by host.id, process.entity_id with maxspan=1s
 62  [process where host.os.type == "linux" and event.type == "start" and event.action in ("exec", "fork") and (
 63    (process.name : "python*" and process.args : "-c" and process.args : (
 64     "*import*pty*spawn*", "*import*subprocess*call*"
 65    )) or
 66    (process.name : "perl*" and process.args : "-e" and process.args : "*socket*" and process.args : (
 67     "*exec*", "*system*"
 68    )) or
 69    (process.name : "ruby*" and process.args : ("-e", "-rsocket") and process.args : (
 70     "*TCPSocket.new*", "*TCPSocket.open*"
 71     )) or
 72    (process.name : "lua*" and process.args : "-e" and process.args : "*socket.tcp*" and process.args : (
 73     "*io.popen*", "*os.execute*"
 74    )) or
 75    (process.name : "php*" and process.args : "-r" and process.args : "*fsockopen*" and process.args : "*/bin/*sh*") or 
 76    (process.name : ("awk", "gawk", "mawk", "nawk") and process.args : "*/inet/tcp/*") or
 77    (process.name : "openssl" and process.args : "-connect") or
 78    (process.name : ("nc", "ncat", "netcat") and process.args == "-e" and process.args_count >= 3 and 
 79     not process.args == "-z") or
 80    (process.name : "telnet" and process.args_count >= 3)
 81  ) and process.parent.name : (
 82    "bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish", "python*", "php*", "perl", "ruby", "lua*",
 83    "openssl", "nc", "netcat", "ncat", "telnet", "awk")]
 84  [network where host.os.type == "linux" and event.type == "start" and event.action in ("connection_attempted", "connection_accepted") and 
 85    process.name : ("python*", "php*", "perl", "ruby", "lua*", "openssl", "nc", "netcat", "ncat", "telnet", "awk") and 
 86    destination.ip != null and not cidrmatch(destination.ip, "127.0.0.0/8", "169.254.0.0/16", "224.0.0.0/4", "::1")]
 87'''
 88
 89[[rule.threat]]
 90framework = "MITRE ATT&CK"
 91
 92[rule.threat.tactic]
 93name = "Execution"
 94id = "TA0002"
 95reference = "https://attack.mitre.org/tactics/TA0002/"
 96
 97[[rule.threat.technique]]
 98id = "T1059"
 99name = "Command and Scripting Interpreter"
100reference = "https://attack.mitre.org/techniques/T1059/"
101
102[[rule.threat.technique.subtechnique]]
103id = "T1059.004"
104name = "Unix Shell"
105reference = "https://attack.mitre.org/techniques/T1059/004/"
106
107[[rule.threat]]
108framework = "MITRE ATT&CK"
109
110[rule.threat.tactic]
111name = "Command and Control"
112id = "TA0011"
113reference = "https://attack.mitre.org/tactics/TA0011/"
114
115[[rule.threat.technique]]
116name = "Application Layer Protocol"
117id = "T1071"
118reference = "https://attack.mitre.org/techniques/T1071/"

References

Related rules

to-top