2022-10-14 18:19:13 +00:00
|
|
|
-- Find unexpected executables in temp directories, often used by malware droppers
|
|
|
|
--
|
|
|
|
-- false positives:
|
|
|
|
-- * developers building code out of /tmp
|
|
|
|
--
|
2023-02-09 22:01:29 +00:00
|
|
|
-- tags: persistent seldom
|
2023-01-27 13:46:48 +00:00
|
|
|
-- platform: darwin
|
2023-02-09 22:01:29 +00:00
|
|
|
SELECT DISTINCT
|
|
|
|
file.path,
|
2022-09-24 15:12:23 +00:00
|
|
|
uid,
|
|
|
|
gid,
|
|
|
|
mode,
|
2023-01-09 20:10:48 +00:00
|
|
|
REGEX_MATCH (RTRIM(file.path, '/'), '.*\.(.*?)$', 1) AS extension,
|
2023-01-18 14:49:56 +00:00
|
|
|
file.btime,
|
|
|
|
file.ctime,
|
2022-09-24 15:12:23 +00:00
|
|
|
file.mtime,
|
2023-05-23 15:31:37 +00:00
|
|
|
file.type,
|
2022-09-24 15:12:23 +00:00
|
|
|
file.size,
|
|
|
|
hash.sha256,
|
2023-01-18 19:10:33 +00:00
|
|
|
magic.data,
|
|
|
|
signature.identifier,
|
|
|
|
signature.authority
|
2023-02-09 22:01:29 +00:00
|
|
|
FROM
|
|
|
|
file
|
2022-09-24 15:12:23 +00:00
|
|
|
LEFT JOIN hash on file.path = hash.path
|
|
|
|
LEFT JOIN magic ON file.path = magic.path
|
2023-01-18 19:10:33 +00:00
|
|
|
LEFT JOIN signature ON file.path = signature.path
|
2023-02-09 01:06:10 +00:00
|
|
|
WHERE -- Optimization: don't join things until we have a whittled down list of files
|
|
|
|
file.path IN (
|
2023-02-09 22:01:29 +00:00
|
|
|
SELECT
|
|
|
|
path
|
|
|
|
FROM
|
|
|
|
file
|
|
|
|
WHERE
|
|
|
|
(
|
2023-02-09 01:06:10 +00:00
|
|
|
file.directory = '/tmp'
|
|
|
|
OR file.directory LIKE '/tmp/%'
|
|
|
|
OR file.directory LIKE '/tmp/%/%'
|
|
|
|
OR file.directory LIKE '/tmp/%/.%'
|
|
|
|
OR file.directory LIKE '/tmp/.%'
|
|
|
|
OR file.directory LIKE '/tmp/.%/%'
|
|
|
|
or file.directory LIKE '/tmp/.%/.%'
|
|
|
|
) -- Prevent weird recursion
|
|
|
|
AND NOT file.directory LIKE '%/../%'
|
|
|
|
AND NOT file.directory LIKE '%/./%' -- Exclude very temporary files
|
|
|
|
AND NOT (strftime('%s', 'now') - ctime) < 60 -- Only executable files
|
|
|
|
AND file.type = 'regular'
|
|
|
|
AND (
|
|
|
|
file.mode LIKE '%7%'
|
|
|
|
or file.mode LIKE '%5%'
|
|
|
|
or file.mode LIKE '%1%'
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
uid > 500
|
|
|
|
AND (
|
|
|
|
file.path LIKE '%/go-build%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '%/bin/%'
|
2023-05-02 19:25:36 +00:00
|
|
|
OR file.path LIKE '%/sbin/%'
|
2023-03-24 14:42:06 +00:00
|
|
|
OR file.path LIKE '/tmp/%ctl'
|
2023-02-09 01:06:10 +00:00
|
|
|
OR file.path LIKE '%/CCLBS/%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '%/checkout/%'
|
2024-02-05 15:45:17 +00:00
|
|
|
OR file.path LIKE '/tmp/lima/%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '%/ci/%'
|
|
|
|
OR file.path LIKE '%/debug/%'
|
|
|
|
OR file.path LIKE '%/dist/%'
|
|
|
|
OR file.path LIKE '%/etc/network/if-up.d/%'
|
|
|
|
OR file.path LIKE '%/flow/%.npmzS_cacachezStmpzSgit-clone%'
|
2023-03-20 21:05:02 +00:00
|
|
|
OR file.path LIKE '/tmp/GoLand/___Test%.test'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '%/git/%'
|
|
|
|
OR file.path LIKE '%/github/%'
|
2024-01-22 15:36:01 +00:00
|
|
|
OR file.path LIKE '%/elastic-agent-%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '%/go.%.sum'
|
|
|
|
OR file.path LIKE "%/%/gradlew"
|
|
|
|
OR file.path LIKE '%/guile-%/guile-%'
|
2023-02-09 01:06:10 +00:00
|
|
|
OR file.path LIKE '%/ko/%'
|
2023-02-15 00:46:36 +00:00
|
|
|
OR file.path LIKE '%/nix/%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '%/kots/%'
|
2023-09-14 21:13:12 +00:00
|
|
|
OR file.path LIKE '/tmp/KSInstallAction.%/m/.keystone_install'
|
2023-03-04 17:20:53 +00:00
|
|
|
OR file.path LIKE '/tmp/%/AdobePIM.dylib'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE "%/lib/%.so"
|
2023-03-30 22:44:01 +00:00
|
|
|
OR file.path LIKE '/tmp/melange%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE "%/lib/%.so.%"
|
2023-02-09 01:06:10 +00:00
|
|
|
OR file.path LIKE '%/pdf-tools/%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '%/Photoshop Installer.app/Contents/%'
|
|
|
|
OR file.path LIKE '%-release%/%'
|
|
|
|
OR file.path LIKE '%/site-packages/markupsafe/_speedups.cpython-%'
|
|
|
|
OR file.path LIKE '%/src/%'
|
|
|
|
OR file.path LIKE '%/target/%'
|
|
|
|
OR file.path LIKE '%/terraformer/%'
|
|
|
|
OR file.path LIKE '/tmp/com.apple.installer%'
|
2024-01-18 22:15:37 +00:00
|
|
|
OR file.path LIKE '%.tfstate.sh'
|
2023-02-09 01:06:10 +00:00
|
|
|
OR file.path LIKE '%/tmp/epdf%'
|
2023-02-09 22:01:29 +00:00
|
|
|
OR file.path LIKE '/tmp/flow/%.npmzS_cacachezStmpzSgit-clone%'
|
2024-01-26 19:07:37 +00:00
|
|
|
OR file.filename IN (
|
|
|
|
'mysqld_exporter',
|
|
|
|
'goreleaser',
|
|
|
|
'golangci-lint',
|
|
|
|
'cosign',
|
|
|
|
'grype',
|
|
|
|
'chainctl',
|
|
|
|
'configure'
|
|
|
|
)
|
2023-01-18 15:57:43 +00:00
|
|
|
)
|
2023-07-13 23:43:35 +00:00
|
|
|
)
|
|
|
|
-- Melange
|
|
|
|
AND NOT file.directory LIKE '/tmp/melange-guest-%'
|
2023-09-01 21:09:47 +00:00
|
|
|
-- Nix
|
2023-02-09 01:06:10 +00:00
|
|
|
AND NOT (
|
|
|
|
file.directory LIKE '/tmp/tmp%'
|
|
|
|
AND gid = 0
|
|
|
|
AND uid > 300
|
|
|
|
AND uid < 350
|
|
|
|
) -- Babel
|
|
|
|
AND NOT (
|
|
|
|
file.directory LIKE '/tmp/babel-%/sh-script-%'
|
|
|
|
AND gid > 900
|
|
|
|
AND uid = 1000
|
|
|
|
AND size < 1024
|
|
|
|
) -- Random Testdata
|
|
|
|
AND NOT (
|
|
|
|
gid > 900
|
|
|
|
AND uid = 1000
|
|
|
|
AND (
|
|
|
|
file.directory LIKE '/tmp/%/test'
|
|
|
|
OR file.directory LIKE '/tmp/%/testdata'
|
|
|
|
)
|
2023-02-09 22:01:29 +00:00
|
|
|
) -- macOS updates
|
2023-02-09 01:06:10 +00:00
|
|
|
AND NOT file.directory LIKE '/tmp/msu-target-%' -- I don't know man. I don't work here.
|
|
|
|
AND NOT file.directory LIKE '/tmp/UpdateBrain-%/AssetData/com.apple.MobileSoftwareUpdate.UpdateBrainService.xpc/Contents/MacOS' -- terraform
|
2023-05-23 15:31:37 +00:00
|
|
|
AND NOT file.directory LIKE '/tmp/staged-updates%'
|
2023-02-09 01:06:10 +00:00
|
|
|
AND NOT (
|
|
|
|
uid > 500
|
|
|
|
AND file.path LIKE '/tmp/terraform_%/terraform'
|
|
|
|
)
|
|
|
|
AND NOT (
|
|
|
|
file.path LIKE '/tmp/%compressed'
|
|
|
|
AND size < 4000
|
|
|
|
AND uid > 500
|
|
|
|
) -- Executables too small to even hold '#!/bin/sh\nuid'
|
|
|
|
AND NOT (
|
|
|
|
file.type = 'regular'
|
|
|
|
AND size < 10
|
2023-02-24 21:30:17 +00:00
|
|
|
) -- TODO: Remove this hardcoded entry after Apr 2023
|
|
|
|
AND NOT (
|
|
|
|
file.path = '/tmp/policy-tester'
|
|
|
|
AND file.uid = 501
|
|
|
|
AND file.gid = 20
|
|
|
|
AND file.size = 90921938
|
|
|
|
)
|
2022-11-16 21:52:39 +00:00
|
|
|
)
|
2023-12-08 22:12:27 +00:00
|
|
|
AND NOT signature.authority IN (
|
|
|
|
'Developer ID Application: Adobe Inc. (JQ525L2MZD)',
|
|
|
|
'Developer ID Application: Docker Inc (9BNSXJN65R)'
|
|
|
|
)
|
2023-01-18 19:41:36 +00:00
|
|
|
AND NOT (
|
2024-01-26 19:07:37 +00:00
|
|
|
magic.data IN ('JSON data', 'ASCII text')
|
|
|
|
OR magic.data LIKE 'ELF %-bit %SB executable%'
|
|
|
|
OR magic.data LIKE 'symbolic link to %'
|
|
|
|
OR magic.data LIKE 'ELF %-bit LSB shared object%'
|
|
|
|
OR magic.data LIKE 'libtool library file,%'
|
|
|
|
OR magic.data LIKE "POSIX shell script, ASCII text executable%"
|
|
|
|
OR (
|
|
|
|
file.size < 50000
|
|
|
|
AND file.uid > 500
|
|
|
|
AND extension IN (
|
|
|
|
'adoc',
|
|
|
|
'md',
|
|
|
|
'bat',
|
|
|
|
'java',
|
|
|
|
'js',
|
|
|
|
'json',
|
|
|
|
'log',
|
|
|
|
'nib',
|
|
|
|
'pem',
|
|
|
|
'conf',
|
|
|
|
'perl',
|
|
|
|
'pl',
|
|
|
|
'rb',
|
|
|
|
'py',
|
|
|
|
'script',
|
|
|
|
'sh',
|
|
|
|
'status',
|
|
|
|
'strings',
|
|
|
|
'txt',
|
|
|
|
'yaml',
|
|
|
|
'yml'
|
|
|
|
)
|
|
|
|
AND (
|
|
|
|
magic.data IS NULL
|
|
|
|
OR magic.data NOT LIKE "%Mach-O%"
|
2023-02-09 22:01:29 +00:00
|
|
|
)
|
2023-01-18 19:41:36 +00:00
|
|
|
)
|
2023-01-20 14:24:24 +00:00
|
|
|
)
|