You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
287 lines
8.8 KiB
287 lines
8.8 KiB
5 years ago
|
"""Sherlock Notify Module
|
||
|
|
||
|
This module defines the objects for notifying the caller about the
|
||
|
results of queries.
|
||
|
"""
|
||
6 months ago
|
from sherlock_project.result import QueryStatus
|
||
3 years ago
|
from colorama import Fore, Style
|
||
2 years ago
|
import webbrowser
|
||
2 years ago
|
|
||
|
# Global variable to count the number of results.
|
||
|
globvar = 0
|
||
|
|
||
5 years ago
|
|
||
3 years ago
|
class QueryNotify:
|
||
5 years ago
|
"""Query Notify Object.
|
||
|
|
||
|
Base class that describes methods available to notify the results of
|
||
|
a query.
|
||
|
It is intended that other classes inherit from this base class and
|
||
|
override the methods to implement specific functionality.
|
||
|
"""
|
||
3 years ago
|
|
||
5 years ago
|
def __init__(self, result=None):
|
||
|
"""Create Query Notify Object.
|
||
|
|
||
|
Contains information about a specific method of notifying the results
|
||
|
of a query.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
result -- Object of type QueryResult() containing
|
||
|
results for this query.
|
||
|
|
||
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
|
|
||
|
self.result = result
|
||
|
|
||
3 years ago
|
# return
|
||
5 years ago
|
|
||
5 years ago
|
def start(self, message=None):
|
||
|
"""Notify Start.
|
||
|
|
||
|
Notify method for start of query. This method will be called before
|
||
|
any queries are performed. This method will typically be
|
||
|
overridden by higher level classes that will inherit from it.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
message -- Object that is used to give context to start
|
||
|
of query.
|
||
|
Default is None.
|
||
|
|
||
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
|
|
||
2 years ago
|
# return
|
||
5 years ago
|
|
||
5 years ago
|
def update(self, result):
|
||
|
"""Notify Update.
|
||
|
|
||
|
Notify method for query result. This method will typically be
|
||
|
overridden by higher level classes that will inherit from it.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
result -- Object of type QueryResult() containing
|
||
|
results for this query.
|
||
|
|
||
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
|
|
||
|
self.result = result
|
||
|
|
||
3 years ago
|
# return
|
||
5 years ago
|
|
||
5 years ago
|
def finish(self, message=None):
|
||
|
"""Notify Finish.
|
||
|
|
||
|
Notify method for finish of query. This method will be called after
|
||
|
all queries have been performed. This method will typically be
|
||
|
overridden by higher level classes that will inherit from it.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
message -- Object that is used to give context to start
|
||
|
of query.
|
||
|
Default is None.
|
||
|
|
||
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
|
|
||
3 years ago
|
# return
|
||
5 years ago
|
|
||
5 years ago
|
def __str__(self):
|
||
|
"""Convert Object To String.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
|
||
|
Return Value:
|
||
|
Nicely formatted string to get information about this object.
|
||
|
"""
|
||
2 years ago
|
return str(self.result)
|
||
|
|
||
5 years ago
|
|
||
|
class QueryNotifyPrint(QueryNotify):
|
||
|
"""Query Notify Print Object.
|
||
|
|
||
|
Query notify class that prints results.
|
||
|
"""
|
||
3 years ago
|
|
||
2 years ago
|
def __init__(self, result=None, verbose=False, print_all=False, browse=False):
|
||
5 years ago
|
"""Create Query Notify Print Object.
|
||
|
|
||
|
Contains information about a specific method of notifying the results
|
||
|
of a query.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
result -- Object of type QueryResult() containing
|
||
|
results for this query.
|
||
|
verbose -- Boolean indicating whether to give verbose output.
|
||
4 years ago
|
print_all -- Boolean indicating whether to only print all sites, including not found.
|
||
2 years ago
|
browse -- Boolean indicating whether to open found sites in a web browser.
|
||
5 years ago
|
|
||
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
|
|
||
|
super().__init__(result)
|
||
|
self.verbose = verbose
|
||
4 years ago
|
self.print_all = print_all
|
||
2 years ago
|
self.browse = browse
|
||
5 years ago
|
|
||
|
return
|
||
2 years ago
|
|
||
5 years ago
|
def start(self, message):
|
||
|
"""Notify Start.
|
||
|
|
||
|
Will print the title to the standard output.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
message -- String containing username that the series
|
||
|
of queries are about.
|
||
|
|
||
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
|
|
||
|
title = "Checking username"
|
||
3 years ago
|
|
||
3 years ago
|
print(Style.BRIGHT + Fore.GREEN + "[" +
|
||
|
Fore.YELLOW + "*" +
|
||
|
Fore.GREEN + f"] {title}" +
|
||
|
Fore.WHITE + f" {message}" +
|
||
|
Fore.GREEN + " on:")
|
||
3 years ago
|
# An empty line between first line and the result(more clear output)
|
||
|
print('\r')
|
||
5 years ago
|
|
||
|
return
|
||
|
|
||
3 years ago
|
def countResults(self):
|
||
2 years ago
|
"""This function counts the number of results. Every time the function is called,
|
||
3 years ago
|
the number of results is increasing.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
|
||
|
Return Value:
|
||
|
The number of results by the time we call the function.
|
||
|
"""
|
||
|
global globvar
|
||
|
globvar += 1
|
||
|
return globvar
|
||
2 years ago
|
|
||
5 years ago
|
def update(self, result):
|
||
|
"""Notify Update.
|
||
|
|
||
|
Will print the query result to the standard output.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
result -- Object of type QueryResult() containing
|
||
|
results for this query.
|
||
|
|
||
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
|
self.result = result
|
||
|
|
||
3 years ago
|
response_time_text = ""
|
||
2 years ago
|
if self.result.query_time is not None and self.verbose is True:
|
||
3 years ago
|
response_time_text = f" [{round(self.result.query_time * 1000)}ms]"
|
||
2 years ago
|
|
||
4 years ago
|
# Output to the terminal is desired.
|
||
5 years ago
|
if result.status == QueryStatus.CLAIMED:
|
||
3 years ago
|
self.countResults()
|
||
3 years ago
|
print(Style.BRIGHT + Fore.WHITE + "[" +
|
||
|
Fore.GREEN + "+" +
|
||
|
Fore.WHITE + "]" +
|
||
|
response_time_text +
|
||
|
Fore.GREEN +
|
||
|
f" {self.result.site_name}: " +
|
||
|
Style.RESET_ALL +
|
||
2 years ago
|
f"{self.result.site_url_user}")
|
||
2 years ago
|
if self.browse:
|
||
2 years ago
|
webbrowser.open(self.result.site_url_user, 2)
|
||
4 years ago
|
|
||
5 years ago
|
elif result.status == QueryStatus.AVAILABLE:
|
||
4 years ago
|
if self.print_all:
|
||
3 years ago
|
print(Style.BRIGHT + Fore.WHITE + "[" +
|
||
|
Fore.RED + "-" +
|
||
|
Fore.WHITE + "]" +
|
||
|
response_time_text +
|
||
|
Fore.GREEN + f" {self.result.site_name}:" +
|
||
|
Fore.YELLOW + " Not Found!")
|
||
4 years ago
|
|
||
5 years ago
|
elif result.status == QueryStatus.UNKNOWN:
|
||
4 years ago
|
if self.print_all:
|
||
3 years ago
|
print(Style.BRIGHT + Fore.WHITE + "[" +
|
||
8 months ago
|
Fore.RED + "-" +
|
||
3 years ago
|
Fore.WHITE + "]" +
|
||
|
Fore.GREEN + f" {self.result.site_name}:" +
|
||
|
Fore.RED + f" {self.result.context}" +
|
||
2 years ago
|
Fore.YELLOW + " ")
|
||
4 years ago
|
|
||
5 years ago
|
elif result.status == QueryStatus.ILLEGAL:
|
||
4 years ago
|
if self.print_all:
|
||
5 years ago
|
msg = "Illegal Username Format For This Site!"
|
||
3 years ago
|
print(Style.BRIGHT + Fore.WHITE + "[" +
|
||
|
Fore.RED + "-" +
|
||
|
Fore.WHITE + "]" +
|
||
|
Fore.GREEN + f" {self.result.site_name}:" +
|
||
|
Fore.YELLOW + f" {msg}")
|
||
8 months ago
|
|
||
|
elif result.status == QueryStatus.WAF:
|
||
|
if self.print_all:
|
||
|
print(Style.BRIGHT + Fore.WHITE + "[" +
|
||
8 months ago
|
Fore.RED + "-" +
|
||
8 months ago
|
Fore.WHITE + "]" +
|
||
|
Fore.GREEN + f" {self.result.site_name}:" +
|
||
8 months ago
|
Fore.RED + " Blocked by bot detection" +
|
||
|
Fore.YELLOW + " (proxy may help)")
|
||
4 years ago
|
|
||
5 years ago
|
else:
|
||
4 years ago
|
# It should be impossible to ever get here...
|
||
3 years ago
|
raise ValueError(
|
||
|
f"Unknown Query Status '{result.status}' for site '{self.result.site_name}'"
|
||
|
)
|
||
5 years ago
|
|
||
|
return
|
||
2 years ago
|
|
||
3 years ago
|
def finish(self, message="The processing has been finished."):
|
||
|
"""Notify Start.
|
||
|
Will print the last line to the standard output.
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
3 years ago
|
message -- The 2 last phrases.
|
||
3 years ago
|
Return Value:
|
||
|
Nothing.
|
||
|
"""
|
||
3 years ago
|
NumberOfResults = self.countResults() - 1
|
||
3 years ago
|
|
||
|
print(Style.BRIGHT + Fore.GREEN + "[" +
|
||
|
Fore.YELLOW + "*" +
|
||
2 years ago
|
Fore.GREEN + "] Search completed with" +
|
||
|
Fore.WHITE + f" {NumberOfResults} " +
|
||
|
Fore.GREEN + "results" + Style.RESET_ALL
|
||
|
)
|
||
5 years ago
|
|
||
|
def __str__(self):
|
||
|
"""Convert Object To String.
|
||
|
|
||
|
Keyword Arguments:
|
||
|
self -- This object.
|
||
|
|
||
|
Return Value:
|
||
|
Nicely formatted string to get information about this object.
|
||
|
"""
|
||
2 years ago
|
return str(self.result)
|