2022-10-14 18:19:13 +00:00
|
|
|
-- Catch applications running from unusual directories, such as /tmp
|
|
|
|
--
|
|
|
|
-- references:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1074/
|
|
|
|
--
|
|
|
|
-- false positives:
|
|
|
|
-- * software installers and updaters
|
|
|
|
-- * developers running programs out of /tmp
|
|
|
|
--
|
|
|
|
-- interval: 60
|
|
|
|
-- platform: darwin
|
|
|
|
-- tags: filesystem events
|
2022-09-29 16:40:44 +00:00
|
|
|
SELECT
|
|
|
|
p.pid,
|
|
|
|
p.path,
|
2022-11-03 20:00:19 +00:00
|
|
|
REGEX_MATCH (p.path, '(.*)/', 1) AS dir,
|
2022-11-07 15:03:43 +00:00
|
|
|
REGEX_MATCH (p.path, '(/.*?/.*?/.*?)/', 1) AS top_dir, -- 3 levels deep
|
2022-10-13 18:59:32 +00:00
|
|
|
REPLACE(file.directory, u.directory, '~') AS homedir,
|
2022-11-16 16:02:29 +00:00
|
|
|
REGEX_MATCH (
|
|
|
|
REPLACE(file.directory, u.directory, '~'),
|
|
|
|
'(~/.*?/)',
|
|
|
|
1
|
|
|
|
) AS top_homedir, -- 1 level deep
|
2022-09-29 16:40:44 +00:00
|
|
|
p.cmdline,
|
|
|
|
p.mode,
|
|
|
|
p.cwd,
|
|
|
|
p.euid,
|
|
|
|
p.parent,
|
|
|
|
pp.path AS parent_path,
|
|
|
|
pp.name AS parent_name,
|
2022-10-07 16:46:55 +00:00
|
|
|
pp.cmdline AS parent_cmd,
|
2022-09-29 16:40:44 +00:00
|
|
|
pp.euid AS parent_euid,
|
2022-11-04 14:32:45 +00:00
|
|
|
hash.sha256 AS child_sha256,
|
|
|
|
phash.sha256 AS parent_sha256,
|
2022-11-03 20:00:19 +00:00
|
|
|
signature.identifier,
|
|
|
|
signature.authority
|
2022-09-29 16:40:44 +00:00
|
|
|
FROM
|
|
|
|
process_events p
|
|
|
|
LEFT JOIN processes ON p.pid = processes.pid
|
2022-09-29 19:42:27 +00:00
|
|
|
LEFT JOIN file ON p.path = file.path
|
2022-10-07 16:46:55 +00:00
|
|
|
LEFT JOIN users u ON p.uid = u.uid
|
2022-09-29 16:40:44 +00:00
|
|
|
LEFT JOIN processes pp ON p.parent = pp.pid
|
2022-11-04 14:32:45 +00:00
|
|
|
LEFT JOIN hash ON p.path = hash.path
|
|
|
|
LEFT JOIN hash phash ON pp.path = phash.path
|
2022-11-03 20:00:19 +00:00
|
|
|
LEFT JOIN signature ON p.path = signature.path
|
2022-09-29 16:40:44 +00:00
|
|
|
WHERE
|
2022-11-04 14:32:45 +00:00
|
|
|
p.time > (strftime('%s', 'now') -60)
|
2022-09-29 16:40:44 +00:00
|
|
|
-- The process_events table on macOS ends up with relative directories for some reason?
|
2022-11-03 20:00:19 +00:00
|
|
|
AND dir LIKE '/%'
|
2022-09-29 19:42:27 +00:00
|
|
|
AND file.size > 0
|
2022-11-03 20:00:19 +00:00
|
|
|
AND dir NOT IN (
|
2022-10-13 18:59:32 +00:00
|
|
|
'/bin',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/Library/Application Support/Logitech.localized/Logitech Options.localized/LogiMgrUpdater.app/Contents/Resources',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/Library/DropboxHelperTools/Dropbox_u501',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/Library/Filesystems/kbfuse.fs/Contents/Resources',
|
|
|
|
'/Library/Frameworks/Python.framework/Versions/3.10/bin',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Helpers.app/Contents/MacOS',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Helpers/GoogleSoftwareUpdateAgent.app/Contents/MacOS',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/Library/Printers/DYMO/Utilities',
|
|
|
|
'/Library/PrivilegedHelperTools',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/Library/TeX/texbin',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/nix/store',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/nix/var/nix/profiles/default/bin',
|
|
|
|
'/node_modules/.bin',
|
|
|
|
'/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gke-gcloud-auth-plugin',
|
|
|
|
'/opt/usr/bin',
|
|
|
|
'/opt/X11/bin',
|
|
|
|
'/opt/X11/libexec',
|
|
|
|
'/run/current-system/sw/bin',
|
|
|
|
'/sbin',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/bin',
|
|
|
|
'/usr/lib',
|
|
|
|
'/usr/lib/bluetooth',
|
|
|
|
'/usr/lib/cups/notifier',
|
|
|
|
'/usr/libexec',
|
|
|
|
'/usr/libexec/ApplicationFirewall',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/usr/libexec/AssetCache',
|
2022-11-07 15:03:43 +00:00
|
|
|
'/usr/libexec/firmwarecheckers',
|
2022-10-13 18:59:32 +00:00
|
|
|
'/usr/libexec/firmwarecheckers/eficheck',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/usr/libexec/rosetta',
|
|
|
|
'/usr/lib/fwupd',
|
|
|
|
'/usr/lib/ibus',
|
|
|
|
'/usr/lib/system',
|
2022-11-07 15:03:43 +00:00
|
|
|
'/usr/local/bin',
|
2022-11-03 20:00:19 +00:00
|
|
|
'/usr/sbin'
|
2022-09-29 16:40:44 +00:00
|
|
|
)
|
2022-11-07 15:03:43 +00:00
|
|
|
AND top_dir NOT IN (
|
|
|
|
'/Applications/Firefox.app/Contents',
|
|
|
|
'/Applications/Google Chrome.app/Contents',
|
|
|
|
'/Library/Apple/System',
|
|
|
|
'/Library/Application Support/Adobe',
|
|
|
|
'/Library/Application Support/GPGTools',
|
|
|
|
'/Library/Google/GoogleSoftwareUpdate',
|
|
|
|
'/System/Applications/Mail.app',
|
|
|
|
'/System/Applications/Music.app',
|
|
|
|
'/System/Applications/News.app',
|
|
|
|
'/System/Applications/TV.app',
|
|
|
|
'/System/Applications/Weather.app',
|
|
|
|
'/System/Library/CoreServices',
|
|
|
|
'/System/Library/Filesystems',
|
|
|
|
'/System/Library/Frameworks',
|
|
|
|
'/System/Library/PrivateFrameworks',
|
|
|
|
'/System/Library/SystemConfiguration',
|
|
|
|
'/System/Library/SystemProfiler',
|
|
|
|
'/System/Volumes/Preboot',
|
|
|
|
'/usr/local/kolide-k2'
|
|
|
|
)
|
2022-11-03 20:00:19 +00:00
|
|
|
AND homedir NOT IN (
|
|
|
|
'~/bin',
|
|
|
|
'~/code/bin',
|
2022-11-22 14:21:03 +00:00
|
|
|
'~/Downloads/google-cloud-sdk/bin',
|
2022-11-03 20:00:19 +00:00
|
|
|
'~/go/bin',
|
|
|
|
'~/.local/bin',
|
2022-11-22 14:21:03 +00:00
|
|
|
'~/.magefile',
|
2022-12-15 21:51:58 +00:00
|
|
|
'~/Downloads/protoc/bin',
|
2022-11-03 20:00:19 +00:00
|
|
|
'~/projects/go/bin'
|
2022-09-29 16:40:44 +00:00
|
|
|
)
|
2022-11-07 15:03:43 +00:00
|
|
|
AND top_homedir NOT IN (
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/Applications/',
|
2022-11-22 14:21:03 +00:00
|
|
|
'~/Applications (Parallels)/',
|
2022-11-10 17:55:09 +00:00
|
|
|
'~/bin/',
|
2022-11-18 15:27:43 +00:00
|
|
|
'~/.cargo/',
|
2022-12-15 15:20:16 +00:00
|
|
|
'~/chainguard/',
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/code/',
|
2022-12-15 15:20:16 +00:00
|
|
|
'~/Code/',
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/.config/',
|
2022-11-22 14:21:03 +00:00
|
|
|
'~/git/',
|
2022-11-28 21:06:07 +00:00
|
|
|
'~/github/',
|
2022-11-10 17:55:09 +00:00
|
|
|
'~/go/',
|
2022-11-22 14:21:03 +00:00
|
|
|
'~/google-cloud-sdk/',
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/homebrew/',
|
2022-11-22 14:21:03 +00:00
|
|
|
'~/.kuberlr/',
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/Library/',
|
2023-01-03 13:50:19 +00:00
|
|
|
'~/.gradle/',
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/.local/',
|
2022-12-15 15:20:16 +00:00
|
|
|
'~/Parallels/',
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/projects/',
|
2022-11-22 14:21:03 +00:00
|
|
|
'~/.pulumi/',
|
2022-12-15 21:51:58 +00:00
|
|
|
'~/.provisio/',
|
2022-11-16 19:49:36 +00:00
|
|
|
'~/.pyenv/',
|
2022-12-15 15:20:16 +00:00
|
|
|
'~/.rustup/',
|
2022-11-18 15:27:43 +00:00
|
|
|
'~/src/',
|
2022-11-08 01:36:37 +00:00
|
|
|
'~/.tflint.d/',
|
|
|
|
'~/.vscode/',
|
2022-12-15 15:20:16 +00:00
|
|
|
'~/.vs-kubernetes/'
|
2022-11-07 15:03:43 +00:00
|
|
|
)
|
|
|
|
-- Locally built executables
|
|
|
|
AND NOT (
|
2022-12-15 15:20:16 +00:00
|
|
|
signature.identifier = 'a.out'
|
2022-11-07 15:03:43 +00:00
|
|
|
AND homedir LIKE '~/%'
|
2022-11-08 01:36:37 +00:00
|
|
|
AND pp.name IN ('fish', 'sh', 'bash', 'zsh', 'terraform', 'code')
|
2022-11-07 15:03:43 +00:00
|
|
|
)
|
2022-12-15 15:20:16 +00:00
|
|
|
AND NOT (
|
|
|
|
signature.authority = ''
|
|
|
|
AND homedir LIKE '~/%'
|
|
|
|
AND pp.name IN ('fish', 'sh', 'bash', 'zsh')
|
|
|
|
AND p.cmdline LIKE './%'
|
|
|
|
)
|
2022-11-07 15:03:43 +00:00
|
|
|
AND dir NOT LIKE '../%' -- data issue
|
|
|
|
AND dir NOT LIKE '/Applications/%'
|
|
|
|
AND dir NOT LIKE '/private/tmp/%.app/Contents/MacOS'
|
|
|
|
AND dir NOT LIKE '/private/tmp/go-build%/exe'
|
|
|
|
AND dir NOT LIKE '/private/tmp/KSInstallAction.%/Install Google Software Update.app/Contents/Helpers'
|
|
|
|
AND dir NOT LIKE '/private/tmp/nix-build-%'
|
|
|
|
AND dir NOT LIKE '/private/tmp/PKInstallSandbox.%/Scripts/com.microsoft.OneDrive.%'
|
|
|
|
AND dir NOT LIKE '/private/var/db/com.apple.xpc.roleaccountd.staging/%.xpc/Contents/MacOS'
|
|
|
|
AND dir NOT LIKE '/private/var/folders/%/bin'
|
|
|
|
AND dir NOT LIKE '/private/var/folders/%/Contents/%'
|
|
|
|
AND dir NOT LIKE '/private/var/folders/%/d/Wrapper/%.app'
|
|
|
|
AND dir NOT LIKE '/private/var/folders/%/go-build%'
|
|
|
|
AND dir NOT LIKE '/private/var/folders/%/GoLand'
|
2022-11-22 14:21:03 +00:00
|
|
|
AND dir NOT LIKE '%/.terraform/providers/%'
|
2022-11-07 15:03:43 +00:00
|
|
|
AND dir NOT LIKE '/Volumes/com.getdropbox.dropbox-%'
|
2022-11-22 14:21:03 +00:00
|
|
|
AND homedir NOT LIKE '~/%/google-cloud-sdk/bin/%'
|
2022-11-07 15:03:43 +00:00
|
|
|
AND homedir NOT LIKE '~/Library/Caches/ms-playwright/%'
|
2022-11-22 21:30:09 +00:00
|
|
|
AND homedir NOT LIKE '~/%/node_modules/.pnpm/%'
|
2022-12-15 15:20:16 +00:00
|
|
|
AND homedir NOT LIKE '~/%repo%'
|
|
|
|
AND homedir NOT LIKE '~/%sigstore%'
|
|
|
|
AND homedir NOT LIKE '~/%/bin'
|
2022-11-03 20:00:19 +00:00
|
|
|
AND signature.authority NOT IN (
|
|
|
|
'Apple iPhone OS Application Signing',
|
|
|
|
'Apple Mac OS Application Signing',
|
|
|
|
'Developer ID Application: Adobe Inc. (JQ525L2MZD)',
|
|
|
|
'Developer ID Application: Cisco (DE8Y96K9QP)',
|
|
|
|
'Developer ID Application: CodeWeavers Inc. (9C6B7X7Z8E)',
|
|
|
|
'Developer ID Application: Corsair Memory, Inc. (Y93VXCB8Q5)',
|
|
|
|
'Developer ID Application: Docker Inc (9BNSXJN65R)',
|
|
|
|
'Developer ID Application: Dropbox, Inc. (G7HH3F8CAK)',
|
|
|
|
'Developer ID Application: Figma, Inc. (T8RA8NE3B7)',
|
|
|
|
'Developer ID Application: GEORGE NACHMAN (H7V7XYVQ7D)',
|
|
|
|
'Developer ID Application: Google LLC (EQHXZ8M8AV)',
|
|
|
|
'Developer ID Application: Hashicorp, Inc. (D38WU7D763)',
|
|
|
|
'Developer ID Application: Logitech Inc. (QED4VVPZWA)',
|
|
|
|
'Developer ID Application: Microsoft Corporation (UBF8T346G9)',
|
2022-11-04 14:22:35 +00:00
|
|
|
'Developer ID Application: Ned Deily (DJ3H93M7VJ)', -- Python
|
2022-11-03 20:00:19 +00:00
|
|
|
'Developer ID Application: Node.js Foundation (HX7739G8FX)',
|
|
|
|
'Developer ID Application: Objective Development Software GmbH (MLZF7K7B5R)',
|
|
|
|
'Developer ID Application: Objective-See, LLC (VBG97UB4TA)',
|
|
|
|
'Developer ID Application: Opal Camera Inc (97Z3HJWCRT)',
|
|
|
|
'Developer ID Application: Oracle America, Inc. (VB5E2TV963)',
|
|
|
|
'Developer ID Application: TablePlus Inc (3X57WP8E8V)',
|
|
|
|
'Developer ID Application: Tenable, Inc. (4B8J598M7U)',
|
|
|
|
'Developer ID Application: Valve Corporation (MXGJJ98X76)',
|
|
|
|
'Developer ID Application: Wireshark Foundation, Inc. (7Z6EMTD2C6)',
|
|
|
|
'Software Signing'
|
2022-09-29 16:40:44 +00:00
|
|
|
)
|
|
|
|
-- Don't spam alerts with repeated invocations of the same command-line
|
|
|
|
GROUP BY
|
|
|
|
p.cmdline,
|
|
|
|
p.cwd,
|
2022-11-03 20:00:19 +00:00
|
|
|
p.euid;
|