Spot the format
| Looks like | Hint |
|---|
| hex | only 0-9a-f, even length often matters |
| base64 | A-Z a-z 0-9 + / with optional = padding |
| base32 | A-Z 2-7 and often lots of = |
| url encoding | %2f %3d style escapes |
| binary string | 01001000... |
| escaped bytes | \x41\x42 or %41%42 |
| compressed | file/binwalk show gzip, zlib, zip |
Quick probes
file sample
xxd sample | head
python3 - <<'PY'
import base64
s='...'.encode()
for fn in (base64.b16decode, base64.b32decode, base64.b64decode, base64.urlsafe_b64decode):
try: print(fn.__name__, fn(s))
except Exception: pass
PYAuto decoders
# ciphey: brute-force encoding/cipher chains
ciphey -t "aGVsbG8="
ciphey -f blob.txt
# ares: faster Rust successor (bee-san)
ares -t "IWRscm9X..."
# CyberChef "Magic" auto-detects; cchef = CLI
cchef magic -i "41 42 43 44"
cchef bake -e "From_Base64()From_Hex()" input
Binary / integers / endianness
python3 -c "print(int('01110000',2))"
python3 -c "print((0xdeadbeef).to_bytes(4,'little'))"
python3 -c "print(int.from_bytes(bytes.fromhex('efbeadde'),'little'))"
Compression layers
file blob
binwalk -e blob
python3 - <<'PY'
import zlib,sys
raw=open('blob','rb').read()
for w in (zlib.MAX_WBITS, -zlib.MAX_WBITS, 15|32):
try: print(w, zlib.decompress(raw, w)[:80])
except Exception: pass
PY
Single-byte XOR
python3 - <<'PY'
data = bytes.fromhex('3a2b2c')
for k in range(256):
p = bytes(b ^ k for b in data)
if b'flag' in p.lower() or all(9 <= c < 127 for c in p):
print(k, p)
PYKnown-plaintext XOR
# ciphertext = plaintext XOR key
# key = plaintext XOR ciphertext
python3 - <<'PY'
pt = b'picoCTF{'
ct = bytes.fromhex('0011223344556677')
key = bytes(a ^ b for a,b in zip(pt, ct))
print(key)
PYROT / Caesar
tr 'A-Za-z' 'N-ZA-Mn-za-m'
python3 - <<'PY'
import string
s='uryyb'
a=string.ascii_lowercase
for k in range(26):
t=''.join(a[(a.index(c)+k)%26] if c in a else c for c in s)
print(k,t)
PYxortool (repeating-key XOR)
# guess key length from freq of equal chars
xortool cipher.bin
# hex input, assume 0x00 is most frequent byte
xortool -x -c 00 cipher.hex
# fix length + most-common byte -> key + plaintext
xortool -l 8 -c 20 cipher.bin
# results land in xortool_out/