osquery-defense-kit/detection/evasion/unexpected-dev-executables-...

82 lines
2.1 KiB
MySQL
Raw Normal View History

2022-09-29 19:42:27 +00:00
-- Find unexpected executables in /dev
2022-10-14 18:19:13 +00:00
--
-- references:
-- * https://www.sandflysecurity.com/blog/bpfdoor-an-evasive-linux-backdoor-technical-analysis/
--
-- tags: persistent state filesystem
2023-01-20 14:24:24 +00:00
SELECT
file.path,
2022-09-29 19:42:27 +00:00
file.directory,
uid,
gid,
mode,
file.mtime,
file.size,
hash.sha256,
magic.data
2023-01-20 14:24:24 +00:00
FROM
file
2022-09-29 19:42:27 +00:00
LEFT JOIN hash on file.path = hash.path
LEFT JOIN magic ON file.path = magic.path
2023-01-20 14:24:24 +00:00
WHERE
(
-- This list is the result of multiple queries combined and can likely be minimized
file.path LIKE '/dev/%%'
OR file.path LIKE '/dev/%%/%%'
OR file.path LIKE '/dev/mqueue/%%'
OR file.path LIKE '/dev/mqueue/.%/%%'
OR file.path LIKE '/dev/mqueue/%/%%'
OR file.path LIKE '/dev/mqueue/%/%/.%'
OR file.path LIKE '/dev/mqueue/%/.%/%%'
OR file.path LIKE '/dev/shm/%%'
OR file.path LIKE '/dev/shm/.%/%%'
OR file.path LIKE '/dev/shm/%/%%'
OR file.path LIKE '/dev/shm/%/%/.%'
OR file.path LIKE '/dev/shm/%/.%/%%'
)
AND file.type = 'regular'
AND file.size > 64
AND file.path NOT LIKE '%/../%'
AND file.path NOT LIKE '%/./%'
2022-09-29 19:42:27 +00:00
AND (
file.mode LIKE '%7%'
or file.mode LIKE '%5%'
or file.mode LIKE '%1%'
2023-01-14 13:19:26 +00:00
) -- Seen on Ubuntu
AND NOT (
file.uid = 1000
AND file.gid = 1000
2022-11-16 16:01:22 +00:00
AND file.mode = '0700'
AND magic.data = 'data'
AND file.path LIKE '/dev/shm/pulse-shm-%'
AND file.size > 60000000
2023-01-14 13:19:26 +00:00
) -- Seen with Steam
AND NOT (
file.uid = 1000
2023-01-13 20:24:18 +00:00
AND file.gid IN (100, 1000)
AND file.mode IN ('0755', '0775')
2023-01-14 13:19:26 +00:00
AND magic.data IN (
'data',
'Applesoft BASIC program data, first line number 86',
'mc68k executable (shared)',
'OpenPGP Secret Key',
'',
'floppy image data (IBM SaveDskF, old)',
2023-01-14 13:19:26 +00:00
'DOS executable (COM)'
)
AND file.path LIKE '/dev/shm/u1000-Shm_%'
)
AND NOT (
file.uid = 1000
AND file.gid IN (100, 1000)
AND file.mode IN ('0755', '0775')
AND magic.data IS NULL
AND file.path LIKE '/dev/shm/u1000-Shm_%'
)
AND NOT (
file.uid = 1000
AND file.mode = '0755'
AND file.path LIKE '/dev/shm/flatpak-com.valvesoftware.Steam-%/u1000-Shm_%'
AND file.size > 1000000
2023-01-20 14:24:24 +00:00
)