osquery-defense-kit/detection/evasion/unexpected-dev-entries.sql

54 lines
1.5 KiB
MySQL
Raw Normal View History

2022-10-14 18:19:13 +00:00
-- Find unexpected files in /dev
--
-- references:
-- * https://www.sandflysecurity.com/blog/bpfdoor-an-evasive-linux-backdoor-technical-analysis/
--
-- false positives:
2022-10-18 00:37:44 +00:00
-- * programs which have legimate uses for /dev/shm (Chrome, etc)
2022-10-14 18:19:13 +00:00
--
-- tags: persistent state filesystem
2022-10-20 11:59:06 +00:00
-- platform: posix
SELECT
file.path,
file.type,
2022-09-29 19:42:27 +00:00
file.size,
file.mtime,
file.uid,
file.ctime,
file.gid,
hash.sha256,
magic.data
FROM
file
LEFT JOIN hash ON file.path = hash.path
LEFT JOIN magic ON file.path = magic.path
WHERE
(
file.path LIKE '/dev/shm/%%'
OR file.path LIKE '/dev/%/.%'
OR file.path LIKE '/dev/.%'
OR file.path LIKE '/dev/.%/%'
OR file.path LIKE '/dev/%%/.%/%'
OR file.path LIKE '/dev/mqueue/%%'
2022-09-29 19:42:27 +00:00
) -- We should also use uid for making decisions here
AND NOT (
file.uid > 499
2023-04-17 20:20:35 +00:00
AND (
file.path LIKE '/dev/shm/.com.google.%'
2022-09-29 19:42:27 +00:00
OR file.path LIKE '/dev/shm/.org.chromium.%'
OR file.path LIKE '/dev/shm/wayland.mozilla.%'
OR file.path LIKE '/dev/shm/shm-%-%-%'
OR file.path LIKE '/dev/shm/pulse-shm-%'
OR file.path LIKE '/dev/shm/u1000-Shm%'
OR file.path LIKE '/dev/shm/u1000-Valve%'
OR file.path LIKE '/dev/shm/aomshm.%'
OR file.path LIKE '/dev/shm/jack_db%'
2022-09-29 19:42:27 +00:00
)
)
AND file.path NOT LIKE '/dev/shm/lttng-ust-wait-%'
AND file.path NOT LIKE '/dev/shm/flatpak-%'
AND file.path NOT LIKE '/dev/shm/libpod_rootless_lock_%'
AND file.path NOT LIKE '%/../%'
AND file.path NOT LIKE '%/./%'
AND file.path NOT IN ('/dev/.mdadm/')