From b2cb0506a3c74b4b52667d75486380434a2b317e Mon Sep 17 00:00:00 2001 From: Mike Pieters Date: Sat, 29 Dec 2018 01:50:25 +0100 Subject: [PATCH 1/4] Adds option to connect over TOR --- requirements.txt | 1 + sherlock.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index f229360..1d8fa42 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ requests +torrequest \ No newline at end of file diff --git a/sherlock.py b/sherlock.py index c9f7077..a8c2c84 100644 --- a/sherlock.py +++ b/sherlock.py @@ -10,7 +10,7 @@ import sys import re from argparse import ArgumentParser, RawDescriptionHelpFormatter import platform - +from torrequest import TorRequest module_name = "Sherlock: Find Usernames Across Social Networks" __version__ = "0.1.0" @@ -30,9 +30,10 @@ def print_error(err, errstr, var, debug = False): print(f"\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m {errstr}\033[93;1m {var}") -def make_request(url, headers, error_type, social_network, verbose=False): +def make_request(url, headers, error_type, social_network, verbose=False, tor=False): + r = TorRequest() if tor else requests try: - r = requests.get(url, headers=headers) + r = r.get(url, headers=headers) if r.status_code: return r, error_type except requests.exceptions.HTTPError as errh: @@ -46,7 +47,7 @@ def make_request(url, headers, error_type, social_network, verbose=False): return None, "" -def sherlock(username, verbose=False): +def sherlock(username, verbose=False, tor=False): fname = username+".txt" if os.path.isfile(fname): @@ -74,7 +75,7 @@ def sherlock(username, verbose=False): 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)) continue - r, error_type = make_request(url=url, headers=headers, error_type=error_type, social_network=social_network, verbose=verbose) + r, error_type = make_request(url=url, headers=headers, error_type=error_type, social_network=social_network, verbose=verbose, tor=tor) if error_type == "message": error = data.get(social_network).get("errorMsg") @@ -132,6 +133,9 @@ def main(): action="store_false", dest="verbose", help="Disable debugging information (Default Option)." ) + parser.add_argument("--tor", "-t", + action="store_true", dest="tor", default=False, + help="Make requests over TOR; requires TOR to be installed and in system path.") parser.add_argument("username", nargs='+', metavar='USERNAMES', action="store", @@ -152,10 +156,13 @@ def main(): \033[37;1m .'`-._ `.\ | J / \033[37;1m / `--.| \__/\033[0m""") - # Run report on all specified users. + if args.tor: + 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. for username in args.username: print() - sherlock(username, verbose=args.verbose) + sherlock(username, verbose=args.verbose, tor=args.tor) From 49f65021bb421b76053a2b26a7de779ef5594c6a Mon Sep 17 00:00:00 2001 From: Mike Pieters Date: Sat, 29 Dec 2018 02:31:31 +0100 Subject: [PATCH 2/4] Adds option to use new TOR circuit for each request --- sherlock.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sherlock.py b/sherlock.py index a8c2c84..b8842a6 100644 --- a/sherlock.py +++ b/sherlock.py @@ -30,12 +30,14 @@ def print_error(err, errstr, var, debug = False): print(f"\033[37;1m[\033[91;1m-\033[37;1m]\033[91;1m {errstr}\033[93;1m {var}") -def make_request(url, headers, error_type, social_network, verbose=False, tor=False): - r = TorRequest() if tor else requests +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 try: - r = r.get(url, headers=headers) - if r.status_code: - return r, error_type + rsp = r.get(url, headers=headers) + if unique_tor: + r.reset_identity() + if rsp.status_code: + return rsp, error_type except requests.exceptions.HTTPError as errh: print_error(errh, "HTTP Error:", social_network, verbose) except requests.exceptions.ConnectionError as errc: @@ -47,7 +49,7 @@ def make_request(url, headers, error_type, social_network, verbose=False, tor=Fa return None, "" -def sherlock(username, verbose=False, tor=False): +def sherlock(username, verbose=False, tor=False, unique_tor=False): fname = username+".txt" if os.path.isfile(fname): @@ -75,7 +77,7 @@ def sherlock(username, verbose=False, tor=False): 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)) continue - r, error_type = make_request(url=url, headers=headers, error_type=error_type, social_network=social_network, verbose=verbose, tor=tor) + 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) if error_type == "message": error = data.get(social_network).get("errorMsg") @@ -135,7 +137,10 @@ def main(): ) parser.add_argument("--tor", "-t", action="store_true", dest="tor", default=False, - help="Make requests over TOR; requires TOR to be installed and in system path.") + 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.") parser.add_argument("username", nargs='+', metavar='USERNAMES', action="store", @@ -156,13 +161,13 @@ def main(): \033[37;1m .'`-._ `.\ | J / \033[37;1m / `--.| \__/\033[0m""") - if args.tor: + if args.tor or args.unique_tor: 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. for username in args.username: print() - sherlock(username, verbose=args.verbose, tor=args.tor) + sherlock(username, verbose=args.verbose, tor=args.tor, unique_tor=args.unique_tor) From feef27b2e49b8a1674d72e1bef9a91a4cfbd8051 Mon Sep 17 00:00:00 2001 From: Mike Pieters Date: Sat, 29 Dec 2018 02:45:19 +0100 Subject: [PATCH 3/4] Removed accidental whitespace --- sherlock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sherlock.py b/sherlock.py index b8842a6..25bf1d5 100644 --- a/sherlock.py +++ b/sherlock.py @@ -164,7 +164,7 @@ def main(): if args.tor or args.unique_tor: 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. + # Run report on all specified users. for username in args.username: print() sherlock(username, verbose=args.verbose, tor=args.tor, unique_tor=args.unique_tor) From 6cd18fb5bb17de47b7466f2312b24c284e9384a4 Mon Sep 17 00:00:00 2001 From: Mike Pieters Date: Sat, 29 Dec 2018 03:27:31 +0100 Subject: [PATCH 4/4] Update README to reflect added TOR arguments --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e668f6..b0b5ed4 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ $ pip3 install -r requirements.txt ```bash $ python3 sherlock.py --help -usage: sherlock.py [-h] [--version] [--verbose] [--quiet] +usage: sherlock.py [-h] [--version] [--verbose] [--quiet] [--tor] [--unique-tor] USERNAMES [USERNAMES ...] Sherlock: Find Usernames Across Social Networks (Version 0.1.0) @@ -37,6 +37,8 @@ optional arguments: --verbose, -v, -d, --debug Display extra debugging information. --quiet, -q Disable debugging information (Default Option). + --tor, -t Make requests over TOR; increases runtime; requires TOR to be installed and in system path. + --unique-tor, -u Make requests over TOR with new TOR circuit after each request; increases runtime; requires TOR to be installed and in system path. ``` For example, run ```python3 sherlock.py user123```, and all of the accounts