agentsec · Tools · shellfence

Offline · stdlib-only · MIT

shellfence: detect dangerous shell commands an agent ran in AI agents


Offline dangerous-shell-command auditor for commands an AI agent actually ran (or attempted) via Bash / shell / terminal tools.

What it detects

Offline dangerous-shell-command auditor for commands an AI agent actually ran (or attempted) via Bash / shell / terminal tools.

When an agent can Bash, run_command, shell, or PowerShell, a prompt injection or confused tool choice can steer it into curl | bash, rm -rf /, reverse shells, chmod 777, force-pushes, publishes, firewall flushes, env exfil, or crontab persistence. shellfence extracts those commands from saved transcripts (or a plain command list), classifies each one, and reports findings with tool and turn attribution.

Standard library only. It never executes a command and never contacts the network.

Rules

RuleSeverityWhat it flags
SF01criticalPipe-to-shell / remote script execution (`curl\
SF02criticalDestructive wipe / disk destroy (rm -rf /, mkfs, dd of=/dev/…)
SF03highPrivilege escalation (sudo, su -, doas, pkexec, runas)
SF04criticalReverse shell / remote listener (nc -e, bash -i >& /dev/tcp, ncat)
SF05criticalEval of encoded or remote content (`base64\
SF06highPermission weakening (chmod 777, chmod -R a+rwx, icacls Everyone:F)
SF07highDangerous git mutation (push --force, reset --hard, clean -fdx)
SF08highPublish / release / registry push (npm publish, twine upload, docker push)
SF09highFirewall / network defense change (iptables -F, ufw disable, nft flush)
SF10mediumEnvironment / secret dump piped outbound (`printenv\
SF11mediumPersistence install (crontab, systemd unit drop, LaunchAgent, /etc/ld.so.preload, LD_PRELOAD=)
SF12infoInventory of every observed shell command (disable in CI with --disable SF12)
SF13highAI-CLI bypass / YOLO-mode flags that disable confirmation
SF14highDestructive infra commands (terraform destroy -auto-approve, kubectl delete --force, DROP … CASCADE)
SF15highAuthorized-keys / SSH backdoor writes
SF16highSecret-scanner run against a broad root plus a public exfil sink (gist, public repo)
SF17criticalLOLBAS remote download or execute (certutil -urlcache, mshta https://…, bitsadmin /transfer, and similar)
SF18criticalDownload-then-execute without a pipe (curl -o / wget -O, chmod +x, then run the file)
SF19criticalLOLBin / exec-trampoline or cloud-sync exfil (tar --checkpoint-action=exec, forfiles /c, MSBuild PostBuildEvent, rclone of $HOME)

Usage

python3 shellfence.py transcript.json [more.jsonl dir/ commands.txt -]
  --as-commands         treat inputs as plain command lists (one per line)
  --allow-command GLOB  fnmatch allowlist for the full command (repeatable)
  --disable RULE ...    skip rule ids (e.g. SF03 SF12)
  --json                machine-readable output
  --min-severity S      hide findings below S (default info)
  --fail-on S           exit 1 if any finding >= S (default high; any, none)
  --list-rules

After pip install of the kit, the same options work as agentsec shellfence …. Every tool also accepts --help and almost every tool accepts --json.

Example output

Flags SF01 on curl … | bash, SF02+SF03 on sudo rm -rf /, SF04 on the /dev/tcp reverse shell, SF05 on base64 -d | bash, SF06–SF08 on chmod 777 / force-push / npm publish, SF09–SF11 on firewall flush, env exfil and crontab (exit 1). examples/clean_openai.json is clean (exit 0). See also risky_anthropic.json, generic_commands.jsonl and commands.txt. All example secrets/payloads are FAKE-EXAMPLE-* or reserved documentation IPs.

python3 shellfence.py examples/risky_openai.json --disable SF12

SARIF and CI

agentsec shellfence path/to/input --sarif > shellfence.sarif

# GitHub Actions (composite action ships with the repo)
- uses: dunkleschitz/agentsec@v0
  with:
    tools: shellfence
    paths: path/to/input
    fail-on: high

SARIF 2.1.0 can be uploaded to GitHub code scanning. The composite action writes per-tool reports under agentsec-sarif/ by default.

OWASP mapping

Heuristic mapping of what this tool helps a reviewer look for. Not an official OWASP endorsement, and not complete coverage of any item. Sources: OWASP Top 10 for LLM Applications 2025 and OWASP Top 10 for Agentic Applications 2026.

Known limits

payload may be missed unless you extract commands and pass --as-commands.

at runtime, multi-stage decode that never appears as one string in the log).

sandbox, command allowlist, or toolgate policy in front of the agent.

match — use --allow-command or --disable for known-good patterns in CI.

Full source, tests, and fixtures: tools/shellfence/ in the repository. Install the kit with pip install git+https://github.com/dunkleschitz/agentsec.git.