2022-10-05 12:41:34 +00:00
|
|
|
-- Detect unusual calls to osascript
|
2022-10-14 18:19:13 +00:00
|
|
|
--
|
2022-10-24 18:40:51 +00:00
|
|
|
-- This query does some gymnastics, as the information on the parent process may be
|
|
|
|
-- found in the 'process' (currently running) or 'process_events' table (recently started).
|
|
|
|
--
|
|
|
|
-- In the case of a long-running process that was recently terminated, parent information
|
|
|
|
-- may not be in either.
|
|
|
|
--
|
2022-10-14 18:19:13 +00:00
|
|
|
-- false positives:
|
|
|
|
-- * none observed, but they are expected
|
|
|
|
--
|
2023-03-21 18:07:06 +00:00
|
|
|
-- interval: 300
|
2022-10-14 18:19:13 +00:00
|
|
|
-- platform: darwin
|
|
|
|
-- tags: process events
|
2023-01-09 20:10:48 +00:00
|
|
|
SELECT
|
2023-01-26 16:40:54 +00:00
|
|
|
-- Child
|
|
|
|
pe.path AS p0_path,
|
|
|
|
REGEX_MATCH (pe.path, '.*/(.*)', 1) AS p0_name,
|
|
|
|
TRIM(pe.cmdline) AS p0_cmd,
|
2023-02-01 18:55:55 +00:00
|
|
|
pe.cwd AS p0_cwd,
|
2023-05-17 14:54:16 +00:00
|
|
|
pe.time AS p0_time,
|
2023-01-26 16:40:54 +00:00
|
|
|
pe.pid AS p0_pid,
|
|
|
|
pe.euid AS p0_euid,
|
|
|
|
s.authority AS p0_authority,
|
|
|
|
-- Parent
|
|
|
|
pe.parent AS p1_pid,
|
|
|
|
TRIM(COALESCE(p1.cmdline, pe1.cmdline)) AS p1_cmd,
|
|
|
|
COALESCE(p1.path, pe1.path) AS p1_path,
|
|
|
|
COALESCE(p_hash1.sha256, pe_hash1.sha256) AS p1_hash,
|
2023-02-02 22:58:19 +00:00
|
|
|
REGEX_MATCH (COALESCE(p1.path, pe1.path), '.*/(.*)', 1) AS p1_name,
|
2023-01-26 16:40:54 +00:00
|
|
|
pe_sig1.authority AS p1_authority,
|
|
|
|
-- Grandparent
|
|
|
|
COALESCE(p1.parent, pe1.parent) AS p2_pid,
|
2023-02-02 22:58:19 +00:00
|
|
|
TRIM(
|
|
|
|
COALESCE(p1_p2.cmdline, pe1_p2.cmdline, pe1_pe2.cmdline)
|
|
|
|
) AS p2_cmd,
|
2023-01-26 16:40:54 +00:00
|
|
|
COALESCE(p1_p2.path, pe1_p2.path, pe1_pe2.path) AS p2_path,
|
2023-02-02 22:58:19 +00:00
|
|
|
COALESCE(
|
|
|
|
p1_p2_hash.path,
|
|
|
|
pe1_p2_hash.path,
|
|
|
|
pe1_pe2_hash.path
|
|
|
|
) AS p2_hash,
|
|
|
|
REGEX_MATCH (
|
|
|
|
COALESCE(p1_p2.path, pe1_p2.path, pe1_pe2.path),
|
|
|
|
'.*/(.*)',
|
|
|
|
1
|
|
|
|
) AS p2_name,
|
|
|
|
COALESCE(
|
|
|
|
p1_p2_sig.authority,
|
|
|
|
pe1_p2_sig.authority,
|
|
|
|
pe1_pe2_sig.authority
|
|
|
|
) AS p2_authority
|
2023-01-09 20:10:48 +00:00
|
|
|
FROM
|
|
|
|
process_events pe
|
2023-01-06 20:31:08 +00:00
|
|
|
LEFT JOIN processes p ON pe.pid = p.pid
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN signature s ON pe.path = s.path
|
|
|
|
-- Parents (via two paths)
|
|
|
|
LEFT JOIN processes p1 ON pe.parent = p1.pid
|
|
|
|
LEFT JOIN hash p_hash1 ON p1.path = p_hash1.path
|
2023-02-02 22:58:19 +00:00
|
|
|
LEFT JOIN process_events pe1 ON pe.parent = pe1.pid
|
|
|
|
AND pe1.cmdline != ''
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN hash pe_hash1 ON pe1.path = pe_hash1.path
|
|
|
|
LEFT JOIN signature pe_sig1 ON pe1.path = pe_sig1.path
|
|
|
|
-- Grandparents (via 3 paths)
|
|
|
|
LEFT JOIN processes p1_p2 ON p1.parent = p1_p2.pid -- Current grandparent via parent processes
|
|
|
|
LEFT JOIN processes pe1_p2 ON pe1.parent = pe1_p2.pid -- Current grandparent via parent events
|
2023-02-02 22:58:19 +00:00
|
|
|
LEFT JOIN process_events pe1_pe2 ON pe1.parent = pe1_p2.pid
|
|
|
|
AND pe1_pe2.cmdline != '' -- Past grandparent via parent events
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN hash p1_p2_hash ON p1_p2.path = p1_p2_hash.path
|
|
|
|
LEFT JOIN hash pe1_p2_hash ON pe1_p2.path = pe1_p2_hash.path
|
|
|
|
LEFT JOIN hash pe1_pe2_hash ON pe1_pe2.path = pe1_pe2_hash.path
|
|
|
|
LEFT JOIN signature p1_p2_sig ON p1_p2.path = p1_p2_sig.path
|
|
|
|
LEFT JOIN signature pe1_p2_sig ON pe1_p2.path = pe1_p2_sig.path
|
|
|
|
LEFT JOIN signature pe1_pe2_sig ON pe1_pe2.path = pe1_pe2_sig.path
|
2023-01-09 20:10:48 +00:00
|
|
|
WHERE
|
|
|
|
pe.path IN ('/usr/bin/osascript', '/usr/bin/osacompile')
|
2023-03-21 18:07:06 +00:00
|
|
|
AND pe.time > (strftime('%s', 'now') -300)
|
2023-01-26 16:40:54 +00:00
|
|
|
AND pe.cmdline != ''
|
2023-01-18 14:49:56 +00:00
|
|
|
-- Only include successful executions: On macOS, process_events includes unsuccessful path lookups!
|
|
|
|
AND pe.status = 0
|
2022-11-03 15:51:54 +00:00
|
|
|
AND NOT (
|
2023-01-13 18:55:03 +00:00
|
|
|
pe.euid > 500
|
2023-01-06 20:31:08 +00:00
|
|
|
AND (
|
2023-03-21 18:07:06 +00:00
|
|
|
p0_cmd IN (
|
|
|
|
'osascript -e user locale of (get system info)',
|
|
|
|
'osascript -e tell application "Finder" to reveal application file id "com.garmin.renu.client"',
|
|
|
|
'osascript ./ExpressLoginItem.scpt',
|
|
|
|
'osascript -e get POSIX path of (path to application id "com.garmin.LifetimeMapUpdate")',
|
|
|
|
'osascript -e get POSIX path of (path to application id "com.garmin.expressfit")',
|
|
|
|
'osascript -e get POSIX path of (path to application id "com.garmin.antagent")'
|
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%"CFBundleName" of property list file (app_path & ":Contents:Info.plist")'
|
|
|
|
OR p0_cmd LIKE 'osascript -e set zoomStatus to "closed"%'
|
2023-03-14 23:00:44 +00:00
|
|
|
OR p0_cmd LIKE 'osascript -l JavaScript%com.elgato.StreamDeck%'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE 'osascript -e%tell application "System Preferences"%reveal anchor "shortcutsTab"%"com.apple.preference.keyboard"'
|
|
|
|
OR p0_cmd LIKE 'osascript -e tell application "zoom.us"%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR p0_cmd LIKE 'osascript -l JavaScript /tmp/PKInstallSandbox.%/Scripts/org.gpgtools.gpgmailloader.pkg.%/mailbundle-enabled.jxa -- GPGMailLoader.mailbundle'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE 'osascript openChrome.applescript http://127.0.0.1:%'
|
|
|
|
OR p0_cmd LIKE 'osascript openChrome.applescript http%://localhost%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR p0_cmd LIKE '/usr/bin/osascript /Applications/Amazon Photos.app/Contents/Resources/quit_and_restart_app.scpt /Applications/Amazon Photos.app com.amazon.clouddrive.mac%'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '/usr/bin/osascript /Users/%/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/%'
|
|
|
|
OR p0_cmd LIKE '/usr/bin/osascript /Users/%/osx-trash/trashfile.AppleScript %'
|
2023-02-17 16:57:23 +00:00
|
|
|
OR p1_cmd LIKE '%aws %sso%'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR p1_cmd LIKE '%gcloud% auth %login%'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p1_cmd LIKE '% /opt/homebrew/bin/jupyter%notebook'
|
2023-06-12 14:10:57 +00:00
|
|
|
OR p1_cmd LIKE '/bin/sh %/opt/homebrew/bin/git-gui%'
|
2023-02-03 02:46:53 +00:00
|
|
|
OR p1_authority = 'Developer ID Application: Docker Inc (9BNSXJN65R)'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p1_name IN ('yubikey-agent')
|
2023-01-06 22:11:24 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
p1_authority = 'Developer ID Application: VNG ONLINE CO.,LTD (CVB6BX97VM)'
|
|
|
|
AND p0_cmd = 'osascript -ss'
|
2023-01-06 22:11:24 +00:00
|
|
|
)
|
2023-08-15 22:13:06 +00:00
|
|
|
OR (
|
|
|
|
p1_authority = 'Developer ID Application: Dropbox, Inc. (G7HH3F8CAK)'
|
|
|
|
AND p0_cmd = 'osascript'
|
2023-08-15 22:29:27 +00:00
|
|
|
)
|
2023-01-06 20:31:08 +00:00
|
|
|
)
|
2022-11-03 15:51:54 +00:00
|
|
|
)
|
2023-01-16 17:56:39 +00:00
|
|
|
-- The following apply to all uids
|
2023-05-23 15:31:37 +00:00
|
|
|
AND NOT p0_cmd IN (
|
|
|
|
'osascript -e do shell script "/bin/rm -Rf /opt/vagrant /usr/local/bin/vagrant" with administrator privileges',
|
|
|
|
'osascript -e user locale of (get system info)',
|
2023-05-23 15:55:11 +00:00
|
|
|
'/usr/bin/osascript -e do shell script "/bin/rm -Rf /opt/vagrant /usr/local/bin/vagrant" with administrator privileges'
|
2023-05-23 15:31:37 +00:00
|
|
|
)
|
2023-01-09 20:10:48 +00:00
|
|
|
GROUP BY
|
2023-02-02 22:58:19 +00:00
|
|
|
pe.pid
|