class CommonAnalyzer(Analyzer):
    def __init__(self, properties):
        Analyzer.__init__(self, properties)
        self.printer = Printer(properties, 'CommonAnalyzer')

        self.detect_reflected_patterns()
        self.clean_reflected_rows(self.standard_response)

    def analyze(self):
        common_payloads = self.get_payloads('fuzzing/common.txt')
        response_dict = defaultdict(lambda: defaultdict(list))

        encode_list = [url_encode, double_url_encode, overlong_utf8_encode]
        modified_request_groups = self.get_modified_request_groups(
            common_payloads, encode_list)
        modified_requests = reduce(add, zip(*modified_request_groups))

        # self.print_standard_resp_info()

        requester = Requester(modified_requests, self.response_queue,
                              self.properties)
        requester.run()

        self.printer.print_head()

        while requester.is_running() or not self.response_queue.empty():
            response_obj = self.response_queue.get()
            # self.clean_reflected_rows(response_obj)
            response_dict[response_obj.gid][response_obj.id].append(
                response_obj)

            if len(response_dict[response_obj.gid].keys()) == len(encode_list):
                self.printer.print_result_for_response_group(
                    response_dict[response_obj.gid])
示例#2
0
文件: memorite.py 项目: Pomb/memorite
class App:
    def __init__(self, text_file, **kargs):
        self.enabled = True
        self.text_file = text_file
        self.printer = Printer()
        self.lines = line_splitter.extract(text_file)
        self.quest_track = QuestTrack(
            lines=self.lines,
            num_options=kargs['options'],
            num_shown_lines=kargs['lines'])

    def run(self):
        '''The core loop of the application'''
        while(self.enabled):
            clear()

            if self.quest_track.complete:
                self.quest_track.debrief()
                self.enabled = False
                break
            elif self.quest_track.next():
                wait_for_anykey()
            else:
                self.printer.leave()
                break
示例#3
0
文件: memorite.py 项目: Pomb/memorite
 def __init__(self, text_file, **kargs):
     self.enabled = True
     self.text_file = text_file
     self.printer = Printer()
     self.lines = line_splitter.extract(text_file)
     self.quest_track = QuestTrack(
         lines=self.lines,
         num_options=kargs['options'],
         num_shown_lines=kargs['lines'])
示例#4
0
 def __init__(self, lines, num_options, num_shown_lines):
     self.lines = lines
     self.index = 0
     self.correct = 0
     self.printer = Printer()
     self.question_factory = QuestionFactory(
         lines=self.lines,
         num_options=num_options,
         num_shown_lines=num_shown_lines)
     self.question = None
示例#5
0
 def __init__(self, lines, index, num_options, num_shown_lines):
     super().__init__(lines, index)
     self.question_text = 'Choose next line?'
     self.num_options = num_options
     self.num_shown_lines = num_shown_lines
     self.printer = Printer()
     self.answer = lines[index]
     self.options = [self.answer]
     self.user_answer = None
     self.is_answered = False
示例#6
0
class BlindBooleanBasedSqlAnalyzer(Analyzer):
    def __init__(self, properties):
        Analyzer.__init__(self, properties)

        self.printer = Printer(properties, 'BlindBooleanBasedSqlAnalyzer')

        self.blind_sql_and_payloads = self.get_payloads(
            '/fuzzing/sql_blind_and.txt')
        self.blind_sql_or_payloads = self.get_payloads(
            '/fuzzing/sql_blind_or.txt')

        encode_list = [url_encode, double_url_encode, overlong_utf8_encode]
        self.blind_sql_and_payloads = reduce(add, [
            list(map(encode, self.blind_sql_and_payloads))
            for encode in encode_list
        ])
        self.blind_sql_or_payloads = reduce(add, [
            list(map(encode, self.blind_sql_or_payloads))
            for encode in encode_list
        ])

        self.modified_requests = self.get_modified_requests(
            self.blind_sql_and_payloads + self.blind_sql_or_payloads, flags=5)
        for index, request in enumerate(self.modified_requests):
            request.id = index

    def analyze(self):
        print('[!] Запускаю Blind Boolean Based SqlAnalyzer')
        requester = Requester(self.modified_requests, self.response_queue,
                              self.properties)
        requester.run()

        responses = dict()
        self.printer.print_head()

        while requester.is_running() or not self.response_queue.empty():
            response_obj = self.response_queue.get()
            responses[response_obj.id] = response_obj

            if response_obj.id % 2 == 0:
                index = response_obj.id + 1
            else:
                index = response_obj.id - 1

            if responses.get(index) is not None:
                resp1 = response_obj
                resp2 = responses[index]
                # print("[D] Проверка {} и {} запросов".format(resp1.id, resp2.id))
                self._check_diff(resp1, resp2)

    def _check_diff(self, resp1, resp2):
        if resp1.response_code != resp2.response_code or resp1.content_length != resp2.content_length \
                or resp1.row_count != resp2.row_count or resp1.word_count != resp2.word_count:

            self.printer.print_footer()
            self.printer.print_resp_info(resp1)
            self.printer.print_resp_info(resp2)
            self.printer.print_footer()
示例#7
0
 def __init__(self, lines, index, num_options, num_shown_lines):
     super().__init__(lines, index)
     self.question_text = 'Type the missing word?'
     self.num_options = num_options
     self.num_shown_lines = num_shown_lines
     self.printer = Printer()
     self.answer = None
     self.options = []
     self.user_answer = None
     self.is_answered = False
示例#8
0
    def __init__(self, properties):
        Analyzer.__init__(self, properties)

        self.printer = Printer(properties, 'BlindBooleanBasedSqlAnalyzer')

        self.blind_sql_and_payloads = self.get_payloads(
            '/fuzzing/sql_blind_and.txt')
        self.blind_sql_or_payloads = self.get_payloads(
            '/fuzzing/sql_blind_or.txt')

        encode_list = [url_encode, double_url_encode, overlong_utf8_encode]
        self.blind_sql_and_payloads = reduce(add, [
            list(map(encode, self.blind_sql_and_payloads))
            for encode in encode_list
        ])
        self.blind_sql_or_payloads = reduce(add, [
            list(map(encode, self.blind_sql_or_payloads))
            for encode in encode_list
        ])

        self.modified_requests = self.get_modified_requests(
            self.blind_sql_and_payloads + self.blind_sql_or_payloads, flags=5)
        for index, request in enumerate(self.modified_requests):
            request.id = index
    def __init__(self, properties):
        Analyzer.__init__(self, properties)
        self.printer = Printer(properties, 'CommonAnalyzer')

        self.detect_reflected_patterns()
        self.clean_reflected_rows(self.standard_response)
示例#10
0
class ChooseLine(Question):
    def __init__(self, lines, index, num_options, num_shown_lines):
        super().__init__(lines, index)
        self.question_text = 'Choose next line?'
        self.num_options = num_options
        self.num_shown_lines = num_shown_lines
        self.printer = Printer()
        self.answer = lines[index]
        self.options = [self.answer]
        self.user_answer = None
        self.is_answered = False

    @property
    def start_line_index(self):
        return max(self.index - self.num_shown_lines, 0)

    @property
    def answered_correctly(self):
        return self.answer == self.user_answer

    @property
    def allow_duplicates(self):
        return len(self.lines) <= self.num_options

    def print_question(self):
        for i in range(self.start_line_index, self.index):
            print('\t' + self.lines[i])
        self.printer.line(prefix='\t')
        print(f'\nQ: {self.question_text}', '\n')

    def execute(self):
        '''Creates options from the given text then asks'''
        while len(self.options) < self.num_options:
            randomOption = random.choice(self.lines)
            if randomOption != self.answer:
                if self.allow_duplicates:
                    self.options.append(randomOption)
                elif randomOption not in self.options:
                    self.options.append(randomOption)

        random.shuffle(self.options)

    def ask(self):
        '''Displays the question and asks for user answer'''
        self.print_question()
        self.print_options()

        action = Action.Invalid
        displayOptions = {}
        for i, x in enumerate(self.options):
            displayOptions[str(i + 1)] = x

        choice = input('\nAnswer: ')
        if 'q' == choice:
            action = Action.Quit
            self.is_answered = True
            action = Action.Quit
        elif displayOptions.__contains__(choice):
            self.is_answered = True
            self.user_answer = displayOptions[choice]
            action = Action.Continue
        else:
            print('\nInvalid option, please try again!\n')

        return action

    def print_options(self):
        '''Prints the options with the numbers'''
        for i, x in enumerate(self.options):
            print(f'{i+1}: {x}')
示例#11
0
class QuestTrack:
    '''Quest track generates and prompts questions for a length that
    satisfies the number of lines'''
    def __init__(self, lines, num_options, num_shown_lines):
        self.lines = lines
        self.index = 0
        self.correct = 0
        self.printer = Printer()
        self.question_factory = QuestionFactory(
            lines=self.lines,
            num_options=num_options,
            num_shown_lines=num_shown_lines)
        self.question = None

    @property
    def total(self):
        return len(self.lines)

    @property
    def out_of(self):
        return f' {self.index}/{self.total} '

    @property
    def percent(self):
        return f'{self.percent_raw}%'

    @property
    def percent_raw(self):
        return int((self.correct / self.total) * 100)

    def add_score(self, correct):
        if correct:
            self.correct += 1

    @property
    def complete(self):
        return self.index == self.total

    def next(self):
        '''Generates and prompts the next question'''
        self.question = self.question_factory.next(index=self.index)
        complete = False

        while not self.question.is_answered:
            clear()
            self.printer.header(out_of=self.out_of)

            if self.question.ask() == Action.Continue:
                self.add_score(self.question.answered_correctly)
                self.printer.answer_statement(self.question.answered_correctly)
                self.index += 1
                complete = True

        return complete

    def debrief(self):
        self.printer.debrief(percent=self.percent, out_of=self.out_of)
        self.printer.lines(self.lines)
        print(self.get_progress_message())

    def get_progress_message(self):
        if self.percent_raw < 50:
            return 'Read through the text a couple times and then try again'
        elif self.percent_raw < 75:
            return "Oh It's not great, you need to practice more"
        elif self.percent_raw < 90:
            return "It's close but not close enough, try again"
        elif self.percent_raw < 100:
            return "You so close, You'll get it on your next attempt"
        else:
            return "Well done, you know this text"