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
|
|
|
|
p.pid,
|
2022-09-24 15:12:23 +00:00
|
|
|
p.path,
|
|
|
|
p.name,
|
|
|
|
p.cmdline,
|
|
|
|
p.cwd,
|
|
|
|
p.euid,
|
|
|
|
p.parent,
|
|
|
|
pp.path AS parent_path,
|
|
|
|
pp.name AS parent_name,
|
|
|
|
pp.cmdline AS parent_cmdline,
|
|
|
|
pp.cwd AS parent_cwd,
|
|
|
|
pp.euid AS parent_euid,
|
2022-10-05 12:36:35 +00:00
|
|
|
hash.sha256,
|
2022-10-13 18:59:32 +00:00
|
|
|
REPLACE(p.cwd, u.directory, '~') AS dir,
|
2022-11-03 15:51:54 +00:00
|
|
|
REGEX_MATCH (
|
|
|
|
REPLACE(p.cwd, u.directory, '~'),
|
|
|
|
'([/~].*?/.*?)/',
|
|
|
|
1
|
|
|
|
) AS top_dir,
|
2022-10-12 01:53:36 +00:00
|
|
|
CONCAT (
|
2022-10-05 12:36:35 +00:00
|
|
|
p.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 (
|
2022-10-13 18:59:32 +00:00
|
|
|
REPLACE(p.cwd, u.directory, '~'),
|
|
|
|
'([/~].*?/.*?/.*?)/',
|
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 (
|
2022-10-13 18:59:32 +00:00
|
|
|
REPLACE(p.cwd, u.directory, '~'),
|
|
|
|
'([/~].*?/.*?/.*?)/',
|
2022-10-05 12:36:35 +00:00
|
|
|
1
|
|
|
|
),
|
2022-10-13 18:59:32 +00:00
|
|
|
REPLACE(p.cwd, u.directory, '~')
|
2022-10-05 12:36:35 +00:00
|
|
|
)
|
|
|
|
) AS exception_key
|
2022-10-12 01:53:36 +00:00
|
|
|
FROM
|
|
|
|
processes p
|
2022-09-30 18:12:24 +00:00
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
2022-10-05 12:36:35 +00:00
|
|
|
LEFT JOIN users u ON p.uid = u.uid
|
2022-09-24 15:12:23 +00:00
|
|
|
LEFT JOIN hash ON p.path = hash.path
|
2022-10-12 01:53:36 +00:00
|
|
|
WHERE
|
2022-10-13 18:59:32 +00:00
|
|
|
dir LIKE '%/.%'
|
2022-10-05 20:15:40 +00:00
|
|
|
AND NOT (
|
|
|
|
exception_key IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'bash,~/.local/share',
|
|
|
|
'bash,~/go/src',
|
|
|
|
'Electron,~/.vscode/extensions',
|
|
|
|
'fish,~/.local/share',
|
|
|
|
'git,~/.local/share',
|
|
|
|
'makepkg,~/.cache/yay',
|
2022-10-18 18:51:51 +00:00
|
|
|
'zsh,~/.Trash',
|
2022-11-03 15:51:54 +00:00
|
|
|
'cgo,~/.gimme/versions',
|
2022-10-18 18:51:51 +00:00
|
|
|
'bash,~/.Trash',
|
|
|
|
'fish,~/.Trash',
|
2022-10-13 18:59:32 +00:00
|
|
|
'make,~/.cache/yay',
|
|
|
|
'java,~/.gradle/daemon',
|
|
|
|
'java,~/.local/share',
|
|
|
|
'rust-analyzer-p,~/.cargo/registry',
|
|
|
|
'as,~/.cache/yay',
|
|
|
|
'c++,~/.cache/yay',
|
|
|
|
'cc1plus,~/.cache/yay',
|
2022-10-19 21:07:52 +00:00
|
|
|
'npm install,~/.npm/_cacache',
|
2022-10-13 18:59:32 +00:00
|
|
|
'mysqld,~/.local/share'
|
2022-10-05 20:15:40 +00:00
|
|
|
)
|
2022-10-27 14:23:15 +00:00
|
|
|
OR exception_key LIKE '%sh,~/.Trash/%'
|
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',
|
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
|
|
|
)
|
|
|
|
OR p.name IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'bindfs',
|
|
|
|
'vim',
|
|
|
|
'nvim',
|
|
|
|
'code',
|
|
|
|
'updatedb',
|
|
|
|
'git',
|
|
|
|
'gitsign',
|
|
|
|
'Code Helper'
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|
2022-11-08 19:22:12 +00:00
|
|
|
OR dir LIKE '~/.%'
|
2022-10-25 15:39:51 +00:00
|
|
|
OR dir LIKE '~/code/%'
|
|
|
|
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/%'
|
|
|
|
OR dir LIKE '~/%/src/%'
|
2022-10-25 15:39:51 +00:00
|
|
|
OR dir LIKE '~/src/%'
|
2023-01-03 13:50:19 +00:00
|
|
|
OR dir LIKE '~/%/node_modules/.pnpm/%'
|
2022-10-25 15:39:51 +00:00
|
|
|
OR dir LIKE '~/%/.terraform%'
|
2022-11-03 15:51:54 +00:00
|
|
|
OR dir LIKE '/tmp/.mount_%'
|
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/%'
|
|
|
|
AND p.euid = 0
|
|
|
|
)
|
2022-10-12 01:53:36 +00:00
|
|
|
)
|