Base64 — Quick Reference
Ctrl+F:
base64·base64 -d·base64 -w0
Base64 encodes binary data as ASCII text — common for transferring files through shells, decoding cookies/JWTs, and PHP LFI filters.
📌 Encode / decode (stdin)
# Encode string
echo -n 'password123' | base64
# cGFzc3dvcmQxMjM=
# Decode string
echo 'cGFzc3dvcmQxMjM=' | base64 -d
# password123📌 Encode / decode files
# Encode file → text (no line wrap — best for copy/paste)
base64 -w0 shell.elf > shell.b64
# Decode file
base64 -d shell.b64 > shell.elf
chmod +x shell.elf
# macOS (no -w0) — use tr to strip newlines
base64 -i shell.elf | tr -d '\n' > shell.b64📌 One-liners
# Quick decode in terminal
base64 -d <<< 'cGFzc3dvcmQxMjM='
# Encode command output for exfil
cat /etc/shadow | base64 -w0
# Decode multi-line paste from clipboard/file
base64 -d credentials.b64 > credentials.bin📌 Python alternative
# Encode file
python3 -c "import base64; print(base64.b64encode(open('file','rb').read()).decode())"
# Decode string
python3 -c "import base64; print(base64.b64decode('cGFzc3dvcmQxMjM=').decode())"See Python
📌 OSCP use cases
| Situation | Command |
|---|---|
| Transfer binary through restricted shell | base64 -w0 file > file.b64 → paste → base64 -d on target |
| Decode Flask/JWT cookie payload | echo 'PAYLOAD' | base64 -d → Cookie Decoding |
| PHP LFI read source | php://filter/convert.base64-encode/resource=file.php → Local File Inclusion (LFI) |
| Reverse shell obfuscation | Encode one-liner → echo B64 | base64 -d | bash → Reverse Shell - Base64 bash-c echo and One-Liners |
| Windows encode/decode | certutil -encode / -decode |
| PowerShell payload | Msfvenom cmd/powershell_base64 |
📌 Quick cheat sheet
echo -n 'secret' | base64
echo 'c2VjcmV0' | base64 -d
base64 -w0 payload.bin > payload.b64
base64 -d payload.b64 > payload.bin