<s> from injector import GetInjector , PostInjector , CookieInjector , UserAgentInjector , CmdInjector <EOL> from context import Context <EOL> from exceptions import OutboundException , PluginMustOverride , Unavailable <EOL> from async import AsyncPool <EOL> from wrappers import DatabaseWrapper , TableWrapper , FieldWrapper <EOL> DBS_ENUM = <NUM_LIT> <EOL> TABLES_ENUM = <NUM_LIT> <EOL> COLS_ENUM = <NUM_LIT> <EOL> FIELDS_ENUM = <NUM_LIT> <EOL> STR = <NUM_LIT> <EOL> COMMENT = <NUM_LIT> <EOL> class DBMSFactory : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , plugin_class , name , desc ) : <EOL> self . _clazz = plugin_class <EOL> self . _name = name <EOL> self . _desc = desc <EOL> def get ( self , context = Context ( ) , limit_max_count = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> inst = self . _clazz ( GetInjector ( context ) , limit_max_count ) <EOL> inst . name = self . _name <EOL> inst . desc = self . _desc <EOL> return inst <EOL> def post ( self , context = Context ( ) , limit_max_count = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> inst = self . _clazz ( PostInjector ( context ) , limit_max_count ) <EOL> inst . name = self . _name <EOL> inst . desc = self . _desc <EOL> return inst <EOL> def user_agent ( self , method , context = Context ( ) , limit_max_count = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> inst = self . _clazz ( UserAgentInjector ( method , context ) , limit_max_count ) <EOL> inst . name = self . _name <EOL> inst . desc = self . _desc <EOL> return inst <EOL> def cookie ( self , method = '<STR_LIT:GET>' , context = Context ( ) , limit_max_count = <NUM_LIT> , data = None , content_type = None ) : <EOL> """<STR_LIT>""" <EOL> inst = self . _clazz ( CookieInjector ( method , context , data , content_type ) , limit_max_count ) <EOL> inst . name = self . _name <EOL> inst . desc = self . _desc <EOL> return inst <EOL> def cmd ( self , context = Context ( ) , limit_max_count = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> inst = self . _clazz ( CmdInjector ( context ) , limit_max_count ) <EOL> inst . name = self . _name <EOL> inst . desc = self . _desc <EOL> return inst <EOL> def custom ( self , injector , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in kwargs : <EOL> limit_max_count = kwargs [ '<STR_LIT>' ] <EOL> del kwargs [ '<STR_LIT>' ] <EOL> else : <EOL> limit_max_count = <NUM_LIT> <EOL> inst = self . _clazz ( injector ( * args , ** kwargs ) , limit_max_count ) <EOL> inst . name = self . _name <EOL> inst . desc = self . _desc <EOL> return inst <EOL> class dbms : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , desc ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . desc = desc <EOL> def __call__ ( self , inst ) : <EOL> return DBMSFactory ( inst , self . name , self . desc ) <EOL> class allow : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , flags ) : <EOL> self . flags = flags <EOL> def __call__ ( self , inst ) : <EOL> def wrapped_ ( * args ) : <EOL> a = inst ( * args ) <EOL> if hasattr ( a , '<STR_LIT>' ) : <EOL> a . capabilities |= self . flags <EOL> else : <EOL> a . capabilities = self . flags <EOL> return a <EOL> return wrapped_ <EOL> class DBMS : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , forge , injector = None , limit_count_max = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> self . forge_class = forge <EOL> self . context = injector . get_context ( ) <EOL> self . forge = forge ( self . context ) <EOL> self . injector = injector <EOL> self . limit_count_max = limit_count_max <EOL> self . current_db = None <EOL> self . current_user = None <EOL> def has_cap ( self , cap ) : <EOL> """<STR_LIT>""" <EOL> return ( self . capabilities & cap ) == cap <EOL> def determine ( self ) : <EOL> """<STR_LIT>""" <EOL> raise PluginMustOverride <EOL> def get_forge ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . forge <EOL> def set_injector ( self , injector ) : <EOL> """<STR_LIT>""" <EOL> method = self . injector . getMethod ( ) <EOL> self . injector = injector ( self . context , method ) <EOL> def get_injector ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . injector <EOL> def set_forge ( self , forge ) : <EOL> """<STR_LIT>""" <EOL> self . forge_class = forge <EOL> self . forge = forge ( self . context ) <EOL> def set_trigger ( self , trigger ) : <EOL> """<STR_LIT>""" <EOL> self . injector . set_trigger ( trigger ) <EOL> def use ( self , db ) : <EOL> """<STR_LIT>""" <EOL> self . current_db = db <EOL> return DatabaseWrapper ( self , self . current_db ) <EOL> def apply_bisec ( self , cdt , min , max ) : <EOL> """<STR_LIT>""" <EOL> while ( max - min ) > <NUM_LIT:1> : <EOL> mid = ( max - min ) / <NUM_LIT:2> + min <EOL> if self . injector . inject ( self . forge . wrap_bisec ( self . forge . forge_cdt ( cdt , mid ) ) ) : <EOL> max = mid <EOL> else : <EOL> min = mid <EOL> return min <EOL> def get_inband_str ( self , sql ) : <EOL> """<STR_LIT>""" <EOL> return self . injector . inject ( self . forge . wrap_sql ( self . forge . forge_second_query ( sql ) ) ) <EOL> def get_inband_int ( self , sql ) : <EOL> """<STR_LIT>""" <EOL> return int ( self . get_inband_str ( sql ) ) <EOL> def get_blind_int ( self , sql ) : <EOL> """<STR_LIT>""" <EOL> pool = AsyncPool ( self ) <EOL> if self . context . is_multithread ( ) : <EOL> pool . add_bisec_task ( sql , <NUM_LIT:0> , self . limit_count_max ) <EOL> else : <EOL> pool . add_classic_bisec_task ( sql , <NUM_LIT:0> , self . limit_count_max ) <EOL> pool . solve_tasks ( ) <EOL> return pool . result [ <NUM_LIT:0> ] <EOL> def get_char ( self , sql , pos ) : <EOL> """<STR_LIT>""" <EOL> return self . forge . get_char ( sql , pos ) <EOL> def get_blind_str ( self , sql ) : <EOL> """<STR_LIT>""" <EOL> size = self . get_blind_int ( self . forge . string_len ( sql ) ) <EOL> if size == ( self . limit_count_max - <NUM_LIT:1> ) : <EOL> raise OutboundException ( ) <EOL> if self . context . is_multithread ( ) : <EOL> pool = AsyncPool ( self ) <EOL> for p in range ( size ) : <EOL> pool . add_bisec_task ( self . forge . ascii ( self . forge . get_char ( sql , p + <NUM_LIT:1> ) ) , <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> pool . solve_tasks ( ) <EOL> return pool . get_str_result ( ) <EOL> else : <EOL> result = '<STR_LIT>' <EOL> for p in range ( size ) : <EOL> pool = AsyncPool ( self ) <EOL> pool . add_classic_bisec_task ( self . forge . ascii ( self . forge . get_char ( sql , p + <NUM_LIT:1> ) ) , <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> pool . solve_tasks ( ) <EOL> result += pool . get_str_result ( ) <EOL> return result <EOL> def get_int ( self , sql ) : <EOL> """<STR_LIT>""" <EOL> if self . context . is_blind ( ) : <EOL> return self . get_blind_int ( sql ) <EOL> else : <EOL> return self . get_inband_int ( sql ) <EOL> def get_str ( self , sql ) : <EOL> """<STR_LIT>""" <EOL> if self . context . is_blind ( ) : <EOL> return self . get_blind_str ( sql ) <EOL> else : <EOL> return self . get_inband_str ( sql ) <EOL> def version ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_str ( self . forge . get_version ( ) ) <EOL> def database ( self , db = None ) : <EOL> """<STR_LIT>""" <EOL> if db is not None : <EOL> return DatabaseWrapper ( self , db ) <EOL> else : <EOL> self . current_db = self . get_str ( self . forge . get_current_database ( ) ) <EOL> return DatabaseWrapper ( self , self . current_db ) <EOL> def get_nb_databases ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_int ( self . forge . get_nb_databases ( ) ) <EOL> def get_database_name ( self , id ) : <EOL> """<STR_LIT>""" <EOL> return self . get_str ( self . forge . get_database_name ( id ) ) <EOL> def databases ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . has_cap ( DBS_ENUM ) : <EOL> n = self . get_nb_databases ( ) <EOL> for i in range ( n ) : <EOL> yield DatabaseWrapper ( self , self . get_database_name ( i ) ) <EOL> else : <EOL> raise Unavailable ( ) <EOL> def get_nb_tables ( self , db = None ) : <EOL> """<STR_LIT>""" <EOL> if db : <EOL> return self . get_int ( self . forge . get_nb_tables ( db = db ) ) <EOL> else : <EOL> db = self . database ( ) <EOL> return self . get_int ( self . forge . get_nb_tables ( db = db ) ) <EOL> def get_table_name ( self , id , db = None ) : <EOL> """<STR_LIT>""" <EOL> return self . get_str ( self . forge . get_table_name ( id , db = db ) ) <EOL> def tables ( self , db = None ) : <EOL> """<STR_LIT>""" <EOL> if self . has_cap ( TABLES_ENUM ) : <EOL> if db is None : <EOL> if self . current_db is None : <EOL> self . database ( ) <EOL> db = self . current_db <EOL> n = self . get_nb_tables ( db ) <EOL> for i in range ( n ) : <EOL> yield TableWrapper ( self , self . get_table_name ( i , db ) , db ) <EOL> else : <EOL> raise Unavailable ( ) <EOL> def get_nb_fields ( self , table , db ) : <EOL> """<STR_LIT>""" <EOL> return self . get_int ( self . forge . get_nb_fields ( table , db = db ) ) <EOL> def get_field_name ( self , table , id , db ) : <EOL> """<STR_LIT>""" <EOL> return self . get_str ( self . forge . get_field_name ( table , id , db ) ) <EOL> def fields ( self , table , db = None ) : <EOL> """<STR_LIT>""" <EOL> if self . has_cap ( FIELDS_ENUM ) : <EOL> if db is None : <EOL> if self . current_db is None : <EOL> self . database ( ) <EOL> db = self . current_db <EOL> n = self . get_nb_fields ( table , db ) <EOL> for i in range ( n ) : <EOL> yield FieldWrapper ( self , table , db , self . get_field_name ( table , i , db ) ) <EOL> else : <EOL> raise Unavailable ( ) <EOL> def user ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_str ( self . forge . get_user ( ) ) <EOL> def count_table_records ( self , table , db = None , max = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> if db is None : <EOL> if self . currrent_db is None : <EOL> self . database ( ) <EOL> db = self . current_db <EOL> return self . get_int ( self . forge . count ( self . forge . select_all ( table , db ) ) ) <EOL> def get_record_field_value ( self , field , table , pos , db = None ) : <EOL> """<STR_LIT>""" <EOL> if db is None : <EOL> if self . currrent_db is None : <EOL> self . database ( ) <EOL> db = self . current_db <EOL> return self . get_str ( self . forge . get_table_field_record ( field , table , db , pos ) ) <EOL> def __getitem__ ( self , i ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( i , ( int , long ) ) : <EOL> d = self . getDatabaseName ( i ) <EOL> if d is None : <EOL> raise IndexError <EOL> else : <EOL> return DatabaseWrapper ( self , d ) <EOL> elif isinstance ( i , basestring ) : <EOL> return DatabaseWrapper ( self , i ) <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_nb_databases ( ) </s>
