Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions sherlock_project/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions sherlock_project/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
34 changes: 18 additions & 16 deletions sherlock_project/sherlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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("+++++++++++++++++++++")
Expand Down Expand Up @@ -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.
Expand All @@ -527,15 +529,15 @@ 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
"""
sys.exit(0)


def main():
def main() -> None:
parser = ArgumentParser(
formatter_class=RawDescriptionHelpFormatter,
description=f"{__longname__} (Version {__version__})",
Expand Down
14 changes: 8 additions & 6 deletions sherlock_project/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down