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
|
2023-02-01 18:55:55 +00:00
|
|
|
pe.key,
|
|
|
|
pe.value,
|
|
|
|
LENGTH(pe.value) AS value_len,
|
|
|
|
-- Child
|
2023-02-09 22:01:29 +00:00
|
|
|
p0.pid AS p0_pid,
|
2023-02-01 18:55:55 +00:00
|
|
|
p0.path AS p0_path,
|
|
|
|
p0.name AS p0_name,
|
|
|
|
p0.cmdline AS p0_cmd,
|
|
|
|
p0.cwd AS p0_cwd,
|
|
|
|
p0.cgroup_path AS p0_cgroup,
|
|
|
|
p0.euid AS p0_euid,
|
|
|
|
p0_hash.sha256 AS p0_sha256,
|
|
|
|
-- Parent
|
|
|
|
p0.parent AS p1_pid,
|
|
|
|
p1.path AS p1_path,
|
|
|
|
p1.name AS p1_name,
|
|
|
|
p1.cmdline AS p1_cmd,
|
|
|
|
p1_hash.sha256 AS p1_sha256,
|
|
|
|
-- Grandparent
|
|
|
|
p1.parent AS p2_pid,
|
|
|
|
p2.name AS p2_name,
|
|
|
|
p2.path AS p2_path,
|
|
|
|
p2.cmdline AS p2_cmd,
|
|
|
|
p2_hash.sha256 AS p2_sha256
|
|
|
|
FROM
|
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
|
2023-02-01 18:55:55 +00:00
|
|
|
processes p0
|
|
|
|
JOIN process_envs pe ON p0.pid = pe.pid
|
|
|
|
LEFT JOIN file f ON p0.path = f.path
|
|
|
|
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
|
|
|
|
LEFT JOIN processes p1 ON p0.parent = p1.pid
|
|
|
|
LEFT JOIN hash p1_hash ON p1.path = p1_hash.path
|
|
|
|
LEFT JOIN processes p2 ON p1.parent = p2.pid
|
|
|
|
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
|
2022-10-27 15:26:35 +00:00
|
|
|
WHERE -- This time should match the interval
|
2023-02-01 18:55:55 +00:00
|
|
|
p0.start_time > (strftime('%s', 'now') - 300)
|
2022-10-27 15:26:35 +00:00
|
|
|
AND (
|
2023-02-01 18:55:55 +00:00
|
|
|
pe.key = 'HISTFILE'
|
|
|
|
AND NOT pe.value LIKE '/home/%/.%_history'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
OR (
|
2023-02-01 18:55:55 +00:00
|
|
|
pe.key = 'LD_PRELOAD'
|
2023-02-14 13:33:05 +00:00
|
|
|
AND NOT pe.value = ''
|
2023-02-01 18:55:55 +00:00
|
|
|
AND NOT p0.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 (
|
2023-02-01 18:55:55 +00:00
|
|
|
LENGTH(pe.value) > 1024
|
|
|
|
AND pe.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
|
|
|
)
|