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
|
|
|
|
p.pid,
|
|
|
|
p.name,
|
|
|
|
p.path,
|
|
|
|
p.euid,
|
|
|
|
p.gid,
|
|
|
|
f.ctime,
|
|
|
|
f.directory AS dirname,
|
|
|
|
p.cmdline,
|
|
|
|
mnt_namespace,
|
|
|
|
hash.sha256,
|
2022-11-16 15:37:38 +00:00
|
|
|
pp.path AS parent_path,
|
2022-10-12 01:53:36 +00:00
|
|
|
pp.name AS parent_name,
|
|
|
|
pp.cmdline AS parent_cmdline
|
|
|
|
FROM
|
|
|
|
processes p
|
|
|
|
LEFT JOIN file f ON p.path = f.path
|
|
|
|
LEFT JOIN process_namespaces ON p.pid = process_namespaces.pid
|
|
|
|
LEFT JOIN hash ON p.path = hash.path
|
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
|
|
|
WHERE
|
|
|
|
p.uid = 0
|
|
|
|
AND (strftime('%s', 'now') - p.start_time) > 15 -- use osquery as the reference mount namespace
|
|
|
|
AND mnt_namespace IN (
|
|
|
|
SELECT DISTINCT
|
|
|
|
(mnt_namespace)
|
|
|
|
FROM
|
|
|
|
process_namespaces
|
|
|
|
JOIN processes ON processes.pid = process_namespaces.pid
|
|
|
|
WHERE
|
2022-10-13 18:59:32 +00:00
|
|
|
processes.name IN ('osqueryi', 'osqueryd')
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|
|
|
|
AND p.path NOT IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'',
|
|
|
|
'/sbin/apcupsd',
|
|
|
|
'/usr/bin/abrt-dump-journal-core',
|
|
|
|
'/usr/bin/abrt-dump-journal-oops',
|
|
|
|
'/usr/bin/abrt-dump-journal-xorg',
|
|
|
|
'/usr/bin/anacron',
|
|
|
|
'/usr/bin/apcupsd',
|
2022-10-27 20:55:00 +00:00
|
|
|
'/usr/bin/clamscan',
|
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-10-27 14:23:15 +00:00
|
|
|
'/usr/bin/dbus-daemon',
|
|
|
|
'/usr/bin/dbus-launch',
|
2022-11-10 16:04:48 +00:00
|
|
|
'/usr/libexec/dconf-service',
|
|
|
|
'/usr/libexec/at-spi-bus-launcher',
|
|
|
|
'/usr/bin/dbus-broker-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-11-10 16:04:48 +00:00
|
|
|
'/usr/bin/dbus-broker',
|
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',
|
|
|
|
'/usr/bin/tailscaled',
|
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',
|
|
|
|
'/usr/libexec/accounts-daemon',
|
|
|
|
'/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',
|
|
|
|
'/usr/lib/systemd/systemd-homed',
|
|
|
|
'/usr/lib/systemd/systemd-journald',
|
|
|
|
'/usr/lib/systemd/systemd-machined',
|
2022-11-16 15:37:38 +00:00
|
|
|
'/usr/lib/systemd/systemd-fsckd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/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',
|
|
|
|
'/usr/sbin/alsactl',
|
|
|
|
'/usr/sbin/anacron',
|
|
|
|
'/usr/sbin/cron',
|
|
|
|
'/usr/sbin/cups-browsed',
|
|
|
|
'/usr/sbin/cupsd',
|
|
|
|
'/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',
|
|
|
|
'/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
|
2022-10-12 01:53:36 +00:00
|
|
|
AND p.cmdline NOT IN (
|
2022-10-27 20:55:00 +00:00
|
|
|
'xargs logger -s',
|
|
|
|
'/usr/bin/xargs',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid',
|
|
|
|
'/usr/bin/python /usr/bin/firewalld --nofork --nopid',
|
2022-11-16 15:37:38 +00:00
|
|
|
'/usr/bin/python3 /usr/libexec/blueman-mechanism',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal',
|
|
|
|
'/usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers'
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|
2022-10-19 18:51:33 +00:00
|
|
|
AND NOT p.cmdline LIKE '/usr/bin/python3 /usr/bin/dnf %'
|
2022-11-07 15:03:43 +00:00
|
|
|
AND NOT p.cmdline LIKE '/usr/bin/python3 /usr/bin/yum %'
|
2022-10-13 18:59:32 +00:00
|
|
|
AND p.path NOT LIKE '/usr/local/kolide-k2/bin/osqueryd-updates/%/osqueryd'
|
|
|
|
AND p.path NOT LIKE '/usr/local/kolide-k2/bin/launcher-updates/%/launcher'
|
|
|
|
AND p.path NOT LIKE '/nix/store/%/bin/%'
|
|
|
|
AND p.path NOT LIKE '/nix/store/%-systemd-%/lib/systemd/systemd%'
|
|
|
|
AND p.path NOT LIKE '/nix/store/%/libexec/%'
|
|
|
|
AND p.path NOT LIKE '/snap/snapd/%/usr/lib/snapd/snapd'
|