| ID | Technique | Tactic |
|---|---|---|
| T1021.004 | SSH | Lateral Movement |
| T1078.003 | Local Accounts | Initial Access |
| T1548.003 | Sudo and Sudo Caching | Persistence |
Detection: Linux Non-User Privilege Escalation via Doas
Description
The following analytic detects an accepted SSH password login of a non-user account followed by a doas command run as root by the same account on the same Linux endpoint within ten minutes. The sequence can indicate an attacker using a compromised or bypassed SSH account to gain root access.
Search
1`linux_syslog`
2("Accepted password for" OR "as root from")
3
4
5| rex field=_raw "^[A-Za-z]{3} +[0-9]+ +[0-9:]+ +(?<syslog_dest>[^ ]+)"
6
7| rex field=_raw "Accepted password for (?:invalid user )?(?<ssh_user>[^ ]+) from (?<src_ip>[^ ]+) port (?<src_port>[0-9]+) ssh2"
8
9| rex field=_raw "(?<doas_user>[^ ]+) ran command (?<command>.+) as root from (?<working_directory>.*)$"
10
11
12| eval dest=coalesce(dest, syslog_dest, host), user=lower(coalesce(ssh_user, doas_user))
13
14
15| eval ssh_login=if(match(_raw, "Accepted password for"), 1, 0), doas_root_command=if(match(_raw, "ran command .* as root from"), 1, 0)
16
17
18| where ssh_login=1 OR doas_root_command=1
19
20
21| where isnotnull(user)
22
23
24| where in(user, "daemon", "bin", "sys", "sync", "shutdown", "halt", "games", "man", "lp", "mail", "news", "uucp", "operator", "www-data", "backup", "list", "irc", "gnats", "nobody", "_apt", "systemd-network", "systemd-resolve", "messagebus", "uuidd", "sshd", "ntp", "ftp", "chrony", "postfix", "redis", "mysql", "mariadb", "postgres", "alpine", "guest")
25
26
27| eval event_priority=if(ssh_login=1, 0, 1)
28
29
30| sort 0 _time event_priority
31
32
33| streamstats time_window=10m max(eval(if(ssh_login=1, _time, null()))) as ssh_login_time values(eval(if(ssh_login=1, src_ip, null()))) as src_ips values(eval(if(ssh_login=1, src_port, null()))) as src_ports by dest user
34
35
36| where doas_root_command=1 AND isnotnull(ssh_login_time)
37
38
39| eval doas_time=_time, elapsed_seconds=doas_time-ssh_login_time
40
41
42| stats values(src_ips) as src_ips values(src_ports) as src_ports values(command) as command values(working_directory) as working_directory by dest user ssh_login_time doas_time elapsed_seconds
43
44
45| `security_content_ctime(ssh_login_time)`
46
47| `security_content_ctime(doas_time)`
48
49
50| table ssh_login_time doas_time elapsed_seconds dest
51 user src_ips src_ports command working_directory
52
53
54| `linux_non_user_privilege_escalation_via_doas_filter`
Data Source
| Name | Platform | Sourcetype | Source |
|---|---|---|---|
| Linux Messages Syslog | 'linux_messages_syslog' |
'/var/log/kern' |
Macros Used
| Name | Value |
|---|---|
| security_content_ctime | convert timeformat="%Y-%m-%dT%H:%M:%S" ctime($field$) |
| linux_non_user_privilege_escalation_via_doas_filter | search * |
linux_non_user_privilege_escalation_via_doas_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.
Annotations
CVE
Default Configuration
This detection is configured by default in Splunk Enterprise Security to run with the following settings:
| Setting | Value |
|---|---|
| Disabled | true |
| Cron Schedule | 0 * * * * |
| Earliest Time | -70m@m |
| Latest Time | -10m@m |
| Schedule Window | auto |
| Creates Finding (Notable) | No |
| Creates Intermediate Finding (Risk Event) | Yes |
Implementation
To successfully implement this search, you need to ingest Linux syslog logs. These logs should be collected with the Splunk Add-on for Unix and Linux (https://splunkbase.splunk.com/app/833).
Known False Positives
Administrators may legitimately use SSH and doas during the same ten-minute period. Tune the search for authorized privileged accounts and expected management sources.
Associated Analytic Story
Intermediate Findings
| Message | Entity Field | Entity Type | Risk Score |
|---|---|---|---|
| Non-user account [$user$] logged in via ssh and ran a doas root command on [$dest$]. | dest | system | 20 |
References
Detection Testing
| Test Type | Status | Dataset | Source | Sourcetype |
|---|---|---|---|---|
| Validation | ✅ Passing | N/A | N/A | N/A |
| Unit | ✅ Passing | Dataset | /var/log/messages |
linux_messages_syslog |
| Integration | ✅ Passing | Dataset | /var/log/messages |
linux_messages_syslog |
Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI.
Alternatively you can replay a dataset into a Splunk Attack Range
Source: GitHub |
Version: 1