Linux Auditd Web or Application Server Spawning a Shell
Description
The following analytic detects instances where Java, web server, or application server processes attempts to spawn a Linux shell, which may indicate exploitation attempts. This detection leverages Endpoint Detection and Response (EDR) telemetry, focusing on process names and parent-child process relationships. This activity may indicate a compromised service leading to unauthorized shell access. If confirmed malicious, attackers could execute commands, escalate privileges, or maintain persistent access.
Query · spl
`linux_auditd`
type=SYSCALL
comm IN (
"apache*",
"bash",
"caddy",
"csh",
"dash",
"eshell",
"fish",
"httpd",
"ion",
"java",
"ksh",
"lighttpd",
"nginx",
"php*",
"rbash",
"sh",
"tcsh",
"tomcat*",
"zsh"
)
| eval web_process=if(match(comm, "^(apache.*|caddy|httpd|java|lighttpd|nginx|php.*|tomcat.*)$"),exe,null())
| eval shell_process=if(match(comm, "^(sh|ksh|zsh|bash|dash|rbash|fish|csh|tcsh|ion|eshell)$"),exe,null())
| eval web_process_name=if(match(comm, "^(apache.*|caddy|httpd|java|lighttpd|nginx|php.*|tomcat.*)$"),comm,null())
| eval shell_process_name=if(match(comm, "^(sh|ksh|zsh|bash|dash|rbash|fish|csh|tcsh|ion|eshell)$"),comm,null())
| eval web_pid=if(match(comm, "^(apache.*|caddy|httpd|java|lighttpd|nginx|php.*|tomcat.*)$"),pid,null())
| eval shell_ppid=if(match(comm, "^(sh|ksh|zsh|bash|dash|rbash|fish|csh|tcsh|ion|eshell)$"),ppid,null())
| eval shell_pid=if(match(comm, "^(sh|ksh|zsh|bash|dash|rbash|fish|csh|tcsh|ion|eshell)$"),pid,null())
| eval parent_pid=coalesce(web_pid, shell_ppid)
| stats count min(_time) as firstTime last(_time) as lastTime
values(web_process_name) as parent_process_name
values(web_process) as parent_process
values(shell_pid) as pid
values(shell_process_name) as process_name
values(shell_process) as process
by host parent_pid
| rename host as dest
| where isnotnull(parent_process) AND isnotnull(process)
| `security_content_ctime(firstTime)`
| `security_content_ctime(lastTime)`
| `linux_auditd_web_or_application_server_spawning_a_shell_filter`
Implementation guide
To implement this detection, the process begins by ingesting auditd data, that consists of SYSCALL, TYPE, EXECVE and
PROCTITLE events, which captures command-line executions and process details on Unix/Linux systems. These logs should
be ingested and processed using Splunk Add-on for Unix and Linux (https://splunkbase.splunk.com/app/833), which is
essential for correctly parsing and categorizing the data. The next step involves normalizing the field names to match
the field names set by the Splunk Common Information Model (CIM) to ensure consistency across different data sources
and enhance the efficiency of data modeling. This approach enables effective monitoring and detection of Linux endpoints
where auditd is deployed. Importantly, auditd must also be configured with syscall rules that target the web server
executable (for example, -a always,exit -F arch=b64 -F exe=/usr/sbin/apache2 -S execve -S execveat -k apache_syscall,
repeated for arch=b32). Web server workers typically run as a service account with auid=unset, so human-session rules
in a base ruleset do not cover them, and without such rules the web server's syscalls will not be captured and this
detection will not fire. Adjust the exe path for your web server (e.g., nginx, httpd, or java).
Known false positives
- Filtering may be required on internal developer build systems or classify assets as web facing and restrict the analytic based on asset type.
Analyst notes
Known false positives: Filtering may be required on internal developer build systems or classify assets as web facing and restrict the analytic based on asset type.