diff --git a/.github/workflows/Testing.yml b/.github/workflows/Testing.yml index 2a32a11..1581e06 100644 --- a/.github/workflows/Testing.yml +++ b/.github/workflows/Testing.yml @@ -17,8 +17,14 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install Poetry + uses: snok/install-poetry@v1.3 + with: + virtualenvs-create: false + virtualenvs-in-project: false + - name: Install dependencies - run: pip install --upgrade -r requirements.txt + run: make setup - - name: Build - run: python -c "import dirMagic" + - name: Run build + run: make build \ No newline at end of file diff --git a/.gitignore b/.gitignore index 97a76c4..b9a8e58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,13 @@ directories_found.txt -.DS_Store +*.py[cod] +*$py.class +.pytest_cache +*egg-info +dist +.DS_STORE +__pycache__ + +.coverage +coverage.xml +.vscode/ +.idea \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..be4c16a --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +setup: ## Dependencies + poetry update + poetry install + poetry shell + +inspect: ## Run code analysis + poetry run flake8 dir_magic tests + +test: ## Run tests + poetry run pytest -vv --cov-report=xml --cov=dir_magic tests/ + +build: ## Run build + poetry build + +deploy: ## Deploy package + poetry config pypi-token.pypi $(token) + poetry build + poetry publish diff --git a/dir_magic/__main__.py b/dir_magic/__main__.py new file mode 100644 index 0000000..73b767f --- /dev/null +++ b/dir_magic/__main__.py @@ -0,0 +1,23 @@ +import sys +from dir_magic.header import Header +from dir_magic.dirMagic import DirMagic + +if __name__ == "__main__": + Header().setup() + dir_magic = DirMagic() + + print("1 - Find Directories") + print("2 - Find Subdomains \n") + + try: + item = input("Choose some of the options: ") + + if item == "1": + dir_magic.find_dir() + elif item == "2": + dir_magic.find_subdomains() + else: + print("This option does not exist") + except KeyboardInterrupt: + print("\n Bye!!!") + sys.exit() \ No newline at end of file diff --git a/dir_magic/dirMagic.py b/dir_magic/dirMagic.py index c2dd169..bcc3133 100644 --- a/dir_magic/dirMagic.py +++ b/dir_magic/dirMagic.py @@ -3,119 +3,87 @@ import dns.resolver from rich.console import Console -def header(): - print(r""" - _______ __ .______ .___ ___. ___ _______ __ ______ - | \ | | | _ \ | \/ | / \ / _____|| | / | - | .--. || | | |_) | | \ / | / ^ \ | | __ | | | ,----' - | | | || | | / | |\/| | / /_\ \ | | |_ | | | | | - | '--' || | | |\ \----. | | | | / _____ \ | |__| | | | | `----. - |_______/ |__| | _| `._____| |__| |__| /__/ \__\ \______| |__| \______| (1.1.1) - - About: DirMagic is a library written in Python to brute force directories and subdomains - Author: João Lucas - Language: Python - GitHub: https://github.com/heroesofcode/DirMagic - """) - -def find_dir(): - try: - print("\n") - url = input("URL: ") - wordlist = input("WordList: ") - - console = Console() - console.print("\n -------------- search .... --------------", style="#af00ff") - - all_results = [] - - with open(wordlist, "r") as file: - directories = file.readlines() - - for directory in directories: - directory = directory.strip() - response = requests.get(url + directory) - - if response.status_code != 404: - print("{} - {}".format(url + directory, response.status_code)) - all_results.append("{} - {}".format(url + directory, response.status_code)) - - with open("directories_found.txt", 'w') as file: - for item in all_results: - file.write("{}\n".format(item)) - - console.print("Saved in the directories_found.txt file", style="#008000") - except KeyboardInterrupt: - print("\n Bye!!!") - sys.exit() - except Exception as e: - print(f"An error happened: {e}") - sys.exit() - -def test_subdomain(subdomain): - try: - resolver = dns.resolver.Resolver() - responses = resolver.resolve(subdomain, "A") - return True - except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.NoNameservers): - return False - except Exception as e: - print(f"An error happened: {e}") - return False - -def find_subdomains(): - try: - print("\n") - domain = input("Domain: ") - wordlist = input("WordList: ") - - console = Console() - console.print("\n -------------- search --------------", style="#af00ff") - - all_results = [] - - with open(wordlist, "r") as file: - words = file.read().splitlines() - - for word in words: - subdomain = "{}.{}".format(word, domain) - - if test_subdomain(subdomain): - try: - response = requests.get("http://" + subdomain) - if response.status_code != 404: - print("{}".format(subdomain)) - all_results.append(subdomain) - except requests.RequestException as e: - print(f"Failed to request {subdomain}: {e}") - - with open("subdomains_found.txt", 'w') as file: - for item in all_results: - file.write("{}\n".format(item)) - - console.print("Saved in the subdomains_found.txt file", style="#008000") - except KeyboardInterrupt: - print("\n Bye!!!") - sys.exit() - except Exception as e: - print(f"An error happened: {e}") - sys.exit() - -if __name__ == "__main__": - header() - - print("1 - Find Directories") - print("2 - Find Subdomains \n") - - try: - item = input("Choose some of the options: ") - - if item == "1": - find_dir() - elif item == "2": - find_subdomains() - else: - print("This option does not exist") - except KeyboardInterrupt: - print("\n Bye!!!") - sys.exit() \ No newline at end of file +class DirMagic(object): + + def find_dir(self): + try: + print("\n") + url = input("URL: ") + wordlist = input("WordList: ") + + console = Console() + console.print("\n -------------- search .... --------------", style="#af00ff") + + all_results = [] + + with open(wordlist, "r") as file: + directories = file.readlines() + + for directory in directories: + directory = directory.strip() + response = requests.get(url + directory) + + if response.status_code != 404: + print("{} - {}".format(url + directory, response.status_code)) + all_results.append("{} - {}".format(url + directory, response.status_code)) + + with open("directories_found.txt", 'w') as file: + for item in all_results: + file.write("{}\n".format(item)) + + console.print("Saved in the directories_found.txt file", style="#008000") + except KeyboardInterrupt: + print("\n Bye!!!") + sys.exit() + except Exception as e: + print(f"An error happened: {e}") + sys.exit() + + def test_subdomain(self, subdomain): + try: + resolver = dns.resolver.Resolver() + responses = resolver.resolve(subdomain, "A") + return True + except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.NoNameservers): + return False + except Exception as e: + print(f"An error happened: {e}") + return False + + def find_subdomains(self): + try: + print("\n") + domain = input("Domain: ") + wordlist = input("WordList: ") + + console = Console() + console.print("\n -------------- search --------------", style="#af00ff") + + all_results = [] + + with open(wordlist, "r") as file: + words = file.read().splitlines() + + for word in words: + subdomain = "{}.{}".format(word, domain) + + if self.test_subdomain(subdomain): + try: + response = requests.get("http://" + subdomain) + if response.status_code != 404: + print("{}".format(subdomain)) + all_results.append(subdomain) + except requests.RequestException as e: + print(f"Failed to request {subdomain}: {e}") + + with open("subdomains_found.txt", 'w') as file: + for item in all_results: + file.write("{}\n".format(item)) + + console.print("Saved in the subdomains_found.txt file", style="#008000") + except KeyboardInterrupt: + print("\n Bye!!!") + sys.exit() + except Exception as e: + print(f"An error happened: {e}") + sys.exit() \ No newline at end of file diff --git a/dir_magic/header.py b/dir_magic/header.py new file mode 100644 index 0000000..153d848 --- /dev/null +++ b/dir_magic/header.py @@ -0,0 +1,16 @@ +class Header(object): + + def setup(self): + print(r""" + _______ __ .______ .___ ___. ___ _______ __ ______ + | \ | | | _ \ | \/ | / \ / _____|| | / | + | .--. || | | |_) | | \ / | / ^ \ | | __ | | | ,----' + | | | || | | / | |\/| | / /_\ \ | | |_ | | | | | + | '--' || | | |\ \----. | | | | / _____ \ | |__| | | | | `----. + |_______/ |__| | _| `._____| |__| |__| /__/ \__\ \______| |__| \______| (1.1.1) + + About: DirMagic is a library written in Python to brute force directories and subdomains + Author: João Lucas + Language: Python + GitHub: https://github.com/heroesofcode/DirMagic + """)