LoFP LoFP / administrators may legitimately use ssh and doas during the same ten-minute period. tune the search for authorized privileged accounts and expected management sources.

Techniques

Sample rules

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.

Detection logic

`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>.*)$"


| eval dest=coalesce(dest, syslog_dest, host), user=lower(coalesce(ssh_user, doas_user))


| eval ssh_login=if(match(_raw, "Accepted password for"), 1, 0), doas_root_command=if(match(_raw, "ran command .* as root from"), 1, 0)


| where ssh_login=1 OR doas_root_command=1


| where isnotnull(user)


| 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")


| eval event_priority=if(ssh_login=1, 0, 1)


| sort 0 _time event_priority


| 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)


| eval doas_time=_time, elapsed_seconds=doas_time-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


| `security_content_ctime(ssh_login_time)`

| `security_content_ctime(doas_time)`


| table ssh_login_time doas_time elapsed_seconds dest
        user src_ips src_ports command working_directory


| `linux_non_user_privilege_escalation_via_doas_filter`