Suspicious Child Execution via Web Server

Identifies suspicious child processes executed via a web server, which may suggest a vulnerability and remote shell access. Attackers may exploit a vulnerability in a web application to execute commands via a web server, or place a backdoor file that can be abused to gain code execution as a mechanism for persistence.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/03/04"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2026/06/01"
  6
  7[transform]
  8[[transform.osquery]]
  9label = "Osquery - Retrieve Listening Ports"
 10query = "SELECT pid, address, port, socket, protocol, path FROM listening_ports"
 11
 12[[transform.osquery]]
 13label = "Osquery - Retrieve Open Sockets"
 14query = "SELECT pid, family, remote_address, remote_port, socket, state FROM process_open_sockets"
 15
 16[[transform.osquery]]
 17label = "Osquery - Retrieve Process Info"
 18query = "SELECT name, cmdline, parent, path, uid FROM processes"
 19
 20[[transform.osquery]]
 21label = "Osquery - Retrieve Process Info for Webapp User"
 22query = "SELECT name, cmdline, parent, path, uid FROM processes WHERE uid = {{process.user.id}}"
 23
 24[[transform.osquery]]
 25label = "Osquery - Retrieve Crontab Information"
 26query = "SELECT * FROM crontab"
 27
 28[rule]
 29author = ["Elastic"]
 30description = """
 31Identifies suspicious child processes executed via a web server, which may suggest a vulnerability and remote shell access.
 32Attackers may exploit a vulnerability in a web application to execute commands via a web server, or place a backdoor
 33file that can be abused to gain code execution as a mechanism for persistence.
 34"""
 35false_positives = [
 36    """
 37    Network monitoring or management products may have a web server component that runs shell commands as part of normal
 38    behavior.
 39    """,
 40]
 41from = "now-9m"
 42index = ["logs-endpoint.events.process*"]
 43language = "eql"
 44license = "Elastic License v2"
 45name = "Suspicious Child Execution via Web Server"
 46note = """## Triage and analysis
 47
 48### Investigating Suspicious Child Execution via Web Server
 49
 50Adversaries may backdoor web servers with web shells to establish persistent access to systems. A web shell is a malicious script, often embedded into a compromised web server, that grants an attacker remote access and control over the server. This enables the execution of arbitrary commands, data exfiltration, and further exploitation of the target network.
 51
 52This rule detects a web server process spawning script and command line interface programs, potentially indicating attackers executing commands using the web shell.
 53
 54> **Note**:
 55> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/current/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
 56> This investigation guide uses [placeholder fields](https://www.elastic.co/guide/en/security/current/osquery-placeholder-fields.html) to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
 57
 58#### Possible investigation steps
 59
 60- Investigate abnormal behaviors by the subject process such as network connections, file modifications, and any other spawned child processes.
 61  - Investigate listening ports and open sockets to look for potential reverse shells or data exfiltration.
 62    - $osquery_0
 63    - $osquery_1
 64  - Investigate the process information for malicious or uncommon processes/process trees.
 65    - $osquery_2
 66  - Investigate the process tree spawned from the user that is used to run the web application service. A user that is running a web application should not spawn other child processes.
 67    - $osquery_3
 68- Examine the command line to determine which commands or scripts were executed.
 69- Investigate other alerts associated with the user/host during the past 48 hours.
 70- If scripts or executables were dropped, retrieve the files and determine if they are malicious:
 71  - Use a private sandboxed malware analysis system to perform analysis.
 72    - Observe and collect information about the following activities:
 73      - Attempts to contact external domains and addresses.
 74        - Check if the domain is newly registered or unexpected.
 75        - Check the reputation of the domain or IP address.
 76      - File access, modification, and creation activities.
 77      - Cron jobs, services and other persistence mechanisms.
 78        - $osquery_4
 79
 80### False positive analysis
 81
 82- This activity is unlikely to happen legitimately. Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.
 83
 84### Response and remediation
 85
 86- Initiate the incident response process based on the outcome of the triage.
 87- Isolate the involved host to prevent further post-compromise behavior.
 88- If the triage identified malware, search the environment for additional compromised hosts.
 89  - Implement temporary network rules, procedures, and segmentation to contain the malware.
 90  - Stop suspicious processes.
 91  - Immediately block the identified indicators of compromise (IoCs).
 92  - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
 93- Remove and block malicious artifacts identified during triage.
 94- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
 95- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 96- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 97- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
 98"""
 99references = [
100    "https://pentestlab.blog/tag/web-shell/",
101    "https://www.elastic.co/security-labs/elastic-response-to-the-the-spring4shell-vulnerability-cve-2022-22965",
102]
103risk_score = 47
104rule_id = "f16fca20-4d6c-43f9-aec1-20b6de3b0aeb"
105setup = """## Setup
106
107This rule requires data coming in from Elastic Defend.
108
109### Elastic Defend Integration Setup
110Elastic 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.
111
112#### Prerequisite Requirements:
113- Fleet is required for Elastic Defend.
114- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
115
116#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
117- Go to the Kibana home page and click "Add integrations".
118- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
119- Click "Add Elastic Defend".
120- Configure the integration name and optionally add a description.
121- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
122- 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).
123- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
124- 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.
125For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
126- Click "Save and Continue".
127- 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.
128For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
129"""
130severity = "medium"
131tags = [
132    "Domain: Endpoint",
133    "OS: Linux",
134    "Use Case: Threat Detection",
135    "Tactic: Persistence",
136    "Tactic: Initial Access",
137    "Use Case: Vulnerability",
138    "Resources: Investigation Guide",
139    "Data Source: Elastic Defend"
140]
141timestamp_override = "event.ingested"
142type = "eql"
143query = '''
144process where host.os.type == "linux" and event.type == "start" and event.action == "exec" and (
145  process.parent.name in (
146    "nginx", "apache2", "httpd", "caddy", "mongrel_rails", "uwsgi", "daphne", "httpd.worker", "flask",
147    "php-cgi", "php-fcgi", "php-cgi.cagefs", "lswsctrl", "varnishd", "uvicorn", "waitress-serve", "starman",
148    "frankenphp", "zabbix_server", "asterisk", "sw-engine-fpm"
149  ) or
150  process.parent.name like ("php-fpm*", "gunicorn*", "*.cgi", "*.fcgi") or
151  (
152    process.parent.name like "ruby*" and
153    process.parent.command_line like~ ("*puma*", "*rails*", "*passenger*")
154  ) or
155  (
156    process.parent.name like "python*" and
157    process.parent.command_line like~ (
158      "*hypercorn*", "*flask*", "*uvicorn*", "*django*", "*app.py*", "*server.py*", "*wsgi.py*", "*asgi.py*"
159    )
160  ) or
161  (process.parent.name like "perl*" and process.parent.command_line like~ "*plackup*") or
162  (
163    process.parent.name == "java" and (
164      process.parent.args like~ (
165        /* Tomcat */
166        "org.apache.catalina.startup.Bootstrap", "-Dcatalina.base=*",
167
168        /* Jetty */
169        "org.eclipse.jetty.start.Main", "-Djetty.home=*",
170
171        /* WildFly / JBoss */
172        "org.jboss.modules.Main", "-Djboss.home.dir=*",
173
174        /* WebLogic */
175        "weblogic.Server", "-Dweblogic.Name=*", "*weblogic-launcher.jar*",
176
177        /* WebSphere traditional + Liberty */
178        "com.ibm.ws.runtime.WsServer", "com.ibm.ws.kernel.boot.cmdline.Bootstrap",
179
180        /* GlassFish */
181        "com.sun.enterprise.glassfish.bootstrap.ASMain",
182
183        /* Resin */
184        "com.caucho.server.resin.Resin",
185
186        /* Spring Boot */
187        "org.springframework.boot.loader.*",
188
189        /* Quarkus */
190        "*quarkus-run.jar*", "io.quarkus.runner.GeneratedMain",
191
192        /* Micronaut */
193        "io.micronaut.runtime.Micronaut",
194
195        /* Dropwizard */
196        "io.dropwizard.cli.ServerCommand",
197
198        /* Play */
199        "play.core.server.ProdServerStart",
200
201        /* Helidon */
202        "io.helidon.microprofile.server.Main", "io.helidon.webserver*",
203
204        /* Vert.x */
205        "io.vertx.core.Launcher",
206
207        /* Keycloak */
208        "org.keycloak*",
209
210        /* Apereo CAS */
211        "org.apereo.cas*",
212
213        /* Elasticsearch */
214        "org.elasticsearch.bootstrap.Elasticsearch",
215
216        /* Atlassian / Gerrit */
217        "com.atlassian.jira.startup.Launcher", "*BitbucketServerLauncher*", "com.google.gerrit.pgm.Daemon",
218
219        /* Solr */
220        "*-Dsolr.solr.home=*",
221
222        /* Jenkins */
223        "*jenkins.war*"
224      ) or
225      ?process.working_directory like "/u0?/*"
226    )
227  )
228) and (
229  process.executable like (
230    "/tmp/*", "/var/tmp/*", "/dev/shm/*", "./*", "/run/*", "/var/run/*", "/boot/*", "/sys/*", "/lost+found/*",
231    "/proc/*", "/var/mail/*", "/var/www/*", "/home/*/*", "/root/*" 
232  ) or
233  process.name like~ (
234    // Hidden processes
235    ".*",
236
237    // Suspicious file formats
238    "*.elf", "*.sh", "*.py", "*.rb", "*.pl", "*.lua*", "*.php*", ".js", "*.bin", "*.jar", "*.mjs",
239
240    // Network utilities often used for reverse shells
241    "nc", "netcat", "ncat", "telnet", "socat", "openssl", "nc.openbsd", "ngrok", "nc.traditional",
242
243    // Cloud CLI
244    "az", "gcloud", "aws", "kubectl", "helm", "docker", "ctr", "crictl",
245
246    // Misc. tools
247    "whoami", "ifconfig", "ip", "ss", "top", "htop", "df", "du", "lsblk", "lsof", "tcpdump",
248    "strace", "ltrace", "curl", "wget", "dig", "nslookup", "host", "nmap", "arp", "traceroute",
249    "cat", "touch", "cp", "mv", "rm", "mkdir", "ln", "chmod", "sudo", "xxd", "base64", "basez",
250    "base64plain", "base64url", "base64mime", "base64pem", "basenc", "base32", "base16", "chpasswd",
251    "passwd"
252  ) 
253)
254'''
255
256[[rule.threat]]
257framework = "MITRE ATT&CK"
258
259[[rule.threat.technique]]
260id = "T1505"
261name = "Server Software Component"
262reference = "https://attack.mitre.org/techniques/T1505/"
263
264[[rule.threat.technique.subtechnique]]
265id = "T1505.003"
266name = "Web Shell"
267reference = "https://attack.mitre.org/techniques/T1505/003/"
268
269[rule.threat.tactic]
270id = "TA0003"
271name = "Persistence"
272reference = "https://attack.mitre.org/tactics/TA0003/"
273
274[[rule.threat]]
275framework = "MITRE ATT&CK"
276
277[[rule.threat.technique]]
278id = "T1190"
279name = "Exploit Public-Facing Application"
280reference = "https://attack.mitre.org/techniques/T1190/"
281
282[rule.threat.tactic]
283id = "TA0001"
284name = "Initial Access"
285reference = "https://attack.mitre.org/tactics/TA0001/"
286
287[[rule.threat]]
288framework = "MITRE ATT&CK"
289
290[[rule.threat.technique]]
291id = "T1059"
292name = "Command and Scripting Interpreter"
293reference = "https://attack.mitre.org/techniques/T1059/"
294
295[rule.threat.tactic]
296id = "TA0002"
297name = "Execution"
298reference = "https://attack.mitre.org/tactics/TA0002/"

Triage and analysis

Investigating Suspicious Child Execution via Web Server

Adversaries may backdoor web servers with web shells to establish persistent access to systems. A web shell is a malicious script, often embedded into a compromised web server, that grants an attacker remote access and control over the server. This enables the execution of arbitrary commands, data exfiltration, and further exploitation of the target network.

This rule detects a web server process spawning script and command line interface programs, potentially indicating attackers executing commands using the web shell.

Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide. This investigation guide uses placeholder fields to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.

Possible investigation steps

  • Investigate abnormal behaviors by the subject process such as network connections, file modifications, and any other spawned child processes.
    • Investigate listening ports and open sockets to look for potential reverse shells or data exfiltration.
      • $osquery_0
      • $osquery_1
    • Investigate the process information for malicious or uncommon processes/process trees.
      • $osquery_2
    • Investigate the process tree spawned from the user that is used to run the web application service. A user that is running a web application should not spawn other child processes.
      • $osquery_3
  • Examine the command line to determine which commands or scripts were executed.
  • Investigate other alerts associated with the user/host during the past 48 hours.
  • If scripts or executables were dropped, retrieve the files and determine if they are malicious:
    • Use a private sandboxed malware analysis system to perform analysis.
      • Observe and collect information about the following activities:
        • Attempts to contact external domains and addresses.
          • Check if the domain is newly registered or unexpected.
          • Check the reputation of the domain or IP address.
        • File access, modification, and creation activities.
        • Cron jobs, services and other persistence mechanisms.
          • $osquery_4

False positive analysis

  • This activity is unlikely to happen legitimately. Any activity that triggered the alert and is not inherently malicious must be monitored by the security team.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Isolate the involved host to prevent further post-compromise behavior.
  • If the triage identified malware, search the environment for additional compromised hosts.
    • Implement temporary network rules, procedures, and segmentation to contain the malware.
    • Stop suspicious processes.
    • Immediately block the identified indicators of compromise (IoCs).
    • Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
  • Remove and block malicious artifacts identified during triage.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
  • Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
  • Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

References

Related rules

to-top