Guest User

Untitled

a guest
Jun 25th, 2023
1,525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import mitmproxy
  2. from mitmproxy import ctx
  3. from base64 import b64encode
  4.  
  5. origin_client_id = "5JHxEu-4wnFfBA"
  6. custom_client_id = "YOUR_CLIENT_ID_HERE"
  7.  
  8. authorize_url = f"reddit.com/api/v1/authorize?client_id={origin_client_id}"
  9. wanted_url = f"https://www.reddit.com/api/v1/authorize?client_id={custom_client_id}&response_type=code&state=RedditKit&redirect_uri=apollo://reddit-oauth&duration=permanent&scope=account,creddits,edit,flair,history,identity,livemanage,modconfig,modflair,modlog,modothers,modposts,modself,modwiki,mysubreddits,privatemessages,read,report,save,submit,subscribe,vote,wikiedit,wikiread,modcontributors,modtraffic,modmail,structuredstyles"
  10. access_token_url = "https://www.reddit.com/api/v1/access_token"
  11.  
  12. class FixApolloToken:
  13. def response(self, flow: mitmproxy.http.HTTPFlow):
  14. # check for the URL we want to intercept
  15. if authorize_url in flow.request.pretty_url:
  16. ctx.log.info("Intercepted log-in!")
  17. # replace Apollo's client ID with custom client ID by redirecting
  18. flow.response = mitmproxy.http.Response.make(
  19. 302, "", {"Location": wanted_url}
  20. )
  21.  
  22.  
  23. class RewriteBasicAuthUsername:
  24. def request(self, flow: mitmproxy.http.HTTPFlow):
  25. # check for the URL we want to intercept
  26. if flow.request.pretty_url == access_token_url:
  27. ctx.log.info("Intercepted token request!")
  28. # replace Apollo's client ID with custom client ID in the username field of the HTTP Basic auth header
  29. flow.request.headers["Authorization"] = f"Basic {b64encode(f'{custom_client_id}:'.encode()).decode()}"
  30.  
  31.  
  32. addons = [FixApolloToken(), RewriteBasicAuthUsername()]
  33.  
  34. # mitmweb -s mitmproxy_script.py
Add Comment
Please, Sign In to add comment