osquery-defense-kit/detection/evasion/unexpected-hidden-system-fo...

136 lines
3.6 KiB
MySQL
Raw Normal View History

-- Find unexpected hidden directories in operating-system foldersbin/
2022-10-14 18:19:13 +00:00
--
2022-10-18 14:08:34 +00:00
-- references:
-- * https://themittenmac.com/what-does-apt-activity-look-like-on-macos/
--
2022-10-14 18:19:13 +00:00
-- false positives:
-- * unusual installers
--
2022-10-18 14:08:34 +00:00
-- platform: posix
2022-10-14 18:19:13 +00:00
-- tags: persistent filesystem state
SELECT
file.path,
2022-10-18 18:26:47 +00:00
file.directory,
uid,
gid,
mode,
mtime,
ctime,
type,
size,
hash.sha256,
magic.data
FROM
file
LEFT JOIN hash ON file.path = hash.path
LEFT JOIN magic ON file.path = magic.path
WHERE
(
file.path LIKE '/lib/.%'
OR file.path LIKE '/.%'
OR file.path LIKE '/bin/%/.%'
2022-10-18 18:26:47 +00:00
OR file.path LIKE '/dev/.%'
OR file.path LIKE '/etc/.%'
OR file.path LIKE '/etc/%/.%'
OR file.path LIKE '/lib/%/.%'
OR file.path LIKE '/libexec/.%'
OR file.path LIKE '/Library/.%'
OR file.path LIKE '/sbin/.%'
OR file.path LIKE '/sbin/%/.%'
OR file.path LIKE '/tmp/.%'
OR file.path LIKE '/usr/bin/.%'
OR file.path LIKE '/usr/lib/.%'
OR file.path LIKE '/usr/lib/%/.%'
OR file.path LIKE '/usr/libexec/.%'
OR file.path LIKE '/usr/local/bin/.%'
OR file.path LIKE '/usr/local/lib/.%'
OR file.path LIKE '/usr/local/lib/.%'
OR file.path LIKE '/usr/local/libexec/.%'
OR file.path LIKE '/usr/local/sbin/.%'
OR file.path LIKE '/usr/sbin/.%'
OR file.path LIKE '/var/.%'
OR file.path LIKE '/var/lib/.%'
OR file.path LIKE '/var/tmp/.%'
2022-10-18 18:26:47 +00:00
) -- Avoid mentioning extremely temporary files
AND strftime('%s', 'now') - file.ctime > 20
AND file.path NOT IN (
'/.autorelabel',
'/dev/.mdadm/',
2022-10-18 18:26:47 +00:00
'/etc/.clean',
'/etc/.java/',
'/etc/selinux/.config_backup',
'/etc/skel/.mozilla/',
2022-10-18 18:26:47 +00:00
'/.file',
'/tmp/../',
'/tmp/./',
2022-11-03 18:24:40 +00:00
'/tmp/.DS_Store',
'/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress',
2022-10-18 18:26:47 +00:00
'/tmp/._contentbarrier_installed',
'/tmp/.dotnet/',
2022-10-18 18:26:47 +00:00
'/tmp/.dracula-tmux-data',
'/tmp/.dracula-tmux-weather.lock',
'/tmp/.font-unix/',
'/tmp/.ICE-unix/',
'/tmp/.Test-unix/',
2022-10-18 18:26:47 +00:00
'/tmp/.vbox-t-ipc/',
'/tmp/.X0-lock',
'/tmp/.X1-lock',
'/tmp/.X2-lock',
'/tmp/.X11-unix/',
2022-10-18 18:26:47 +00:00
'/tmp/.X1-lock',
'/tmp/.XIM-unix/',
'/var/.ntw_cache',
'/var/.Parallels_swap/',
2022-10-18 18:26:47 +00:00
'/var/.pwd_cache',
'/etc/.resolv.conf.systemd-resolved.bak',
2022-10-18 18:26:47 +00:00
'/.vol/',
'/.VolumeIcon.icns'
)
2022-10-18 18:26:47 +00:00
AND file.directory NOT IN ('/etc/skel', '/etc/skel/.config')
AND file.path NOT LIKE '/%bin/bootstrapping/.default_components'
AND file.path NOT LIKE '/tmp/.#%'
2023-01-13 20:24:18 +00:00
AND file.path NOT LIKE '/tmp/.wine-%'
2022-10-18 18:26:47 +00:00
AND file.path NOT LIKE '/tmp/.%.gcode'
AND file.path NOT LIKE '/tmp/.vbox-%-ipc/'
AND file.path NOT LIKE '/tmp/.io.nwjs.%'
AND file.path NOT LIKE '/tmp/.com.google.Chrome.%'
AND file.path NOT LIKE '/tmp/.org.chromium.Chromium%'
AND file.path NOT LIKE '/tmp/.X1%-lock'
AND file.path NOT LIKE '/usr/local/%/.keepme'
AND file.path NOT LIKE '%/../'
AND file.path NOT LIKE '%/./'
AND file.path NOT LIKE '%/.build-id/'
AND file.path NOT LIKE '%/.dwz/'
AND file.path NOT LIKE '%/.updated'
AND file.path NOT LIKE '%/google-cloud-sdk/.install/'
AND NOT (
type = 'regular'
AND (
filename LIKE '%.swp'
OR size < 2
2022-08-31 18:34:42 +00:00
)
)
2022-10-18 18:26:47 +00:00
AND NOT (
type = 'regular'
AND filename = '.placeholder'
) -- A curious addition seen on NixOS and Fedora machines
2022-09-29 19:42:27 +00:00
AND NOT (
file.path = '/.cache/'
2022-09-29 19:42:27 +00:00
AND file.uid = 0
AND file.gid = 0
AND file.mode IN ('0755', '0700')
AND file.size < 4
2022-09-29 19:42:27 +00:00
)
AND NOT (
file.path = '/.config/'
2022-09-29 19:42:27 +00:00
AND file.uid = 0
AND file.gid = 0
AND file.mode IN ('0755', '0700')
2022-09-29 19:42:27 +00:00
AND file.size = 4
)
AND NOT (
file.path LIKE '/tmp/.java_pid%'
AND file.type = 'socket'
AND file.size = 0
)