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.

pull/590/head
Christopher K. Hoadley 5 years ago
parent c07d3967aa
commit ae2fd7a729

@ -31,7 +31,8 @@ class QueryResult():
Describes result of query about a given username. 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. """Create Query Result Object.
Contains information about a specific method of detecting usernames on Contains information about a specific method of detecting usernames on
@ -39,6 +40,13 @@ class QueryResult():
Keyword Arguments: Keyword Arguments:
self -- This object. 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 status -- Enumeration of type QueryStatus() indicating
the status of the query. the status of the query.
query_time -- Time (in seconds) required to perform query. query_time -- Time (in seconds) required to perform query.
@ -53,9 +61,12 @@ class QueryResult():
Nothing. Nothing.
""" """
self.status = status self.username = username
self.query_time = query_time self.site_name = site_name
self.context = context self.site_url_user = site_url_user
self.status = status
self.query_time = query_time
self.context = context
return return

@ -274,6 +274,9 @@ def sherlock(username, site_data, query_notify, verbose=False,
# Override/append any extra headers required by a given site. # Override/append any extra headers required by a given site.
headers.update(net_info["headers"]) 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 # Don't make request if username is invalid for the site
regex_check = net_info.get("regexCheck") regex_check = net_info.get("regexCheck")
if regex_check and re.search(regex_check, username) is None: 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: if (print_output == True) and not print_found_only:
print_invalid(social_network, "Illegal Username Format For This Site!", color) 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["url_user"] = ""
results_site['http_status'] = "" results_site['http_status'] = ""
results_site['response_text'] = "" results_site['response_text'] = ""
query_notify.update(results_site['status']) query_notify.update(results_site['status'])
else: else:
# URL of user on site (if it exists) # URL of user on site (if it exists)
url = net_info["url"].format(username)
results_site["url_user"] = url results_site["url_user"] = url
url_probe = net_info.get("urlProbe") url_probe = net_info.get("urlProbe")
if url_probe is None: if url_probe is None:
@ -381,25 +386,40 @@ def sherlock(username, site_data, query_notify, verbose=False,
response_text = "" response_text = ""
if error_text is not None: if error_text is not None:
result = QueryResult(QueryStatus.UNKNOWN, result = QueryResult(username,
social_network,
url,
QueryStatus.UNKNOWN,
query_time=response_time, query_time=response_time,
context=error_text) context=error_text)
elif error_type == "message": elif error_type == "message":
error = net_info.get("errorMsg") error = net_info.get("errorMsg")
# Checks if the error message is in the HTML # Checks if the error message is in the HTML
if not error in r.text: if not error in r.text:
result = QueryResult(QueryStatus.CLAIMED, result = QueryResult(username,
social_network,
url,
QueryStatus.CLAIMED,
query_time=response_time) query_time=response_time)
else: else:
result = QueryResult(QueryStatus.AVAILABLE, result = QueryResult(username,
social_network,
url,
QueryStatus.AVAILABLE,
query_time=response_time) query_time=response_time)
elif error_type == "status_code": elif error_type == "status_code":
# Checks if the status code of the response is 2XX # Checks if the status code of the response is 2XX
if not r.status_code >= 300 or r.status_code < 200: 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) query_time=response_time)
else: else:
result = QueryResult(QueryStatus.AVAILABLE, result = QueryResult(username,
social_network,
url,
QueryStatus.AVAILABLE,
query_time=response_time) query_time=response_time)
elif error_type == "response_url": elif error_type == "response_url":
# For this detection method, we have turned off the redirect. # 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 # code indicates that the request was successful (i.e. no 404, or
# forward to some odd redirect). # forward to some odd redirect).
if 200 <= r.status_code < 300: if 200 <= r.status_code < 300:
result = QueryResult(QueryStatus.CLAIMED, result = QueryResult(username,
social_network,
url,
QueryStatus.CLAIMED,
query_time=response_time) query_time=response_time)
else: else:
result = QueryResult(QueryStatus.AVAILABLE, result = QueryResult(username,
social_network,
url,
QueryStatus.AVAILABLE,
query_time=response_time) query_time=response_time)
else: else:
#It should be impossible to ever get here... #It should be impossible to ever get here...

Loading…
Cancel
Save