-
Notifications
You must be signed in to change notification settings - Fork 2
/
shadowcloak.py
261 lines (186 loc) · 8.86 KB
/
shadowcloak.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
256
257
258
259
260
261
# /undead_warlock
# GPL3.0-or-foward
from ctypes import *
import secrets
import optparse
import winreg
import os
import re
### READ THE READ.ME PLEASE
##############################################################################
def optparser():
parser = optparse.OptionParser()
parser.add_option("-m", "--mtd", dest = "mtd", help = "True | False")
parser.add_option("-r", "--registry", dest= "registry", help = "True | False" )
parser.add_option("-e", "--extension", dest = "extension_list", help= " .txt ")
parser.add_option("-d", "--directory", dest = "dir_list", default= None, help = " .txt or None")
parser.add_option("-s", "--subdirs", dest = "recursive", help = "True | False ")
parser.add_option("-l", "--loop", dest = "loop", help = "True | False ")
parser.add_option("-w", "--whitelist", dest = "whitelist", default = None, help = " .txt or None")
(inputs,args) = parser.parse_args()
return (inputs.mtd, inputs.registry, inputs.extension_list, inputs.dir_list, inputs.recursive, inputs.loop, inputs.whitelist)
#############################################################################################
def tratamento_argumentos():
def erro():
print("Read the documentation or use -h to check available arguments")
quit()
return
args_aceitos1 = ["false", "true"]
(mtd, registry, extension_list, dir_list, recursive, loop, whitelist) = optparser()
arg_bool = [mtd] + [registry] + [recursive] + [loop]
for arg in arg_bool:
try:
index = arg_bool.index(arg)
arg_bool[index] = arg_bool[index].lower()
if arg_bool[index] not in args_aceitos1:
print(arg)
erro()
except:
erro()
mtd,registry,recursive,loop = arg_bool
if loop == "true":
registry = "false"
if registry == "true" and not windll.shell32.IsUserAnAdmin():
print("[X] If you want to add the file associations to Registry, make sure to run this script with special privileges")
quit()
return (mtd, registry, extension_list, dir_list, recursive, loop, whitelist)
#############################################################################################
def confirmar():
confirmar = windll.user32.MessageBoxA(0, b"Are you Sure ? ", b"Confirm", 4)
if confirmar != 6:
quit()
return
#########################################################################################
def readFile(file, access, readmode): #readmode 2 -> read()
# 3 -> splitlines()
if "r" in access:
with open(file, access) as readfile:
if readmode == 2:
content = readfile.read()
if readmode == 3:
content = readfile.read().splitlines()
return content
else:
return 0
#########################################################################
def extension_lister(extension_list, mtd, loop):
extensions_old = []
extensions_new = []
if mtd == "true" and loop == "false":
extensions_old = readFile(extension_list, "r", 3)
if mtd == "true" and loop == "true":
dump = readFile(extension_list, "r", 2)
extregex = re.findall(r"((\.\w*):(\.\w*)\|)", dump)
extensions_old = [ext[1] for ext in extregex]
extensions_new = [exten[2] for exten in extregex]
if mtd == "false":
dump = readFile(extension_list, "r", 2)
extregex = re.findall(r"((\.\w*):(\.\w*)\|)", dump)
extensions_old = [exten[2] for exten in extregex]
extensions_new = [ext[1] for ext in extregex]
return extensions_old, extensions_new
#########################################################
def dir_lister(recursive, extension_list, mtd, loop, dir_list=None, whitelist=None):
extensions = extension_lister(extension_list, mtd, loop)
file_list = []
filtered_list = []
whitelist_files = []
if dir_list == None:
for (dirpath, dirnames, filenames) in os.walk("C:\\"):
file_list += [os.path.join(dirpath, file) for file in filenames]
for arquivo in file_list:
for extensao in extensions:
if extensao in arquivo:
filtered_list += [arquivo]
else:
directory_list = readFile(dir_list, "r", 3)
if recursive == "false":
for j in directory_list:
for h in os.listdir(j):
if os.path.isfile(j + "\\" + h):
filtered_list += [j + "\\" + h]
if recursive == "true":
for dir in directory_list:
for (dirpath, dirnames, filenames) in os.walk(dir):
file_list += [os.path.join(dirpath, file) for file in filenames]
for arquivo in file_list:
for extensao in extensions[0]:
if extensao in arquivo:
filtered_list += [arquivo]
if whitelist:
wlist = readFile(whitelist, "r", 3)
for wstring in wlist:
for filtered_file in filtered_list:
if wstring in filtered_file:
index = filtered_list.index(filtered_file)
del filtered_list[index]
return filtered_list
###############################################################################################
def randomFourLenGen():
alfabeto = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
string = str()
lista_random = []
while len(lista_random) != 4:
randomnum = secrets.randbelow(26)
if randomnum not in lista_random:
lista_random += [randomnum]
for num in range(0,4):
string += alfabeto[lista_random[num]]
return string
#################################################################################################
class Extension:
def __init__(self, oldexts, newexts = None):
self.oldexts = oldexts
self.newexts = list()
if newexts:
self.newexts += newexts
def fileExtChanger(self, mtd, registry, loop, files, recursive, extension_list, dir_list, whitelist):
loop_flag = 1
while loop_flag:
if mtd == "true" and loop == "false":
while len(self.oldexts) != len(self.newexts):
random_ext = randomFourLenGen()
try:
winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, random_ext, reserved = 0, access = winreg.KEY_READ )
continue
except:
random_ext = "." + random_ext
self.newexts += [random_ext]
output_archive = open(randomFourLenGen(), "a")
for item in self.oldexts:
indice = self.oldexts.index(item)
output_archive.write("%s:%s|" %(self.oldexts[indice], self.newexts[indice]) )
output_archive.close()
for fullpath_file in files:
try:
pre, afterdot = os.path.splitext(fullpath_file)
oldext_index = self.oldexts.index(afterdot)
os.rename(fullpath_file, pre + self.newexts[oldext_index] )
except:
continue
if registry == "true":
for itemlist in self.oldexts:
oldext_index = self.oldexts.index(itemlist)
oldext_key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, itemlist, reserved=0, access= winreg.KEY_READ)
winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, self.newexts[oldext_index])
try:
regvalue = winreg.EnumValue(oldext_key, 0)[1]
winreg.SetValue(winreg.HKEY_CLASSES_ROOT, self.newexts[oldext_index], winreg.REG_SZ, regvalue)
except:
pass
if loop == "false":
loop_flag = 0
else:
files = dir_lister(recursive, extension_list, mtd, loop, dir_list, whitelist)
#######################################################################
def main():
(mtd, registry, extension_list, dir_list, recursive, loop, whitelist) = tratamento_argumentos()
confirmar()
oldexts, newexts = extension_lister(extension_list, mtd, loop)
filelist = dir_lister (recursive, extension_list, mtd, loop, dir_list, whitelist)
MTDExtension = Extension(oldexts, newexts )
MTDExtension.fileExtChanger(mtd, registry, loop, filelist, recursive, extension_list, dir_list, whitelist)
return
#######################################################################
if __name__ == "__main__":
main()