- from: shell
test: '(?:^|\s)curl\s+.*\|\s*(?:sudo\s+)?(bash|sh|zsh|fish|source\s)'
description: "Piping remote content directly to shell executes arbitrary code without inspection."
id: shell:curl_pipe_to_shell
severity: High
alternative: "curl -o script.sh <url> && cat script.sh"
alternative_info: "Download it and read it. Run it (`bash script.sh`) in a separate command once you have reviewed it."
- from: shell
test: '(?:^|\s)wget\s+.*-\S*O\s*-\s.*\|\s*(?:sudo\s+)?(bash|sh|zsh|fish)'
description: "Piping downloaded content to shell executes arbitrary code without inspection."
id: shell:wget_pipe_to_shell
severity: High
alternative: "wget -O script.sh <url> && cat script.sh"
alternative_info: "Download it and read it. Run it (`bash script.sh`) in a separate command once you have reviewed it."
- from: shell
test: '(?:^|\s)eval\s+"?\$\(curl'
description: "Evaluating remote content executes arbitrary code without inspection."
id: shell:eval_curl
severity: High
alternative: "curl -o script.sh <url> && cat script.sh"
alternative_info: "Download it and read it. Source it (`source script.sh`) in a separate command once you have reviewed it."
- from: shell
test: '(?:^|\s)(?:curl|wget)\s+.*\|\s*(?:sudo\s+)?(python[\d.]*|perl|ruby|node|nodejs|bun|deno|php|lua)\b'
description: "Piping remote content to an interpreter executes arbitrary code without inspection."
id: shell:curl_pipe_to_interpreter
severity: High
filters:
# `curl … | python3 -m json.tool` only pretty-prints the JSON: one
# download, piped into exactly json.tool with its own options and no
# file, and nothing else on the line.
- type: NotMatches
value: '^(?:curl|wget)\s+[^|;&<>`()]*\|\s*python[\d.]*\s+(?:-m\s+json\.tool|-mjson\.tool)(?:\s+(?:--sort-keys|--tab|--compact|--no-ensure-ascii|--json-lines|--no-indent|--indent(?:=|\s+)\d+|-))*\s*$'
alternative: "curl -o script.py <url> && cat script.py"
alternative_info: "Download it and read it. Run it (`python script.py`) in a separate command once you have reviewed it."
- from: shell
# Also hex (`xxd -r`), reversed (`rev`) and compressed text.
test: '(?:^|\s)(?:(?:base64|base32)\s+(?:\S+\s+)*?(?:-d|--decode|-D)|xxd\s+(?:\S+\s+)*?-r|rev|(?:gzip|bzip2|xz|zstd)\s+(?:\S+\s+)*?-d|gunzip|zcat|openssl\s+(?:enc|base64)\s+(?:\S+\s+)*?-d)(?:\s.*)?\|\s*(?:sudo\s+(?:-\S+\s+)*)?(?:ba|z|da|k|fi)?sh(?:\s|$)'
description: "This decodes hidden text and runs it as shell commands, so you cannot see what it does."
id: shell:decode_pipe_to_shell
severity: High
alternative: "base64 -d <<< '<data>'"
alternative_info: "Decode and read the text first; run it only after reviewing it."
- from: shell
# Emitted by shellfirm for `eval "$(rev <<< '/ fr- mr')"`, `eval "$(echo …
# | xxd -r -p)"`, `sh -c "$(… | base64 -d)"`: the code is hidden by a text
# transform and only exists when it runs.
test: '^shellfirm-transformed-code\s'
description: "This runs (eval) text that is decoded or transformed first, so you cannot see the commands it runs."
id: shell:eval_transformed_text
severity: High
alternative: "echo \"$(<transform>)\""
alternative_info: "Print the decoded text and read it before running it."
- from: shell
test: '(?:^|\s)(?:(?:ba|z|da|k)?sh|source|\.|python[\d.]*|perl|ruby|node|php)\s+(?:-\S+\s+)*<\s*\(\s*(?:curl|wget)\b'
description: "This runs a downloaded script directly (process substitution) without inspection."
id: shell:process_substitution_remote
severity: High
alternative: "curl -o script.sh <url> && cat script.sh"
alternative_info: "Download it and read it. Run it (`bash script.sh`) in a separate command once you have reviewed it."
- from: shell
test: '^shellfirm-nesting-limit\s'
description: "The command is nested too deeply (eval / $( ) / bash -c inside each other) or is too large or malformed to be analyzed safely."
id: shell:nesting_too_deep
severity: High
# `sh -c "$(curl …)"`: the installer idiom, the same as `curl … | sh`.
- from: shell
test: '(?:^|\s)(?:(?:ba|z|da|k|mk|fi|c|tc)?sh|nu|elvish|xonsh|pwsh|powershell)\s+(?:-\S+\s+)*?-[a-zA-Z]*c\s+["'']?(?:\$\(|`)\s*(?:sudo\s+)?(?:curl|wget|fetch|aria2c|http|https|xh)\b'
description: "This downloads a script and runs it as shell code without inspection (`sh -c \"$(curl …)\"` is the same as `curl … | sh`)."
id: shell:shell_c_remote_script
severity: High
alternative: "curl -o script.sh <url> && cat script.sh"
alternative_info: "Download it and read it. Run it (`bash script.sh`) in a separate command once you have reviewed it."
- from: shell
test: '^shellfirm-unknown-shell-payload\s'
description: "This runs shell code that shellfirm cannot see before it runs (input lines executed as commands, as in `xargs -I{} sh -c '{}'`), so it cannot be checked."
id: shell:unknown_shell_payload
severity: High
# The shell hooks follow the functions a line calls (and the functions those
# call) within a size budget; past it they emit this marker.
- from: shell
test: '^shellfirm-function-depth-limit\s'
description: "This calls a shell function too large or too deeply nested for the shell hook to read ahead, so part of what it runs was not checked."
id: shell:function_depth_limit
severity: Medium
- from: shell
# PowerShell download-and-run: `irm URL | iex`, `iex (iwr URL)`,
# `IEX(New-Object Net.WebClient).DownloadString(URL)`,
# `[Net.WebClient]::new().DownloadString(URL) | iex`, with intermediate
# pipe stages, or piped into `powershell -` (the PowerShell `curl … | bash`).
test: '(?i)(?:^|\s|\()(?:irm|iwr|Invoke-RestMethod|Invoke-WebRequest|curl|wget)\b[^;\n]*\|\s*(?:(?:iex|Invoke-Expression)\b|(?:pwsh|powershell)(?:\.exe)?\s+-(?:\s|$))|(?:^|\s)(?:iex|Invoke-Expression)\s*\$?\(?\s*\(?\s*(?:irm|iwr|Invoke-RestMethod|Invoke-WebRequest|New-Object\s+(?:System\.)?Net\.WebClient|\[(?:System\.)?Net\.WebClient\])\b|\.Download(?:String|Data)\s*\(|\[scriptblock\]::Create\s*\('
description: "This downloads a PowerShell script and runs it (Invoke-Expression) without inspection."
id: shell:powershell_download_exec
severity: High
alternative: "Invoke-WebRequest <url> -OutFile script.ps1; Get-Content script.ps1"
alternative_info: "Download it and read it. Run it (`./script.ps1`) in a separate command once you have reviewed it."
- from: shell
# Windows LOLBins that fetch and run remote code: certutil `-urlcache` /
# `-verifyctl` downloads, bitsadmin `/transfer`, `mshta http(s)://…` or a
# `javascript:` / `vbscript:` payload, and `regsvr32 /i:http(s)://…`.
test: '(?i)(?:^|\s)(?:certutil(?:\.exe)?\s+(?:[-/]\S+\s+)*?[-/](?:urlcache|verifyctl)\b|bitsadmin(?:\.exe)?\s+(?:\S+\s+)*?/transfer\b|mshta(?:\.exe)?\s+(?:https?|javascript|vbscript):|regsvr32(?:\.exe)?\s+(?:/\S+\s+)*?/i:https?:)'
description: "This uses a Windows built-in tool (certutil, bitsadmin, mshta or regsvr32) to download and run code from a URL, bypassing normal download controls."
id: shell:lolbin_download_exec
severity: High
alternative: "Invoke-WebRequest <url> -OutFile file; Get-FileHash file"
alternative_info: "Download it to a file and inspect it before running."
- from: shell
# `powershell -EncodedCommand <base64>`: the command is hidden in base64.
# Any unambiguous prefix of `-EncodedCommand` works (`-e`, `-enc`, `-enco`,
# `-encodedc`), plus the `-ec` shorthand (Cobalt Strike's default), with a
# space, `:` or `=`, and the `/enc` slash form.
test: '(?i)(?:^|\s)(?:pwsh|powershell)(?:\.exe)?\s+(?:\S+\s+)*?[-/]e(?:c|n(?:c(?:o(?:d(?:e(?:d(?:c(?:o(?:m(?:m(?:a(?:n(?:d)?)?)?)?)?)?)?)?)?)?)?)?)?[:\s=]+[A-Za-z0-9+/=]{8,}(?:\s|$)'
description: "This runs a PowerShell command hidden in base64 (-EncodedCommand), so you cannot see what it does."
id: shell:powershell_encoded_command
severity: High
- from: shell
# Inline code that downloads more code and runs it: `python3 -c
# "exec(urlopen(URL).read())"`, `node -e "https.get(URL, … eval(d))"`,
# `ruby -e "eval(Net::HTTP.get(…))"`, the same as `curl URL | python3`.
# A method named eval (`model.eval()`, `df.eval(…)`) is not the builtin;
# `builtins.exec(…)`, `__builtins__.exec(…)` and
# `getattr(__builtins__, 'exec')(…)` are.
test: '^(?:(?:python[0-9.]*|pypy[0-9.]*)\s+(?:\S+\s+)*?-[a-zA-Z]*c(?:\s\S*)?[^.\w](?:(?:(?:__builtins__\.|builtins\.)?(?:exec|eval)|getattr\(\x01*(?:__builtins__|builtins)\x01*,\x01*\W?(?:exec|eval)\W?\x01*\))\s*\(\S*(?:urlopen|urllib|requests\.|httpx\.|http\.client|urlretrieve)|(?:urlopen|urllib\.request|requests\.get|httpx\.get|http\.client)\S*[^.\w](?:(?:__builtins__\.|builtins\.)?(?:exec|eval)|getattr\(\x01*(?:__builtins__|builtins)\x01*,\x01*\W?(?:exec|eval)\W?\x01*\))\s*\()|(?:node|nodejs|bun|deno)\s+(?:\S+\s+)*?(?:-[a-zA-Z]*[ep]|--eval|--print|eval)(?:\s+|=)\S*(?:(?:\beval\b|\b(?:Function|vm\.run\w*)\s*\()\S*(?:https?\W{1,4}\.get\s*\(|https?\.request\s*\(|\bfetch\s*\(|axios)|(?:https?\W{1,4}\.get\s*\(|https?\.request\s*\(|\bfetch\s*\(|axios)\S*(?:\beval\b|\b(?:Function|vm\.run\w*)\s*\())|ruby\s+(?:\S+\s+)*?-[a-zA-Z]*e\s+\S*(?:\b(?:eval|instance_eval|class_eval)\b\S*(?:Net::HTTP|open-uri|URI\.open|URI\(\S*\)\.read|open\(\W?https?:)|(?:Net::HTTP|open-uri|URI\.open)\S*\b(?:eval|instance_eval)\b)|perl\s+(?:\S+\s+)*?-[a-zA-Z]*[eE]\s+\S*(?:\beval\b\S*(?:LWP|HTTP::Tiny|IO::Socket)|(?:LWP|HTTP::Tiny)\S*\beval\b)|php\s+(?:\S+\s+)*?-r\s+\S*\beval\s*\(\S*(?:file_get_contents|curl_exec|fopen)\s*\(\S*https?:)'
description: "This inline script downloads code from the network and runs it, without any chance to review it first."
id: shell:interpreter_remote_exec
severity: High
alternative: "curl -o script <url> && cat script"
alternative_info: "Download the code to a file and read it before running it."