2022-09-22 23:35:24 +00:00
|
|
|
-- Find unexpected executables in temp directories
|
2022-09-24 15:12:23 +00:00
|
|
|
SELECT
|
|
|
|
file.path,
|
|
|
|
uid,
|
|
|
|
gid,
|
|
|
|
mode,
|
|
|
|
file.mtime,
|
|
|
|
file.size,
|
|
|
|
hash.sha256,
|
|
|
|
magic.data
|
|
|
|
FROM
|
|
|
|
file
|
|
|
|
LEFT JOIN hash on file.path = hash.path
|
|
|
|
LEFT JOIN magic ON file.path = magic.path
|
|
|
|
WHERE
|
|
|
|
(
|
2022-09-30 17:47:10 +00:00
|
|
|
-- Recursive queries don't seem to work well with hidden directories :(
|
|
|
|
file.path LIKE '/tmp/%%'
|
|
|
|
OR file.path LIKE '/tmp/.%/%%'
|
|
|
|
OR file.path LIKE '/tmp/%/%%'
|
|
|
|
OR file.path LIKE '/tmp/%/%/.%'
|
|
|
|
OR file.path LIKE '/tmp/%/.%/%%'
|
|
|
|
|
|
|
|
OR file.path LIKE '/var/tmp/%%'
|
|
|
|
OR file.path LIKE '/var/tmp/.%/%%'
|
|
|
|
OR file.path LIKE '/var/tmp/%/%%'
|
|
|
|
OR file.path LIKE '/var/tmp/%/%/.%'
|
|
|
|
OR file.path LIKE '/var/tmp/%/.%/%%'
|
|
|
|
|
|
|
|
OR file.path LIKE '/var/spool/%%'
|
|
|
|
OR file.path LIKE '/var/spool/.%/%%'
|
|
|
|
OR file.path LIKE '/var/spool/%/%%'
|
|
|
|
OR file.path LIKE '/var/spool/%/%/.%'
|
|
|
|
OR file.path LIKE '/var/spool/%/.%/%%'
|
|
|
|
|
|
|
|
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/%/.%/%%'
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
AND file.type = "regular"
|
2022-09-30 17:47:10 +00:00
|
|
|
AND file.path NOT LIKE "%/../%"
|
|
|
|
AND file.path NOT LIKE "%/./%"
|
2022-09-24 15:12:23 +00:00
|
|
|
AND (
|
|
|
|
file.mode LIKE "%7%"
|
|
|
|
or file.mode LIKE "%5%"
|
|
|
|
or file.mode LIKE "%1%"
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
uid > 500
|
2022-09-22 23:35:24 +00:00
|
|
|
AND (
|
2022-09-30 17:47:10 +00:00
|
|
|
file.path LIKE "%/go-build%"
|
2022-09-27 15:54:17 +00:00
|
|
|
OR file.path LIKE "/tmp/checkout/%"
|
|
|
|
OR file.path LIKE "/tmp/com.apple.installer%"
|
|
|
|
OR file.path LIKE "/tmp/flow/%.npmzS_cacachezStmpzSgit-clone%"
|
|
|
|
OR file.path LIKE "/tmp/go.%.sum"
|
|
|
|
OR file.path LIKE "/tmp/guile-%/guile-%"
|
|
|
|
OR file.path LIKE "/tmp/terraformer/%"
|
|
|
|
OR file.path LIKE "/tmp/tmp.%"
|
2022-09-24 15:12:23 +00:00
|
|
|
OR file.path LIKE "%/bin/%-gen"
|
|
|
|
OR file.path LIKE "%/bin/%"
|
|
|
|
OR file.path LIKE "%/CCLBS/%"
|
2022-09-27 15:54:17 +00:00
|
|
|
OR file.path LIKE "%/ko/%"
|
2022-09-24 15:12:23 +00:00
|
|
|
OR file.path LIKE "%/pdf-tools/%"
|
2022-09-27 15:54:17 +00:00
|
|
|
OR file.path LIKE "%/tmp/epdf%"
|
2022-09-24 15:12:23 +00:00
|
|
|
OR
|
|
|
|
-- These regular expressions can be narrowed down
|
|
|
|
(
|
|
|
|
file.size < 4000
|
|
|
|
AND file.path LIKE "/tmp/%.sh"
|
|
|
|
)
|
|
|
|
OR (
|
|
|
|
file.size < 4000
|
|
|
|
AND file.path LIKE "/tmp/%.py"
|
|
|
|
)
|
2022-09-22 23:35:24 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
-- Nix
|
|
|
|
AND NOT (
|
|
|
|
file.directory LIKE "/tmp/tmp%"
|
|
|
|
AND gid = 0
|
|
|
|
AND uid > 300
|
|
|
|
AND uid < 350
|
|
|
|
)
|
|
|
|
AND NOT magic.data LIKE "%nix-shell script%"
|
|
|
|
-- Don't alert if the file is only on disk for a moment
|
|
|
|
AND NOT (
|
|
|
|
file.directory LIKE "/tmp/%"
|
|
|
|
AND (strftime('%s', 'now') - ctime) < 60
|
|
|
|
)
|
|
|
|
-- macOS updates
|
|
|
|
AND NOT file.directory LIKE "/tmp/msu-target-%"
|
2022-09-27 15:54:17 +00:00
|
|
|
-- I don't know man. I don't work here.
|
|
|
|
AND NOT (file.path LIKE ("/tmp/%compressed") AND size < 4000 AND uid>500)
|
2022-09-29 15:38:14 +00:00
|
|
|
-- Executables too small to even hold "#!/bin/sh\nuid"
|
|
|
|
AND NOT (file.type = "regular" AND size < 10)
|