Пример #1
0
 def get_waf_rules(self, waf_key_a, waf_key_b, rules_a_already_used,
                   rules_b_already_used):
     """
     Args:
         waf_key_a (str): The WAF name
         waf_key_b (str): The WAF name
         rules_a_already_used (list): A list containing the names of the files
                             that will be excluded
         rules_b_already_used (list): A list containing the names of the files
                             that will be excluded
     Returns:
         str,str: Two file paths, which are the selected rulesets
     """
     available_files_a = [
         x for x in self.seed_files_list if x not in rules_a_already_used
     ]
     available_files_b = [
         x for x in self.seed_files_list if x not in rules_b_already_used
     ]
     if self.configuration['RANDOM']:
         random.shuffle(available_files_a)
         random.shuffle(available_files_b)
     selected_rule_a = findlibrary(available_files_a[0])
     selected_rule_b = findlibrary(available_files_b[0])
     print ' * Rules ' + selected_rule_a, " and " + selected_rule_b + " where selected in this test"
     return selected_rule_a, selected_rule_b
Пример #2
0
 def __init__(self, configuration):
     self.mma = self.read_file(findlibrary(configuration['FILE_A']), findlibrary(configuration['FILE_TYPE_A']))
     self.states_a = len(self.mma)
     self.mmb = self.read_file(findlibrary(configuration['FILE_B']), findlibrary(configuration['FILE_TYPE_B']))
     self.states_b = len(self.mmb)
     self.mmc = None
     self.operation = configuration['OPERATION']
     self.result = configuration['RESULT']
     self.alphabet = createalphabet(configuration['ALPHABET'])
     pass
Пример #3
0
 def get_waf_rules(self, waf_key_a, waf_key_b, rules_a_already_used,
                   rules_b_already_used):
     """
     Args:
         waf_key_a (str): The WAF name
         waf_key_b (str): The WAF name
         rules_a_already_used (list): A list containing the names of the files
                             that will be excluded
         rules_b_already_used (list): A list containing the names of the files
                             that will be excluded
     Returns:
         str,str: Two file paths, which are the selected rulesets
     """
     waf_a_rules_folder = findlibrary(self.wafs[waf_key_a]["data"]["RULE"])
     waf_b_rules_folder = findlibrary(self.wafs[waf_key_b]["data"]["RULE"])
     if os.path.isfile(waf_a_rules_folder):
         selected_rule_a = waf_a_rules_folder
     else:
         ruleslist = self.get_files_by_file_size(waf_a_rules_folder,
                                                 rules_a_already_used)
         if self.configuration['RANDOM']:
             random.shuffle(ruleslist)
         if len(ruleslist) == 0:
             selected_rule_a = ''
         else:
             selected_rule_a = ruleslist[0]
     if os.path.isfile(waf_b_rules_folder):
         selected_rule_b = waf_b_rules_folder
     else:
         ruleslist = self.get_files_by_file_size(waf_b_rules_folder,
                                                 rules_b_already_used)
         if self.configuration['RANDOM']:
             random.shuffle(ruleslist)
         if len(ruleslist) == 0:
             selected_rule_b = ''
         else:
             selected_rule_b = ruleslist[0]
     print ' * Rules ' + selected_rule_a, " and " + selected_rule_b + " where selected in this test"
     return selected_rule_a, selected_rule_b
Пример #4
0
 def __init__(self, configuration):
     self.configuration = configuration
     self.distinguisher = None
     self.name = None
     self.queries = 0
     with open(findlibrary(configuration['FILE_IN']), 'r') as fp:
         self.wafs = json.load(fp, object_pairs_hook=OrderedDict)
     self.membership_queries = 0
     self.cache_membership_queries = 0
     self.equivalence_queries = 0
     self.cache_equivalence_queries = 0
     self.equivalence_queries_cached_membership = 0
     self.browserstates = 0
     self.cross_check_times = 0
Пример #5
0
 def __init__(self, configuration):
     """
     Overides the init constructor in order to set
     the handler instance as class variable
     Args:
         configuration (dict): The dictionary to be used
         as input in the default setup function of the
         class
     Returns:
         None
     """
     self.distinguisher = None
     self.loadfile(findlibrary(configuration['FILE']))
     self.httphandler = handler_class(handler_configuration)
     self.name = None
     self.queries = 0
Пример #6
0
    def __init__(self, configuration, shared_memory, cross):
        self.setup(configuration)
        if not self.alphabet or isinstance(self.alphabet, str):
            self.alphabet = createalphabet(self.alphabet)
        super(SFADiff, self).__init__(self.alphabet)
        self.membership_queries = 0
        self.cache_membership_queries = 0
        self.equivalence_queries = 0
        self.cache_equivalence_queries = 0
        self.cache_equivalence = []
        self.cache_membership = {}
        self.ids_membership_queries = 0
        self.ids_cache_membership_queries = 0
        self.ids_equivalence_queries = 0
        self.ids_cache_equivalence_queries = 0
        self.ids_states = 0
        self.browserstates = 0
        self.cross_check_times = 0
        self.equivalence_queries_cached_membership = 0
        self.ids_equivalence_queries_cached_membership = 0
        self.num_diff = 2
        self.shared_memory = shared_memory
        self.cross = cross
        self.dfa1_minus_dfa2 = accept_bool(self.dfa1_minus_dfa2)
        self.mma = None
        self.mmac = None
        self.pda = None
        self.bypass = None

        if self.seed_file is not None and self.seed_file_type is not None:
            if self.seed_file_type == "FLEX":
                flex_object_m = _Flexparser(self.alphabet)
                self.mma = flex_object_m.yyparse(findlibrary(self.seed_file))
                self.mma.minimize()
            elif self.seed_file_type == "GRAMMAR":
                cfgtopda = _CfgPDA(self.alphabet)
                self.mma = cfgtopda.yyparse(findlibrary(self.seed_file), 1)
            elif self.seed_file_type == "FST":
                self.mma = _DFA(self.alphabet)
                self.mma.load(findlibrary(self.seed_file))
                self.mma.minimize()

        if self.tests_file is not None and self.tests_file_type is not None:
            if self.tests_file_type == "FLEX":
                flex_object_m = _Flexparser(self.alphabet)
                self.mmac = flex_object_m.yyparse(findlibrary(self.tests_file))
                self.mmac.minimize()
            elif self.tests_file_type == "GRAMMAR":
                cfgtopda = _CfgPDA(self.alphabet)
                self.mmac = cfgtopda.yyparse(findlibrary(self.tests_file), 1)
            elif self.tests_file_type == "FST":
                self.mmac = _DFA(self.alphabet)
                self.mmac.load(findlibrary(self.tests_file))
                self.mmac.minimize()
Пример #7
0
 def __init__(self, configuration):
     self.setup(configuration)
     if not self.alphabet or isinstance(self.alphabet, str):
         self.alphabet = createalphabet(self.alphabet)
     super(GOFA, self).__init__(self.alphabet)
     self.membership_queries = 0
     self.cache_membership_queries = 0
     self.equivalence_queries = 0
     self.cache_equivalence_queries = 0
     self.cache_equivalence = []
     self.cache_membership = {}
     self.mma = None
     self.mmac = None
     self.bypass = None
     if self.seed_file is not None and self.seed_file_type is not None:
         if self.seed_file_type == "FLEX":
             flex_object_m = _Flexparser(self.alphabet)
             self.mma = flex_object_m.yyparse(findlibrary(self.seed_file))
             self.mma.minimize()
         elif self.seed_file_type == "GRAMMAR":
             cfgtopda = _CfgPDA(self.alphabet)
             self.mma = cfgtopda.yyparse(findlibrary(self.seed_file), 1)
         elif self.seed_file_type == "FST":
             self.mma = _DFA(self.alphabet)
             self.mma.load(findlibrary(self.seed_file))
             self.mma.minimize()
     if self.tests_file is not None and self.tests_file_type is not None:
         if self.tests_file_type == "FLEX":
             flex_object_m = _Flexparser(self.alphabet)
             self.mmac = flex_object_m.yyparse(findlibrary(self.tests_file))
             self.mmac.minimize()
         elif self.tests_file_type == "GRAMMAR":
             cfgtopda = _CfgPDA(self.alphabet)
             self.mmac = cfgtopda.yyparse(findlibrary(self.tests_file), 1)
         elif self.tests_file_type == "FST":
             self.mmac = _DFA(self.alphabet)
             self.mmac.load(findlibrary(self.tests_file))
             self.mmac.minimize()
Пример #8
0
 def learn(self):
     newdistinguisher = self.generate_distinguish_tree(list(self.wafs))
     with open(findlibrary(self.configuration['FILE_OUT']), 'w') as fp:
         json.dump(newdistinguisher, fp, sort_keys=True, indent=4)