2018-12-27 03:54:25 +00:00
|
|
|
"""Sherlock: Find Usernames Across Social Networks Module
|
|
|
|
|
|
|
|
This module contains the main logic to search for usernames at social
|
|
|
|
networks.
|
|
|
|
"""
|
2018-12-24 14:31:34 +00:00
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import os
|
2018-12-25 16:01:01 +00:00
|
|
|
import sys
|
2018-12-27 01:41:11 +00:00
|
|
|
import re
|
2018-12-28 19:15:41 +00:00
|
|
|
from argparse import ArgumentParser, RawDescriptionHelpFormatter
|
|
|
|
import platform
|
2018-12-29 00:50:25 +00:00
|
|
|
from torrequest import TorRequest
|
2018-12-24 14:31:34 +00:00
|
|
|
|
2018-12-27 03:54:25 +00:00
|
|
|
module_name = "Sherlock: Find Usernames Across Social Networks"
|
|
|
|
__version__ = "0.1.0"
|
|
|
|
|
2018-12-26 10:10:09 +00:00
|
|
|
|
2018-12-26 08:22:37 +00:00
|
|
|
# TODO: fix tumblr
|
|
|
|
|
2018-12-24 14:31:34 +00:00
|
|
|
def write_to_file(url, fname):
|
|
|
|
with open(fname, "a") as f:
|
|
|
|
f.write(url+"\n")
|
|
|
|
|
2018-12-28 19:15:41 +00:00
|
|
|
|
2018-12-26 17:25:28 +00:00
|
|
|
def print_error(err, errstr, var, debug = False):
|
|
|
|
if debug:
|
2018-12-28 19:15:41 +00:00
|
|
|
print(f"\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m {errstr}\033[93;1m {err}")
|
2018-12-26 17:25:28 +00:00
|
|
|
else:
|
2018-12-28 19:15:41 +00:00
|
|
|
print(f"\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m {errstr}\033[93;1m {var}")
|
|
|
|
|
2018-12-26 17:25:28 +00:00
|
|
|
|
2018-12-29 01:31:31 +00:00
|
|
|
def make_request(url, headers, error_type, social_network, verbose=False, tor=False, unique_tor=False):
|
|
|
|
r = TorRequest() if (tor or unique_tor) else requests
|
2018-12-25 16:01:01 +00:00
|
|
|
try:
|
2018-12-29 01:31:31 +00:00
|
|
|
rsp = r.get(url, headers=headers)
|
|
|
|
if unique_tor:
|
|
|
|
r.reset_identity()
|
|
|
|
if rsp.status_code:
|
|
|
|
return rsp, error_type
|
2018-12-25 16:01:01 +00:00
|
|
|
except requests.exceptions.HTTPError as errh:
|
2018-12-27 03:54:25 +00:00
|
|
|
print_error(errh, "HTTP Error:", social_network, verbose)
|
2018-12-25 16:01:01 +00:00
|
|
|
except requests.exceptions.ConnectionError as errc:
|
2018-12-27 03:54:25 +00:00
|
|
|
print_error(errc, "Error Connecting:", social_network, verbose)
|
2018-12-25 16:01:01 +00:00
|
|
|
except requests.exceptions.Timeout as errt:
|
2018-12-27 03:54:25 +00:00
|
|
|
print_error(errt, "Timeout Error:", social_network, verbose)
|
2018-12-25 16:01:01 +00:00
|
|
|
except requests.exceptions.RequestException as err:
|
2018-12-27 03:54:25 +00:00
|
|
|
print_error(err, "Unknown error:", social_network, verbose)
|
2018-12-25 16:01:01 +00:00
|
|
|
return None, ""
|
2018-12-24 14:31:34 +00:00
|
|
|
|
2018-12-28 19:15:41 +00:00
|
|
|
|
2018-12-29 01:31:31 +00:00
|
|
|
def sherlock(username, verbose=False, tor=False, unique_tor=False):
|
2018-12-24 14:31:34 +00:00
|
|
|
fname = username+".txt"
|
|
|
|
|
|
|
|
if os.path.isfile(fname):
|
|
|
|
os.remove(fname)
|
|
|
|
print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Removing previous file:\033[1;37m {}\033[0m".format(fname))
|
|
|
|
|
|
|
|
print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Checking username\033[0m\033[1;37m {}\033[0m\033[1;92m on: \033[0m".format(username))
|
2018-12-26 01:34:47 +00:00
|
|
|
raw = open("data.json", "r", encoding="utf-8")
|
2018-12-24 14:31:34 +00:00
|
|
|
data = json.load(raw)
|
|
|
|
|
2018-12-27 03:54:25 +00:00
|
|
|
# User agent is needed because some sites does not
|
2018-12-24 14:31:34 +00:00
|
|
|
# return the correct information because it thinks that
|
|
|
|
# we are bot
|
|
|
|
headers = {
|
|
|
|
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0'
|
|
|
|
}
|
|
|
|
|
|
|
|
for social_network in data:
|
|
|
|
url = data.get(social_network).get("url").format(username)
|
|
|
|
error_type = data.get(social_network).get("errorType")
|
2018-12-27 01:41:11 +00:00
|
|
|
regex_check = data.get(social_network).get("regexCheck")
|
2018-12-24 14:31:34 +00:00
|
|
|
|
2018-12-28 16:39:10 +00:00
|
|
|
if regex_check and re.search(regex_check, username) is None:
|
2018-12-27 01:41:11 +00:00
|
|
|
#No need to do the check at the site: this user name is not allowed.
|
2018-12-28 19:15:41 +00:00
|
|
|
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Illegal Username Format For This Site!".format(social_network))
|
2018-12-26 12:29:26 +00:00
|
|
|
continue
|
2018-12-27 01:41:11 +00:00
|
|
|
|
2018-12-29 01:31:31 +00:00
|
|
|
r, error_type = make_request(url=url, headers=headers, error_type=error_type, social_network=social_network, verbose=verbose, tor=tor, unique_tor=unique_tor)
|
2018-12-27 03:54:25 +00:00
|
|
|
|
2018-12-24 14:31:34 +00:00
|
|
|
if error_type == "message":
|
|
|
|
error = data.get(social_network).get("errorMsg")
|
2018-12-26 08:22:37 +00:00
|
|
|
# Checks if the error message is in the HTML
|
2018-12-24 14:31:34 +00:00
|
|
|
if not error in r.text:
|
|
|
|
print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url)
|
2018-12-27 03:54:25 +00:00
|
|
|
write_to_file(url, fname)
|
|
|
|
|
2018-12-24 14:31:34 +00:00
|
|
|
else:
|
|
|
|
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network))
|
2018-12-27 03:54:25 +00:00
|
|
|
|
2018-12-24 14:31:34 +00:00
|
|
|
elif error_type == "status_code":
|
2018-12-26 08:22:37 +00:00
|
|
|
# Checks if the status code of the repsonse is 404
|
2018-12-24 14:31:34 +00:00
|
|
|
if not r.status_code == 404:
|
|
|
|
print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url)
|
|
|
|
write_to_file(url, fname)
|
2018-12-27 03:54:25 +00:00
|
|
|
|
2018-12-24 14:31:34 +00:00
|
|
|
else:
|
|
|
|
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network))
|
|
|
|
|
|
|
|
elif error_type == "response_url":
|
2018-12-26 08:22:37 +00:00
|
|
|
error = data.get(social_network).get("errorUrl")
|
|
|
|
# Checks if the redirect url is the same as the one defined in data.json
|
2018-12-24 14:31:34 +00:00
|
|
|
if not error in r.url:
|
|
|
|
print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url)
|
|
|
|
write_to_file(url, fname)
|
|
|
|
else:
|
|
|
|
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network))
|
|
|
|
|
2018-12-25 16:01:01 +00:00
|
|
|
elif error_type == "":
|
|
|
|
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Error!".format(social_network))
|
|
|
|
|
2018-12-24 14:31:34 +00:00
|
|
|
print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Saved: \033[37;1m{}\033[0m".format(username+".txt"))
|
2018-12-26 08:26:03 +00:00
|
|
|
|
2018-12-27 03:54:25 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
|
2018-12-28 19:15:41 +00:00
|
|
|
def main():
|
2018-12-27 03:54:25 +00:00
|
|
|
version_string = f"%(prog)s {__version__}\n" + \
|
|
|
|
f"{requests.__description__}: {requests.__version__}\n" + \
|
|
|
|
f"Python: {platform.python_version()}"
|
|
|
|
|
|
|
|
parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
|
|
|
|
description=f"{module_name} (Version {__version__})"
|
|
|
|
)
|
|
|
|
parser.add_argument("--version",
|
|
|
|
action="version", version=version_string,
|
|
|
|
help="Display version information and dependencies."
|
|
|
|
)
|
|
|
|
parser.add_argument("--verbose", "-v", "-d", "--debug",
|
|
|
|
action="store_true", dest="verbose", default=False,
|
|
|
|
help="Display extra debugging information."
|
|
|
|
)
|
|
|
|
parser.add_argument("--quiet", "-q",
|
|
|
|
action="store_false", dest="verbose",
|
|
|
|
help="Disable debugging information (Default Option)."
|
|
|
|
)
|
2018-12-29 00:50:25 +00:00
|
|
|
parser.add_argument("--tor", "-t",
|
|
|
|
action="store_true", dest="tor", default=False,
|
2018-12-29 01:31:31 +00:00
|
|
|
help="Make requests over TOR; increases runtime; requires TOR to be installed and in system path.")
|
|
|
|
parser.add_argument("--unique-tor", "-u",
|
|
|
|
action="store_true", dest="unique_tor", default=False,
|
|
|
|
help="Make requests over TOR with new TOR circuit after each request; increases runtime; requires TOR to be installed and in system path.")
|
2018-12-27 03:54:25 +00:00
|
|
|
parser.add_argument("username",
|
|
|
|
nargs='+', metavar='USERNAMES',
|
|
|
|
action="store",
|
|
|
|
help="One or more usernames to check with social networks."
|
|
|
|
)
|
2018-12-26 17:25:28 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
2018-12-26 08:26:03 +00:00
|
|
|
|
2018-12-28 19:15:41 +00:00
|
|
|
# Banner
|
2018-12-27 03:54:25 +00:00
|
|
|
print(
|
|
|
|
"""\033[37;1m .\"\"\"-.
|
|
|
|
\033[37;1m / \\
|
|
|
|
\033[37;1m ____ _ _ _ | _..--'-.
|
|
|
|
\033[37;1m/ ___|| |__ ___ _ __| | ___ ___| |__ >.`__.-\"\"\;\"`
|
|
|
|
\033[37;1m\___ \| '_ \ / _ \ '__| |/ _ \ / __| |/ / / /( ^\\
|
|
|
|
\033[37;1m ___) | | | | __/ | | | (_) | (__| < '-`) =|-.
|
|
|
|
\033[37;1m|____/|_| |_|\___|_| |_|\___/ \___|_|\_\ /`--.'--' \ .-.
|
|
|
|
\033[37;1m .'`-._ `.\ | J /
|
|
|
|
\033[37;1m / `--.| \__/\033[0m""")
|
|
|
|
|
2018-12-29 01:31:31 +00:00
|
|
|
if args.tor or args.unique_tor:
|
2018-12-29 00:50:25 +00:00
|
|
|
print("Warning: some websites might refuse connecting over TOR, so note that using this option might increase connection errors.")
|
|
|
|
|
|
|
|
# Run report on all specified users.
|
2018-12-27 03:54:25 +00:00
|
|
|
for username in args.username:
|
|
|
|
print()
|
2018-12-29 01:31:31 +00:00
|
|
|
sherlock(username, verbose=args.verbose, tor=args.tor, unique_tor=args.unique_tor)
|
2018-12-28 19:15:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|