pub fn deobfuscate(command: &str) -> StringExpand description
Normalize an obfuscated shell command string for blocklist and policy evaluation.
Applies transformations in order:
- Truncate to 8 KiB.
- Decode
\xNNhex escapes. - Decode
\NNNoctal escapes. - Decode
\uNNNNUnicode escapes. - Collapse backslash line-continuations (
\↵). - Expand
${VAR}/$VARto[var:VAR]. - Replace backtick subshells
`cmd`with[subshell: cmd]. - Replace
$(cmd)with[subshell: cmd]. - Strip unescaped quotes used for string concatenation.
- Normalize runs of whitespace to a single space and trim.
§Examples
use zeph_tools::shell::deobfuscate::deobfuscate;
assert_eq!(deobfuscate(r"\x63url"), "curl");
assert_eq!(deobfuscate(r"\143at"), "cat");
assert_eq!(deobfuscate("$(whoami)"), "[subshell: whoami]");
assert_eq!(deobfuscate("${HOME}/file"), "[var:HOME]/file");