Initial Access (TA0001)(external, opens in a new tab or window)
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).