Created
June 24, 2023 08:27
-
-
Save fuegoblanco/e32bba444155ba4518d99887fe7ddd95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import hashlib | |
import base64 | |
import uuid | |
from art import * | |
def set_challenge(): | |
code_verifier = base64.urlsafe_b64encode(os.urandom(60)).decode('utf-8') | |
code_verifier = code_verifier.rstrip('=') | |
sha256_hash = hashlib.sha256(code_verifier.encode()).digest() | |
code_challenge = base64.urlsafe_b64encode(sha256_hash).decode('utf-8') | |
code_challenge = code_challenge.replace('=', '') | |
verifychall = 'verifier:\n' + code_verifier + '\n' + 'challenge:\n' + code_challenge | |
print(verifychall) | |
with open('challengeverifier.txt', 'w') as f: | |
f.write(verifychall) | |
def display_challenge(): | |
if os.path.exists('challengeverifier.txt'): | |
with open('challengeverifier.txt', 'r') as f: | |
print(f.read()) | |
else: | |
print("Challenge & Verifier not set\n\n\n\n\n") | |
def unset_challenge(): | |
if os.path.exists('challengeverifier.txt'): | |
os.remove('challengeverifier.txt') | |
else: | |
print("Challenge & Verifier not set") | |
def unset_auth_params(): | |
if os.path.exists('AUTHparams.txt'): | |
os.remove('AUTHparams.txt') | |
else: | |
print("AUTH Params not set") | |
def set_auth_params(): | |
client_id = input('client_id: ') | |
print('that neat number from the dev portal\n') | |
redirect_uri = input('redirect_uri: ') | |
print('https://the.same.url.u.gave.twitter.duh\n') | |
scope = input('scope: ') | |
print('tweet.write%20tweet.read%20users.read%20offline.access') | |
state = str(uuid.uuid4()) | |
with open('AUTHparams.txt', 'a') as file: | |
file.write(f"{client_id}\n") | |
file.write(f"{redirect_uri}\n") | |
file.write(f"{scope}\n") | |
file.write(f"{state}\n") | |
def display_auth_params(): | |
if os.path.exists('AUTHparams.txt'): | |
with open('AUTHparams.txt', 'r') as f: | |
lines = f.readlines() | |
if len(lines) >= 4: | |
client_id = lines[0].strip() | |
redirect_uri = lines[1].strip() | |
scope = lines[2].strip() | |
state = lines[3].strip() | |
print("client_id:", client_id) | |
print("redirect_uri:", redirect_uri) | |
print("scope:", scope) | |
print("state:", state) | |
else: | |
print("Incomplete AUTH params") | |
else: | |
print("AUTH params not set") | |
def generate_authorization_url(): | |
if os.path.exists('AUTHparams.txt'): | |
with open('AUTHparams.txt', 'r') as f: | |
client_id = f.readline().strip() | |
redirect_uri = f.readline().strip() | |
scope = f.readline().strip() | |
state = f.readline().strip() | |
code_challenge = base64.urlsafe_b64encode(os.urandom(60)).decode('utf-8') | |
code_challenge = code_challenge.rstrip('=') | |
url = 'https://twitter.com/i/oauth2/authorize' | |
url += '?response_type=code' | |
url += '&client_id=' + client_id | |
url += '&redirect_uri=' + redirect_uri | |
url += '&scope=' + scope | |
url += '&state=' + state | |
url += '&code_challenge=' + code_challenge | |
url += '&code_challenge_method=S256' | |
print('\nauth_url:\n\n' + url + '\n') | |
with open('AuthURL.txt', 'w') as f: | |
f.write(url) | |
else: | |
print("AUTH params not set") | |
def display_authorization_url(): | |
if os.path.exists('AuthURL.txt'): | |
with open('AuthURL.txt', 'r') as f: | |
print(f.read()) | |
else: | |
print("AuthURL not set") | |
def unset_auth_url(): | |
if os.path.exists('AuthURL.txt'): | |
os.remove('AuthURL.txt') | |
else: | |
print("AuthURL not set") | |
def display_menu(): | |
menu = """ | |
** URLS ** | |
1. Display Authorization URL | |
2. Generate Authorization URL | |
3. Remove Authorization URL | |
** URL PARAMS ** | |
4. Display AUTH URL Params | |
5. Set AUTH URL Params | |
6. Unset AUTH URL Params | |
** CHALLENGE ** | |
7. Display Challenge | |
8. Set Challenge | |
9. Unset Challenge | |
69. exit | |
enter option 1-69: """ | |
appname = text2art(' '+"0AUTH\n"+' '+'BIRD\n'+' '+"RANGLER",font='tinker-toy',chr_ignore=True) | |
print(appname) | |
return input(menu) | |
def main(): | |
while True: | |
choice = display_menu() | |
if choice == '9': | |
display_challenge() | |
elif choice == '8': | |
set_challenge() | |
elif choice == '7': | |
unset_challenge() | |
elif choice == '4': | |
display_auth_params() | |
elif choice == '5': | |
set_auth_params() | |
elif choice == '6': | |
unset_auth_params() | |
elif choice == '3': | |
generate_authorization_url() | |
elif choice == '2': | |
display_authorization_url() | |
elif choice == '1': | |
unset_auth_url() | |
elif choice == '69': | |
break | |
else: | |
print("Invalid choice. Please try again.") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment