2022-10-12 01:53:36 +00:00
|
|
|
-- Detects unexpected programs opening files in /dev on Linux
|
|
|
|
--
|
|
|
|
-- references:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1056/001/ (Input Capture: Keylogging)
|
|
|
|
--
|
2022-10-14 14:18:01 +00:00
|
|
|
-- false positives:
|
|
|
|
-- * any program which needs access to device drivers
|
|
|
|
--
|
2022-10-12 01:53:36 +00:00
|
|
|
-- platform: linux
|
2022-10-14 18:26:49 +00:00
|
|
|
-- tags: persistent state sniffer
|
2022-10-12 01:53:36 +00:00
|
|
|
SELECT
|
|
|
|
pof.pid,
|
2022-09-24 15:12:23 +00:00
|
|
|
pof.path AS device,
|
|
|
|
p.path AS program,
|
|
|
|
p.name AS program_name,
|
|
|
|
p.cmdline AS cmdline,
|
|
|
|
hash.sha256,
|
|
|
|
CONCAT (
|
|
|
|
IIF(
|
2022-10-12 01:53:36 +00:00
|
|
|
REGEX_MATCH (
|
2022-10-14 14:18:01 +00:00
|
|
|
TRIM(REPLACE(pof.path, ' (deleted)', '')),
|
2022-10-13 18:59:32 +00:00
|
|
|
'(/dev/.*)[\d ]+$',
|
2022-09-29 19:42:27 +00:00
|
|
|
1
|
2022-10-13 18:59:32 +00:00
|
|
|
) != '',
|
2022-10-12 01:53:36 +00:00
|
|
|
REGEX_MATCH (
|
2022-10-14 14:18:01 +00:00
|
|
|
TRIM(REPLACE(pof.path, ' (deleted)', '')),
|
2022-10-13 18:59:32 +00:00
|
|
|
'(/dev/.*)[\d ]+$',
|
2022-09-29 19:42:27 +00:00
|
|
|
1
|
|
|
|
),
|
2022-10-14 14:18:01 +00:00
|
|
|
TRIM(REPLACE(pof.path, ' (deleted)', ''))
|
2022-09-24 15:12:23 +00:00
|
|
|
),
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-09-24 15:12:23 +00:00
|
|
|
REPLACE(
|
|
|
|
p.path,
|
2022-10-13 18:59:32 +00:00
|
|
|
RTRIM(p.path, REPLACE(p.path, '/', '')),
|
|
|
|
''
|
2022-09-21 01:56:01 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
) AS path_exception,
|
|
|
|
CONCAT (
|
|
|
|
TRIM(
|
|
|
|
REPLACE(
|
|
|
|
pof.path,
|
|
|
|
CONCAT (
|
2022-10-13 18:59:32 +00:00
|
|
|
'/',
|
2022-09-24 15:12:23 +00:00
|
|
|
REPLACE(
|
|
|
|
pof.path,
|
2022-10-13 18:59:32 +00:00
|
|
|
RTRIM(pof.path, REPLACE(pof.path, '/', '')),
|
|
|
|
''
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
),
|
2022-10-13 18:59:32 +00:00
|
|
|
''
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
),
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-09-24 15:12:23 +00:00
|
|
|
REPLACE(
|
|
|
|
p.path,
|
2022-10-13 18:59:32 +00:00
|
|
|
RTRIM(p.path, REPLACE(p.path, '/', '')),
|
|
|
|
''
|
2022-09-21 01:56:01 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
) AS dir_exception
|
2022-10-12 01:53:36 +00:00
|
|
|
FROM
|
|
|
|
process_open_files pof
|
2022-09-24 15:12:23 +00:00
|
|
|
LEFT JOIN processes p ON pof.pid = p.pid
|
|
|
|
LEFT JOIN hash ON hash.path = p.path
|
2022-10-12 01:53:36 +00:00
|
|
|
WHERE
|
2022-10-13 18:59:32 +00:00
|
|
|
pof.path LIKE '/dev/%'
|
2022-09-24 15:12:23 +00:00
|
|
|
AND pof.path NOT IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/dri/card0',
|
|
|
|
'/dev/dri/card1',
|
|
|
|
'/dev/dri/renderD128',
|
|
|
|
'/dev/dri/renderD129',
|
|
|
|
'/dev/fuse',
|
|
|
|
'/dev/io8log',
|
|
|
|
'/dev/io8logmt',
|
|
|
|
'/dev/io8logtemp',
|
|
|
|
'/dev/null',
|
|
|
|
'/dev/nvidia-modeset',
|
|
|
|
'/dev/nvidia-uvm',
|
|
|
|
'/dev/nvidia0',
|
|
|
|
'/dev/nvidiactl',
|
|
|
|
'/dev/ptmx',
|
|
|
|
'/dev/pts/ptmx',
|
2022-10-30 16:00:43 +00:00
|
|
|
'/dev/shm/u1000-ValveIPCSharedObj-Steam',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/random',
|
|
|
|
'/dev/rfkill',
|
|
|
|
'/dev/snd/seq',
|
|
|
|
'/dev/urandom',
|
|
|
|
'/dev/vga_arbiter',
|
|
|
|
'/dev/video10' -- workaround for poor regex management (ffmpeg)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
2022-10-13 18:59:32 +00:00
|
|
|
AND pof.path NOT LIKE '/dev/pts/%'
|
|
|
|
AND pof.path NOT LIKE '/dev/snd/%'
|
|
|
|
AND pof.path NOT LIKE '/dev/tty%'
|
|
|
|
AND pof.path NOT LIKE '/dev/hidraw%'
|
|
|
|
AND pof.path NOT LIKE '/dev/shm/.com.google.Chrome.%'
|
|
|
|
AND pof.path NOT LIKE '/dev/shm/.org.chromium.Chromium.%'
|
|
|
|
AND pof.path NOT LIKE '/dev/shm/authentik_%'
|
2022-09-24 15:12:23 +00:00
|
|
|
AND NOT dir_exception IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/bus/usb,pcscd',
|
|
|
|
'/dev/input,acpid',
|
2022-10-30 16:00:43 +00:00
|
|
|
'/dev/shm,gameoverlayui',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/input,gnome-shell',
|
|
|
|
'/dev/input,systemd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/dev/input,systemd-logind',
|
|
|
|
'/dev/input,thermald',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/input,upowerd',
|
|
|
|
'/dev/input,Xorg',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/dev/kmsg,systemd-coredump',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/net,tailscaled',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/dev/net,.tailscaled-wrapped',
|
|
|
|
'/dev/net/tun,qemu-system-x86_64',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/shm,1password',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/dev/shm,Brackets',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/shm,chrome',
|
|
|
|
'/dev/shm,code',
|
|
|
|
'/dev/shm,electron',
|
|
|
|
'/dev/shm,firefox',
|
|
|
|
'/dev/shm,gopls',
|
|
|
|
'/dev/shm,java',
|
|
|
|
'/dev/shm,jcef_helper',
|
|
|
|
'/dev/shm,slack',
|
|
|
|
'/dev/shm,spotify',
|
|
|
|
'/dev/shm,steam',
|
|
|
|
'/dev/shm,steamwebhelper',
|
|
|
|
'/dev/shm,wine64-preloader',
|
|
|
|
'/dev/shm,winedevice.exe',
|
|
|
|
'/dev/snd,alsactl',
|
|
|
|
'/dev/snd,pipewire',
|
|
|
|
'/dev/snd,pulseaudio',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/dev/snd,.pulseaudio-wrapped',
|
2022-10-17 23:01:16 +00:00
|
|
|
'/dev/snd,wireplumber',
|
|
|
|
'/dev/usb,apcupsd',
|
|
|
|
'/dev/usb,upowerd'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
AND NOT path_exception IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/autofs,systemd',
|
|
|
|
'/dev/hidraw,chrome',
|
|
|
|
'/dev/input/event,thermald',
|
|
|
|
'/dev/input/event,Xorg',
|
|
|
|
'/dev/kmsg,kubelet',
|
|
|
|
'/dev/kmsg,systemd',
|
|
|
|
'/dev/kmsg,systemd-journald',
|
|
|
|
'/dev/kvm,qemu-system-x86_64',
|
|
|
|
'/dev/mapper/control,dockerd',
|
|
|
|
'/dev/mcelog,mcelog',
|
2022-10-18 00:37:44 +00:00
|
|
|
'/dev/media0,pipewire',
|
|
|
|
'/dev/media0,wireplumber',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/media,pipewire',
|
|
|
|
'/dev/media,wireplumber',
|
2022-10-21 15:27:42 +00:00
|
|
|
'/dev/uhid,bluetoothd',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/net/tun,slirp4netns',
|
|
|
|
'/dev/tty,agetty',
|
|
|
|
'/dev/tty,gdm-wayland-session',
|
|
|
|
'/dev/tty,gdm-x-session',
|
|
|
|
'/dev/tty,systemd-logind',
|
|
|
|
'/dev/tty,Xorg',
|
|
|
|
'/dev/uinput,bluetoothd',
|
|
|
|
'/dev/usb/hiddev,apcupsd',
|
|
|
|
'/dev/usb/hiddev,upowerd',
|
2022-10-14 14:18:01 +00:00
|
|
|
'/dev/video0,chrome',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/video,chrome',
|
|
|
|
'/dev/video,ffmpeg',
|
|
|
|
'/dev/video,firefox',
|
|
|
|
'/dev/video,obs',
|
|
|
|
'/dev/video,obs-ffmpeg-mux',
|
2022-10-18 00:37:44 +00:00
|
|
|
'/dev/video,pipewire',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/video,vlc',
|
|
|
|
'/dev/video,wireplumber',
|
2022-10-18 00:37:44 +00:00
|
|
|
'/dev/video,zoom',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/dev/zfs,zed',
|
|
|
|
'/dev/zfs,zfs',
|
|
|
|
'/dev/zfs,zpool'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
AND NOT (
|
2022-10-13 18:59:32 +00:00
|
|
|
device LIKE '/dev/bus/usb/%'
|
2022-09-29 19:42:27 +00:00
|
|
|
AND program_name IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'fwupd',
|
2022-10-17 23:01:16 +00:00
|
|
|
'gphoto2',
|
2022-10-13 18:59:32 +00:00
|
|
|
'gvfs-gphoto2-vo',
|
2022-10-17 23:01:16 +00:00
|
|
|
'gvfs-gphoto2-volume-monitor',
|
|
|
|
'gvfsd-gphoto2',
|
|
|
|
'pcscd',
|
|
|
|
'streamdeck',
|
|
|
|
'usbmuxd'
|
2022-09-29 19:42:27 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
2022-10-12 01:53:36 +00:00
|
|
|
GROUP BY
|
|
|
|
pof.pid
|