2022-10-14 18:19:13 +00:00
|
|
|
-- Pick out exotic processes based on their command-line (events-based)
|
|
|
|
--
|
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:
|
|
|
|
-- * possible, but none known
|
|
|
|
--
|
|
|
|
-- tags: transient process events
|
|
|
|
-- platform: darwin
|
2023-02-01 21:17:36 +00:00
|
|
|
-- interval: 180
|
2023-01-27 15:38:01 +00:00
|
|
|
SELECT -- Child
|
2023-01-26 16:40:54 +00:00
|
|
|
pe.path AS p0_path,
|
2023-05-16 21:18:39 +00:00
|
|
|
pe.time AS p0_time,
|
2023-01-26 16:40:54 +00:00
|
|
|
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-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-01-27 15:38:01 +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-01-27 15:38:01 +00:00
|
|
|
COALESCE(
|
|
|
|
p1_p2_hash.path,
|
|
|
|
pe1_p2_hash.path,
|
|
|
|
pe1_pe2_hash.path
|
|
|
|
) AS p2_hash,
|
2023-02-02 22:58:19 +00:00
|
|
|
REGEX_MATCH (
|
2023-01-27 15:38:01 +00:00
|
|
|
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-26 16:40:54 +00:00
|
|
|
-- Exception key
|
2023-02-02 22:58:19 +00:00
|
|
|
REGEX_MATCH (pe.path, '.*/(.*)', 1) || ',' || MIN(pe.euid, 500) || ',' || REGEX_MATCH (COALESCE(p1.path, pe1.path), '.*/(.*)', 1) || ',' || REGEX_MATCH (
|
2023-01-27 15:38:01 +00:00
|
|
|
COALESCE(p1_p2.path, pe1_p2.path, pe1_pe2.path),
|
|
|
|
'.*/(.*)',
|
|
|
|
1
|
|
|
|
) AS exception_key
|
2023-02-02 22:58:19 +00:00
|
|
|
FROM
|
|
|
|
process_events pe,
|
2023-01-27 15:38:01 +00:00
|
|
|
uptime
|
2023-01-18 14:49:56 +00:00
|
|
|
LEFT JOIN processes p ON pe.pid = p.pid
|
2023-01-27 15:38:01 +00:00
|
|
|
LEFT JOIN signature s ON pe.path = s.path -- Parents (via two paths)
|
2023-01-26 16:40:54 +00:00
|
|
|
LEFT JOIN processes p1 ON pe.parent = p1.pid
|
|
|
|
LEFT JOIN hash p_hash1 ON p1.path = p_hash1.path
|
2023-01-27 15:38:01 +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
|
2023-01-27 15:38:01 +00:00
|
|
|
LEFT JOIN signature pe_sig1 ON pe1.path = pe_sig1.path -- Grandparents (via 3 paths)
|
2023-01-26 16:40:54 +00:00
|
|
|
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-01-27 15:38:01 +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-02-02 22:58:19 +00:00
|
|
|
WHERE
|
|
|
|
pe.time > (strftime('%s', 'now') -180)
|
2023-01-18 14:49:56 +00:00
|
|
|
AND pe.status = 0
|
2023-01-26 16:40:54 +00:00
|
|
|
AND pe.cmdline != ''
|
|
|
|
AND pe.cmdline IS NOT NULL
|
2022-09-24 15:12:23 +00:00
|
|
|
AND (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_name IN (
|
2022-09-24 15:12:23 +00:00
|
|
|
'bitspin',
|
|
|
|
'bpftool',
|
|
|
|
'csrutil',
|
|
|
|
'heyoka',
|
|
|
|
'nstx',
|
|
|
|
'dnscat2',
|
|
|
|
'tuns',
|
|
|
|
'iodine',
|
|
|
|
'rshell',
|
|
|
|
'rsh',
|
|
|
|
'incbit',
|
|
|
|
'kmod',
|
|
|
|
'lushput',
|
|
|
|
'mkfifo',
|
|
|
|
'msfvenom',
|
|
|
|
'nc',
|
|
|
|
'socat'
|
2022-10-21 21:42:44 +00:00
|
|
|
) -- Chrome Stealer
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%set visible of front window to false%'
|
|
|
|
OR p0_cmd LIKE '%chrome%-load-extension%' -- Known attack scripts
|
|
|
|
OR p0_name LIKE '%pwn%'
|
|
|
|
OR p0_name LIKE '%attack%' -- Unusual behaviors
|
2023-03-17 10:32:54 +00:00
|
|
|
OR p0_cmd LIKE '%chattr -i%'
|
2023-03-17 19:38:22 +00:00
|
|
|
OR p0_cmd LIKE '%dd if=/dev/%'
|
2023-03-17 10:32:54 +00:00
|
|
|
OR p0_cmd LIKE '%cat /dev/null >%'
|
|
|
|
OR p0_cmd LIKE '%truncate -s0 %'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%touch%acmr%'
|
|
|
|
OR p0_cmd LIKE '%touch -r%'
|
|
|
|
OR p0_cmd LIKE '%ld.so.preload%'
|
2024-02-01 18:04:07 +00:00
|
|
|
OR p0_cmd LIKE 'killall%NotificationCenter'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%urllib.urlopen%'
|
|
|
|
OR p0_cmd LIKE '%nohup%tmp%'
|
|
|
|
OR p0_cmd LIKE '%killall Terminal%'
|
2022-11-18 15:27:43 +00:00
|
|
|
OR (
|
2023-01-18 14:49:56 +00:00
|
|
|
pe.euid = 0
|
2022-11-18 15:27:43 +00:00
|
|
|
AND (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd LIKE '%pkill -f%'
|
|
|
|
OR p0_cmd LIKE '%xargs kill -9%'
|
2022-11-18 15:27:43 +00:00
|
|
|
)
|
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%rm -f /var/tmp%'
|
|
|
|
OR p0_cmd LIKE '%rm -f /tmp%'
|
|
|
|
OR p0_cmd LIKE '%nohup /bin/bash%'
|
2023-01-09 15:46:30 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
INSTR(p0_cmd, 'history') > 0
|
|
|
|
AND p0_cmd LIKE '%history'
|
2023-03-14 23:00:44 +00:00
|
|
|
AND p0_cmd NOT LIKE '% history'
|
2023-01-09 15:46:30 +00:00
|
|
|
)
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%echo%|%base64 --decode %|%'
|
2023-09-14 20:39:35 +00:00
|
|
|
OR p0_cmd LIKE '%echo%|%base64 -d %|%'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%launchctl bootout%'
|
|
|
|
OR p0_cmd LIKE '%chflags uchg%'
|
2022-10-21 21:42:44 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd LIKE '%UserKnownHostsFile=/dev/null%'
|
|
|
|
AND NOT p1_name = 'limactl'
|
2024-02-16 22:14:11 +00:00
|
|
|
AND NOT p1_cmd LIKE '%gcloud.py%'
|
2022-10-21 21:42:44 +00:00
|
|
|
) -- Random keywords
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%ransom%' -- Reverse shells
|
|
|
|
OR p0_cmd LIKE '%fsockopen%'
|
|
|
|
OR p0_cmd LIKE '%openssl%quiet%'
|
|
|
|
OR p0_cmd LIKE '%pty.spawn%'
|
2022-10-21 21:42:44 +00:00
|
|
|
OR (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd LIKE '%sh -i'
|
|
|
|
AND NOT p1_name IN ('sh', 'java')
|
|
|
|
AND NOT p1_cmd LIKE "%pipenv shell"
|
2022-10-21 21:42:44 +00:00
|
|
|
)
|
2023-04-17 20:20:35 +00:00
|
|
|
OR p0_cmd LIKE 'socat %'
|
2023-01-26 16:40:54 +00:00
|
|
|
OR p0_cmd LIKE '%SOCK_STREAM%'
|
|
|
|
OR INSTR(p0_cmd, 'Socket.') > 0
|
2022-09-24 15:12:23 +00:00
|
|
|
) -- Things that could reasonably happen at boot.
|
|
|
|
AND NOT (
|
2023-01-18 14:49:56 +00:00
|
|
|
pe.path = '/usr/bin/mkfifo'
|
2023-03-03 12:24:42 +00:00
|
|
|
AND (
|
|
|
|
p0_cmd LIKE '%/org.gpgtools.log.%/fifo'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR p0_cmd LIKE '%/var/%/gitstatus.POWERLEVEL9K.%'
|
|
|
|
OR p0_cmd LIKE '%/var/%/p10k.worker.%'
|
2023-03-03 12:24:42 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
|
|
|
AND NOT (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd LIKE '%csrutil status'
|
|
|
|
AND p1_name IN ('Dropbox')
|
2022-11-10 16:04:48 +00:00
|
|
|
)
|
2022-09-24 15:12:23 +00:00
|
|
|
AND NOT (
|
2023-01-26 16:40:54 +00:00
|
|
|
p0_cmd IN (
|
2023-01-30 19:58:47 +00:00
|
|
|
'/bin/launchctl bootout gui/501 /Library/LaunchAgents/com.logi.optionsplus.plist',
|
|
|
|
'/bin/launchctl bootout system/com.docker.socket',
|
2022-12-19 23:06:06 +00:00
|
|
|
'/bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress',
|
|
|
|
'git history',
|
2023-03-30 22:44:01 +00:00
|
|
|
'dd if=/dev/urandom bs=15 count=1 status=none',
|
|
|
|
'launchctl bootout gui/501/com.grammarly.ProjectLlama.UninstallAgent',
|
2023-03-14 23:00:44 +00:00
|
|
|
'helm history',
|
2023-03-21 18:07:06 +00:00
|
|
|
'/Library/Apple/System/Library/StagedFrameworks/Safari/SafariShared.framework/XPCServices/com.apple.Safari.History.xpc/Contents/MacOS/com.apple.Safari.History',
|
2023-03-14 23:00:44 +00:00
|
|
|
'nc -h',
|
2023-10-02 15:35:11 +00:00
|
|
|
'nc',
|
2023-03-14 23:00:44 +00:00
|
|
|
'nc -uv 8.8.8.8 53',
|
2023-05-05 16:44:46 +00:00
|
|
|
'nc localhost 8080 -vz',
|
2023-03-21 18:07:06 +00:00
|
|
|
'nix profile history',
|
2023-03-28 20:25:26 +00:00
|
|
|
'dd if=/dev/stdin conv=unblock cbs=79',
|
2023-03-21 18:07:06 +00:00
|
|
|
'rm -f /tmp/mysql.sock',
|
|
|
|
'sh -c launchctl bootout system "/Library/LaunchDaemons/com.ecamm.EcammAudioXPCHelper.plist"',
|
2022-11-18 15:27:43 +00:00
|
|
|
'/usr/bin/csrutil report',
|
|
|
|
'/usr/bin/csrutil status',
|
2023-01-27 13:46:48 +00:00
|
|
|
'/usr/bin/pkill -F /private/var/run/lima/shared_socket_vmnet.pid',
|
2023-03-21 18:07:06 +00:00
|
|
|
'/usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress',
|
2023-01-27 13:46:48 +00:00
|
|
|
'/usr/bin/xattr -d com.apple.writer_bundle_identifier /Applications/Safari.app',
|
2022-12-19 23:06:06 +00:00
|
|
|
'xpcproxy com.apple.Safari.History'
|
2023-01-27 15:38:01 +00:00
|
|
|
) -- The source of these commands is still a mystery to me.
|
2023-01-18 14:49:56 +00:00
|
|
|
OR pe.parent = -1
|
2022-09-24 15:12:23 +00:00
|
|
|
)
|
2023-02-20 23:04:17 +00:00
|
|
|
AND NOT p0_cmd LIKE 'launchctl bootout gui/501 /Users/%/Library/LaunchAgents/com.elgato.StreamDeck.plist'
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE '-history%'
|
2023-02-14 13:33:05 +00:00
|
|
|
AND NOT p0_cmd LIKE 'dirname %history'
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE '/bin/rm -f /tmp/periodic.%'
|
2023-03-14 23:00:44 +00:00
|
|
|
AND NOT p0_cmd LIKE '/bin/rm -f /tmp/nix-shell.%'
|
2023-02-14 13:33:05 +00:00
|
|
|
AND NOT p0_cmd LIKE 'touch -r . /private/tmp/nix-build%'
|
|
|
|
AND NOT p0_cmd LIKE '%GNU Libtool%touch -r%'
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE 'rm -f /tmp/locate%/_updatedb%'
|
|
|
|
AND NOT p0_cmd LIKE 'rm -f /tmp/locate%/mklocate%/_mklocatedb%'
|
|
|
|
AND NOT p0_cmd LIKE 'rm -f /tmp/insttmp_%'
|
2023-07-19 19:22:43 +00:00
|
|
|
AND NOT p0_cmd LIKE '%nc localhost%'
|
2024-01-22 15:36:01 +00:00
|
|
|
AND NOT p0_cmd LIKE '%nc -vz localhost%'
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE '/bin/cp %history%sessions/%'
|
2023-09-20 13:30:46 +00:00
|
|
|
AND NOT p0_cmd LIKE '%ssh %/lima/%'
|
2023-01-26 16:40:54 +00:00
|
|
|
AND NOT p0_cmd LIKE 'touch -r /tmp/KSInstallAction.%'
|
|
|
|
AND NOT p0_cmd LIKE '%find /Applications/LogiTuneInstaller.app -type d -exec chmod 777 {}%'
|
|
|
|
AND NOT p0_cmd LIKE '/bin/rm -f /tmp/com.adobe.%.updater/%'
|
2023-10-02 15:35:11 +00:00
|
|
|
AND NOT p0_name IN ('cc1', 'compile', 'yara')
|
2023-07-19 19:22:43 +00:00
|
|
|
AND NOT exception_key IN (
|
|
|
|
'dd,500,zsh,login',
|
2024-01-22 15:36:01 +00:00
|
|
|
'bash,500,idea,launchd',
|
2023-10-02 15:35:11 +00:00
|
|
|
'yara,500,bash,fish',
|
2023-09-20 13:30:46 +00:00
|
|
|
'ssh,500,limactl.ventura,launchd',
|
|
|
|
'git,500,zsh,login',
|
2023-10-02 20:11:44 +00:00
|
|
|
'bat,500,zsh,login',
|
2023-07-19 19:22:43 +00:00
|
|
|
'git,500,zsh,goland',
|
2024-01-26 19:07:37 +00:00
|
|
|
'jq,500,zsh,login',
|
2023-08-15 22:13:06 +00:00
|
|
|
'sh,0,Ecamm Live,launchd',
|
2023-07-19 19:22:43 +00:00
|
|
|
'cat,500,zsh,login'
|
|
|
|
)
|