-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathgenerator.py
255 lines (165 loc) · 6.48 KB
/
generator.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
from random import randint
import random
import string
import xlsxwriter
from fpdf import FPDF
import os
import urllib.request
import sys
import zipfile
import os.path
import tkinter
from tkinter import messagebox
from shutil import copyfile
import subprocess
import re
import locale
import win32com.client
root = tkinter.Tk()
root.withdraw()
# XLS Files
def randomxls (path) :
numxls = (randint(2000,5000))
for i in range(10):
name = path + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))]) + ".xlsx"
workbook = xlsxwriter.Workbook(name)
worksheet = workbook.add_worksheet()
numrows = (randint(100,500))
for i in range(numrows):
coord = 'A' + str(i)
textinrow = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))])
worksheet.write(coord , textinrow)
workbook.close()
for i in range(numxls):
dupli = path + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))]) + ".xlsx"
copyfile(name, dupli)
#PDF Files
def randompdf (path) :
numpdf = (randint(1500,2000))
for i in range(10):
name = path + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))]) + ".pdf"
numwords = (randint(200,1000))
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
words =[]
for i in range(numwords):
randomword = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))])
words.append(randomword)
wordsinstring = ''.join(words)
pdf.cell(200, 10, txt=wordsinstring, align="C")
pdf.output(name)
for i in range(numpdf):
dupli = path + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))]) + ".pdf"
copyfile(name, dupli)
#first sysinternals file
url1 = 'https://download.sysinternals.com/files/Procdump.zip'
file1 = 'Procdump.zip';
try :
urllib.request.urlretrieve (url1, file1)
except Exception as ex:
print (ex)
if not os.path.isfile(file1):
messagebox.showerror("Error", "Can't download Sysinternals's Files\nTry manually")
sys.exit()
zip_ref = zipfile.ZipFile(file1, 'r')
zip_ref.extractall()
zip_ref.close()
## second file
url2 = 'https://download.sysinternals.com/files/Handle.zip'
file2 = 'Handle.zip';
try :
urllib.request.urlretrieve (url2, file2)
except :
if not os.path.isfile(file1):
messagebox.showerror("Error", "Can't download Sysinternals's Files\nTry manually")
sys.exit()
zip_ref = zipfile.ZipFile(file2, 'r')
zip_ref.extractall()
zip_ref.close()
langlocal = locale.getdefaultlocale()
if langlocal[0] == "es_ES" :
messagebox.showinfo("AntiRansom V5", "La instalacion puede durar hasta 5 minutos\nPor favor, sea paciente")
else :
messagebox.showinfo("AntiRansom V5", "Installation could take up to 5 minutes\nPlease be patient")
finalpathsys = os.environ['USERPROFILE'] + "\\" + str((randint(1,100))) + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))]) + "\\"
os.mkdir (finalpathsys)
randomxls(finalpathsys)
randompdf(finalpathsys)
finalpathexes = os.environ['USERPROFILE'] + "\\" + ''.join([random.choice(string.ascii_letters) for n in range(randint(5,15))]) + "\\"
os.mkdir (finalpathexes)
procdumpfinal = finalpathexes + 'procdump.exe'
copyfile("procdump.exe", procdumpfinal)
handlefinal = finalpathexes + 'handle.exe'
copyfile("handle.exe", handlefinal)
monitexe = str((randint(1,9))) + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))]) + ".exe"
namemonit = finalpathexes + monitexe
namesplash = finalpathexes+ 'splash.exe'
copyfile("monit.exe", namemonit)
copyfile("splash.exe", namesplash)
taskrandom = str((randint(1,100))) + ''.join([random.choice(string.ascii_letters + string.digits) for n in range(randint(5,15))])
#taskpath = re.sub(r"\\", r"\\\\", finalpathsys)
# Task Stuff borrowed from https://dzone.com/articles/create-and-run-scheduled-task
action_id = taskrandom
action_path = namemonit
action_arguments = finalpathsys[:-1]
action_workdir = finalpathexes
task_id = taskrandom
task_hidden = False
run_flags = "TASK_RUN_NO_FLAGS"
TASK_TRIGGER_DAILY = 2
TASK_CREATE = 2
TASK_CREATE_OR_UPDATE = 6
TASK_ACTION_EXEC = 0
RUNFLAGSENUM = {
"TASK_RUN_NO_FLAGS" : 0,
"TASK_RUN_AS_SELF" : 1,
"TASK_RUN_IGNORE_CONSTRAINTS" : 2,
"TASK_RUN_USE_SESSION_ID" : 4,
"TASK_RUN_USER_SID" : 8,
}
scheduler = win32com.client.Dispatch("Schedule.Service")
scheduler.Connect()
rootFolder = scheduler.GetFolder("\\")
taskDef = scheduler.NewTask(0)
colTriggers = taskDef.Triggers
trigger = colTriggers.Create(9)
trigger.Enabled = True
colActions = taskDef.Actions
action = colActions.Create(TASK_ACTION_EXEC)
action.ID = action_id
action.Path = action_path
action.WorkingDirectory = action_workdir
action.Arguments = action_arguments
info = taskDef.RegistrationInfo
settings = taskDef.Settings
settings.Enabled = True
settings.Hidden = task_hidden
settings.ExecutionTimeLimit = "PT0S"
settings.StopIfGoingOnBatteries = False
settings.DisallowStartIfOnBatteries = False
principal = taskDef.Principal
principal.RunLevel = 1
result = rootFolder.RegisterTaskDefinition(task_id, taskDef, TASK_CREATE_OR_UPDATE, "", "", RUNFLAGSENUM[run_flags] )
task = rootFolder.GetTask(task_id)
task.Enabled = True
runningTask = task.Run("")
###
file = open("uninstall.bat", "w")
file.write("taskkill /F /IM " + monitexe + "\n")
file.write("schtasks /delete /TN " + taskrandom + " /f" + "\n")
file.write("rmdir " + finalpathsys + " /s /q" + "\n")
file.write("rmdir " + finalpathexes + " /s /q" + "\n")
file.close()
nameunis = finalpathexes + 'uninstall.bat'
copyfile("uninstall.bat", nameunis)
disabindex = 'sc config WSearch start= disabled'
disabperm = 'sc stop WSearch'
os.system(disabindex)
os.system(disabperm)
startcommand = "schtasks /Run /TN " + taskrandom
subprocess.Popen(startcommand, shell=True)
if langlocal[0] == "es_ES" :
messagebox.showinfo("AntiRansom V5", "Instalacion finalizada !!\nNo borre la carpeta desde la que instalo Anti Ransom")
else :
messagebox.showinfo("AntiRansom V5", "Installation finished !!\nDo NOT delete this installation folder")