コード例 #1
0
    def post(self):
        '''
        Start a binary search
        The parameter `uid` is optional and can be specified if the user wants to search the files of a single firmware
        `rule_file` can be something like `rule rule_name {strings: $a = \"foobar\" condition: $a}`
        '''
        payload_data = self.validate_payload_data(binary_search_model)
        if not is_valid_yara_rule_file(payload_data["rule_file"]):
            return error_message('Error in YARA rule file',
                                 self.URL,
                                 request_data=request.data)
        if payload_data["uid"] and not self._is_firmware(payload_data["uid"]):
            return error_message(
                f'Firmware with UID {payload_data["uid"]} not found in database',
                self.URL,
                request_data=request.data)

        with ConnectTo(InterComFrontEndBinding, self.config) as intercom:
            search_id = intercom.add_binary_search_request(
                payload_data["rule_file"].encode(), payload_data["uid"])

        return success_message(
            {
                'message':
                'Started binary search. Please use GET and the search_id to get the results'
            },
            self.URL,
            request_data={'search_id': search_id})
コード例 #2
0
ファイル: rest_binary_search.py プロジェクト: TingHL/FACT3.0
    def _get_yara_rules(request_data):
        if 'rule_file' not in request_data:
            raise RestBinarySearchException(
                'rule_file could not be found in the request data')
        yara_rules = request_data['rule_file']

        if isinstance(yara_rules, str):
            yara_rules = yara_rules.encode()

        if not is_valid_yara_rule_file(yara_rules):
            raise RestBinarySearchException('Error in YARA rule file')

        return yara_rules
コード例 #3
0
 def _app_start_binary_search(self):
     error = None
     if request.method == 'POST':
         yara_rule_file, firmware_uid, only_firmware = self._get_items_from_binary_search_request(request)
         if firmware_uid and not self._firmware_is_in_db(firmware_uid):
             error = 'Error: Firmware with UID {} not found in database'.format(repr(firmware_uid))
         elif yara_rule_file is not None:
             if is_valid_yara_rule_file(yara_rule_file):
                 with ConnectTo(InterComFrontEndBinding, self._config) as connection:
                     request_id = connection.add_binary_search_request(yara_rule_file, firmware_uid)
                 return redirect(url_for('database/database_binary_search_results.html', request_id=request_id, only_firmware=only_firmware))
             error = 'Error in YARA rules: {}'.format(get_yara_error(yara_rule_file))
         else:
             error = 'please select a file or enter rules in the text area'
     return render_template('database/database_binary_search.html', error=error)