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

SituationCommand
Transfer binary through restricted shellbase64 -w0 file > file.b64 → paste → base64 -d on target
Decode Flask/JWT cookie payloadecho 'PAYLOAD' | base64 -dCookie Decoding
PHP LFI read sourcephp://filter/convert.base64-encode/resource=file.phpLocal File Inclusion (LFI)
Reverse shell obfuscationEncode one-liner → echo B64 | base64 -d | bashReverse Shell - Base64 bash-c echo and One-Liners
Windows encode/decodecertutil -encode / -decode
PowerShell payloadMsfvenom 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