Exemple #1
0
def test_reset_datastore_encryptor(key_file):
    unlock_datastore_encryptor(key_file.parent, MOCK_SECRET, key_file.name)
    key_file_hash_1 = get_file_sha256_hash(key_file)

    reset_datastore_encryptor(key_file.parent, MOCK_SECRET, key_file.name)
    key_file_hash_2 = get_file_sha256_hash(key_file)

    assert key_file_hash_1 != key_file_hash_2
Exemple #2
0
def test_file_encrypted(in_place_bitflip_file_encryptor, ransomware_target,
                        file_name, cleartext_hash, encrypted_hash):
    test_keyboard = ransomware_target / file_name

    assert get_file_sha256_hash(test_keyboard) == cleartext_hash

    in_place_bitflip_file_encryptor(test_keyboard)

    assert get_file_sha256_hash(test_keyboard) == encrypted_hash
Exemple #3
0
def test_existing_key_reused(key_file):
    assert not key_file.is_file()

    unlock_datastore_encryptor(key_file.parent, MOCK_SECRET, key_file.name)
    key_file_hash_1 = get_file_sha256_hash(key_file)

    unlock_datastore_encryptor(key_file.parent, MOCK_SECRET, key_file.name)
    key_file_hash_2 = get_file_sha256_hash(key_file)

    assert key_file_hash_1 == key_file_hash_2
Exemple #4
0
def test_reset_when_encryptor_is_none(key_file):
    with key_file.open(mode="w") as f:
        f.write("")

    reset_datastore_encryptor(key_file.parent, MOCK_SECRET, key_file.name)
    assert (get_file_sha256_hash(key_file) !=
            "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
Exemple #5
0
def test_encrypted_file_has_new_extension(ransomware_target):
    test_keyboard = ransomware_target / TEST_KEYBOARD_TXT
    encrypted_test_keyboard = ransomware_target / with_extension(
        TEST_KEYBOARD_TXT)
    encryptor = InPlaceFileEncryptor(encrypt_bytes=flip_bits,
                                     new_file_extension=EXTENSION)

    encryptor(test_keyboard)

    assert not test_keyboard.exists()
    assert encrypted_test_keyboard.exists()
    assert get_file_sha256_hash(
        encrypted_test_keyboard) == TEST_KEYBOARD_TXT_ENCRYPTED_SHA256
def test_leave_readme(src_readme, dest_readme):
    leave_readme(src_readme, dest_readme)

    assert get_file_sha256_hash(dest_readme) == README_HASH
def test_readme_already_exists(src_readme, dest_readme):
    dest_readme.touch()

    leave_readme(src_readme, dest_readme)

    assert get_file_sha256_hash(dest_readme) == EMPTY_FILE_HASH
def test_get_file_sha256_hash(stable_file, stable_file_sha256_hash):
    assert get_file_sha256_hash(stable_file) == stable_file_sha256_hash
Exemple #9
0
def _is_not_ransomware_readme_filter(filepath: Path) -> bool:
    if filepath.name != README_FILE_NAME:
        return True

    return get_file_sha256_hash(filepath) != README_SHA256_HASH