Suspicious Child Process of Homebrew's Bundled Ruby Interpreter

Last updated 4 months ago on 2026-08-07
Created 4 months ago on 2026-08-07

About

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.
Tags
Domain: EndpointOS: macOSUse Case: Threat DetectionTactic: ExecutionTactic: Initial AccessData Source: Elastic DefendRule Type: Event Correlation (EQL)Platform: macOSLanguage: eql
Severity
medium
Risk Score
47
MITRE ATT&CK™

Initial Access (TA0001)(external, opens in a new tab or window)

Execution (TA0002)(external, opens in a new tab or window)

False Positive Examples
A cask whose own install step legitimately runs one of the listed tools will match, for example a vendor helper that is unsigned or ad-hoc signed, a `launchctl load` of the vendor's agent, or a vendor script run through `python3`. Verify the cask and its tap, then scope an exception to that cask's executable path. Homebrew's own nested `ruby` processes are ad-hoc signed and are excluded by their executable path (`vendor/portable-ruby/<version>/bin/ruby`). A Homebrew release that starts running a different unsigned helper of its own during installs would match. Compare against a clean install on the same Homebrew version before excluding it.
License
Elastic License v2(external, opens in a new tab or window)

Definition

Rule Type
Event Correlation Rule
Integration Pack
Prebuilt Security Detection Rules
Index Patterns
logs-endpoint.events.process*
Related Integrations

endpoint(external, opens in a new tab or window)

Query
text code block:
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") )

Install detection rules in Elastic Security

Detect Suspicious Child Process of Homebrew's Bundled Ruby Interpreter in the Elastic Security detection engine by installing this rule into your Elastic Stack.

To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).