vibecoded simple asf jwt forger for ctfs - since jwt_tool is usually overkill, jwt-hack, and jwt-cli are missing specific stupid simple features xd
- {header,payload}claims as JSON in args
- preserves json (if parser on target is fkin around how spaces are used in claims)
- preserves claim order
help:
jwt-forge -h
Usage of jwt-forge:
-decode string
Decode JWT (pass token as value)
-header string
Header as JSON string
-key string
Path to PEM private key
-payload string
Payload as JSON string
-secret string
HMAC secret (raw, b64:prefix, or @file)
-verify-key string
Path to PEM public key for verification
-verify-secret string
Secret to verify HMAC signature
install:
go install github.com/matesz44/jwt-forge/v3/cmd/jwt-forge@latest
usage (e.g., TryHackMe - Hammer):
jwt-forge -header '{"typ":"JWT","alg":"HS256","kid":"/foo/bar/baz.key"}' -payload '{"iss":"http://hammer.thm","aud":"http://hammer.thm","iat":1786915918,"exp":1786919518,"data":{"user_id":1,"email":"qwe@hammer.thm","role":"admin"}}' -secret rty
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6Ii9mb28vYmFyL2Jhei5rZXkifQ.eyJpc3MiOiJodHRwOi8vaGFtbWVyLnRobSIsImF1ZCI6Imh0dHA6Ly9oYW1tZXIudGhtIiwiaWF0IjoxNzg2OTE1OTE4LCJleHAiOjE3ODY5MTk1MTgsImRhdGEiOnsidXNlcl9pZCI6MSwiZW1haWwiOiJxd2VAaGFtbWVyLnRobSIsInJvbGUiOiJhZG1pbiJ9fQ.0MXIDMaLkmGmhMk_uViGRxvuNJHvqpBxlhpZXRprNgU
jwt-forge -decode eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6Ii9mb28vYmFyL2Jhei5rZXkifQ.eyJpc3MiOiJodHRwOi8vaGFtbWVyLnRobSIsImF1ZCI6Imh0dHA6Ly9oYW1tZXIudGhtIiwiaWF0IjoxNzg2OTE1OTE4LCJleHAiOjE3ODY5MTk1MTgsImRhdGEiOnsidXNlcl9pZCI6MSwiZW1haWwiOiJxd2VAaGFtbWVyLnRobSIsInJvbGUiOiJhZG1pbiJ9fQ.0MXIDMaLkmGmhMk_uViGRxvuNJHvqpBxlhpZXRprNgU
{"typ":"JWT","alg":"HS256","kid":"/foo/bar/baz.key"}
{"iss":"http://hammer.thm","aud":"http://hammer.thm","iat":1786915918,"exp":1786919518,"data":{"user_id":1,"email":"qwe@hammer.thm","role":"admin"}}
jwt-forge -decode eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6Ii9mb28vYmFyL2Jhei5rZXkifQ.eyJpc3MiOiJodHRwOi8vaGFtbWVyLnRobSIsImF1ZCI6Imh0dHA6Ly9oYW1tZXIudGhtIiwiaWF0IjoxNzg2OTE1OTE4LCJleHAiOjE3ODY5MTk1MTgsImRhdGEiOnsidXNlcl9pZCI6MSwiZW1haWwiOiJxd2VAaGFtbWVyLnRobSIsInJvbGUiOiJhZG1pbiJ9fQ.0MXIDMaLkmGmhMk_uViGRxvuNJHvqpBxlhpZXRprNgU -verify-secret zxc
{"typ":"JWT","alg":"HS256","kid":"/foo/bar/baz.key"}
{"iss":"http://hammer.thm","aud":"http://hammer.thm","iat":1786915918,"exp":1786919518,"data":{"user_id":1,"email":"qwe@hammer.thm","role":"admin"}}
error: signature: INVALID
jwt-forge -decode eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6Ii9mb28vYmFyL2Jhei5rZXkifQ.eyJpc3MiOiJodHRwOi8vaGFtbWVyLnRobSIsImF1ZCI6Imh0dHA6Ly9oYW1tZXIudGhtIiwiaWF0IjoxNzg2OTE1OTE4LCJleHAiOjE3ODY5MTk1MTgsImRhdGEiOnsidXNlcl9pZCI6MSwiZW1haWwiOiJxd2VAaGFtbWVyLnRobSIsInJvbGUiOiJhZG1pbiJ9fQ.0MXIDMaLkmGmhMk_uViGRxvuNJHvqpBxlhpZXRprNgU -verify-secret rty
{"typ":"JWT","alg":"HS256","kid":"/foo/bar/baz.key"}
{"iss":"http://hammer.thm","aud":"http://hammer.thm","iat":1786915918,"exp":1786919518,"data":{"user_id":1,"email":"qwe@hammer.thm","role":"admin"}}
signature: VALID