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/04/07"
  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"
 22note = """ ## Triage and analysis
 23
 24> **Disclaimer**:
 25> 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.
 26
 27### Investigating Unusual Command Execution from Web Server Parent
 28
 29Web servers, such as Apache or Nginx, are crucial for hosting web applications, often running on Linux systems. Adversaries exploit vulnerabilities in these servers to execute arbitrary commands, typically through web shells, blending malicious activity with legitimate server processes. The detection rule identifies suspicious command executions originating from web server processes, focusing on unusual patterns and contexts, such as unexpected working directories or command structures, to flag potential compromises.
 30
 31### Possible investigation steps
 32
 33- Review the process.command_line field to understand the specific command executed and assess its legitimacy or potential malicious intent.
 34- Examine the process.working_directory to determine if the command was executed from an unusual or suspicious directory, which could indicate a compromise.
 35- Check the process.parent.executable and process.parent.name fields to identify the parent process and verify if it is a known web server or related service that could be exploited.
 36- Investigate the user.name and user.id fields to confirm if the command was executed by a legitimate user or service account, or if it was potentially executed by an unauthorized user.
 37- Correlate the @timestamp with other logs and events to identify any related activities or anomalies occurring around the same time, which could provide additional context or evidence of an attack.
 38- Assess the agent.id to determine if the alert is isolated to a single host or if similar activities are observed across multiple hosts, indicating a broader issue.
 39
 40### False positive analysis
 41
 42- Web development or testing environments may frequently execute commands from web server processes. To handle this, exclude specific working directories like /var/www/dev or /var/www/test from the rule.
 43- Automated scripts or cron jobs running under web server user accounts can trigger alerts. Identify these scripts and add exceptions for their specific command lines or user IDs.
 44- Legitimate administrative tasks performed by web server administrators might appear suspicious. Document these tasks and exclude their associated command lines or parent executables.
 45- Continuous integration or deployment processes that involve web server interactions can be mistaken for threats. Exclude known CI/CD tool command lines or working directories from the rule.
 46- Monitoring or logging tools that interact with web server processes may generate false positives. Identify these tools and exclude their specific process names or parent executables.
 47
 48### Response and remediation
 49
 50- Isolate the affected host immediately to prevent further malicious activity and lateral movement within the network. This can be done by removing the host from the network or applying network segmentation.
 51
 52- Terminate any suspicious processes identified by the detection rule, especially those originating from web server parent processes executing shell commands. Use process IDs and command lines from the alert to target specific processes.
 53
 54- Conduct a thorough review of the web server logs and application logs to identify any unauthorized access or modifications. Look for patterns that match the command execution detected and any other anomalies.
 55
 56- Patch the web server and any associated applications to address known vulnerabilities that may have been exploited. Ensure that all software is up to date with the latest security patches.
 57
 58- Restore the affected system from a known good backup if any unauthorized changes or persistent threats are detected. Ensure that the backup is free from compromise before restoration.
 59
 60- Implement additional monitoring and alerting for similar activities, focusing on unusual command executions and web server behavior. Enhance logging and alerting to capture more detailed information about process executions and network connections.
 61
 62- Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if the attack is part of a larger campaign. Provide them with all relevant data and findings from the initial containment and remediation steps.
 63"""
 64risk_score = 47
 65rule_id = "8a7933b4-9d0a-4c1c-bda5-e39fb045ff1d"
 66setup = """## Setup
 67
 68This rule requires data coming in from Elastic Defend.
 69
 70### Elastic Defend Integration Setup
 71Elastic 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.
 72
 73#### Prerequisite Requirements:
 74- Fleet is required for Elastic Defend.
 75- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 76
 77#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 78- Go to the Kibana home page and click "Add integrations".
 79- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 80- Click "Add Elastic Defend".
 81- Configure the integration name and optionally add a description.
 82- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 83- 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).
 84- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 85- 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.
 86For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 87- Click "Save and Continue".
 88- 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.
 89For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 90"""
 91severity = "medium"
 92tags = [
 93    "Domain: Endpoint",
 94    "OS: Linux",
 95    "Use Case: Threat Detection",
 96    "Tactic: Persistence",
 97    "Tactic: Execution",
 98    "Tactic: Command and Control",
 99    "Data Source: Elastic Defend",
100    "Resources: Investigation Guide",
101]
102timestamp_override = "event.ingested"
103type = "esql"
104
105query = '''
106from logs-endpoint.events.process-*
107| 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, host.name
108| where @timestamp > now() - 1 hours
109| where host.os.type == "linux" and event.type == "start" and event.action == "exec" and (
110  process.parent.name in (
111    "apache", "nginx", "apache2", "httpd", "lighttpd", "caddy", "node", "mongrel_rails", "java", "gunicorn",
112    "uwsgi", "openresty", "cherokee", "h2o", "resin", "puma", "unicorn", "traefik", "tornado", "hypercorn",
113    "daphne", "twistd", "yaws", "webfsd", "httpd.worker", "flask", "rails", "mongrel"
114  ) or
115  process.parent.name like "php-*" or
116  process.parent.name like "python*" or
117  process.parent.name like "ruby*" or
118  process.parent.name like "perl*" or
119  user.name in (
120    "apache", "www-data", "httpd", "nginx", "lighttpd", "tomcat", "tomcat8", "tomcat9", "ftp", "ftpuser", "ftpd"
121  ) or
122  user.id in ("99", "33", "498", "48") or
123  process.working_directory like "/var/www/*"
124) and
125  process.name in ("bash", "dash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and process.command_line like "* -c *" and
126  not (
127  process.working_directory like "/home/*" or
128  process.working_directory like "/" or
129  process.working_directory like "/vscode/vscode-server/*" or
130  process.parent.executable like "/vscode/vscode-server/*" or
131  process.parent.executable == "/usr/bin/xfce4-terminal"
132)
133| stats cc = count(), agent_count = count_distinct(agent.id), host.name = VALUES(host.name), agent.id = VALUES(agent.id) by process.command_line, process.working_directory, process.parent.executable
134| where agent_count == 1 and cc < 5
135| sort cc asc
136| limit 100
137'''
138
139
140[[rule.threat]]
141framework = "MITRE ATT&CK"
142[[rule.threat.technique]]
143id = "T1505"
144name = "Server Software Component"
145reference = "https://attack.mitre.org/techniques/T1505/"
146[[rule.threat.technique.subtechnique]]
147id = "T1505.003"
148name = "Web Shell"
149reference = "https://attack.mitre.org/techniques/T1505/003/"
150
151
152
153[rule.threat.tactic]
154id = "TA0003"
155name = "Persistence"
156reference = "https://attack.mitre.org/tactics/TA0003/"
157[[rule.threat]]
158framework = "MITRE ATT&CK"
159[[rule.threat.technique]]
160id = "T1059"
161name = "Command and Scripting Interpreter"
162reference = "https://attack.mitre.org/techniques/T1059/"
163[[rule.threat.technique.subtechnique]]
164id = "T1059.004"
165name = "Unix Shell"
166reference = "https://attack.mitre.org/techniques/T1059/004/"
167
168
169
170[rule.threat.tactic]
171id = "TA0002"
172name = "Execution"
173reference = "https://attack.mitre.org/tactics/TA0002/"
174[[rule.threat]]
175framework = "MITRE ATT&CK"
176[[rule.threat.technique]]
177id = "T1071"
178name = "Application Layer Protocol"
179reference = "https://attack.mitre.org/techniques/T1071/"
180
181
182[rule.threat.tactic]
183id = "TA0011"
184name = "Command and Control"
185reference = "https://attack.mitre.org/tactics/TA0011/"
...
toml

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.

Web servers, such as Apache or Nginx, are crucial for hosting web applications, often running on Linux systems. Adversaries exploit vulnerabilities in these servers to execute arbitrary commands, typically through web shells, blending malicious activity with legitimate server processes. The detection rule identifies suspicious command executions originating from web server processes, focusing on unusual patterns and contexts, such as unexpected working directories or command structures, to flag potential compromises.

  • Review the process.command_line field to understand the specific command executed and assess its legitimacy or potential malicious intent.
  • Examine the process.working_directory to determine if the command was executed from an unusual or suspicious directory, which could indicate a compromise.
  • Check the process.parent.executable and process.parent.name fields to identify the parent process and verify if it is a known web server or related service that could be exploited.
  • Investigate the user.name and user.id fields to confirm if the command was executed by a legitimate user or service account, or if it was potentially executed by an unauthorized user.
  • Correlate the @timestamp with other logs and events to identify any related activities or anomalies occurring around the same time, which could provide additional context or evidence of an attack.
  • Assess the agent.id to determine if the alert is isolated to a single host or if similar activities are observed across multiple hosts, indicating a broader issue.
  • Web development or testing environments may frequently execute commands from web server processes. To handle this, exclude specific working directories like /var/www/dev or /var/www/test from the rule.
  • Automated scripts or cron jobs running under web server user accounts can trigger alerts. Identify these scripts and add exceptions for their specific command lines or user IDs.
  • Legitimate administrative tasks performed by web server administrators might appear suspicious. Document these tasks and exclude their associated command lines or parent executables.
  • Continuous integration or deployment processes that involve web server interactions can be mistaken for threats. Exclude known CI/CD tool command lines or working directories from the rule.
  • Monitoring or logging tools that interact with web server processes may generate false positives. Identify these tools and exclude their specific process names or parent executables.
  • Isolate the affected host immediately to prevent further malicious activity and lateral movement within the network. This can be done by removing the host from the network or applying network segmentation.

  • Terminate any suspicious processes identified by the detection rule, especially those originating from web server parent processes executing shell commands. Use process IDs and command lines from the alert to target specific processes.

  • Conduct a thorough review of the web server logs and application logs to identify any unauthorized access or modifications. Look for patterns that match the command execution detected and any other anomalies.

  • Patch the web server and any associated applications to address known vulnerabilities that may have been exploited. Ensure that all software is up to date with the latest security patches.

  • Restore the affected system from a known good backup if any unauthorized changes or persistent threats are detected. Ensure that the backup is free from compromise before restoration.

  • Implement additional monitoring and alerting for similar activities, focusing on unusual command executions and web server behavior. Enhance logging and alerting to capture more detailed information about process executions and network connections.

  • Escalate the incident to the security operations center (SOC) or incident response team for further investigation and to determine if the attack is part of a larger campaign. Provide them with all relevant data and findings from the initial containment and remediation steps.

Related rules

to-top