diff --git a/HashmobAPI.py b/HashmobAPI.py index 2b2ac84..31ad83b 100644 --- a/HashmobAPI.py +++ b/HashmobAPI.py @@ -1,4 +1,4 @@ -from configparser import ConfigParser +from configparser import ConfigParser, DuplicateSectionError from pathlib import Path import logging import requests @@ -7,8 +7,7 @@ import time CONFIG_PATH = 'hashmob_config.ini' -POTFILE_PATH = 'hashcat.potfile' -API_ENDPOINT = 'https://hashmob.net/api/v2/submit' +DEFAULT_API_ENDPOINT = 'https://hashmob.net/api/v2/submit' def setup(): @@ -74,14 +73,27 @@ def main(): # Use defined config or ask for defaults on first time try: + api_endpoint = config['API']['api_endpoint'] + except KeyError: + try: + config.add_section('API') + except DuplicateSectionError: + pass + + # We're here because no api_endpoint was defined, so don't need to worry about overwriting it + config['API']['api_endpoint'] = DEFAULT_API_ENDPOINT + api_endpoint = DEFAULT_API_ENDPOINT + + try: + # If we've got this far, we can safely assume the API section exists api_key = config['API']['api_key'] - resubmission_delay = int(config['API']['resubmission_delay']) except KeyError: - config.add_section('API') - api_key = input("Enter your API key: ") config['API']['api_key'] = api_key + try: + resubmission_delay = int(config['API']['resubmission_delay']) + except KeyError: while not (resubmission_delay := input("Enter the delay between resubmissions in seconds: ")).isdigit(): print('Please provide an integer for the delay!') @@ -116,7 +128,7 @@ def main(): # Upload data to API try: - response = upload_to_api(data, API_ENDPOINT, api_key) + response = upload_to_api(data, api_endpoint, api_key) if response.status_code == 200: logging.info('Successfully sent new finds!') previous_size = os.path.getsize(potfile_path) @@ -128,6 +140,7 @@ def main(): else: logging.error(f'Failed to send new finds! We were given a status code of {response.status_code}. ' 'Retrying after resubmission delay...') + time.sleep(resubmission_delay) except Exception as e: logging.error(f'Error encountered when trying to send new finds: {e}') diff --git a/README.md b/README.md index a271f0a..f4db087 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This Python script allows you to parse a `hashcat.potfile`, convert its contents Before using this script, ensure you have the following installed: - Python 3 -- Requests library (install via `pip install requests`) +- Requests library (install via `pip install -r requirements.txt`) ## Usage @@ -17,20 +17,19 @@ Before using this script, ensure you have the following installed: 3. Run the script using the following command: -python hashcat_parser.py +python HashmobAPI.py /path/to/hashcat.potfile 4. Follow the prompts to enter the required information: -- Path to the `hashcat.potfile` -- Path for the JSON output file -- API endpoint URL - API key -- Value for the 'algorithm' - Delay between resubmissions in seconds +- Value for the 'algorithm' (i.e. hashcat mode number) 5. The script will continuously monitor the `hashcat.potfile`, converting its contents into JSON format and uploading them to the specified API endpoint. It will wait for the specified delay between resubmissions. -**Note:** This script was written to submit hashes to Hashmob.net's API and does not currently support salted submissions, though their API does. +**Note 1:** This script was written to submit hashes to Hashmob.net's API and does not currently support salted submissions, though their API does. + +**Note 2:** The API endpoint can be modified in the `hashmob_config.ini` file created on first run. ## Contributing diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests