ItsWanheda/jwt-analyzer
GitHub: ItsWanheda/jwt-analyzer
一款模块化的 JWT 命令行分析与安全测试工具,支持 Token 解析、签名验证、密钥暴力破解、漏洞检测及 Token 伪造。
Stars: 0 | Forks: 1
# JWT Analyzer v1.0.0
一款专业、模块化且安全的基于 CLI 的工具,用于分析、验证和测试 JSON Web Tokens (JWTs)。
## 功能
* **算法与元数据解析器**:提取 `alg`、`typ` 和标准 claims。
* **时间敏感验证器**:自动计算剩余有效时间。
* **安全测试套件**:检测 'none' 算法漏洞。
* **暴力破解钩子**:集成基于 wordlist 的签名验证。
* **Payload 对比**:对比两个 JWT payload 以识别状态变更。
* **RSA/JWK 验证**:针对公钥 (RS256/ES256) 验证 token。
* **Token 伪造**:修改 payload 并对 token 重新签名,用于主动测试。
* **自动化报告**:生成 JSON 报告以供记录。
## 安装说明
```
git clone https://github.com/yourusername/jwt_analyzer.git
cd jwt_analyzer
pip install -r requirements.txt
```
## 项目结构
```
BUILD/jwt_analyzer/
├── core/
│ ├── __init__.py
│ ├── diff.py
│ ├── forgery.py
│ ├── parser.py
│ ├── security.py
│ └── verification.py
├── tests/
├── utils/
│ ├── __init__.py
│ ├── io.py
│ └── wordlists/
├── .gitignore
├── CHANGELOG.md
├── config.py
├── CONTRIBUTING.md
├── LICENSE
├── main.py
├── README.md
├── requirements.txt
├── sample_token.txt
└── SECURITY.md
```
## 用法
### 分析 Token
```
python main.py analyze --token-file token.txt
```
### 使用公钥验证
```
python main.py verify-rsa --token-file token.txt --public-key public.pem
```
### 伪造 Token
```
python main.py forge --token-file original.txt --payload-file new_payload.json --secret mysecret
```
### 暴力破解 Secret
```
python main.py brute-force --token-file token.txt --wordlist wordlists/common_secrets.txt
```
### diff
```
python main.py diff --token1 --token2
or
python main.py diff --token1 old_token.txt --token2 new_token.txt
```
### 输出:
```
Payload Differences
┌──────────┬──────────────┬──────────────┐
│ Key │ Old Value │ New Value │
├──────────┼──────────────┼──────────────┤
│ role │ user │ admin │
│ exp │ 1678890000 │ 1678893600 │
└──────────┴──────────────┴──────────────┘
```
### verify-rsa
```
python main.py verify-rsa --token-file token.txt --public-key public_key.pem
```
### 输出:
```
✅ Token is valid!
Payload: {'sub': '1234567890', 'name': 'John Doe'}
If invalid:
❌ Token verification failed: Invalid signature.
With Report:
python main.py verify-rsa --token-file token.txt
--public-key public_key.pem --output report.json
```
## 高级用法
使用环境变量
```
You can customize the tool's behavior using environment variables:
JWT_ANALYZER_WORDLIST_PATH: Path to a custom wordlist.
JWT_ANALYZER_TIMEOUT: Timeout for brute-force operations (in seconds).
JWT_ANALYZER_LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR).
JWT_ANALYZER_ENABLE_RICH: Enable/disable Rich formatting (true/false).
Example:
JWT_ANALYZER_WORDLIST_PATH=/path/to/my/wordlist.txt python main.py brute-force --token-file token.txt
Generating Help
To see all available commands and options:
python main.py --help
To see help for a specific command:
python main.py analyze --help
```
## 故障排除
*ModuleNotFoundError:* 确保您已安装依赖项 (pip install -r requirements.txt)。
*FileNotFoundError:* 检查您的 token、wordlist 和公钥文件路径是否正确。
*Invalid JWT format:* 确保 token 文件仅包含 JWT 字符串(没有多余的空格或换行符)。
*Invalid signature:* 使用 verify-rsa 时,请确保公钥与用于签署 token 的私钥匹配。
## 示例工作流
* **分析 token 以查看其内容和过期时间。**
* **检查安全性以确保它没有使用 'none' 算法。**
* **使用服务器的公钥验证 token 以确保其合法。**
* **将其与另一个 token 进行比较,查看哪些 claims 发生了变化。**
* **伪造一个具有提升权限的新 token(例如,role: admin),以测试应用程序是否正确验证了签名。**
* **生成报告以供记录之用。**
## 贡献指南
我们欢迎您的贡献!有关如何提交您的想法、bug 报告或 pull requests 的详细信息,请参阅 CONTRIBUTING.md。
## 许可证
本项目根据 LICENSE 文件获得许可。
标签:JWT, Python, StruQ, 文档结构分析, 无后门, 逆向工具