2022-10-14 18:19:13 +00:00
|
|
|
-- Unexpected long-running processes running as root
|
|
|
|
--
|
|
|
|
-- false positives:
|
|
|
|
-- * new software requiring escalated privileges
|
|
|
|
--
|
2022-10-19 20:56:32 +00:00
|
|
|
-- references:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1543/
|
|
|
|
--
|
2022-10-14 18:26:49 +00:00
|
|
|
-- tags: persistent process state
|
2022-10-14 18:19:13 +00:00
|
|
|
-- platform: linux
|
2022-10-12 01:53:36 +00:00
|
|
|
SELECT
|
2023-02-01 18:55:55 +00:00
|
|
|
DATETIME(f.ctime, 'unixepoch') AS p0_changed,
|
|
|
|
DATETIME(f.mtime, 'unixepoch') AS p0_modified,
|
|
|
|
(strftime('%s', 'now') - p0.start_time) AS p0_runtime_s,
|
|
|
|
-- Child
|
|
|
|
p0.pid AS p0_pid,
|
|
|
|
p0.path AS p0_path,
|
|
|
|
p0.name AS p0_name,
|
|
|
|
p0.cmdline AS p0_cmd,
|
|
|
|
p0.cwd AS p0_cwd,
|
|
|
|
p0.cgroup_path AS p0_cgroup,
|
|
|
|
p0.euid AS p0_euid,
|
|
|
|
p0_hash.sha256 AS p0_sha256,
|
|
|
|
-- Parent
|
|
|
|
p0.parent AS p1_pid,
|
|
|
|
p1.path AS p1_path,
|
|
|
|
p1.name AS p1_name,
|
|
|
|
p1_f.mode AS p1_mode,
|
|
|
|
p1.euid AS p1_euid,
|
|
|
|
p1.cmdline AS p1_cmd,
|
|
|
|
p1_hash.sha256 AS p1_sha256,
|
|
|
|
-- Grandparent
|
|
|
|
p1.parent AS p2_pid,
|
|
|
|
p2.name AS p2_name,
|
|
|
|
p2.path AS p2_path,
|
|
|
|
p2.cmdline AS p2_cmd,
|
|
|
|
p2_hash.sha256 AS p2_sha256
|
2022-10-12 01:53:36 +00:00
|
|
|
FROM
|
2023-02-01 18:55:55 +00:00
|
|
|
processes p0
|
|
|
|
LEFT JOIN file f ON p0.path = f.path
|
|
|
|
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
|
|
|
|
LEFT JOIN processes p1 ON p0.parent = p1.pid
|
|
|
|
LEFT JOIN file p1_f ON p1.path = p1_f.path
|
|
|
|
LEFT JOIN hash p1_hash ON p1.path = p1_hash.path
|
|
|
|
LEFT JOIN processes p2 ON p1.parent = p2.pid
|
|
|
|
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
|
2022-10-12 01:53:36 +00:00
|
|
|
WHERE
|
2023-02-01 18:55:55 +00:00
|
|
|
p0.euid = 0
|
|
|
|
AND p0.parent > 0
|
|
|
|
AND (strftime('%s', 'now') - p0.start_time) > 15
|
|
|
|
AND p0.path NOT IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'',
|
|
|
|
'/sbin/apcupsd',
|
2022-12-19 23:06:06 +00:00
|
|
|
'/sbin/mount.ntfs',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/abrt-dump-journal-core',
|
|
|
|
'/usr/bin/abrt-dump-journal-oops',
|
|
|
|
'/usr/bin/abrt-dump-journal-xorg',
|
|
|
|
'/usr/bin/anacron',
|
2023-02-01 18:55:55 +00:00
|
|
|
'/usr/bin/NetworkManager',
|
|
|
|
'/usr/lib/upowerd',
|
|
|
|
'/usr/bin/fusermount3',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/apcupsd',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/bin/bash',
|
2022-10-27 20:55:00 +00:00
|
|
|
'/usr/bin/clamscan',
|
2023-02-01 18:55:55 +00:00
|
|
|
'/usr/lib/fwupd/fwupd',
|
|
|
|
'/usr/lib/accounts-daemon',
|
|
|
|
'/usr/lib/systemd/systemd-logind',
|
|
|
|
'/usr/lib/boltd',
|
|
|
|
'/usr/lib/power-profiles-daemon',
|
|
|
|
'/usr/bin/udevadm',
|
|
|
|
'/usr/bin/doas',
|
|
|
|
'/usr/bin/auditd',
|
|
|
|
'/usr/lib/boltd',
|
|
|
|
'/usr/lib/bluetooth/bluetoothd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/containerd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/bin/containerd-shim-runc-v2',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/crond',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/bin/dbus-broker',
|
2023-01-14 13:19:26 +00:00
|
|
|
'/usr/bin/nvidia-powerd',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/bin/dbus-broker-launch',
|
2022-10-27 14:23:15 +00:00
|
|
|
'/usr/bin/dbus-daemon',
|
|
|
|
'/usr/bin/dbus-launch',
|
2022-11-08 01:36:37 +00:00
|
|
|
'/usr/bin/dnsmasq',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/dockerd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/bin/docker-proxy',
|
|
|
|
'/usr/bin/fish',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/gdm',
|
|
|
|
'/usr/bin/gpg-agent',
|
|
|
|
'/usr/bin/journalctl',
|
|
|
|
'/usr/bin/lightdm',
|
|
|
|
'/usr/bin/osqueryd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/bin/pacman',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/sshd',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/bin/system76-power',
|
|
|
|
'/usr/bin/system76-scheduler',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/tailscaled',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/bin/touchegg',
|
2022-11-03 15:51:54 +00:00
|
|
|
'/usr/bin/vim',
|
2022-11-08 01:36:37 +00:00
|
|
|
'/usr/bin/virtlogd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/wpa_supplicant',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/bin/xargs',
|
|
|
|
'/usr/lib/accountsservice/accounts-daemon',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/libexec/accounts-daemon',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/libexec/at-spi-bus-launcher',
|
|
|
|
'/usr/libexec/dconf-service',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/libexec/docker/docker-proxy',
|
|
|
|
'/usr/libexec/flatpak-system-helper',
|
|
|
|
'/usr/libexec/gdm-session-worker',
|
|
|
|
'/usr/libexec/packagekitd',
|
|
|
|
'/usr/libexec/polkitd',
|
|
|
|
'/usr/libexec/scdaemon',
|
|
|
|
'/usr/libexec/snapd/snapd',
|
|
|
|
'/usr/libexec/sssd/sssd_kcm',
|
|
|
|
'/usr/libexec/udisks2/udisksd',
|
2022-10-27 14:23:15 +00:00
|
|
|
'/usr/libexec/xdg-document-portal',
|
|
|
|
'/usr/libexec/xdg-permission-store',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/lib/flatpak-system-helper',
|
|
|
|
'/usr/lib/gdm-session-worker',
|
2022-10-27 14:23:15 +00:00
|
|
|
'/usr/lib/snapd/snapd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/lib/software-properties/software-properties-dbus',
|
|
|
|
'/usr/lib/systemd/systemd',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/lib/systemd/systemd-fsckd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/lib/systemd/systemd-homed',
|
|
|
|
'/usr/lib/systemd/systemd-journald',
|
|
|
|
'/usr/lib/systemd/systemd-machined',
|
|
|
|
'/usr/lib/udisks2/udisksd',
|
|
|
|
'/usr/lib/Xorg',
|
2022-11-03 15:51:54 +00:00
|
|
|
'/usr/local/kolide-k2/bin/launcher',
|
|
|
|
'/usr/local/kolide-k2/bin/osqueryd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/abrtd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/sbin/abrt-dbus',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/acpid',
|
2022-12-19 23:06:06 +00:00
|
|
|
'/usr/sbin/agetty',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/alsactl',
|
|
|
|
'/usr/sbin/anacron',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/sbin/atd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/cron',
|
2022-11-22 14:21:03 +00:00
|
|
|
'/usr/sbin/crond',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/cups-browsed',
|
|
|
|
'/usr/sbin/cupsd',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/sbin/dnsmasq',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/gdm',
|
|
|
|
'/usr/sbin/gdm3',
|
|
|
|
'/usr/sbin/gssproxy',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/sbin/mcelog',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/pcscd',
|
2023-01-03 13:50:19 +00:00
|
|
|
'/usr/sbin/pwrstatd',
|
2023-01-06 21:01:35 +00:00
|
|
|
'/usr/sbin/rsyslogd',
|
|
|
|
'/usr/sbin/smartd',
|
2022-11-28 21:06:07 +00:00
|
|
|
'/usr/sbin/sshd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/tailscaled',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/usr/sbin/thermald',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/sbin/wpa_supplicant',
|
|
|
|
'/usr/sbin/zed'
|
2022-10-14 14:18:01 +00:00
|
|
|
)
|
|
|
|
-- Because I don't want to whitelist all of Python3
|
2023-02-01 18:55:55 +00:00
|
|
|
AND p0.cmdline NOT IN (
|
2023-01-20 13:40:08 +00:00
|
|
|
'/bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held',
|
|
|
|
'/sbin/init splash',
|
|
|
|
'/usr/bin/monitorix -c /etc/monitorix/monitorix.conf -p /run/monitorix.pid',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid',
|
2023-01-20 13:40:08 +00:00
|
|
|
'/usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers',
|
|
|
|
'/usr/bin/python3 /usr/bin/unattended-upgrade --download-only',
|
2022-11-16 15:37:38 +00:00
|
|
|
'/usr/bin/python3 /usr/libexec/blueman-mechanism',
|
2022-11-22 14:21:03 +00:00
|
|
|
'/usr/bin/python3 /usr/lib/pop-transition/service.py',
|
2023-01-20 13:40:08 +00:00
|
|
|
'/usr/bin/python3 /usr/sbin/execsnoop-bpfcc',
|
|
|
|
'/usr/bin/python3 /usr/sbin/lvmdbusd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal',
|
2023-01-20 13:40:08 +00:00
|
|
|
'/usr/bin/python /usr/bin/firewalld --nofork --nopid',
|
|
|
|
'/usr/bin/xargs',
|
|
|
|
'xargs logger -s'
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|
2023-02-01 18:55:55 +00:00
|
|
|
AND NOT p0.cmdline LIKE '/usr/bin/python3 -s% /usr/sbin/firewalld%'
|
|
|
|
AND NOT p0.cmdline LIKE '/usr/bin/python3 /usr/bin/dnf %'
|
|
|
|
AND NOT p0.cmdline LIKE '/usr/bin/python3 /usr/bin/yum %'
|
|
|
|
AND p0.path NOT LIKE '/usr/local/kolide-k2/bin/osqueryd-updates/%/osqueryd'
|
|
|
|
AND p0.path NOT LIKE '/usr/local/kolide-k2/bin/launcher-updates/%/launcher'
|
|
|
|
AND p0.path NOT LIKE '/nix/store/%/bin/%'
|
|
|
|
AND p0.path NOT LIKE '/nix/store/%-systemd-%/lib/systemd/systemd%'
|
|
|
|
AND p0.path NOT LIKE '/nix/store/%/libexec/%'
|
|
|
|
AND p0.path NOT LIKE '/snap/snapd/%/usr/lib/snapd/snapd'
|
2022-11-16 21:52:39 +00:00
|
|
|
-- Exclude processes running inside of Docker containers
|
2023-02-01 18:55:55 +00:00
|
|
|
AND NOT p0.cgroup_path LIKE '/system.slice/docker-%'
|
|
|
|
GROUP BY p0.pid
|