Name:Linux Non-User Privilege Escalation via Doas id:8f7bfeb6-05f8-4ff9-b582-4e19fc0d52c6 version:1 date:None author:Raven Tait, Splunk status:production type:Anomaly 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. Data_source:
-Linux Messages Syslog
search:`linux_syslog` ("Accepted password for" OR "as root from")
| rex field=_raw "^[A-Za-z]{3} +[0-9]+ +[0-9:]+ +(?<syslog_dest>[^ ]+)" | rex field=_raw "Accepted password for (?:invalid user )?(?<ssh_user>[^ ]+) from (?<src_ip>[^ ]+) port (?<src_port>[0-9]+) ssh2" | rex field=_raw "(?<doas_user>[^ ]+) ran command (?<command>.+) as root from (?<working_directory>.*)$"
| 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
| where doas_root_command=1 AND isnotnull(ssh_login_time)
| 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
how_to_implement: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. References: -https://attack.mitre.org/techniques/T1078/003/ -https://attack.mitre.org/techniques/T1548/003/ -https://attack.mitre.org/techniques/T1021/004/ -https://sshhole.com/ drilldown_searches: name:'View the detection results for - "$dest$"' search:'%original_detection_search% | search dest = "$dest$"' earliest_offset:'$info_min_time$' latest_offset:'$info_max_time$' name:'View risk events for the last 7 days for - "$dest$"' search:'| from datamodel Risk.All_Risk | search normalized_risk_object IN ("$dest$") | stats count min(_time) as firstTime max(_time) as lastTime values(search_name) as "Search Name" values(risk_message) as "Risk Message" values(analyticstories) as "Analytic Stories" values(annotations._all) as "Annotations" values(annotations.mitre_attack.mitre_tactic) as "ATT&CK Tactics" by normalized_risk_object | `security_content_ctime(firstTime)` | `security_content_ctime(lastTime)`' earliest_offset:'7d' latest_offset:'0' analytic_story:['Linux Privilege Escalation', 'SSHHole']