2022-10-14 18:19:13 +00:00
|
|
|
-- Applications setting environment variables to bypass security protections
|
|
|
|
--
|
2022-09-08 21:58:56 +00:00
|
|
|
-- Inpsired by BPFdoor and other intrusions
|
|
|
|
-- https://www.sandflysecurity.com/blog/compromised-linux-cheat-sheet/
|
2022-10-14 18:19:13 +00:00
|
|
|
--
|
2022-10-17 21:10:51 +00:00
|
|
|
-- WARNING: This query is known to require a higher than average wall time.
|
|
|
|
--
|
2022-10-20 18:56:16 +00:00
|
|
|
-- tags: transient state
|
2022-10-30 13:40:31 +00:00
|
|
|
-- interval: 300
|
2022-10-17 21:10:51 +00:00
|
|
|
-- platform: linux
|
2022-11-03 15:51:54 +00:00
|
|
|
SELECT
|
|
|
|
p.pid,
|
|
|
|
p.name,
|
2022-10-30 13:40:31 +00:00
|
|
|
key,
|
2022-09-24 15:12:23 +00:00
|
|
|
value,
|
2022-10-30 13:40:31 +00:00
|
|
|
LENGTH(value) AS value_len,
|
2022-09-24 15:12:23 +00:00
|
|
|
p.path,
|
|
|
|
p.cmdline,
|
|
|
|
p.parent AS parent_pid,
|
2022-10-14 18:19:13 +00:00
|
|
|
pp.cmdline AS parent_cmd
|
2022-11-03 15:51:54 +00:00
|
|
|
-- Querying processes first and filtering by time gives a massive 20X speed improvement
|
|
|
|
-- over querying process_envs first and JOIN'ing against processes
|
|
|
|
FROM
|
|
|
|
processes p
|
2022-10-30 13:40:31 +00:00
|
|
|
JOIN process_envs pe ON p.pid = pe.pid
|
|
|
|
LEFT JOIN file f ON p.path = f.path
|
2022-09-24 15:12:23 +00:00
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
2022-10-27 15:26:35 +00:00
|
|
|
WHERE -- This time should match the interval
|
2022-10-30 13:40:31 +00:00
|
|
|
p.start_time > (strftime('%s', 'now') - 300)
|
2022-10-27 15:26:35 +00:00
|
|
|
AND (
|
2022-09-24 15:12:23 +00:00
|
|
|
key = 'HISTFILE'
|
|
|
|
AND NOT VALUE LIKE '/home/%/.%_history'
|
|
|
|
)
|
|
|
|
OR (
|
|
|
|
key = 'LD_PRELOAD'
|
|
|
|
AND NOT p.path LIKE '%/firefox'
|
2022-11-10 16:20:58 +00:00
|
|
|
AND NOT pe.value IN ('libfakeroot.so', '/usr/local/lib/libmimalloc.so')
|
2022-09-24 15:12:23 +00:00
|
|
|
AND NOT pe.value LIKE ':/home/%/.local/share/Steam'
|
|
|
|
AND NOT pe.value LIKE ':/home/%/.var/app/com.valvesoftware.Steam/%'
|
2023-01-18 19:10:33 +00:00
|
|
|
AND NOT pe.value LIKE ':/home/%/.local/share/Steam/ubuntu%/gameoverlayrenderer.so:/home/%/.local/share/Steam/ubuntu%/gameoverlayrenderer.so'
|
2022-09-24 15:12:23 +00:00
|
|
|
AND NOT pe.value LIKE ':/snap/%'
|
|
|
|
AND NOT pe.value LIKE '/app/bin/%'
|
|
|
|
AND NOT pe.value LIKE 'libmozsandbox.so%'
|
2022-10-30 13:40:31 +00:00
|
|
|
)
|
|
|
|
-- setuid
|
|
|
|
OR (
|
|
|
|
LENGTH(value) > 1024
|
2022-10-31 21:40:37 +00:00
|
|
|
AND key != 'LS_COLORS'
|
2022-10-30 13:40:31 +00:00
|
|
|
AND f.mode IS NOT NULL
|
|
|
|
AND f.mode NOT LIKE '0%'
|
2022-11-03 15:51:54 +00:00
|
|
|
)
|