Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(format): reformat codebase using Black #2406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Format Code

on: [pull_request]

jobs:
black-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install Black
run: pip install black

- name: Run Black
run: black --check .
7 changes: 4 additions & 3 deletions devel/site-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Removes schema-specific keywords for proper processing
social_networks: dict = dict(data)
social_networks.pop('$schema', None)
social_networks.pop("$schema", None)

# Sort the social networks in alphanumeric order
social_networks: list = sorted(social_networks.items())
Expand All @@ -23,7 +23,9 @@

# Write the list of supported sites to sites.md
with open("output/sites.mdx", "w") as site_file:
site_file.write("---\ntitle: 'List of supported sites'\nsidebarTitle: 'Supported sites'\nicon: 'globe'\ndescription: 'Sherlock currently supports **400+** sites'\n---\n\n")
site_file.write(
"---\ntitle: 'List of supported sites'\nsidebarTitle: 'Supported sites'\nicon: 'globe'\ndescription: 'Sherlock currently supports **400+** sites'\n---\n\n"
)
for social_network, info in social_networks:
url_main = info["urlMain"]
is_nsfw = "**(NSFW)**" if info.get("isNSFW") else ""
Expand All @@ -36,4 +38,3 @@
data_file.write("\n")

print("Finished updating supported site listing!")

12 changes: 7 additions & 5 deletions sherlock_project/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Sherlock Module
"""Sherlock Module

This module contains the main logic to search for usernames at social
networks.
Expand All @@ -8,8 +8,10 @@
# This variable is only used to check for ImportErrors induced by users running as script rather than as module or package
import_error_test_var = None

__shortname__ = "Sherlock"
__longname__ = "Sherlock: Find Usernames Across Social Networks"
__version__ = "0.15.0"
__shortname__ = "Sherlock"
__longname__ = "Sherlock: Find Usernames Across Social Networks"
__version__ = "0.15.0"

forge_api_latest_release = "https://api.github.com/repos/sherlock-project/sherlock/releases/latest"
forge_api_latest_release = (
"https://api.github.com/repos/sherlock-project/sherlock/releases/latest"
)
5 changes: 4 additions & 1 deletion sherlock_project/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
python_version = sys.version.split()[0]

if sys.version_info < (3, 9):
print(f"Sherlock requires Python 3.9+\nYou are using Python {python_version}, which is not supported by Sherlock.")
print(
f"Sherlock requires Python 3.9+\nYou are using Python {python_version}, which is not supported by Sherlock."
)
sys.exit(1)

from sherlock_project import sherlock

sherlock.main()
145 changes: 101 additions & 44 deletions sherlock_project/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module defines the objects for notifying the caller about the
results of queries.
"""

from sherlock_project.result import QueryStatus
from colorama import Fore, Style
import webbrowser
Expand Down Expand Up @@ -155,13 +156,21 @@ def start(self, message):

title = "Checking username"

print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "*" +
Fore.GREEN + f"] {title}" +
Fore.WHITE + f" {message}" +
Fore.GREEN + " on:")
print(
Style.BRIGHT
+ Fore.GREEN
+ "["
+ Fore.YELLOW
+ "*"
+ Fore.GREEN
+ f"] {title}"
+ Fore.WHITE
+ f" {message}"
+ Fore.GREEN
+ " on:"
)
# An empty line between first line and the result(more clear output)
print('\r')
print("\r")

return

Expand Down Expand Up @@ -201,52 +210,92 @@ def update(self, result):
# Output to the terminal is desired.
if result.status == QueryStatus.CLAIMED:
self.countResults()
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.GREEN + "+" +
Fore.WHITE + "]" +
response_time_text +
Fore.GREEN +
f" {self.result.site_name}: " +
Style.RESET_ALL +
f"{self.result.site_url_user}")
print(
Style.BRIGHT
+ Fore.WHITE
+ "["
+ Fore.GREEN
+ "+"
+ Fore.WHITE
+ "]"
+ response_time_text
+ Fore.GREEN
+ f" {self.result.site_name}: "
+ Style.RESET_ALL
+ f"{self.result.site_url_user}"
)
if self.browse:
webbrowser.open(self.result.site_url_user, 2)

elif result.status == QueryStatus.AVAILABLE:
if self.print_all:
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.RED + "-" +
Fore.WHITE + "]" +
response_time_text +
Fore.GREEN + f" {self.result.site_name}:" +
Fore.YELLOW + " Not Found!")
print(
Style.BRIGHT
+ Fore.WHITE
+ "["
+ Fore.RED
+ "-"
+ Fore.WHITE
+ "]"
+ response_time_text
+ Fore.GREEN
+ f" {self.result.site_name}:"
+ Fore.YELLOW
+ " Not Found!"
)

elif result.status == QueryStatus.UNKNOWN:
if self.print_all:
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.RED + "-" +
Fore.WHITE + "]" +
Fore.GREEN + f" {self.result.site_name}:" +
Fore.RED + f" {self.result.context}" +
Fore.YELLOW + " ")
print(
Style.BRIGHT
+ Fore.WHITE
+ "["
+ Fore.RED
+ "-"
+ Fore.WHITE
+ "]"
+ Fore.GREEN
+ f" {self.result.site_name}:"
+ Fore.RED
+ f" {self.result.context}"
+ Fore.YELLOW
+ " "
)

elif result.status == QueryStatus.ILLEGAL:
if self.print_all:
msg = "Illegal Username Format For This Site!"
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.RED + "-" +
Fore.WHITE + "]" +
Fore.GREEN + f" {self.result.site_name}:" +
Fore.YELLOW + f" {msg}")

print(
Style.BRIGHT
+ Fore.WHITE
+ "["
+ Fore.RED
+ "-"
+ Fore.WHITE
+ "]"
+ Fore.GREEN
+ f" {self.result.site_name}:"
+ Fore.YELLOW
+ f" {msg}"
)

elif result.status == QueryStatus.WAF:
if self.print_all:
print(Style.BRIGHT + Fore.WHITE + "[" +
Fore.RED + "-" +
Fore.WHITE + "]" +
Fore.GREEN + f" {self.result.site_name}:" +
Fore.RED + " Blocked by bot detection" +
Fore.YELLOW + " (proxy may help)")
print(
Style.BRIGHT
+ Fore.WHITE
+ "["
+ Fore.RED
+ "-"
+ Fore.WHITE
+ "]"
+ Fore.GREEN
+ f" {self.result.site_name}:"
+ Fore.RED
+ " Blocked by bot detection"
+ Fore.YELLOW
+ " (proxy may help)"
)

else:
# It should be impossible to ever get here...
Expand All @@ -267,12 +316,20 @@ def finish(self, message="The processing has been finished."):
"""
NumberOfResults = self.countResults() - 1

print(Style.BRIGHT + Fore.GREEN + "[" +
Fore.YELLOW + "*" +
Fore.GREEN + "] Search completed with" +
Fore.WHITE + f" {NumberOfResults} " +
Fore.GREEN + "results" + Style.RESET_ALL
)
print(
Style.BRIGHT
+ Fore.GREEN
+ "["
+ Fore.YELLOW
+ "*"
+ Fore.GREEN
+ "] Search completed with"
+ Fore.WHITE
+ f" {NumberOfResults} "
+ Fore.GREEN
+ "results"
+ Style.RESET_ALL
)

def __str__(self):
"""Convert Object To String.
Expand Down
31 changes: 18 additions & 13 deletions sherlock_project/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This module defines various objects for recording the results of queries.
"""

from enum import Enum


Expand All @@ -10,11 +11,12 @@ class QueryStatus(Enum):

Describes status of query about a given username.
"""
CLAIMED = "Claimed" # Username Detected
AVAILABLE = "Available" # Username Not Detected
UNKNOWN = "Unknown" # Error Occurred While Trying To Detect Username
ILLEGAL = "Illegal" # Username Not Allowable For This Site
WAF = "WAF" # Request blocked by WAF (i.e. Cloudflare)

CLAIMED = "Claimed" # Username Detected
AVAILABLE = "Available" # Username Not Detected
UNKNOWN = "Unknown" # Error Occurred While Trying To Detect Username
ILLEGAL = "Illegal" # Username Not Allowable For This Site
WAF = "WAF" # Request blocked by WAF (i.e. Cloudflare)

def __str__(self):
"""Convert Object To String.
Expand All @@ -27,13 +29,16 @@ def __str__(self):
"""
return self.value

class QueryResult():

class QueryResult:
"""Query Result Object.

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, 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
Expand Down Expand Up @@ -62,12 +67,12 @@ def __init__(self, username, site_name, site_url_user, status,
Nothing.
"""

self.username = username
self.site_name = site_name
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
self.status = status
self.query_time = query_time
self.context = context

return

Expand Down
32 changes: 21 additions & 11 deletions sherlock_project/sherlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import sys

try:
from sherlock_project.__init__ import import_error_test_var # noqa: F401
from sherlock_project.__init__ import import_error_test_var # noqa: F401
except ImportError:
print("Did you run Sherlock with `python3 sherlock/sherlock.py ...`?")
print("This is an outdated method. Please see https://sherlockproject.xyz/installation for up to date instructions.")
print(
"This is an outdated method. Please see https://sherlockproject.xyz/installation for up to date instructions."
)
sys.exit(1)

import csv
Expand Down Expand Up @@ -216,13 +218,21 @@ def sherlock(
from torrequest import TorRequest # noqa: E402
except ImportError:
print("Important!")
print("> --tor and --unique-tor are now DEPRECATED, and may be removed in a future release of Sherlock.")
print("> If you've installed Sherlock via pip, you can include the optional dependency via `pip install 'sherlock-project[tor]'`.")
print("> Other packages should refer to their documentation, or install it separately with `pip install torrequest`.\n")
print(
"> --tor and --unique-tor are now DEPRECATED, and may be removed in a future release of Sherlock."
)
print(
"> If you've installed Sherlock via pip, you can include the optional dependency via `pip install 'sherlock-project[tor]'`."
)
print(
"> Other packages should refer to their documentation, or install it separately with `pip install torrequest`.\n"
)
sys.exit(query_notify.finish())

print("Important!")
print("> --tor and --unique-tor are now DEPRECATED, and may be removed in a future release of Sherlock.")
print(
"> --tor and --unique-tor are now DEPRECATED, and may be removed in a future release of Sherlock."
)

# Requests using Tor obfuscation
try:
Expand Down Expand Up @@ -270,7 +280,7 @@ def sherlock(
headers.update(net_info["headers"])

# URL of user on site (if it exists)
url = interpolate_string(net_info["url"], username.replace(' ', '%20'))
url = interpolate_string(net_info["url"], username.replace(" ", "%20"))

# Don't make request if username is invalid for the site
regex_check = net_info.get("regexCheck")
Expand Down Expand Up @@ -413,10 +423,10 @@ def sherlock(
# be highly targetted. Comment at the end of each fingerprint to
# indicate target and date fingerprinted.
WAFHitMsgs = [
r'.loading-spinner{visibility:hidden}body.no-js .challenge-running{display:none}body.dark{background-color:#222;color:#d9d9d9}body.dark a{color:#fff}body.dark a:hover{color:#ee730a;text-decoration:underline}body.dark .lds-ring div{border-color:#999 transparent transparent}body.dark .font-red{color:#b20f03}body.dark', # 2024-05-13 Cloudflare
r'<span id="challenge-error-text">', # 2024-11-11 Cloudflare error page
r'AwsWafIntegration.forceRefreshToken', # 2024-11-11 Cloudfront (AWS)
r'{return l.onPageView}}),Object.defineProperty(r,"perimeterxIdentifiers",{enumerable:' # 2024-04-09 PerimeterX / Human Security
r".loading-spinner{visibility:hidden}body.no-js .challenge-running{display:none}body.dark{background-color:#222;color:#d9d9d9}body.dark a{color:#fff}body.dark a:hover{color:#ee730a;text-decoration:underline}body.dark .lds-ring div{border-color:#999 transparent transparent}body.dark .font-red{color:#b20f03}body.dark", # 2024-05-13 Cloudflare
r'<span id="challenge-error-text">', # 2024-11-11 Cloudflare error page
r"AwsWafIntegration.forceRefreshToken", # 2024-11-11 Cloudfront (AWS)
r'{return l.onPageView}}),Object.defineProperty(r,"perimeterxIdentifiers",{enumerable:', # 2024-04-09 PerimeterX / Human Security
]

if error_text is not None:
Expand Down
Loading