Powershell Encoded Command
Description
Detects process events where the process is Powershell (pwsh) or a shell interpreter (sh, bash, zsh) with the encoded command flag set in the process arguments. Powershell usage on macOS is extremely rare but usage of Powershell with the encoded command flag, used for executing base64 encoded command strings, is almost always inherently malicious.
Query · eql
process where event.type == "start" and process.args in~ ("-EncodedCommand", "-enc") and
(process.name in ("sh", "bash", "zsh", "pwsh", "dash", "csh", "tcsh", "ksh", "tclsh", "fish") or process.name like "tclsh*") and
not process.args like "/Applications/Visual Studio Code.app/*" and
not process.executable like "/Applications/Docker.app/Contents/Resources/bin/docker" and
not process.parent.executable in ("/Applications/Docker.app/Contents/Resources/bin/com.docker.cli",
"/Applications/VSCodium.app/Contents/Frameworks/VSCodium Helper.app/Contents/MacOS/VSCodium Helper",
"/Applications/Cursor.app/Contents/Frameworks/Cursor Helper.app/Contents/MacOS/Cursor Helper",
"/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper",
"/Applications/Docker.app/Contents/Resources/bin/docker") and
not process.parent.code_signature.team_id in ("UBF8T346G9", "83Z2LHX6XW") and
not process.Ext.effective_parent.name == "electron" and
not ((process.name == "zsh" and process.parent.name == "zsh") or
(process.name == "pwsh" and process.parent.name == "pwsh") or
(process.name == "pwsh" and process.parent.name == "Code Helper"))