Skip to content

Base64 and hex command injection filter bypass

Filter / WAF bypassEncoding (base64 / hex)Linux / UnixWindows

A base64 command injection bypass smuggles the real payload past keyword filters by encoding it, then decoding and executing it on the target. A value like `echo <b64> | base64 -d | sh` contains none of the blocked keywords in plaintext; the shell reconstructs and runs the original command only at execution time.

How it works

The attacker encodes the intended command (for example `id`) as base64, then injects a wrapper that decodes it and pipes the result into a shell. On Linux: `echo aWQK | base64 -d | sh`. Because the filter only sees the base64 blob and the decoder invocation, it can't match on the sensitive command text.

Hex and other encodings work the same way via `xxd -r -p`, `printf '\x69\x64'`, or shell `$'\x69\x64'`. On Windows, PowerShell's `-EncodedCommand` accepts base64-encoded UTF-16LE, and `certutil -decode` reconstructs files. The technique is often layered on top of IFS/quoting tricks for the wrapper itself.

Representative payloads

Illustrative fragments for authorized testing. The injected marker commands (id, whoami) are harmless proofs of execution — swap in your engagement’s agreed markers.

  • echo aWQ= | base64 -d | sh

    Linux / UnixDecodes base64 'aWQ=' (id) and pipes it to sh; no literal 'id' in the request.

  • printf '\x69\x64' | sh

    Linux / UnixReconstructs 'id' from hex escapes via printf, then executes it.

  • powershell -EncodedCommand <base64-utf16le>

    WindowsPowerShell runs a base64 (UTF-16LE) encoded command, hiding the plaintext from filters.

  • bash -c "$(echo aWQK|base64 -d)"

    Linux / UnixCommand substitution feeds the decoded command directly to bash -c.

When it works

  • Input reaches a shell and decoder utilities (base64, xxd, printf, certutil, powershell) are available.
  • The filter inspects plaintext keywords and does not decode or sandbox the payload.

When it fails

  • No shell/exec reaches the input, so the decode-and-run chain can't form.
  • The required decoder isn't present and alternatives are blocked.

Detection

Flag decoder invocations piped into a shell and long base64/hex blobs in inputs; decode suspicious values during analysis.

Signals to look for

  • Inputs containing base64 -d, xxd -r, certutil -decode, or powershell -enc / -EncodedCommand.
  • A decoder process piping into sh/bash/cmd/powershell in process telemetry.
  • High-entropy base64/hex strings in parameters that should hold simple values.

Where to look

WAF / application logsauditd / Sysmon process creation with command linePowerShell script-block logging (Event ID 4104)

Remediation

The correct fix: Shell-free argv execution removes the shell that would decode and run the payload; the encoded blob stays inert data.

Principles

  • Without a shell there is nothing to decode and execute the reconstructed command.
  • Enable PowerShell script-block logging to reveal decoded -EncodedCommand content for monitoring.
  • Allowlist inputs so encoded blobs never reach an exec sink.

Safe APIs by runtime

Node.js

execFile/spawn with args array; never pipe decoded input into a shell.

execFile("convert", [input, output]);
PowerShell / .NET

Avoid Invoke-Expression and -EncodedCommand with user data; call executables with an argument array.

& 'tool.exe' $arg1 $arg2

Not a fix: Blocklisting plaintext keywords. Encoding hides every keyword until runtime, so keyword filters provide no protection here.

For the full secure-coding matrix across languages, see the command injection prevention guide.

References

Related techniques