From ae2fd7a729211c6484ee1c463183fe12d9ca79a0 Mon Sep 17 00:00:00 2001 From: "Christopher K. Hoadley" Date: Sun, 19 Apr 2020 15:41:59 -0500 Subject: [PATCH] Add username and site information to Query Result object. This will allow whoever defines a Query Notify object to have all of the context required to do their notifications. --- sherlock/result.py | 19 +++++++++++++++---- sherlock/sherlock.py | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/sherlock/result.py b/sherlock/result.py index 97acfa9c..3c33ba9c 100644 --- a/sherlock/result.py +++ b/sherlock/result.py @@ -31,7 +31,8 @@ class QueryResult(): Describes result of query about a given username. """ - def __init__(self, status, query_time=None, context=None): + def __init__(self, username, site_name, site_url_user, status, + query_time=None, context=None): """Create Query Result Object. Contains information about a specific method of detecting usernames on @@ -39,6 +40,13 @@ class QueryResult(): Keyword Arguments: self -- This object. + username -- String indicating username that query result + was about. + site_name -- String which identifies site. + site_url_user -- String containing URL for username on site. + NOTE: The site may or may not exist: this + just indicates what the name would + be, if it existed. status -- Enumeration of type QueryStatus() indicating the status of the query. query_time -- Time (in seconds) required to perform query. @@ -53,9 +61,12 @@ class QueryResult(): Nothing. """ - self.status = status - self.query_time = query_time - self.context = context + self.username = username + self.site_name = site_name + self.site_url_user = site_url_user + self.status = status + self.query_time = query_time + self.context = context return diff --git a/sherlock/sherlock.py b/sherlock/sherlock.py index 65ff62dc..658c20dd 100644 --- a/sherlock/sherlock.py +++ b/sherlock/sherlock.py @@ -274,6 +274,9 @@ def sherlock(username, site_data, query_notify, verbose=False, # Override/append any extra headers required by a given site. headers.update(net_info["headers"]) + # URL of user on site (if it exists) + url = net_info["url"].format(username) + # Don't make request if username is invalid for the site regex_check = net_info.get("regexCheck") if regex_check and re.search(regex_check, username) is None: @@ -281,14 +284,16 @@ def sherlock(username, site_data, query_notify, verbose=False, if (print_output == True) and not print_found_only: print_invalid(social_network, "Illegal Username Format For This Site!", color) - results_site['status'] = QueryResult(QueryStatus.ILLEGAL) + results_site['status'] = QueryResult(username, + social_network, + url, + QueryStatus.ILLEGAL) results_site["url_user"] = "" results_site['http_status'] = "" results_site['response_text'] = "" query_notify.update(results_site['status']) else: # URL of user on site (if it exists) - url = net_info["url"].format(username) results_site["url_user"] = url url_probe = net_info.get("urlProbe") if url_probe is None: @@ -381,25 +386,40 @@ def sherlock(username, site_data, query_notify, verbose=False, response_text = "" if error_text is not None: - result = QueryResult(QueryStatus.UNKNOWN, + result = QueryResult(username, + social_network, + url, + QueryStatus.UNKNOWN, query_time=response_time, context=error_text) elif error_type == "message": error = net_info.get("errorMsg") # Checks if the error message is in the HTML if not error in r.text: - result = QueryResult(QueryStatus.CLAIMED, + result = QueryResult(username, + social_network, + url, + QueryStatus.CLAIMED, query_time=response_time) else: - result = QueryResult(QueryStatus.AVAILABLE, + result = QueryResult(username, + social_network, + url, + QueryStatus.AVAILABLE, query_time=response_time) elif error_type == "status_code": # Checks if the status code of the response is 2XX if not r.status_code >= 300 or r.status_code < 200: - result = QueryResult(QueryStatus.CLAIMED, + result = QueryResult(username, + social_network, + url, + QueryStatus.CLAIMED, query_time=response_time) else: - result = QueryResult(QueryStatus.AVAILABLE, + result = QueryResult(username, + social_network, + url, + QueryStatus.AVAILABLE, query_time=response_time) elif error_type == "response_url": # For this detection method, we have turned off the redirect. @@ -408,10 +428,16 @@ def sherlock(username, site_data, query_notify, verbose=False, # code indicates that the request was successful (i.e. no 404, or # forward to some odd redirect). if 200 <= r.status_code < 300: - result = QueryResult(QueryStatus.CLAIMED, + result = QueryResult(username, + social_network, + url, + QueryStatus.CLAIMED, query_time=response_time) else: - result = QueryResult(QueryStatus.AVAILABLE, + result = QueryResult(username, + social_network, + url, + QueryStatus.AVAILABLE, query_time=response_time) else: #It should be impossible to ever get here...