From 6bc8c3863595b65a046cc2dcc322fe1f12d340ed Mon Sep 17 00:00:00 2001 From: Siddharth Dushantha Date: Thu, 3 Sep 2020 11:14:43 +0200 Subject: [PATCH] Print found only by default As mentioned in #718, it would be more useful for the user of Sherlock to only get the results of the sites that return a positive result. With these new changes, if you want to all results to be printed out, then you can do that by using the --verbose flag. --- sherlock/notify.py | 46 +++++++++++++++++++++++--------------------- sherlock/sherlock.py | 8 +------- sherlock/sites.py | 4 +--- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/sherlock/notify.py b/sherlock/notify.py index c232a8cf..e87af14f 100644 --- a/sherlock/notify.py +++ b/sherlock/notify.py @@ -110,8 +110,7 @@ class QueryNotifyPrint(QueryNotify): Query notify class that prints results. """ - def __init__(self, result=None, verbose=False, print_found_only=False, - color=True): + def __init__(self, result=None, verbose=False, color=True): """Create Query Notify Print Object. Contains information about a specific method of notifying the results @@ -122,7 +121,6 @@ class QueryNotifyPrint(QueryNotify): result -- Object of type QueryResult() containing results for this query. verbose -- Boolean indicating whether to give verbose output. - print_found_only -- Boolean indicating whether to only print found sites. color -- Boolean indicating whether to color terminal output Return Value: @@ -134,7 +132,6 @@ class QueryNotifyPrint(QueryNotify): super().__init__(result) self.verbose = verbose - self.print_found_only = print_found_only self.color = color return @@ -185,7 +182,7 @@ class QueryNotifyPrint(QueryNotify): else: response_time_text = f" [{round(self.result.query_time * 1000)} ms]" - #Output to the terminal is desired. + # Output to the terminal is desired. if result.status == QueryStatus.CLAIMED: if self.color: print((Style.BRIGHT + Fore.WHITE + "[" + @@ -198,29 +195,33 @@ class QueryNotifyPrint(QueryNotify): f"{self.result.site_url_user}")) else: print(f"[+]{response_time_text} {self.result.site_name}: {self.result.site_url_user}") + elif result.status == QueryStatus.AVAILABLE: - if not self.print_found_only: + if self.verbose: if self.color: print((Style.BRIGHT + Fore.WHITE + "[" + - Fore.RED + "-" + - Fore.WHITE + "]" + - response_time_text + - Fore.GREEN + f" {self.result.site_name}:" + - Fore.YELLOW + " Not Found!")) + Fore.RED + "-" + + Fore.WHITE + "]" + + response_time_text + + Fore.GREEN + f" {self.result.site_name}:" + + Fore.YELLOW + " Not Found!")) else: print(f"[-]{response_time_text} {self.result.site_name}: Not Found!") + elif result.status == QueryStatus.UNKNOWN: - if self.color: - print(Style.BRIGHT + Fore.WHITE + "[" + - Fore.RED + "-" + - Fore.WHITE + "]" + - Fore.GREEN + f" {self.result.site_name}:" + - Fore.RED + f" {self.result.context}" + - Fore.YELLOW + f" ") - else: - print(f"[-] {self.result.site_name}: {self.result.context} ") + if self.verbose: + if self.color: + print(Style.BRIGHT + Fore.WHITE + "[" + + Fore.RED + "-" + + Fore.WHITE + "]" + + Fore.GREEN + f" {self.result.site_name}:" + + Fore.RED + f" {self.result.context}" + + Fore.YELLOW + f" ") + else: + print(f"[-] {self.result.site_name}: {self.result.context} ") + elif result.status == QueryStatus.ILLEGAL: - if not self.print_found_only: + if self.verbose: msg = "Illegal Username Format For This Site!" if self.color: print((Style.BRIGHT + Fore.WHITE + "[" + @@ -230,8 +231,9 @@ class QueryNotifyPrint(QueryNotify): Fore.YELLOW + f" {msg}")) else: print(f"[-] {self.result.site_name} {msg}") + else: - #It should be impossible to ever get here... + # It should be impossible to ever get here... raise ValueError(f"Unknown Query Status '{str(result.status)}' for " f"site '{self.result.site_name}'") diff --git a/sherlock/sherlock.py b/sherlock/sherlock.py index bf3ee1a3..bc17923d 100644 --- a/sherlock/sherlock.py +++ b/sherlock/sherlock.py @@ -475,10 +475,6 @@ def main(): "A longer timeout will be more likely to get results from slow sites." "On the other hand, this may cause a long delay to gather all results." ) - parser.add_argument("--print-found", - action="store_true", dest="print_found_only", default=False, - help="Do not output sites where the username was not found." - ) parser.add_argument("--no-color", action="store_true", dest="no_color", default=False, help="Don't color terminal output" @@ -583,13 +579,10 @@ def main(): #Create notify object for query results. query_notify = QueryNotifyPrint(result=None, verbose=args.verbose, - print_found_only=args.print_found_only, color=not args.no_color) # Run report on all specified users. for username in args.username: - print() - results = sherlock(username, site_data, query_notify, @@ -642,6 +635,7 @@ def main(): response_time_s ] ) + print() if __name__ == "__main__": diff --git a/sherlock/sites.py b/sherlock/sites.py index 797d34ce..6caafc36 100644 --- a/sherlock/sites.py +++ b/sherlock/sites.py @@ -115,9 +115,7 @@ class SitesInformation(): # Ensure that specified data file has correct extension. if not data_file_path.lower().endswith(".json"): - raise FileNotFoundError(f"Incorrect JSON file extension for " - f"data file '{data_file_path}'." - ) + raise FileNotFoundError(f"Incorrect JSON file extension for data file '{data_file_path}'.") if "http://" == data_file_path[:7].lower() or "https://" == data_file_path[:8].lower(): # Reference is to a URL.