LoFP LoFP / system administrators and automation may run shells under service accounts or accounts that are not locked on a particular image. the search also matches any account with a uid between 1 and 999 (the system account range on most modern distributions), so administrators who use su or sudo to open an interactive shell as a service account such as jenkins or gitlab-runner will trigger it. on legacy systems (for example rhel/centos 6) regular users may start at uid 500, so adjust the threshold if needed. review the account's shadow state and the process context before escalating.

Techniques

Sample rules

Linux Auditd Shell Execution by Non-User Account

Description

The following analytic detects successful auditd execve events that launch an interactive Linux shell, identified by a TTY, under accounts that commonly do not log in. These are identified by a list of well-known service account names or by a system UID (between 1 and 999). An interactive shell for these accounts may indicate password-bypass abuse or unauthorized access.

Detection logic

`linux_auditd` type=SYSCALL
comm IN (
    "ash",
    "bash",
    "csh",
    "dash",
    "fish",
    "ksh",
    "mksh",
    "rbash",
    "sh",
    "tcsh",
    "yash",
    "zsh"
)
success=yes


| where isnotnull(tty) AND tty!="(none)"


| rex field=_raw "\\bUID=[[:punct:]]?(?<audit_user>[[:alnum:]_.-]+)"


| eval audit_user=lower(coalesce(audit_user, user))

| eval uid_num=tonumber(uid)


| where (uid_num>0 AND uid_num<1000) OR in(audit_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")


| rename host as dest


| stats count min(_time) as firstTime
              max(_time) as lastTime
              values(audit_user) as user
              values(uid) as uid
              values(euid) as euid
              values(comm) as shell
              values(exe) as executable
              values(tty) as tty
  by dest


| `security_content_ctime(firstTime)`

| `security_content_ctime(lastTime)`

| `linux_auditd_shell_execution_by_non_user_account_filter`