Yara Mounted Stealer
osquery
Look for sketchy mounted disk images, inspired by Shlayer
Description
ODK (osquery-defense-kit) is unique in that the queries are designed to be used as part of a production detection & response pipeline. The detection queries are formulated to return zero rows during normal expected behavior, so that they may be configured to generate alerts when rows are returned.
Query
-- 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/
--
-- tags: volume filesystem
-- platform: darwin
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,
file.filename, '.*\\.(.*?)$', 1) AS f_ext,
REGEX_MATCH (file.uid AS f_uid,
hash.sha256 AS f_sha256,
data AS f_data,
magic.AS probable_source,
mdfind.path AS probable_source_sha256,
mdhash.sha256 value AS probable_url,
ea.file.path, '/Volumes/(.*?)/', 1) AS vol_name,
REGEX_MATCH (AS s_auth,
signature.authority identifier AS s_id,
signature.*
yara.FROM
file
JOIN yara ON file.path = yara.path
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_devicesJOIN 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/Library/LaunchServices"
OR file.directory LIKE mounts.path || "/%/%.app/Contents/MacOS/"
OR file.directory LIKE mounts.path || "/%/%.app/Contents/Resources/"
WHERE
= 'Disk Image'
model 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 (
file.mode LIKE "%7%"
OR file.mode LIKE "%5%"
OR file.mode LIKE "%1%"
)AND file.type = "regular"
)AND magic.data LIKE "%Executable%"
AND yara.sigrule = '
rule stealer {
strings:
$brave_software = "BraveSoftware" ascii
$cookies_sqlite = "cookies.sqlite" ascii
$data_stealers = "data_stealers" ascii
$find_generic_password = "find-generic-password" ascii
$library_keychains = "/Library/Keychains" ascii
$moz_cookies = "moz_cookies" ascii
$operagx = "OperaGX" ascii
$osascript = "osascript" ascii
condition:
2 of them
}'
AND yara.count > 0
GROUP BY
file.path
tags: SStagSS