Linux Auditd Possible Setuid Execve Privesc
Description
The following detects privilege escalation via execve (syscall 59) where a process transitions from a non-root uid to euid=0 without a corresponding successful PAM authentication event (USER_AUTH, USER_ACCT, or CRED_ACQ) in the same audit session. Legitimate privilege elevation mechanisms such as sudo, su, and pkexec authenticate through PAM and generate these audit records tied to the session ID before granting elevated privileges. The absence of a matching successful PAM event alongside an effective UID change to root is anomalous and may indicate exploitation of a setuid binary, a kernel vulnerability, or another mechanism used to escalate privileges outside the normal authentication flow.
Query · spl
`linux_auditd` ( (type=SYSCALL syscall="59" uid!="0" euid="0") OR (type IN ("USER_AUTH","USER_ACCT","CRED_ACQ") res="success") ) | eval is_suspicious_exec=if(type="SYSCALL" AND syscall="59" AND uid!="0" AND euid="0", 1, 0) | eval is_successful_auth=if(type IN ("USER_AUTH","USER_ACCT","CRED_ACQ") AND res="success", 1, 0) | stats
count(eval(is_suspicious_exec=1)) as exec_count
max(eval(if(is_suspicious_exec=1, _time, null()))) as lastTime
max(is_successful_auth) as has_successful_auth
min(eval(if(is_suspicious_exec=1, _time, null()))) as firstTime
values(eval(if(is_suspicious_exec=1, comm, null()))) as process_name
values(eval(if(is_suspicious_exec=1, euid, null()))) as euid
values(eval(if(is_suspicious_exec=1, exe, null()))) as process_path
values(eval(if(is_suspicious_exec=1, pid, null()))) as pid
values(eval(if(is_suspicious_exec=1, ppid, null()))) as ppid
values(eval(if(is_suspicious_exec=1, uid, null()))) as uid
by host ses
| where exec_count > 0 AND has_successful_auth != 1 | rename host as dest, ses as session_id | `security_content_ctime(firstTime)` | `security_content_ctime(lastTime)` | `linux_auditd_possible_setuid_execve_privesc_filter`
Implementation guide
To implement this detection, the process begins by ingesting auditd data, that consist 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.
Known false positives
- Processes with an unset audit session, such as cron jobs, that legitimately drop and reacquire root privileges outside of PAM, may trigger this detection and require filtering.
Analyst notes
Known false positives: Processes with an unset audit session, such as cron jobs, that legitimately drop and reacquire root privileges outside of PAM, may trigger this detection and require filtering.