Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14
51 changes: 41 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,62 @@ Note that local files in your current working directory will be mapped into the
i.e.
*/tmp/localfile.txt*

### Manual Install
Installation is just a case of downloading the `jwt_tool.py` file (or `git clone` the repo).
(`chmod` the file too if you want to add it to your *$PATH* and call it from anywhere.)
### Install via uv or pip
You can install and run jwt_tool as a CLI.

`$ git clone https://github.com/ticarpi/jwt_tool`
`$ python3 -m pip install -r requirements.txt`
Using uv:
```
uv tool install .
uv tool install git+https://github.com/ticarpi/jwt_tool.git
```

Using pip:
```
python3 -m pip install .
python3 -m pip install git+https://github.com/ticarpi/jwt_tool.git
```

After installation, use the console script:
```
jwt-tool -h
jwt-tool <JWT> [options]
```

On first run the tool will generate a config file, some utility files, logfile, and a set of Public and Private keys in various formats.
Optional: manual script usage (no install)
```
git clone https://github.com/ticarpi/jwt_tool
chmod +x jwt_tool.py
python3 jwt_tool.py <JWT>
```

On first run the tool will generate a config file, some utility files, logfile, and a set of Public and Private keys in various formats.

### Custom Configs
* To make best use of the scanning options it is **strongly advised** to copy the custom-generated JWKS file somewhere that can be accessed remotely via a URL. This address should then be stored in `jwtconf.ini` as the "jwkloc" value.
* In order to capture external service interactions - such as DNS lookups and HTTP requests - put your unique address for Burp Collaborator (or other alternative tools such as RequestBin) into the config file as the "httplistener" value.
***Review the other options in the config file to customise your experience.***

### Colour bug in Windows
To fix broken colours in Windows cmd/Powershell: uncomment the below two lines in `jwt_tool.py` (remove the "# " from the beginning of each line)
You will also need to install colorama: `python3 -m pip install colorama`
If colours are not displaying correctly in Windows cmd/PowerShell, install the optional dependency group. The script will auto-enable colour support when `colorama` is present.

Using uv:
```
# import colorama
# colorama.init()
uv tool install .[win-colour]
```

Using pip:
```
python3 -m pip install .[win-colour]
```

---

## Usage
The first argument should be the JWT itself (*unless providing this in a header or cookie value*). Providing no additional arguments will show you the decoded token values for review.
`$ jwt-tool <JWT>`
or as a module:
`$ python3 -m jwt_tool <JWT>`
or directly from the script:
`$ python3 jwt_tool.py <JWT>`
or the Docker base command:
`$ docker run -it --network "host" --rm -v "${PWD}:/tmp" -v "${HOME}/.jwt_tool:/root/.jwt_tool" ticarpi/jwt_tool`
Expand Down
20 changes: 15 additions & 5 deletions jwt_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
print("On most Linux systems you can run the following command to install:")
print("python3 -m pip install requests\n")
exit(1)
# To fix broken colours in Windows cmd/Powershell: uncomment the below two lines. You will need to install colorama: 'python3 -m pip install colorama'
# import colorama
# colorama.init()
# Attempt to enable ANSI colours on Windows if colorama is available
try:
import colorama
colorama.init()
except Exception:
pass

# CONSTANTS
DEFAULT_RATE_LIMIT = 999999999
Expand Down Expand Up @@ -1847,7 +1850,10 @@ def printLogo():
print(" \x1b[36mVersion "+jwttoolvers+" \x1b[0m \\______| \x1b[36m@ticarpi\x1b[0m ")
print()

if __name__ == '__main__':
def main():
global args, parser, config, path, logFilename, configFileName, jwt
global headDict, paylDict, sig, contents, paylB64, newContents

parser = argparse.ArgumentParser(epilog="If you don't have a token, try this one:\neyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbiI6InRpY2FycGkifQ.bsSwqj2c2uI9n7-ajmi3ixVGhPUiY7jO9SUn9dm15Po", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("jwt", nargs='?', type=str,
help="the JWT to tinker with (no need to specify if in header/cookies)")
Expand Down Expand Up @@ -2216,8 +2222,12 @@ def printLogo():
exit(1)
if args.mode:
if not config['argvals']['targeturl'] and not args.bare:
cprintc("No target secified (-t), cannot scan offline.", "red")
cprintc("No target specified (-t), cannot scan offline.", "red")
exit(1)
runScanning()
runActions()
exit(1)


if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[project]
name = "jwt-tool"
version = "2.3.0"
description = "🐍 A toolkit for testing, tweaking and cracking JSON Web Tokens"
readme = "README.md"
requires-python = ">=3.6"
dependencies = [
"cprint>=1.2.2",
"pycryptodomex>=3.23.0",
"ratelimit>=2.2.1",
"requests>=2.27.1",
"termcolor>=1.1.0",
]

[project.scripts]
jwt-tool = "jwt_tool:main"

[project.optional-dependencies]
win-colour = [
"colorama>=0.4.6",
]
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

16 changes: 13 additions & 3 deletions setup.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Install with uv (recommended)
uv tool install git+https://github.com/ticarpi/jwt_tool.git

# Or install from a local checkout
git clone https://github.com/ticarpi/jwt_tool
cd jwt_tool
sudo apt install python3-pip
python3 -m pip install termcolor cprint pycryptodomex requests
chmod +x jwt_tool.py
uv tool install .

# Install with pip (alternative)
python3 -m pip install git+https://github.com/ticarpi/jwt_tool.git
# Or from the local checkout
python3 -m pip install .

# Run the tool
jwt-tool -h
Loading