Пример #1
0
def create_uid(input_data):
    '''
    creates an unique identifier: SHA256_SIZE
    '''
    hash_value = get_sha256(input_data)
    size = len(make_bytes(input_data))
    return "{}_{}".format(hash_value, size)
Пример #2
0
def _get_meta_data(raw):
    meta = {}
    for item in META_FIELDS:
        tmp = re.search(b'%%%? ?(' + make_bytes(item) + b'):([\\w=., -]+)', raw)
        if tmp:
            meta[make_unicode_string(tmp.group(1))] = remove_uneccessary_spaces(make_unicode_string(tmp.group(2)))
    return meta
Пример #3
0
 def test_app_show_analysis_file_with_preview(self):
     result = self.test_client.get('/analysis/{}'.format(
         TEST_TEXT_FILE.get_uid())).data
     assert b'<strong>UID:</strong> ' + make_bytes(
         TEST_TEXT_FILE.get_uid()) in result
     assert b'Preview' in result
     assert b'test file:\ncontent:'
Пример #4
0
def create_uid(input_data: bytes) -> str:
    '''
    generate a UID (unique identifier) SHA256_SIZE for a byte string containing data (e.g. a binary)

    :param input_data: the data to generate the UID for
    :return: a string containing the UID
    '''
    hash_value = get_sha256(input_data)
    size = len(make_bytes(input_data))
    return '{}_{}'.format(hash_value, size)
Пример #5
0
    def set_binary(self, binary: bytes) -> None:
        '''
        Store the binary representation of the file as byte string.
        Additionally set binary related meta data (size, hash) and compute uid after that.

        :param binary: file in binary representation
        '''
        self.binary = make_bytes(binary)
        self.sha256 = get_sha256(self.binary)
        self.size = len(self.binary)
        self._uid = create_uid(binary)
Пример #6
0
 def test_app_show_analysis_get_valid_fw(self):
     rv = self.test_client.get('/analysis/{}'.format(TEST_FW.get_uid()))
     assert b'<strong>UID:</strong> ' + make_bytes(
         TEST_FW.get_uid()) in rv.data
     assert b'data-toggle="tooltip" title="mandatory plugin description"' in rv.data
     assert b'data-toggle="tooltip" title="optional plugin description"' in rv.data
     assert b'data-toggle="tooltip" title="default plugin description"' not in rv.data
     # check release date not available
     assert b'1970-01-01' not in rv.data
     assert b'unknown' in rv.data
     # check file preview
     assert b'Preview' not in rv.data
Пример #7
0
 def test_app_re_analyze_post_valid(self):
     form_data = {
         'device_name': '',
         'device_name_dropdown': TEST_FW.device_name,
         'device_part': '',
         'device_part_dropdown': TEST_FW.part,
         'device_class': TEST_FW.device_class,
         'version': TEST_FW.version,
         'vendor': TEST_FW.vendor,
         'release_date': TEST_FW.release_date,
         'tags': '',
         'analysis_systems': ["new_system"]}
     rv = self.test_client.post('/update-analysis/{}'.format(TEST_FW.uid), data=form_data)
     assert b'Upload Successful' in rv.data
     assert make_bytes(TEST_FW.uid) in rv.data
     self.assertEqual(self.mocked_interface.tasks[0].uid, TEST_FW.uid, "fw not added to intercom")
     self.assertIn("new_system", self.mocked_interface.tasks[0].scheduled_analysis, "new analysis system not scheduled")
Пример #8
0
 def set_binary(self, binary):
     self.binary = make_bytes(binary)
     self.sha256 = get_sha256(self.binary)
     self.size = len(self.binary)
     self.uid = create_uid(binary)
Пример #9
0
def test_make_bytes(input_data):
    result = make_bytes(input_data)
    assert isinstance(result, bytes)
    assert result == b'test string'
Пример #10
0
def get_hash(hash_function, binary):
    binary = make_bytes(binary)
    raw_hash = new(hash_function)
    raw_hash.update(binary)
    string_hash = raw_hash.hexdigest()
    return string_hash
Пример #11
0
def get_ssdeep(code):
    binary = make_bytes(code)
    raw_hash = ssdeep.Hash()
    raw_hash.update(binary)
    return raw_hash.digest()
Пример #12
0
def get_tlsh(code):
    return tlsh.hash(make_bytes(code))
Пример #13
0
 def check_type_and_content(self, input_data):
     self.assertIsInstance(make_bytes(input_data), bytes, "type is correct")
     self.assertEqual(make_bytes(input_data), b'test string',
                      "content correct")