Unusual Command Execution from Web Server Parent

This rule detects potential command execution from a web server parent process on a Linux host. Adversaries may attempt to execute commands from a web server parent process to blend in with normal web server activity and evade detection. This behavior is commonly observed in web shell attacks where adversaries exploit web server vulnerabilities to execute arbitrary commands on the host. The detection rule identifies unusual command execution from web server parent processes, which may indicate a compromised host or an ongoing attack. ES|QL rules have limited fields available in its alert documents. Make sure to review the original documents to aid in the investigation of this alert.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2025/03/04"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/03/20"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This rule detects potential command execution from a web server parent process on a Linux host. Adversaries may attempt
 11to execute commands from a web server parent process to blend in with normal web server activity and evade detection.
 12This behavior is commonly observed in web shell attacks where adversaries exploit web server vulnerabilities to execute
 13arbitrary commands on the host. The detection rule identifies unusual command execution from web server parent
 14processes, which may indicate a compromised host or an ongoing attack. ES|QL rules have limited fields available in its
 15alert documents. Make sure to review the original documents to aid in the investigation of this alert.
 16"""
 17from = "now-61m"
 18interval = "1h"
 19language = "esql"
 20license = "Elastic License v2"
 21name = "Unusual Command Execution from Web Server Parent"
 22risk_score = 47
 23rule_id = "8a7933b4-9d0a-4c1c-bda5-e39fb045ff1d"
 24setup = """## Setup
 25
 26This rule requires data coming in from Elastic Defend.
 27
 28### Elastic Defend Integration Setup
 29Elastic 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.
 30
 31#### Prerequisite Requirements:
 32- Fleet is required for Elastic Defend.
 33- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 34
 35#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 36- Go to the Kibana home page and click "Add integrations".
 37- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 38- Click "Add Elastic Defend".
 39- Configure the integration name and optionally add a description.
 40- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 41- 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).
 42- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 43- 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.
 44For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 45- Click "Save and Continue".
 46- 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.
 47For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 48"""
 49severity = "medium"
 50tags = [
 51    "Domain: Endpoint",
 52    "OS: Linux",
 53    "Use Case: Threat Detection",
 54    "Tactic: Persistence",
 55    "Tactic: Execution",
 56    "Tactic: Command and Control",
 57    "Data Source: Elastic Defend",
 58]
 59timestamp_override = "event.ingested"
 60type = "esql"
 61
 62query = '''
 63from logs-endpoint.events.process-*
 64| keep @timestamp, host.os.type, event.type, event.action, process.parent.name, user.name, user.id, process.working_directory, process.name, process.command_line, process.parent.executable, agent.id
 65| where @timestamp > now() - 1 hours
 66| where host.os.type == "linux" and event.type == "start" and event.action == "exec" and (
 67  process.parent.name in (
 68    "apache", "nginx", "apache2", "httpd", "lighttpd", "caddy", "node", "mongrel_rails", "java", "gunicorn",
 69    "uwsgi", "openresty", "cherokee", "h2o", "resin", "puma", "unicorn", "traefik", "tornado", "hypercorn",
 70    "daphne", "twistd", "yaws", "webfsd", "httpd.worker", "flask", "rails", "mongrel"
 71  ) or
 72  process.parent.name like "php-*" or
 73  process.parent.name like "python*" or
 74  process.parent.name like "ruby*" or
 75  process.parent.name like "perl*" or
 76  user.name in (
 77    "apache", "www-data", "httpd", "nginx", "lighttpd", "tomcat", "tomcat8", "tomcat9", "ftp", "ftpuser", "ftpd"
 78  ) or
 79  user.id in ("99", "33", "498", "48") or
 80  process.working_directory like "/var/www/*"
 81) and
 82  process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and process.command_line like "* -c *" and
 83  not (
 84  process.working_directory like "/home/*" or
 85  process.working_directory like "/" or
 86  process.working_directory like "/vscode/vscode-server/*" or
 87  process.parent.executable like "/vscode/vscode-server/*" or
 88  process.parent.executable == "/usr/bin/xfce4-terminal"
 89)
 90| stats cc = count(), agent_count = count_distinct(agent.id) by process.command_line, process.working_directory, process.parent.executable
 91| where agent_count == 1 and cc < 5
 92| sort cc asc
 93| limit 100
 94'''
 95
 96
 97[[rule.threat]]
 98framework = "MITRE ATT&CK"
 99[[rule.threat.technique]]
100id = "T1505"
101name = "Server Software Component"
102reference = "https://attack.mitre.org/techniques/T1505/"
103[[rule.threat.technique.subtechnique]]
104id = "T1505.003"
105name = "Web Shell"
106reference = "https://attack.mitre.org/techniques/T1505/003/"
107
108
109
110[rule.threat.tactic]
111id = "TA0003"
112name = "Persistence"
113reference = "https://attack.mitre.org/tactics/TA0003/"
114[[rule.threat]]
115framework = "MITRE ATT&CK"
116[[rule.threat.technique]]
117id = "T1059"
118name = "Command and Scripting Interpreter"
119reference = "https://attack.mitre.org/techniques/T1059/"
120[[rule.threat.technique.subtechnique]]
121id = "T1059.004"
122name = "Unix Shell"
123reference = "https://attack.mitre.org/techniques/T1059/004/"
124
125
126
127[rule.threat.tactic]
128id = "TA0002"
129name = "Execution"
130reference = "https://attack.mitre.org/tactics/TA0002/"
131[[rule.threat]]
132framework = "MITRE ATT&CK"
133[[rule.threat.technique]]
134id = "T1071"
135name = "Application Layer Protocol"
136reference = "https://attack.mitre.org/techniques/T1071/"
137
138
139[rule.threat.tactic]
140id = "TA0011"
141name = "Command and Control"
142reference = "https://attack.mitre.org/tactics/TA0011/"

Related rules

to-top