Suspicious Child Process of Homebrew's Bundled Ruby Interpreter

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.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2026/08/07"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2026/08/07"
  6
  7[rule]
  8author = ["clivoa"]
  9description = """
 10Detects a suspicious child process spawned by Homebrew's bundled Ruby interpreter ("vendor/portable-ruby") during a
 11"brew install", "reinstall" or "upgrade". Cask "preflight" and "postflight" blocks run arbitrary Ruby at install time,
 12including shelling out through "system_command", so a malicious cask from a third-party tap, or a compromised or
 13typosquatted one, can use them to execute code with the installing user's privileges. The rule looks for what such a
 14hook would plausibly run: network and scripting tools, "osascript" prompts or shell-outs, "launchctl" persistence,
 15keychain and directory-service credential access, shells running download, decode or persistence commands, binaries
 16executed from temporary or shared directories, and untrusted or unsigned binaries.
 17"""
 18false_positives = [
 19    """
 20    A cask whose own install step legitimately runs one of the listed tools will match, for example a vendor helper
 21    that is unsigned or ad-hoc signed, a `launchctl load` of the vendor's agent, or a vendor script run through
 22    `python3`. Verify the cask and its tap, then scope an exception to that cask's executable path.
 23    """,
 24    """
 25    Homebrew's own nested `ruby` processes are ad-hoc signed and are excluded by their executable path
 26    (`vendor/portable-ruby/<version>/bin/ruby`). A Homebrew release that starts
 27    running a different unsigned helper of its own during installs would match. Compare against a clean install on
 28    the same Homebrew version before excluding it.
 29    """,
 30]
 31from = "now-9m"
 32index = ["logs-endpoint.events.process*"]
 33language = "eql"
 34license = "Elastic License v2"
 35name = "Suspicious Child Process of Homebrew's Bundled Ruby Interpreter"
 36note = """## Triage and analysis
 37
 38### Investigating Suspicious Child Process of Homebrew's Bundled Ruby Interpreter
 39
 40This rule flags a process spawned by Homebrew's bundled Ruby interpreter
 41(`.../Homebrew/vendor/portable-ruby/.../bin/ruby`) during `brew install`, `reinstall` or `upgrade` that matches a list
 42of tools and behaviours a malicious cask hook would plausibly use. A match most often means a cask's `preflight` or
 43`postflight` Ruby block executed a command. Shells match when they run an inline command, including combined option
 44forms such as `-xc` or `-lc`. The list does not cover `uninstall` hooks, hooks that run a script file instead of an
 45inline command, or exfiltration with tools outside the list such as `ditto`, `zip`, `scp` or `rsync`.
 46
 47### Possible investigation steps
 48
 49- Identify which cask was being installed from the parent's command line (`brew.rb install --cask <tap>/<cask>`) and
 50  whether it is a known first-party cask or comes from a third-party or community tap.
 51- Review the spawned child's full command line for network activity (`curl`, `wget`, `nc`), a scripting interpreter
 52  invocation (`bash -c`, `python3 -c`, `osascript`), or anything writing outside the cask's own Caskroom directory.
 53- If the cask is from a third-party tap, check the tap's Git history/commit author for the cask file for recent,
 54  suspicious changes.
 55- Correlate with any subsequent network connections, persistence (LaunchAgent/LaunchDaemon creation), or credential
 56  file access from the same process tree.
 57
 58### False positive analysis
 59
 60- A vendor helper run by a legitimate cask's install step can match when it is unsigned or ad-hoc signed, or when
 61  the cask runs `launchctl`, `osascript` or an interpreter as part of its setup. Confirm the cask, its tap and the
 62  helper's origin, then exclude that cask's executable path rather than the tool name.
 63
 64### Response and remediation
 65
 66- Determine the cask and its tap. Treat a hook that spawned a shell, an interpreter, or a network client as
 67  execution under the installing user and move to containment while you confirm intent.
 68- Capture the full process tree and command lines, and preserve the cask file from the tap and from the cask's
 69  `Caskroom/<cask>/.metadata` directory for analysis.
 70- Do not run `brew uninstall` or `reinstall` on the suspect cask. Homebrew evaluates the cask's Ruby code
 71  again for both commands and runs its uninstall hooks, which gives the malicious code another execution. Remove the
 72  installed artifacts, the cask's `Caskroom` directory and the tap directory with ordinary file system tools instead,
 73  with the host isolated.
 74- If the hook reached the network or wrote outside the Caskroom, treat the host as potentially compromised: hunt
 75  for persistence (LaunchAgents/LaunchDaemons), rotate any credentials reachable from the user's session, and
 76  review outbound connections from the process tree.
 77- Report a malicious first-party cask to Homebrew, and for a third-party tap warn other users of that tap.
 78"""
 79references = [
 80    "https://docs.brew.sh/Cask-Cookbook#stanza-preflight",
 81    "https://docs.brew.sh/Cask-Cookbook#stanza-postflight",
 82    "https://www.securityweek.com/homebrew-macos-users-targeted-with-information-stealer-malware/",
 83    "https://hunt.io/blog/macos-odyssey-amos-malware-campaign",
 84]
 85risk_score = 47
 86rule_id = "5e07cb07-acdb-49e5-958c-53841e79a1ae"
 87setup = """## Setup
 88
 89This rule requires data coming in from Elastic Defend.
 90
 91### Elastic Defend Integration Setup
 92Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
 93
 94#### Prerequisite Requirements:
 95- Fleet is required for Elastic Defend.
 96- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 97
 98#### The following steps should be executed in order to add the Elastic Defend integration on a macOS System:
 99- Go to the Kibana home page and click "Add integrations".
100- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
101- Click "Add Elastic Defend".
102- Configure the integration name and optionally add a description.
103- Select the type of environment you want to protect, for MacOS it is recommended to select "Traditional Endpoints".
104- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
105- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
106- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
107For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/current/agent-policy.html).
108- Click "Save and Continue".
109- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
110For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
111"""
112severity = "medium"
113tags = [
114    "Domain: Endpoint",
115    "OS: macOS",
116    "Use Case: Threat Detection",
117    "Tactic: Execution",
118    "Tactic: Initial Access",
119    "Data Source: Elastic Defend",
120    "Resources: Investigation Guide",
121    "Rule Type: Event Correlation (EQL)",
122    "Platform: macOS",
123]
124timestamp_override = "event.ingested"
125type = "eql"
126
127query = '''
128process where event.action == "exec" and host.os.type == "macos" and
129 process.parent.executable like~ "*/Homebrew/vendor/portable-ruby/*" and
130 process.parent.args in ("install", "reinstall", "upgrade") and
131 (
132   process.name in ("nc", "ncat", "perl", "node", "sqlite3") or
133   process.name like~ "python*" or
134   (process.name == "osascript" and
135    process.command_line like~ ("*do shell script*", "*display dialog*", "*hidden answer*")) or
136   (process.name == "launchctl" and process.args in ("load", "bootstrap", "submit", "enable")) or
137   (process.name == "security" and
138    process.args in ("find-generic-password", "find-internet-password", "dump-keychain", "export")) or
139   (process.name == "dscl" and process.args == "-authonly") or
140   (process.name in ("bash", "sh", "zsh", "dash") and process.args regex "-[a-zA-Z]*c[a-zA-Z]*" and
141    process.command_line like~ ("*curl *", "*wget *", "*osascript*", "*base64*", "*python -c*", "*python3 -c*",
142                                "*perl -e*", "*eval *", "*launchctl load*", "*launchctl bootstrap*", "*nohup*",
143                                "*LaunchAgents*", "*LaunchDaemons*", "*| sh*", "*|sh*", "*| bash*", "*|bash*",
144                                "*| zsh*", "*chmod +x*", "*com.apple.quarantine*", "*dscl*", "*security find-*",
145                                "*sqlite3*")) or
146   process.executable like~ ("/tmp/*", "/private/tmp/*", "/var/folders/*", "/private/var/folders/*", "/Users/Shared/*") or
147   ((process.code_signature.trusted == false or process.code_signature.exists == false) and
148    not process.executable like~ "*/Homebrew/vendor/portable-ruby/*/bin/ruby")
149 )
150'''
151
152
153[[rule.threat]]
154framework = "MITRE ATT&CK"
155[[rule.threat.technique]]
156id = "T1195"
157name = "Supply Chain Compromise"
158reference = "https://attack.mitre.org/techniques/T1195/"
159[[rule.threat.technique.subtechnique]]
160id = "T1195.002"
161name = "Compromise Software Supply Chain"
162reference = "https://attack.mitre.org/techniques/T1195/002/"
163
164
165
166[rule.threat.tactic]
167id = "TA0001"
168name = "Initial Access"
169reference = "https://attack.mitre.org/tactics/TA0001/"
170[[rule.threat]]
171framework = "MITRE ATT&CK"
172[[rule.threat.technique]]
173id = "T1059"
174name = "Command and Scripting Interpreter"
175reference = "https://attack.mitre.org/techniques/T1059/"
176
177
178[rule.threat.tactic]
179id = "TA0002"
180name = "Execution"
181reference = "https://attack.mitre.org/tactics/TA0002/"

Triage and analysis

Investigating Suspicious Child Process of Homebrew's Bundled Ruby Interpreter

This rule flags a process spawned by Homebrew's bundled Ruby interpreter (.../Homebrew/vendor/portable-ruby/.../bin/ruby) during brew install, reinstall or upgrade that matches a list of tools and behaviours a malicious cask hook would plausibly use. A match most often means a cask's preflight or postflight Ruby block executed a command. Shells match when they run an inline command, including combined option forms such as -xc or -lc. The list does not cover uninstall hooks, hooks that run a script file instead of an inline command, or exfiltration with tools outside the list such as ditto, zip, scp or rsync.

Possible investigation steps

  • Identify which cask was being installed from the parent's command line (brew.rb install --cask <tap>/<cask>) and whether it is a known first-party cask or comes from a third-party or community tap.
  • Review the spawned child's full command line for network activity (curl, wget, nc), a scripting interpreter invocation (bash -c, python3 -c, osascript), or anything writing outside the cask's own Caskroom directory.
  • If the cask is from a third-party tap, check the tap's Git history/commit author for the cask file for recent, suspicious changes.
  • Correlate with any subsequent network connections, persistence (LaunchAgent/LaunchDaemon creation), or credential file access from the same process tree.

False positive analysis

  • A vendor helper run by a legitimate cask's install step can match when it is unsigned or ad-hoc signed, or when the cask runs launchctl, osascript or an interpreter as part of its setup. Confirm the cask, its tap and the helper's origin, then exclude that cask's executable path rather than the tool name.

Response and remediation

  • Determine the cask and its tap. Treat a hook that spawned a shell, an interpreter, or a network client as execution under the installing user and move to containment while you confirm intent.
  • Capture the full process tree and command lines, and preserve the cask file from the tap and from the cask's Caskroom/<cask>/.metadata directory for analysis.
  • Do not run brew uninstall or reinstall on the suspect cask. Homebrew evaluates the cask's Ruby code again for both commands and runs its uninstall hooks, which gives the malicious code another execution. Remove the installed artifacts, the cask's Caskroom directory and the tap directory with ordinary file system tools instead, with the host isolated.
  • If the hook reached the network or wrote outside the Caskroom, treat the host as potentially compromised: hunt for persistence (LaunchAgents/LaunchDaemons), rotate any credentials reachable from the user's session, and review outbound connections from the process tree.
  • Report a malicious first-party cask to Homebrew, and for a third-party tap warn other users of that tap.

References

Related rules

to-top