2022-10-27 14:23:15 +00:00
|
|
|
-- Programs running with a hidden current working directory (state-based)
|
2022-10-14 18:19:13 +00:00
|
|
|
--
|
2022-10-19 20:56:32 +00:00
|
|
|
-- false positives:
|
2022-10-14 18:19:13 +00:00
|
|
|
-- * Users rummaging through their configuration files
|
|
|
|
--
|
2022-10-19 20:56:32 +00:00
|
|
|
-- references:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1564/001/ (Hide Artifacts: Hidden Files and Directories)
|
|
|
|
--
|
2022-10-14 18:19:13 +00:00
|
|
|
-- tags: transient often
|
2022-10-19 21:07:52 +00:00
|
|
|
-- platform: posix
|
2022-10-12 01:53:36 +00:00
|
|
|
SELECT
|
2023-02-09 22:01:29 +00:00
|
|
|
REPLACE(p0.cwd, u.directory, '~') AS dir,
|
2022-11-03 15:51:54 +00:00
|
|
|
REGEX_MATCH (
|
2023-02-09 22:01:29 +00:00
|
|
|
REPLACE(p0.cwd, u.directory, '~'),
|
2022-11-03 15:51:54 +00:00
|
|
|
'([/~].*?/.*?)/',
|
|
|
|
1
|
|
|
|
) AS top_dir,
|
2022-10-12 01:53:36 +00:00
|
|
|
CONCAT (
|
2023-02-09 22:01:29 +00:00
|
|
|
p0.name,
|
2022-10-13 18:59:32 +00:00
|
|
|
',',
|
2022-10-05 12:36:35 +00:00
|
|
|
IIF(
|
2022-10-12 01:53:36 +00:00
|
|
|
REGEX_MATCH (
|
2023-02-09 22:01:29 +00:00
|
|
|
REPLACE(p0.cwd, u.directory, '~'),
|
2022-10-13 18:59:32 +00:00
|
|
|
'([/~].*?/.*?/.*?)/',
|
2022-10-05 12:36:35 +00:00
|
|
|
1
|
2022-10-13 18:59:32 +00:00
|
|
|
) != '',
|
2022-10-12 01:53:36 +00:00
|
|
|
REGEX_MATCH (
|
2023-02-09 22:01:29 +00:00
|
|
|
REPLACE(p0.cwd, u.directory, '~'),
|
2022-10-13 18:59:32 +00:00
|
|
|
'([/~].*?/.*?/.*?)/',
|
2022-10-05 12:36:35 +00:00
|
|
|
1
|
|
|
|
),
|
2023-02-09 22:01:29 +00:00
|
|
|
REPLACE(p0.cwd, u.directory, '~')
|
2022-10-05 12:36:35 +00:00
|
|
|
)
|
2023-02-09 22:01:29 +00:00
|
|
|
) AS exception_key,
|
|
|
|
-- Child
|
|
|
|
p0.pid AS p0_pid,
|
2023-02-17 16:57:23 +00:00
|
|
|
p0.cgroup_path AS p0_cgroup,
|
2023-02-09 22:01:29 +00:00
|
|
|
p0.path AS p0_path,
|
|
|
|
p0.name AS p0_name,
|
|
|
|
p0.cmdline AS p0_cmd,
|
|
|
|
p0.cwd AS p0_cwd,
|
|
|
|
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_f.mode AS p1_mode,
|
|
|
|
p1.euid AS p1_euid,
|
|
|
|
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
|
2022-10-12 01:53:36 +00:00
|
|
|
FROM
|
2023-02-09 22:01:29 +00:00
|
|
|
processes p0
|
|
|
|
LEFT JOIN file f ON p0.path = f.path
|
|
|
|
LEFT JOIN users u ON p0.uid = u.uid
|
|
|
|
LEFT JOIN hash p0_hash ON p0.path = p0_hash.path
|
|
|
|
LEFT JOIN processes p1 ON p0.parent = p1.pid
|
|
|
|
LEFT JOIN file p1_f ON p1.path = p1_f.path
|
|
|
|
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-12 01:53:36 +00:00
|
|
|
WHERE
|
2023-02-09 22:01:29 +00:00
|
|
|
p0.pid IN (
|
|
|
|
SELECT DISTINCT
|
|
|
|
pid
|
|
|
|
FROM
|
|
|
|
processes
|
|
|
|
WHERE
|
|
|
|
cwd LIKE '%/.%'
|
|
|
|
AND NOT name IN (
|
|
|
|
'bindfs',
|
|
|
|
'vim',
|
|
|
|
'find',
|
|
|
|
'nvim',
|
|
|
|
'code',
|
|
|
|
'updatedb',
|
|
|
|
'git',
|
|
|
|
'gitsign',
|
|
|
|
'Code Helper'
|
|
|
|
)
|
|
|
|
AND NOT cgroup_path LIKE '/system.slice/docker-%'
|
2023-03-06 20:11:11 +00:00
|
|
|
AND NOT cgroup_path LIKE '/system.slice/system.slice:docker:%'
|
2023-02-09 22:01:29 +00:00
|
|
|
)
|
2022-10-05 20:15:40 +00:00
|
|
|
AND NOT (
|
|
|
|
exception_key IN (
|
2023-01-09 15:46:30 +00:00
|
|
|
'as,~/.cache/yay',
|
2022-10-13 18:59:32 +00:00
|
|
|
'bash,~/go/src',
|
2023-01-09 15:46:30 +00:00
|
|
|
'bash,~/.local/share',
|
|
|
|
'bash,~/.Trash',
|
2023-02-10 15:21:06 +00:00
|
|
|
'cc1,/home/build/.cache',
|
2023-01-09 15:46:30 +00:00
|
|
|
'cc1plus,~/.cache/yay',
|
|
|
|
'c++,~/.cache/yay',
|
|
|
|
'cgo,~/.gimme/versions',
|
|
|
|
'dirhelper,/private/var/folders',
|
2022-10-13 18:59:32 +00:00
|
|
|
'Electron,~/.vscode/extensions',
|
|
|
|
'fish,~/.local/share',
|
2022-10-18 18:51:51 +00:00
|
|
|
'fish,~/.Trash',
|
2023-01-09 15:46:30 +00:00
|
|
|
'git,~/.local/share',
|
2022-10-13 18:59:32 +00:00
|
|
|
'java,~/.gradle/daemon',
|
|
|
|
'java,~/.local/share',
|
2023-01-09 15:46:30 +00:00
|
|
|
'make,~/.cache/yay',
|
|
|
|
'makepkg,~/.cache/yay',
|
|
|
|
'mysqld,~/.local/share',
|
2022-10-19 21:07:52 +00:00
|
|
|
'npm install,~/.npm/_cacache',
|
2023-02-10 15:21:06 +00:00
|
|
|
'opera_autoupdate,/private/var/folders',
|
2023-01-09 15:46:30 +00:00
|
|
|
'rust-analyzer-p,~/.cargo/registry',
|
2023-02-10 15:21:06 +00:00
|
|
|
'vet,/home/build/.cache',
|
2023-01-09 15:46:30 +00:00
|
|
|
'zsh,~/.Trash'
|
2022-10-05 20:15:40 +00:00
|
|
|
)
|
2022-10-27 14:23:15 +00:00
|
|
|
OR exception_key LIKE '%sh,~/.Trash/%'
|
2023-01-20 22:55:48 +00:00
|
|
|
OR exception_key LIKE '%sh,~/dev/%'
|
2023-02-24 21:30:17 +00:00
|
|
|
OR exception_key LIKE 'wineserver,/tmp/.wine-1000/server-%'
|
2022-10-12 01:53:36 +00:00
|
|
|
OR dir IN (
|
2022-10-25 15:39:51 +00:00
|
|
|
'~/.config',
|
2022-10-28 23:24:00 +00:00
|
|
|
'~/.local/bin',
|
2022-10-13 18:59:32 +00:00
|
|
|
'~/.vim',
|
2023-02-09 01:06:26 +00:00
|
|
|
'~/.provisio',
|
2022-10-27 14:23:15 +00:00
|
|
|
'~/.terraform.d',
|
2022-10-13 18:59:32 +00:00
|
|
|
'~/.cache/yay',
|
2022-11-07 15:03:43 +00:00
|
|
|
'~/.emacs.d',
|
2022-10-13 18:59:32 +00:00
|
|
|
'~/.local/share/chezmoi',
|
2022-10-31 21:40:37 +00:00
|
|
|
'~/.local/share/Steam',
|
2022-10-13 18:59:32 +00:00
|
|
|
'~/.local/share/nvim',
|
2022-10-25 15:39:51 +00:00
|
|
|
'~/.gmailctl',
|
2022-10-31 21:40:37 +00:00
|
|
|
'~/.oh-my-zsh',
|
2022-11-03 15:51:54 +00:00
|
|
|
'~/.hunter/_Base',
|
2022-10-25 15:39:51 +00:00
|
|
|
'~/.zsh'
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|
2023-01-14 13:19:26 +00:00
|
|
|
OR top_dir IN ('~/Sync')
|
2022-11-08 19:22:12 +00:00
|
|
|
OR dir LIKE '~/.%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR dir LIKE '%/.build'
|
2022-10-25 15:39:51 +00:00
|
|
|
OR dir LIKE '~/code/%'
|
2023-01-16 17:56:39 +00:00
|
|
|
OR dir LIKE '~/%/.config/nvim'
|
2023-01-20 13:40:08 +00:00
|
|
|
OR dir LIKE '~/dev/%/dots/%/.config%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR dir LIKE '~/%/.docker%'
|
2023-01-16 17:56:39 +00:00
|
|
|
OR dir LIKE '~/%/.git'
|
2022-10-25 15:39:51 +00:00
|
|
|
OR dir LIKE '~/%/.github%'
|
2022-11-08 17:59:11 +00:00
|
|
|
OR dir LIKE '~/%/github.com/%'
|
2022-11-17 12:20:19 +00:00
|
|
|
OR dir LIKE '~/%google-cloud-sdk/.install/.backup%'
|
|
|
|
OR dir LIKE '~/.gradle/%'
|
2022-10-25 15:39:51 +00:00
|
|
|
OR dir LIKE '/Library/Apple/System/Library/InstallerSandboxes/.PKInstallSandboxManager-SystemSoftware/%'
|
2022-11-17 12:20:19 +00:00
|
|
|
OR dir LIKE '~/%/.modcache/%'
|
2023-01-16 17:56:39 +00:00
|
|
|
OR dir LIKE '~/%/node_modules/.pnpm/%'
|
|
|
|
OR dir LIKE '/opt/homebrew/%/.cache/%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR dir LIKE '/private/tmp/%/.git'
|
2022-11-17 12:20:19 +00:00
|
|
|
OR dir LIKE '~/%/src/%'
|
2022-10-25 15:39:51 +00:00
|
|
|
OR dir LIKE '~/src/%'
|
|
|
|
OR dir LIKE '~/%/.terraform%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR dir LIKE '/tmp/%/.git'
|
2023-01-16 17:56:39 +00:00
|
|
|
OR dir LIKE '/tmp/%/.github/workflows'
|
2022-11-03 15:51:54 +00:00
|
|
|
OR dir LIKE '/tmp/.mount_%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR dir LIKE '~/%/.vercel%'
|
2022-10-27 14:23:15 +00:00
|
|
|
-- For sudo calls to other things
|
2022-11-03 15:51:54 +00:00
|
|
|
OR (
|
|
|
|
dir LIKE '/home/.terraform.d/%'
|
2023-02-09 22:01:29 +00:00
|
|
|
AND p0.euid = 0
|
2022-11-03 15:51:54 +00:00
|
|
|
)
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|
2023-02-09 22:01:29 +00:00
|
|
|
GROUP BY
|
|
|
|
p0.pid
|