Techniques
Sample rules
Suspicious Child Process of Homebrew’s Bundled Ruby Interpreter
- source: elastic
- technicques:
- T1059
- T1195
Description
Detects a suspicious child process spawned by Homebrew’s bundled Ruby interpreter (“vendor/portable-ruby”) during a “brew install”, “reinstall” or “upgrade”. Cask “preflight” and “postflight” blocks run arbitrary Ruby at install time, including shelling out through “system_command”, so a malicious cask from a third-party tap, or a compromised or typosquatted one, can use them to execute code with the installing user’s privileges. The rule looks for what such a hook would plausibly run: network and scripting tools, “osascript” prompts or shell-outs, “launchctl” persistence, keychain and directory-service credential access, shells running download, decode or persistence commands, binaries executed from temporary or shared directories, and untrusted or unsigned binaries.
Detection logic
process where event.action == "exec" and host.os.type == "macos" and
process.parent.executable like~ "*/Homebrew/vendor/portable-ruby/*" and
process.parent.args in ("install", "reinstall", "upgrade") and
(
process.name in ("nc", "ncat", "perl", "node", "sqlite3") or
process.name like~ "python*" or
(process.name == "osascript" and
process.command_line like~ ("*do shell script*", "*display dialog*", "*hidden answer*")) or
(process.name == "launchctl" and process.args in ("load", "bootstrap", "submit", "enable")) or
(process.name == "security" and
process.args in ("find-generic-password", "find-internet-password", "dump-keychain", "export")) or
(process.name == "dscl" and process.args == "-authonly") or
(process.name in ("bash", "sh", "zsh", "dash") and process.args regex "-[a-zA-Z]*c[a-zA-Z]*" and
process.command_line like~ ("*curl *", "*wget *", "*osascript*", "*base64*", "*python -c*", "*python3 -c*",
"*perl -e*", "*eval *", "*launchctl load*", "*launchctl bootstrap*", "*nohup*",
"*LaunchAgents*", "*LaunchDaemons*", "*| sh*", "*|sh*", "*| bash*", "*|bash*",
"*| zsh*", "*chmod +x*", "*com.apple.quarantine*", "*dscl*", "*security find-*",
"*sqlite3*")) or
process.executable like~ ("/tmp/*", "/private/tmp/*", "/var/folders/*", "/private/var/folders/*", "/Users/Shared/*") or
((process.code_signature.trusted == false or process.code_signature.exists == false) and
not process.executable like~ "*/Homebrew/vendor/portable-ruby/*/bin/ruby")
)