diff --git a/sherlock_project/notify.py b/sherlock_project/notify.py index f6c785d63f..cb8c788059 100644 --- a/sherlock_project/notify.py +++ b/sherlock_project/notify.py @@ -20,7 +20,7 @@ class QueryNotify: override the methods to implement specific functionality. """ - def __init__(self, result=None): + def __init__(self, result: None=None) -> None: """Create Query Notify Object. Contains information about a specific method of notifying the results @@ -39,7 +39,7 @@ def __init__(self, result=None): # return - def start(self, message=None): + def start(self, message: None=None) -> None: """Notify Start. Notify method for start of query. This method will be called before @@ -58,7 +58,7 @@ def start(self, message=None): # return - def update(self, result): + def update(self, result: "QueryResult") -> None: """Notify Update. Notify method for query result. This method will typically be @@ -77,7 +77,7 @@ def update(self, result): # return - def finish(self, message=None): + def finish(self, message: None=None) -> None: """Notify Finish. Notify method for finish of query. This method will be called after @@ -114,7 +114,7 @@ class QueryNotifyPrint(QueryNotify): Query notify class that prints results. """ - def __init__(self, result=None, verbose=False, print_all=False, browse=False): + def __init__(self, result: None=None, verbose: bool=False, print_all: bool=False, browse: bool=False) -> None: """Create Query Notify Print Object. Contains information about a specific method of notifying the results @@ -139,7 +139,7 @@ def __init__(self, result=None, verbose=False, print_all=False, browse=False): return - def start(self, message): + def start(self, message: str) -> None: """Notify Start. Will print the title to the standard output. @@ -165,7 +165,7 @@ def start(self, message): return - def countResults(self): + def countResults(self) -> int: """This function counts the number of results. Every time the function is called, the number of results is increasing. @@ -179,7 +179,7 @@ def countResults(self): globvar += 1 return globvar - def update(self, result): + def update(self, result) -> None: """Notify Update. Will print the query result to the standard output. @@ -256,7 +256,7 @@ def update(self, result): return - def finish(self, message="The processing has been finished."): + def finish(self, message: str="The processing has been finished.") -> None: """Notify Start. Will print the last line to the standard output. Keyword Arguments: diff --git a/sherlock_project/result.py b/sherlock_project/result.py index c4d68b1c88..bfd5525c9e 100644 --- a/sherlock_project/result.py +++ b/sherlock_project/result.py @@ -16,7 +16,7 @@ class QueryStatus(Enum): ILLEGAL = "Illegal" # Username Not Allowable For This Site WAF = "WAF" # Request blocked by WAF (i.e. Cloudflare) - def __str__(self): + def __str__(self) -> str: """Convert Object To String. Keyword Arguments: @@ -32,8 +32,9 @@ class QueryResult(): Describes result of query about a given username. """ - def __init__(self, username, site_name, site_url_user, status, - query_time=None, context=None): + def __init__(self, username: str, site_name: str, site_url_user: str, + status: "QueryStatus", + query_time: None=None, context: None=None) -> None: """Create Query Result Object. Contains information about a specific method of detecting usernames on diff --git a/sherlock_project/sherlock.py b/sherlock_project/sherlock.py index f78d4b8cac..1a3607130a 100644 --- a/sherlock_project/sherlock.py +++ b/sherlock_project/sherlock.py @@ -18,13 +18,14 @@ import csv import signal +import logging import pandas as pd import os import re from argparse import ArgumentParser, RawDescriptionHelpFormatter from json import loads as json_loads from time import monotonic -from typing import Optional +from typing import Any, Optional import requests from requests_futures.sessions import FuturesSession @@ -46,7 +47,8 @@ class SherlockFuturesSession(FuturesSession): - def request(self, method, url, hooks=None, *args, **kwargs): + def request(self, method: str, url: str, hooks: None = None, + *args: Any, **kwargs: Any) -> requests.Response: """Request URL. This extends the FuturesSession request method to calculate a response @@ -72,7 +74,7 @@ def request(self, method, url, hooks=None, *args, **kwargs): hooks = {} start = monotonic() - def response_time(resp, *args, **kwargs): + def response_time(resp: requests.Response, *args: Any, **kwargs: Any) -> None: """Response Time Hook. Keyword Arguments: @@ -150,19 +152,19 @@ def interpolate_string(input_object, username): return input_object -def check_for_parameter(username): +def check_for_parameter(username: str) -> bool: """checks if {?} exists in the username if exist it means that sherlock is looking for more multiple username""" return "{?}" in username -checksymbols = ["_", "-", "."] +CHECKSYMBOLS = ["_", "-", "."] -def multiple_usernames(username): +def multiple_usernames(username: str) -> list[str]: """replace the parameter with with symbols and return a list of usernames""" allUsernames = [] - for i in checksymbols: + for i in CHECKSYMBOLS: allUsernames.append(username.replace("{?}", i)) return allUsernames @@ -459,21 +461,21 @@ def sherlock( try: print(f"STATUS CODES : {net_info['errorCode']}") except KeyError: - pass + logging.debug("errorCode not present in net_info") print("Results...") try: print(f"RESPONSE CODE : {r.status_code}") - except Exception: - pass + except Exception as e: + logging.debug(f"Could not print response code: {e}") try: print(f"ERROR TEXT : {net_info['errorMsg']}") except KeyError: - pass + logging.debug("errorMsg not present in net_info") print(">>>>> BEGIN RESPONSE TEXT") try: print(r.text) - except Exception: - pass + except Exception as e: + logging.debug(f"Could not print response text: {e}") print("<<<<< END RESPONSE TEXT") print("VERDICT : " + str(query_status)) print("+++++++++++++++++++++") @@ -502,7 +504,7 @@ def sherlock( return results_total -def timeout_check(value): +def timeout_check(value: float) -> float: """Check Timeout Argument. Checks timeout for validity. @@ -527,7 +529,7 @@ def timeout_check(value): return float_value -def handler(signal_received, frame): +def handler(_signal_received, frame) -> None: """Exit gracefully without throwing errors Source: https://www.devdungeon.com/content/python-catch-sigint-ctrl-c @@ -535,7 +537,7 @@ def handler(signal_received, frame): sys.exit(0) -def main(): +def main() -> None: parser = ArgumentParser( formatter_class=RawDescriptionHelpFormatter, description=f"{__longname__} (Version {__version__})", diff --git a/sherlock_project/sites.py b/sherlock_project/sites.py index b7aaf4c58b..3555ae2614 100644 --- a/sherlock_project/sites.py +++ b/sherlock_project/sites.py @@ -4,6 +4,7 @@ This is the raw data that will be used to search for usernames. """ import json +import logging import requests import secrets @@ -12,8 +13,9 @@ EXCLUSIONS_URL = "https://raw.githubusercontent.com/sherlock-project/sherlock/refs/heads/exclusions/false_positive_exclusions.txt" class SiteInformation: - def __init__(self, name, url_home, url_username_format, username_claimed, - information, is_nsfw, username_unclaimed=secrets.token_urlsafe(10)): + def __init__(self, name: str, url_home: str, url_username_format: str, + username_claimed: str, information: dict, is_nsfw: bool, + username_unclaimed: str = secrets.token_urlsafe(10)) -> None: """Create Site Information Object. Contains information about a specific website. @@ -56,7 +58,7 @@ def __init__(self, name, url_home, url_username_format, username_claimed, self.url_username_format = url_username_format self.username_claimed = username_claimed - self.username_unclaimed = secrets.token_urlsafe(32) + self.username_unclaimed = username_unclaimed self.information = information self.is_nsfw = is_nsfw @@ -81,7 +83,7 @@ def __init__( data_file_path: str|None = None, honor_exclusions: bool = True, do_not_exclude: list[str] = [], - ): + ) -> None: """Create Sites Information Object. Contains information about all supported websites. @@ -179,7 +181,7 @@ def __init__( try: site_data.pop(exclusion, None) except KeyError: - pass + logging.debug(f"Exclusion '{exclusion}' not in site_data") except Exception: # If there was any problem loading the exclusions, just continue without them @@ -210,7 +212,7 @@ def __init__( return - def remove_nsfw_sites(self, do_not_remove: list = []): + def remove_nsfw_sites(self, do_not_remove: list = []) -> None: """ Remove NSFW sites from the sites, if isNSFW flag is true for site