Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Audit Detection Rules

sandtrace audit checks codebases against 50+ built-in detection rules across four categories: credential patterns, obfuscation detection (3 tiers), and supply-chain threats.

Credential patterns

Rule IDSeverityWhat it finds
cred-aws-keyCriticalAWS Access Key IDs (AKIA...)
cred-private-keyCriticalRSA, EC, DSA, OpenSSH private keys
cred-github-tokenCriticalGitHub PATs (ghp_, gho_, ghu_, ghs_, ghr_)
cred-slack-tokenCriticalSlack tokens (xoxb-, xoxp-, xoxa-, xoxr-, xoxs-)
cred-stripe-keyCriticalStripe API keys (sk_live_, pk_live_, sk_test_, pk_test_)
cred-jwt-tokenHighJWT tokens (eyJ...)
cred-generic-passwordHighHardcoded password = "..." assignments
cred-generic-secretHighHardcoded secret, token, api_key assignments

Obfuscation detection

These rules detect code obfuscation techniques used in supply-chain attacks. They are organized into three tiers by sophistication.

Original rules

Rule IDSeverityWhat it finds
obfuscation-trailing-whitespaceHighExcessive trailing whitespace (>20 chars)
obfuscation-hidden-contentCriticalContent hidden past column 200
obfuscation-invisible-charsCriticalZero-width unicode characters (U+200B, U+FEFF, U+2060, etc.)
obfuscation-base64MediumLarge base64-encoded blobs in source files
obfuscation-homoglyphHighCyrillic/Greek homoglyphs mixed with ASCII

Tier 1 — Encoding & string manipulation

Rule IDSeverityWhat it finds
obfuscation-hex-escapeMediumChains of 3+ hex escape sequences (\x63\x75\x72\x6c). Skips .c/.h/.cpp files.
obfuscation-unicode-escapeMediumChains of 3+ unicode escapes (\u0065\u0076\u0061\u006C). Skips .json files.
obfuscation-string-concatHighString concatenation hiding dangerous function names ('ev' + 'al')
obfuscation-charcodeHighString.fromCharCode() and PHP chr() concatenation chains
obfuscation-bracket-notationHighBracket notation hiding dangerous functions (window['ev' + 'al'])
obfuscation-constructor-chainCritical.constructor.constructor() chains — almost exclusively malicious
obfuscation-git-hook-injectionCriticalSuspicious content in .git/hooks/ (curl, wget, eval, pipe-to-shell)
obfuscation-php-variable-functionHighPHP variable functions storing dangerous names ($fn = 'system')

Tier 2 — Advanced obfuscation

Rule IDSeverityWhat it finds
obfuscation-atob-chainHighNested atob(atob(...)) or large atob() payloads
obfuscation-polyglotCriticalBinary magic bytes (PNG/JPEG/PDF/ELF/MZ) in source file extensions
obfuscation-symlink-attackCriticalSymlinks targeting .ssh, .aws, .gnupg, /etc/shadow, .env, etc.
obfuscation-filename-homoglyphHighCyrillic/Greek characters in filenames mixed with ASCII
obfuscation-rot13Medium/HighPHP str_rot13() calls; elevated to High when decoding to dangerous functions
obfuscation-template-literalHighAdjacent template literal fragments in JS/TS (${'ev'}${'al'})
obfuscation-php-create-functionHighcreate_function() — deprecated PHP dynamic code execution
obfuscation-php-backtickCriticalPHP backtick execution operator (equivalent to shell_exec())
obfuscation-python-dangerousHigh__import__('os'), pickle.loads(), exec(compile()), marshal.loads()

Tier 3 — Supply chain

Rule IDSeverityWhat it finds
obfuscation-typosquatHighPackage names 1 edit distance from popular npm/pip packages. Requires enable_typosquat = true.
obfuscation-dependency-confusionHighInternal-looking packages (-internal, -private, @company/) without .npmrc
obfuscation-install-script-chainCriticalnode -e, python -c, hidden dir refs, env var URLs in install scripts
obfuscation-php-preg-replace-eCriticalpreg_replace() with /e modifier — executes replacement as PHP code
obfuscation-suspicious-dotfileMediumUnknown dotfiles in source directories (src/, lib/, app/, etc.)
obfuscation-proxy-reflectMediumnew Proxy() / Reflect.apply() metaprogramming in JS/TS
obfuscation-json-evalCriticaleval(, Function(, javascript:, <script in .json files
obfuscation-encoded-shellCritical`echo B64

What are obfuscation attacks?

Obfuscation attacks hide malicious code using encoding, string manipulation, binary polyglots, or visual tricks. These techniques make payloads invisible to code review while remaining executable. Common vectors include:

  • Encoding — hex escapes, unicode escapes, charcode construction, base64 nesting
  • String splitting — concatenation ('ev'+'al'), bracket notation, template literals, ROT13
  • Binary tricks — polyglot files (PNG header + JS payload), constructor chain exploits
  • Filesystem — symlinks to sensitive files, homoglyph filenames, git hook injection, suspicious dotfiles
  • Supply chain — typosquatting, dependency confusion, malicious install scripts, preg_replace /e

These rules detect the surface indicators that suggest malicious content is hiding in plain sight.

Supply-chain detection

Rule IDSeverityWhat it finds
supply-chain-suspicious-scriptCriticalpackage.json postinstall/preinstall scripts with curl, wget, eval(, base64, pipe-to-shell

Custom IOC patterns

In addition to built-in rules, you can add custom indicators of compromise (IOCs) as detection rules. See Custom Rules — IOC Rules for examples of matching known malicious domains, file hashes, IP addresses, and filenames.

Severity levels

LevelMeaningExit code
criticalConfirmed secret or active threat2
highLikely secret or dangerous pattern1
mediumSuspicious but may be intentional0
lowWorth reviewing0
infoInformational only0

Use --severity to filter the minimum level reported:

sandtrace audit . --severity high    # Only high + critical
sandtrace audit . --severity medium  # Medium and above

Suppressing false positives

See Configuration — Redaction Markers and Configuration — Inline Suppression for ways to suppress known false positives.