Skip to content

Hybrid shell interpreter, AST evasion detection, and prefilter delegation #36

Merged
chen-zichen merged 4 commits intomainfrom
fix/shellutil-depth-check
Feb 28, 2026
Merged

Hybrid shell interpreter, AST evasion detection, and prefilter delegation #36
chen-zichen merged 4 commits intomainfrom
fix/shellutil-depth-check

Conversation

@cyyever
Copy link
Collaborator

@cyyever cyyever commented Feb 27, 2026

Summary

  • Hybrid interpreter+AST shell extraction — safe statements get variable expansion, unsafe ones fall back to
    AST. DIR=/tmp; diff <(ls $DIR) now expands $DIR.
  • AST-level fork bomb and eval detection replaces 8 regex patterns removed from prefilter (only base64/hex
    remain)
  • User-friendly evasive messages with offending command included
  • shellutil package for safe shell argument quoting
  • Docs updated: 10→16 pipeline steps, new shell analysis section

Test plan

  • go build ./... passes
  • go test -race ./... passes
  • Tested manually (describe below)

Security checklist

  • No new path traversal or glob bypass vectors
  • No secrets or credentials in code

…esting

- Add internal/shellutil package that builds shell commands via the
  shell parser's AST (syntax.Quote → parse → CallExpr → Printer)
  instead of manual string concatenation
- Replace hand-rolled shellQuote + string concat in acpwrap/convert.go
  and proxy/sse_buffer.go with shellutil.Command()
- Add jsonDepth check in extractor.Extract() — arguments with nesting
  depth > 2 are flagged as evasive (hard block), preventing attackers
  from hiding security-relevant fields inside deeply nested objects
- Add tests for deep nesting evasion detection
Replace all-or-nothing interpreter fallback with per-statement hybrid
approach: safe statements run through the interpreter for full variable
expansion, unsafe ones (ProcSubst, coproc, background, fd-dup redirects)
use AST extraction with recursive interpretation of inner commands.

Key changes:
- Refactor astHasUnsafe → nodeHasUnsafe (accept syntax.Node)
- Add collectInnerStmts, defuseStmt, extractFromAST skipInner param
- Extract runShellFileInterp, rewrite runShellFile with hybrid loop
- Add ls/exa/eza/lsd to command DB
- Fix [ builtin false-positive in glob detection
- Add false_positive, hybrid, and shell_fuzz test suites (230+ cases)
@cyyever cyyever force-pushed the fix/shellutil-depth-check branch from 223c81b to 8933a10 Compare February 28, 2026 01:00
… parser

- Rewrite all EvasiveReason strings for non-technical users
- Include offending command/value in every evasive message
- Unparseable shell commands no longer flagged as evasive
- Move eval to AST-level recursive parsing (like sh -c)
- Move fork bomb detection to AST-level astForkBomb (FuncDecl self-call)
- Remove network/IFS/indirect-expansion patterns from prefilter
- Prefilter now only has base64 + hex encoding detection
- Add TestForkBombDetection, TestEvalRecursiveParsing, TestUnparseableCommandNotEvasive
@cyyever cyyever force-pushed the fix/shellutil-depth-check branch from 8933a10 to 489937e Compare February 28, 2026 01:10
@cyyever cyyever changed the title security: add shellutil AST-based command builder Hybrid shell interpreter, AST evasion detection, and prefilter delegation Feb 28, 2026
@chen-zichen chen-zichen merged commit 7575c7f into main Feb 28, 2026
6 checks passed
@cyyever cyyever deleted the fix/shellutil-depth-check branch February 28, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants