def test_app_show_analysis_file_with_preview(self):
     result = self.test_client.get('/analysis/{}'.format(
         TEST_TEXT_FILE.uid)).data
     assert b'<strong>UID:</strong> ' + make_bytes(
         TEST_TEXT_FILE.uid) in result
     assert b'Preview' in result
     assert b'test file:\ncontent:'
Esempio n. 2
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)
Esempio n. 3
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)
    def test_app_show_analysis_get_valid_fw(self):
        result = self.test_client.get(f'/analysis/{TEST_FW.uid}').data
        assert b'<strong>UID:</strong> ' + make_bytes(TEST_FW.uid) in result
        assert b'data-toggle="tooltip" title="mandatory plugin description"' in result
        assert b'data-toggle="tooltip" title="optional plugin description"' in result

        # check release date not available
        assert b'1970-01-01' not in result
        assert b'unknown' in result

        result = self.test_client.get(f'/analysis/{TEST_FW_2.uid}').data
        assert b'unknown' not in result
        assert b'2000-01-01' in result
Esempio n. 5
0
def get_hash(hash_function, binary):
    '''
    Hashes binary with hash_function.

    :param hash_function: The hash function to use. See hashlib for more
    :param binary: The data to hash, either as string or array of Integers
    :return: The hash as hexstring
    '''
    binary = make_bytes(binary)
    raw_hash = new(hash_function)
    raw_hash.update(binary)
    string_hash = raw_hash.hexdigest()
    return string_hash
Esempio n. 6
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(f'/update-analysis/{TEST_FW.uid}',
                                data=form_data)
     assert b'Upload Successful' in rv.data
     assert make_bytes(TEST_FW.uid) in rv.data
     assert self.mocked_interface.tasks[
         0].uid == TEST_FW.uid, 'fw not added to intercom'
     assert 'new_system' in self.mocked_interface.tasks[
         0].scheduled_analysis, 'new analysis system not scheduled'
Esempio n. 7
0
def get_tlsh(code):
    return tlsh.hash(make_bytes(code))
Esempio n. 8
0
def get_ssdeep(code):
    binary = make_bytes(code)
    raw_hash = ssdeep.Hash()
    raw_hash.update(binary)
    return raw_hash.digest()
Esempio n. 9
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
Esempio n. 10
0
def get_tlsh(code):
    tlsh_hash = tlsh.hash(make_bytes(code))  # pylint: disable=c-extension-no-member
    return tlsh_hash if tlsh_hash != 'TNULL' else ''
def test_make_bytes(input_data):
    result = make_bytes(input_data)
    assert isinstance(result, bytes)
    assert result == b'test string'