2023-02-08 15:14:32 +00:00
|
|
|
-- Look for sketchy mounted disk images, inspired by Shlayer
|
|
|
|
--
|
|
|
|
-- references:
|
|
|
|
-- * https://attack.mitre.org/techniques/T1566/001/ (Phishing: Spearphishing Attachment)
|
|
|
|
-- * https://attack.mitre.org/techniques/T1204/002/ (User Execution: Malicious File)
|
|
|
|
-- * https://www.crowdstrike.com/blog/how-crowdstrike-uncovered-a-new-macos-browser-hijacking-campaign/
|
|
|
|
--
|
2023-02-08 19:37:09 +00:00
|
|
|
-- tags: transient volume filesystem
|
2023-02-08 15:14:32 +00:00
|
|
|
-- platform: darwin
|
2023-02-09 22:01:29 +00:00
|
|
|
SELECT
|
|
|
|
RTRIM(file.path, '/') AS f,
|
|
|
|
file.bsd_flags AS f_flags,
|
|
|
|
file.gid AS f_gid,
|
|
|
|
file.mode AS f_mode,
|
|
|
|
file.size AS f_size,
|
|
|
|
file.type AS f_type,
|
|
|
|
REGEX_MATCH (file.filename, '.*\.(.*?)$', 1) AS f_ext,
|
|
|
|
file.uid AS f_uid,
|
|
|
|
hash.sha256 AS f_sha256,
|
|
|
|
magic.data AS f_data,
|
|
|
|
mdfind.path AS probable_source,
|
|
|
|
mdhash.sha256 AS probable_source_sha256,
|
|
|
|
ea.value AS probable_url,
|
|
|
|
REGEX_MATCH (file.path, '/Volumes/(.*?)/', 1) AS vol_name,
|
|
|
|
signature.authority AS s_auth,
|
|
|
|
signature.identifier AS s_id
|
|
|
|
FROM
|
|
|
|
file
|
|
|
|
LEFT JOIN mdfind ON mdfind.query = "kMDItemFSName == '*" || REGEX_MATCH (file.path, '/Volumes/(\w+)', 1) || "*.dmg'"
|
|
|
|
LEFT JOIN extended_attributes ea ON mdfind.path = ea.path
|
|
|
|
AND ea.key = 'where_from'
|
|
|
|
LEFT JOIN hash on file.path = hash.path
|
|
|
|
LEFT JOIN hash mdhash ON mdfind.path = mdhash.path
|
|
|
|
LEFT JOIN magic ON file.path = magic.path
|
|
|
|
LEFT JOIN signature ON file.path = signature.path
|
|
|
|
WHERE
|
|
|
|
file.path IN (
|
|
|
|
SELECT
|
|
|
|
file.path
|
|
|
|
FROM
|
|
|
|
block_devices
|
|
|
|
JOIN mounts ON mounts.device = block_devices.name
|
|
|
|
JOIN file ON file.directory = mounts.path
|
|
|
|
OR file.directory LIKE mounts.path || "/%.app/Contents/MacOS/"
|
|
|
|
OR file.directory LIKE mounts.path || "/%.app/Contents/Resources/"
|
|
|
|
OR file.directory LIKE mounts.path || "/%/%.app/Contents/MacOS/"
|
|
|
|
OR file.directory LIKE mounts.path || "/%/%.app/Contents/Resources/"
|
|
|
|
WHERE
|
|
|
|
model = 'Disk Image'
|
|
|
|
AND parent != ""
|
|
|
|
AND mounts.path LIKE "/Volumes/%"
|
|
|
|
-- osquery will traverse symlinks, this prevents following symlinks to /Applications (poorly)
|
|
|
|
AND file.path NOT LIKE "/Volumes/%/Applications/%"
|
|
|
|
)
|
|
|
|
AND (
|
|
|
|
-- Rule 0. App binaries that are hidden, like WnBJLaF/1302.app/Contents/MacOS/1302 (1302.app)
|
|
|
|
(
|
|
|
|
file.directory LIKE '/Volumes/%/Contents/MacOS'
|
|
|
|
AND file.bsd_flags = "HIDDEN"
|
|
|
|
) -- Rule 1. App binaries that are a thin shell script wrapper for another resource (Player_009.app, 1302.app)
|
|
|
|
OR (
|
|
|
|
file.directory LIKE '/Volumes/%/Contents/MacOS'
|
|
|
|
AND file.mode LIKE "%7%"
|
|
|
|
AND file.type != 'directory'
|
|
|
|
AND magic.data LIKE '%script%'
|
2023-05-02 19:25:36 +00:00
|
|
|
AND signature.identifier != 'net.snowflake.snowsql'
|
2023-06-01 15:52:20 +00:00
|
|
|
AND signature.authority NOT IN (
|
2023-06-07 13:55:17 +00:00
|
|
|
'Developer ID Application: Allen Bai (97DN42T837)',
|
|
|
|
'Developer ID Application: Galvanix (5BRAQAFB8B)'
|
2023-06-01 15:52:20 +00:00
|
|
|
)
|
2023-02-09 22:01:29 +00:00
|
|
|
) -- Rule 2. App binaries that have mixed-caps names such as LYwjtu0sc3XqkNVbQe_gM4YiRpmgUpRIew or yWnBJLaF (AdobeFlashPlayer_567.app)
|
|
|
|
OR (
|
|
|
|
file.mode LIKE "%7%"
|
|
|
|
AND file.type != 'directory'
|
2023-04-17 20:20:35 +00:00
|
|
|
AND REGEX_MATCH (file.filename, '([a-z]+[A-Z][A-Z]+[a-z]+)', 1) != ""
|
2023-02-09 22:01:29 +00:00
|
|
|
AND magic.data LIKE "%executable%"
|
|
|
|
-- Some people do weird things!
|
|
|
|
AND signature.authority NOT IN (
|
|
|
|
'Software Signing',
|
|
|
|
'Developer ID Application: Atlassian Pty Ltd (UPXU4CQZ5P)',
|
2023-03-16 21:29:11 +00:00
|
|
|
'Developer ID Application: MacroMates Ltd. (45TL96F76G)',
|
|
|
|
'Developer ID Application: Logitech Inc. (QED4VVPZWA)'
|
2023-02-09 22:01:29 +00:00
|
|
|
)
|
|
|
|
) -- Rule 3. App binaries with a numerical name, such as 2829030009 (Player_009.app)
|
|
|
|
OR (
|
|
|
|
file.mode LIKE "%7%"
|
|
|
|
AND file.type != 'directory'
|
|
|
|
AND REGEX_MATCH (file.filename, '^(\d)+$', 1) != ""
|
|
|
|
) -- 4. App resources that are Mach-O binaries, such as 2829030009, or enc (Player_009.app, AdobeFlashPlayer_567.app)
|
|
|
|
OR (
|
|
|
|
file.directory LIKE '/Volumes/%/Resources'
|
|
|
|
AND magic.data LIKE '%executable%'
|
|
|
|
AND f_ext NOT IN ('py', 'sh', 'metallib')
|
|
|
|
) -- 5. Volumes with a name containing suspicious names: Player, Flash, Update
|
|
|
|
OR (
|
|
|
|
(
|
|
|
|
vol_name LIKE "Install%"
|
|
|
|
OR vol_name LIKE "%Player"
|
|
|
|
OR vol_name LIKE "%Flash%"
|
|
|
|
OR vol_name LIKE "%Update"
|
|
|
|
)
|
|
|
|
AND file.directory LIKE "/Volumes/%/Contents/MacOS"
|
2023-06-14 14:58:41 +00:00
|
|
|
AND signature.authority NOT IN (
|
|
|
|
"Developer ID Application: Logitech Inc. (QED4VVPZWA)",
|
2023-06-30 20:38:31 +00:00
|
|
|
"Developer ID Application: Bookry Ltd (4259LE8SU5)",
|
2023-06-14 14:58:41 +00:00
|
|
|
"Developer ID Application: VideoLAN (75GAHG3SZQ)"
|
|
|
|
)
|
2023-02-09 22:01:29 +00:00
|
|
|
) -- 6. Volumes containing a hidden top-level folder or binary, such as yWnBJLaF (1302.app)
|
|
|
|
OR (
|
|
|
|
file.bsd_flags = "HIDDEN"
|
|
|
|
AND (
|
|
|
|
file.mode LIKE "%7%"
|
|
|
|
OR file.mode LIKE "%5%"
|
|
|
|
OR file.mode LIKE "%1%"
|
|
|
|
)
|
2023-06-01 15:52:20 +00:00
|
|
|
AND file.filename NOT IN (
|
|
|
|
'.Trashes',
|
|
|
|
'.background',
|
|
|
|
'.VolumeIcon.icns',
|
|
|
|
'.TemporaryItems'
|
|
|
|
)
|
2023-05-05 16:44:46 +00:00
|
|
|
-- Brother Printer Utilities
|
|
|
|
AND f != '/Volumes/brotherwdswML_nonPanel/MacResources'
|
2023-02-09 22:01:29 +00:00
|
|
|
AND file.filename NOT LIKE '%.previous'
|
2023-02-14 13:33:05 +00:00
|
|
|
AND file.filename NOT LIKE '%.interrupted'
|
2023-06-07 12:58:02 +00:00
|
|
|
AND signature.authority != 'Developer ID Application: Google LLC (EQHXZ8M8AV)'
|
2023-02-17 16:57:23 +00:00
|
|
|
AND file.filename NOT LIKE '%.backup'
|
2023-02-09 22:01:29 +00:00
|
|
|
) -- 7. Volumes containing a top-level symlink to something other than /Applications, such as yWnBJLaF (1302.app)
|
|
|
|
OR (
|
|
|
|
file.symlink = 1
|
|
|
|
AND magic.data != 'symbolic link to /Applications'
|
2023-03-16 21:29:11 +00:00
|
|
|
AND magic.data != 'symbolic link to /Applications/'
|
2023-04-21 00:45:35 +00:00
|
|
|
AND magic.data != 'symbolic link to .'
|
2023-06-07 13:55:17 +00:00
|
|
|
-- emacs
|
|
|
|
AND magic.data != 'symbolic link to bin-x86%'
|
2023-02-09 22:01:29 +00:00
|
|
|
AND magic.data NOT LIKE 'symbolic link to /Users/%/My Drive'
|
2023-03-03 12:24:42 +00:00
|
|
|
AND magic.data NOT LIKE 'symbolic link to /Library/Application Support/Apple/Safari/SafariForWebKitDevelopment'
|
2023-02-08 15:14:32 +00:00
|
|
|
)
|
2023-02-09 22:01:29 +00:00
|
|
|
)
|
|
|
|
GROUP BY
|
|
|
|
file.path;
|