
    Xh                        d Z ddlZ	 ddlmZ ddlZddlZddl	Z
ddlZddlZddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlZddlmZ ddlmZmZmZmZ ddlmZ ddlm Z  ddl!m"Z" ddl!m#Z# ddl$m%Z% ddl&m'Z' ddlm(Z(  G d de      Z)d Z*d Z+d Z,g dZ-d Z.	 	 	 	 	 d(de/de0de"de1de1d e1d!ee/   d"e2fd#Z3d$ Z4d% Z5d& Z6e7d'k(  r e6        yy# e$ r%  ed        ed        ej                  d       Y w xY w))z
Sherlock: Find Usernames Across Social Networks Module

This module contains the main logic to search for usernames at social
networks.
    N)import_error_test_varz=Did you run Sherlock with `python3 sherlock/sherlock.py ...`?zlThis is an outdated method. Please see https://sherlockproject.xyz/installation for up to date instructions.   )ArgumentParserRawDescriptionHelpFormatter)loads)	monotonic)Optional)FuturesSession)__longname____shortname____version__forge_api_latest_release)QueryStatus)QueryResult)QueryNotify)QueryNotifyPrint)SitesInformation)init)ArgumentTypeErrorc                         e Zd Zd fd	Z xZS )SherlockFuturesSessionc                 f   |i }t               fd}	 t        |d   t              r|d   j                  d|       nDt        |d   t              r't        |d         |d<   |d   j                  d|       n
||d   g|d<   t        t        | "  ||g|d|i|S # t
        $ r	 |g|d<   Y +w xY w)a  Request URL.

        This extends the FuturesSession request method to calculate a response
        time metric to each request.

        It is taken (almost) directly from the following Stack Overflow answer:
        https://github.com/ross/requests-futures#working-in-the-background

        Keyword Arguments:
        self                   -- This object.
        method                 -- String containing method desired for request.
        url                    -- String containing URL for request.
        hooks                  -- Dictionary containing hooks to execute after
                                  request finishes.
        args                   -- Arguments.
        kwargs                 -- Keyword arguments.

        Return Value:
        Request object.
        c                 *    t               z
  | _        y)a  Response Time Hook.

            Keyword Arguments:
            resp                   -- Response object.
            args                   -- Arguments.
            kwargs                 -- Keyword arguments.

            Return Value:
            Nothing.
            N)r   elapsed)respargskwargsstarts      A/var/www/betterdocs.net/sherlock_api/sherlock_project/sherlock.pyresponse_timez5SherlockFuturesSession.request.<locals>.response_timeK   s     %;.DL    responser   hooks)	r   
isinstancelistinserttupleKeyErrorsuperr   request)	selfmethodurlr#   r   r   r    r   	__class__s	          @r   r*   zSherlockFuturesSession.request1   s    , =E	$	0%
+T2j!((M:E*-u5$(z):$;j!j!((M: &3E*4E$Fj!
 +T:C
'+
$
/5
 	
	  	0!.E*	0s   A-B B0/B0N)__name__
__module____qualname__r*   __classcell__)r.   s   @r   r   r   0   s    =
 =
r!   r   c                 T   d }d}d }	 | j                         }|j                  rd }|||fS # t        j                  j                  $ r}d}t        |      }Y d }~4d }~wt        j                  j                  $ r}d}t        |      }Y d }~fd }~wt        j                  j                  $ r}d}t        |      }Y d }~d }~wt        j                  j                  $ r}	d}t        |	      }Y d }	~	d }	~	wt        j                  j                  $ r}
d}t        |
      }Y d }
~
d }
~
ww xY w)NzGeneral Unknown Errorz
HTTP ErrorzProxy ErrorzError ConnectingzTimeout ErrorzUnknown Error)
resultstatus_coderequests
exceptions	HTTPErrorstr
ProxyErrorConnectionErrorTimeoutRequestException)request_future
error_typesocial_networkr"   error_contextexception_texterrherrperrcerrterrs              r   get_responserI   q   s    H+MN"!((* M" ]N22! (( #$T)) #%T.. #*T&& #'T// "'S"sE   + D'A D':B D',B>> D'C00 D'D""D'c           	      0   t        | t              r| j                  d|      S t        | t              r.| j	                         D ci c]  \  }}|t        ||       c}}S t        | t              r| D cg c]  }t        ||       c}S | S c c}}w c c}w )Nz{})r$   r:   replacedictitemsinterpolate_stringr%   )input_objectusernamekvis        r   rN   rN      s    ,$##D(33	L$	'?K?Q?Q?STtq!%a22TT	L$	'9EFA"1h/FF UFs   B5Bc                 
    d| v S )znchecks if {?} exists in the username
    if exist it means that sherlock is looking for more multiple username{?} )rP   s    r   check_for_parameterrW      s     Hr!   )_-.c                 b    g }t         D ]#  }|j                  | j                  d|             % |S )zFreplace the parameter with with symbols and return a list of usernamesrU   )checksymbolsappendrK   )rP   allUsernamesrS   s      r   multiple_usernamesr_      s7    L 8H,,UA678r!   rP   	site_dataquery_notifytor
unique_tordump_responseproxytimeoutc           	        * |j                  |        |s|r2	 ddlm} t	        d       t	        d       	         }		j                  }
n(t        j                         }
t        j                         }	t        |      dk\  rd}nt        |      }t        ||
	      }i }|j                         D ]  \  }}d
|j                  d      i}ddi}d|v r|j!                  |d          t#        |d   | j%                  dd            }|j                  d      }|rZt'        j(                  ||       Dt+        | ||t,        j.                        |d<   d|d<   d|d<   d|d<   |j!                  |d          n||d<   |j                  d      }|j                  d      }|j                  d      }d}|V|dk(  r|j                  }nD|dk(  r|j0                  }n2|dk(  r|j2                  }n |dk(  r|j4                  }nt7        d |       |t#        ||       }||}nt#        ||       }|!|d!   d"k(  r|j0                  }n|j                  }|d!   d#k(  rd$}nd%}|||d&} |||||||'      }n ||||||(      }||d)<   |r|	j9                          |||<    |j                         D ]?  \  }}|j                  |      }|j                  d      }|j                  d      }|=|d!   }|d)   }t;        |||*      \  *}}	 *j<                  }	 *j@                  } 	 *jD                  jG                  *jH                  xs d,      }!t,        jJ                  }"d}#g d-}$||}#nvtM        *fd.|$D              rt,        jN                  }"nP|d/k(  rqd%}%|j                  d0      }&tQ        |&tR              r|&*jD                  v rd$}%n|&D ]  }'|'*jD                  v sd$}% n |%rt,        jT                  }"nt,        jV                  }"n|d"k(  r|j                  d1      }(t,        jT                  }"tQ        |(tX              r|(g}(|(*j@                  |(v rt,        jV                  }"n*j@                  d2k\  s*j@                  d3k  rbt,        jV                  }"nQ|d#k(  r:d3*j@                  cxk  rd2k  rn nt,        jT                  }"n#t,        jV                  }"nt[        d4| d5| d6      |rt	        d7       t	        d8|        t	        d9|         t	        d:|        t	        d;|        	 t	        d<|d1           t	        d=       	 t	        d>*j@                          	 t	        d?|d0           t	        d@       	 t	        *jD                         t	        dA       t	        dBtS        |"      z          t	        d7       t+        | |||"||#C      })|j!                  |)       |)|d<   | |d<   |!|d<   |||<   B |S # t        $ rS t	        d       t	        d       t	        d       t	        d       t        j                  |j                                Y #w xY w# t        $ r2 t	        d       t        j                  |j                                Y Cw xY w# t>        $ r d}Y w xY w# tB        $ r d+} Y w xY w# tB        $ r d}!Y ww xY w# t\        $ r Y w xY w# tB        $ r Y w xY w# t\        $ r Y w xY w# tB        $ r Y ww xY w)Da'  Run Sherlock Analysis.

    Checks for existence of username on various social media sites.

    Keyword Arguments:
    username               -- String indicating username that report
                              should be created against.
    site_data              -- Dictionary containing all of the site data.
    query_notify           -- Object with base type of QueryNotify().
                              This will be used to notify the caller about
                              query results.
    tor                    -- Boolean indicating whether to use a tor circuit for the requests.
    unique_tor             -- Boolean indicating whether to use a new tor circuit for each request.
    proxy                  -- String indicating the proxy URL
    timeout                -- Time in seconds to wait before timing out request.
                              Default is 60 seconds.

    Return Value:
    Dictionary containing results from report. Key of dictionary is the name
    of the social network site, and the value is another dictionary with
    the following keys:
        url_main:      URL of main site.
        url_user:      URL of user on site (if account exists).
        status:        QueryResult() object indicating results of test for
                       account existence.
        http_status:   HTTP status code of query which checked for existence on
                       site.
        response_text: Text that came back from request.  May be None if
                       there was an HTTP error when checking for existence.
    r   )
TorRequestz
Important!z`> --tor and --unique-tor are now DEPRECATED, and may be removed in a future release of Sherlock.zz> If you've installed Sherlock via pip, you can include the optional dependency via `pip install 'sherlock-project[tor]'`.zn> Other packages should refer to their documentation, or install it separately with `pip install torrequest`.
z2Tor not found in system path. Unable to continue.
   )max_workerssessionurl_mainurlMainz
User-AgentzFMozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0headersr-    z%20
regexCheckNstatus url_userhttp_statusresponse_texturlProberequest_methodrequest_payloadGETHEADPOSTPUTzUnsupported request_method for 	errorTyper6   response_urlFT)httphttps)r-   rn   proxiesallow_redirectsrf   json)r-   rn   r   rf   r   r?   )r?   r@   rA   ?zUTF-8)a:  .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.darkz <span id="challenge-error-text">z#AwsWafIntegration.forceRefreshTokenzT{return l.onPageView}}),Object.defineProperty(r,"perimeterxIdentifiers",{enumerable:c              3   :   K   | ]  }|j                   v   y wr/   )text).0hitMsgrs     r   	<genexpr>zsherlock.<locals>.<genexpr>  s     ;f166!;s   messageerrorMsg	errorCodei,     zUnknown Error Type 'z' for site ''z+++++++++++++++++++++zTARGET NAME   : zUSERNAME      : zTARGET URL    : zTEST METHOD   : zSTATUS CODES  : z
Results...zRESPONSE CODE : zERROR TEXT    : z>>>>> BEGIN RESPONSE TEXTz<<<<< END RESPONSE TEXTzVERDICT       : )rP   	site_namesite_url_userrq   
query_timecontext)/r   
torrequestrh   ImportErrorprintsysexitfinishOSErrorrk   r7   Requestlenr   rM   getupdaterN   rK   researchr   r   ILLEGALheadpostputRuntimeErrorreset_identityrI   r   AttributeErrorr6   	Exceptionr   encodeencodingUNKNOWNanyWAFr$   r:   CLAIMED	AVAILABLEint
ValueErrorr(   )+rP   r`   ra   rb   rc   rd   re   rf   rh   underlying_requestunderlying_sessionrj   rk   results_totalrA   net_inforesults_sitern   r-   regex_check	url_proberw   rx   r*   r   r   futurerq   r@   
error_textrC   r    rt   ru   query_statusrB   
WAFHitMsgs
error_flagerrorserrorerror_codesr5   r   s+                                             @r   sherlockr      s   T x 
j	,- 	lpq	,!+
 077 &--/%--/ 9~)n %);G
 M %.OO$5 o5 "HLL$;< b
  NN8I./ !%(2B2B32NO ll<0299[(;C%0.#{/B/B&L" (*L$*,L',.L)X 67 (+L$ Z0I%\\*:;N&ll+<=OG)!U*%kkG#v-%llG#v-%llG#u,%kkG&)H'NOO*"4_h"O 	 /y(C	K(M9 &llG
 &kkG$6 #( #'  #(59 !##$3#( !!#$3#( *0H%& "113 )5n%_o5f %.OO$5 ]5 $((8 z*!!(+ k*
 *+(4!j)
%:~
	!IIM
	--K	FFMM!***?@M #**

 !&M;
;;&??L9$ J\\*-F &#& QVV#!&J $ E%*
 *22*44=(",,{3K&..L +s+*m&1==K+G*44#%)<*44>) amm)c)*22*44 &zl2B>BRRST  )*$^$456$XJ/0$SE*+$ZL12(+)>(?@A ,(89(*)=(>?@ -.aff +,$s<'889)* $$!
 	F# "(X '2]#(5_% )5n%{]5~ s	  	,,tu  O  P  D  EHH\((*+	,  	,GHHH\((*+	,H  	! M	!  	K	  	M	j  
    
  s   W& Y ;ZZ)Z'Z93[	[)[)&AYY7Z ?Z ZZZ$#Z$'Z65Z69	[[		[[	[&%[&)	[65[6c                 D    t        |       }|dk  rt        d|  d      |S )a_  Check Timeout Argument.

    Checks timeout for validity.

    Keyword Arguments:
    value                  -- Time in seconds to wait before timing out request.

    Return Value:
    Floating point number representing the time (in seconds) that should be
    used for the timeout.

    NOTE:  Will raise an exception if the timeout in invalid.
    r   zInvalid timeout value: z$. Timeout must be a positive number.)floatr   )valuefloat_values     r   timeout_checkr     s7     ,Ka%eW,PQ
 	
 r!   c                 .    t        j                  d       y)zwExit gracefully without throwing errors

    Source: https://www.devdungeon.com/content/python-catch-sigint-ctrl-c
    r   N)r   r   )signal_receivedframes     r   handlerr   .  s    
 HHQKr!   c                     t        t        t         dt         d      } | j	                  ddt
         dt         d       | j	                  d	d
dddddd       | j	                  dddd       | j	                  dddd       | j	                  dddddd       | j	                  dd dd!dd"       | j	                  d#dd$dd%       | j	                  d&dd'dd(       | j	                  d)d*d+d,g d-.       | j	                  d/d0d1d2d3d d45       | j	                  d6dd7dd8       | j	                  d9d:d;d<d d=>       | j	                  d?d2d@dAt        dBdCD       | j	                  dEddFddG       | j	                  dHddIdJdK       | j	                  dLddMddN       | j	                  dOdPdQd2dRS       | j	                  dTdUddVddW       | j	                  dXdYdddZ[       | j	                  d\ddd][       | j	                  d^dd_dd`       | j                         }t        j                  t        j                  t               	 t        j                  t              j                  }t        |      }|da   }|dbd  t        k7  rt!        dct         dd|dbd   de|df           |j$                  r|j&                  t#        dh      |j&                  t!        di|j&                  z          |j$                  s|j(                  rt!        dj       t!        dk       |j*                  rt-        dJdl       nt-        dJm       |j.                  ,|j0                   t!        dn       t3        j4                  db       |j.                  8t7        |j8                        dbk7  r t!        do       t3        j4                  db       	 |j:                  rKt=        t>        j@                  jC                  t>        j@                  jE                  tF              dp            }n|jH                  }|jH                  r|jH                  jK                         rq|jH                  }dq| }	t        j                  |	      j                  }
t        |
      }dr|v r$t!        ds| dt       t3        j4                  db       |du   dv   }dw| dx}t=        |      }|jL                  sjO                  |jP                  z       D ci c]  }|jR                  |jT                   }}|jP                  g k(  r|}ni }g }|jP                  D ]U  }d{}|D ]1  }|jW                         |jW                         k(  s%||   ||<   |dbz  }3 |d{k(  sA|jY                  d|| d|       W |rt!        d}d~jC                  |       d       |st3        j4                  db       t[        d |j\                  |j^                  |j`                        }g }|j8                  D ]@  }tc        |      r"te        |      D ]  }|jY                  |        0|jY                  |       B |D ]  }tg        ||||j$                  |j(                  |jh                  |j&                  |jj                        }|j.                  r|j.                  }n`|j0                  rOt?        jl                  |j0                  dJ       t>        j@                  jC                  |j0                  | d      }n| d}|jn                  stq        |dd      5 }d{}|D ]P  }||   }|j                  d      jr                  tt        jv                  k(  s5|dbz  }|jy                  |d   dez          R |jy                  d| de       d d d        |jz                  r9| d}|j0                  rKt?        jl                  |j0                  dJ       t>        j@                  jC                  |j0                  |      }tq        |ddd      5 }t{        j|                  |      }|j                  g d       |D ]  }|j                  r0|j^                  s$||   d   jr                  tt        jv                  k7  r?||   d   j                  }|d}|j                  ||||   d   ||   d   t        ||   d   jr                        ||   d   |g        	 d d d        |j                  rMg } g }!g }"g }#g }$g }%g }|D ]  }|j                  r0|j^                  s$||   d   jr                  tt        jv                  k7  r@||jY                  d       n!|jY                  ||   d   j                         | jY                  |       |!jY                  |       |"jY                  ||   d          |#jY                  ||   d          |$jY                  t        ||   d   jr                               |%jY                  ||   d           t        j                  | |!|"|#|$|%|d      }&|&j                  | ddd       t!                 |j                          y # t"        $ r}t!        dg|        Y d }~d }~ww xY w# t"        $ r.}t!        dy|        t3        j4                  db       Y d }~d }~ww xY wc c}w # 1 sw Y   ,xY w# 1 sw Y   xY w)Nz
 (Version ))formatter_classdescriptionz	--versionversionz vz-Display version information and dependencies.)actionr   helpz	--verbosez-vz-dz--debug
store_trueverboseFz0Display extra debugging information and metrics.)r   destdefaultr   z--folderoutputz-fofolderoutputzTIf using multiple usernames, the output of the results will be saved to this folder.)r   r   z--outputz-ooutputzNIf using single username, the output of the result will be saved to this file.z--torz-trb   z[Make requests over Tor; increases runtime; requires Tor to be installed and in system path.z--unique-torz-urc   zMake requests over Tor with new Tor circuit after each request; increases runtime; requires Tor to be installed and in system path.z--csvcsvz)Create Comma-Separated Values (CSV) File.z--xlsxxlsxzKCreate the standard file for the modern Microsoft Excel spreadsheet (xlsx).z--siter]   	SITE_NAME	site_listz\Limit analysis to just the listed sites. Add multiple options to specify more than one site.)r   metavarr   r   r   z--proxyz-p	PROXY_URLstorere   z8Make requests over a proxy. e.g. socks5://127.0.0.1:1080)r   r   r   r   r   z--dump-responserd   z8Dump the HTTP response to stdout for targeted debugging.z--jsonz-j	JSON_FILE	json_filez]Load data from a JSON file or an online, valid, JSON file. Upstream PR numbers also accepted.)r   r   r   r   z	--timeoutTIMEOUTrf   <   z@Time (in seconds) to wait for response to requests (Default: 60))r   r   r   typer   r   z--print-all	print_allz.Output sites where the username was not found.z--print-foundprint_foundTzEOutput sites where the username was found (also if exported as file).z
--no-colorno_colorzDon't color terminal outputrP   +	USERNAMESzrOne or more usernames to check with social networks. Check similar usernames using {?} (replace to '_', '-', '.').)nargsr   r   r   z--browsez-bbrowsez)Browse to all results on default browser.z--localz-lz*Force the use of the local data.json file.)r   r   r   z--nsfwz1Include checking of NSFW sites from default list.z--no-txtno_txtzDisable creation of a txt filetag_namer   zUpdate available! z --> 
html_urlz1A problem occurred while checking for an update: z-Tor and Proxy cannot be set at the same time.zUsing the proxy: zUsing Tor to make requestszyWarning: some websites might refuse connecting over Tor, so note that using this option might increase connection errors.)stripconvert)	autoresetz+You can only use one of the output methods.z0You can only use --output with a single usernamezresources/data.jsonz=https://api.github.com/repos/sherlock-project/sherlock/pulls/r   zERROR: Pull request #z not found.r   shaz<https://raw.githubusercontent.com/sherlock-project/sherlock/z%/sherlock_project/resources/data.jsonzERROR:  )do_not_remover   r   z Error: Desired sites not found: z, rZ   )r5   r   r   r   )rb   rc   rd   re   rf   )exist_okz.txtwzutf-8)r   rq   rs   z&Total Websites Username Detected On : z.csvrr   )newliner   )rP   namerl   rs   existsrt   response_time_srl   rt   z.xlsxsheet1)
sheet_nameindex)Hr   r   r   r   add_argumentr   r   
parse_argssignalSIGINTr   r7   r   r   r   
json_loadsr   r   rb   re   rc   r   r   r   r   r   r   r   rP   localr   ospathjoindirname__file__r   	isnumericnsfwremove_nsfw_sitesr   r   informationlowerr]   r   r   r   r   rW   r_   r   rd   rf   makedirsr   openrq   r   r   writer   writerwriterowr   r   r:   r   pd	DataFrameto_excelr   )'parserr   latest_release_rawlatest_release_jsonlatest_remote_tagr   sitesjson_file_locationpull_numberpull_urlpull_request_rawpull_request_jsonhead_commit_shasitesite_data_allr`   site_missingcounterexisting_sitera   all_usernamesrP   r   resultsresult_filefileexists_counterwebsite_name
dictionary
csv_reportr  r   	usernamesnamesrl   rs   r   rt   r  s'                                          r   mainr/  6  sx   3#nJ{m1=F  /K=1<	   ?  	 c	   ]	   j    S   8   Z   k   G   G   l   O   =   T   *    B   8   9   @	   -   D MM&--)K%\\*BCHH();</
;QR K/$[M7H7L6M(457 xxTZZ+GHH zz!DJJ./xx4??*+ H	
 }}4' 	t {{4#4#4#@;< {{3t}}#5#:@A::$RWW__X68MNE "&~~>>++-"&..K!^_j^klH'/||H'='B'B$(23C(D% !$55 5k]+NO&7&?&FO+ghwgx  y^  *_&$%78E
 99dnn=
 >CCTTYY 0 00CMC~~!	 	NN 	1DG!. !::<=#6#6#88/<]/KIm,qLG! !|##avQK0	1 4TYY|5L4MQOPHHQK $T\\T^^DKKL
 MMM +x(*84 +$$T*+   *+ " t,,**LL	
 ;;++K KK))D9'',,t'8'8XJd:KLK%Jd+K{{k39 XT!"$+ BL!(!6J!~~h/66+:M:MM&!+

:j#9D#@A	B
 

CNCSSUVWX 88%Jd+K   D--= ggll4+<+<kJk3WE "J/
 $ D(( $#DM(3::k>Q>QQ &-dmH&=&H&HO&.*,OO$ #DM*5#DM*5h 7 > >?#DM-8+
"F 99IEHHFK O A$$ NNh/66+:M:MM"*#**2.#**74=+B+M+MN  *T"j 9:j 9:c'$-"9"@"@AB""74=#?@#A&  )! ( ($#.'6
I (51heTitj E  KA%IJJKz   ! DzX X"" "sW    Ai 5Di+ &j%9j*3j* Cj7	i(i##i(+	j"4#jj"*j4	7k	__main__)FFFNr   )8__doc__r   sherlock_project.__init__r   r   r   r   r   r   pandasr  r  r   argparser   r   r   r   r  timer   typingr	   r7   requests_futures.sessionsr
   r   r   r   r   sherlock_project.resultr   r   sherlock_project.notifyr   r   sherlock_project.sitesr   coloramar   r   r   rI   rN   rW   r\   r_   r:   rL   boolr   r   r   r   r/  r0   rV   r!   r   <module>r=     sI   ?    	 	 @ $    4  0 / / 4 3  &>
^ >
B3<  hhh h 
	h
 h h C=h hV2Wt zF E  	
IJ	
xyCHHQKs   C 'C54C5