1
-
1
+ import os
2
2
import json
3
3
import sys
4
4
5
5
#from core.loader import Loader
6
6
#from base64 import b64decode as b64
7
7
from argparse import ArgumentParser
8
8
from core .loader import Loader
9
+ from core .helpers .error import pcompat , picompat , perror , pnoselect , pexit
9
10
10
11
class Dispatcher :
11
12
@@ -192,8 +193,8 @@ def list_compatible(self, mod):
192
193
print ()
193
194
print (' Listing compatible interfaces:' )
194
195
print ()
195
- for omodule in mod .compatible_interfaces :
196
- print (' ' , omodule )
196
+ for iface in mod .compatible_interfaces :
197
+ print (' ' , iface )
197
198
print ()
198
199
199
200
print ()
@@ -203,7 +204,7 @@ def list_compatible_interfaces(self, mods):
203
204
print ()
204
205
for mod in mods :
205
206
if self .master_args .interface in mod .compatible_interfaces :
206
- print (' ' , mod )
207
+ print (' ' , mod . name )
207
208
print ()
208
209
209
210
@@ -334,72 +335,67 @@ def parse_args(self):
334
335
print ('Listing interfaces:' )
335
336
print ()
336
337
for _ in self .interfaces :
337
- print (f' { _ } ' )
338
+ print (f' { _ . name } ' )
338
339
print ()
339
340
340
341
if list_all or 'ekeys' in self .master_args .list :
341
342
print ('Listing ekeys:' )
342
343
print ()
343
344
for _ in self .ekeys :
344
- print (f' { _ } ' )
345
+ print (f' { _ . name } ' )
345
346
print ()
346
347
if list_all or 'dkeys' in self .master_args .list :
347
348
print ('Listing dkeys:' )
348
349
print ()
349
350
for _ in self .dkeys :
350
- print (f' { _ } ' )
351
+ print (f' { _ . name } ' )
351
352
print ()
352
353
if list_all or 'executors' in self .master_args .list :
353
354
print ('Listing executors:' )
354
355
print ()
355
356
for _ in self .executors :
356
- print (f' { _ } ' )
357
+ print (f' { _ . name } ' )
357
358
print ()
358
359
if list_all or 'crypters' in self .master_args .list :
359
360
print ('Listing crypters:' )
360
361
print ()
361
362
for _ in self .crypters :
362
- print (f' { _ } ' )
363
+ print (f' { _ . name } ' )
363
364
print ()
364
365
if list_all or 'decrypters' in self .master_args .list :
365
366
print ('Listing decrypters:' )
366
367
print ()
367
368
for _ in self .decrypters :
368
- print (f' { _ } ' )
369
+ print (f' { _ . name } ' )
369
370
print ()
370
371
if list_all or 'mutators' in self .master_args .list :
371
372
print ('Listing mutators:' )
372
373
print ()
373
374
for _ in self .mutators :
374
- print (f' { _ } ' )
375
+ print (f' { _ . name } ' )
375
376
print ()
376
377
if list_all or 'runners' in self .master_args .list :
377
378
print ('Listing runners:' )
378
379
print ()
379
380
for _ in self .runners :
380
- print (f' { _ } ' )
381
- print ()
382
- if list_all or 'interfaces' in self .master_args .list :
383
- print ('Listing interfaces:' )
384
- print ()
385
- for _ in self .interfaces :
386
- print (f' { _ } ' )
381
+ print (f' { _ .name } ' )
387
382
print ()
388
383
if list_all or 'premodules' in self .master_args .list :
389
384
print ('Listing premodles:' )
390
385
print ()
391
386
for _ in self .premodules :
392
- print (f' { _ } ' )
387
+ print (f' { _ . name } ' )
393
388
print ()
394
389
if list_all or 'postmodules' in self .master_args .list :
395
390
print ('Listing postmodules:' )
396
391
print ()
397
392
for _ in self .postmodules :
398
- print (f' { _ } ' )
393
+ print (f' { _ . name } ' )
399
394
print ()
400
395
sys .exit ()
401
396
402
- elif self .at_least_one_module_type_is_selected (self .master_args ):
397
+ #elif self.at_least_one_module_type_is_selected(self.master_args):
398
+ elif self .master_args .build :
403
399
404
400
#if self.master_args.ekey is not None:
405
401
@@ -477,6 +473,66 @@ def parse_args(self):
477
473
unknown = self .dkeys [dkey ].parse_args (unknown )
478
474
self .options ['dkeys' ].append (self .dkeys [dkey ].get_options ())
479
475
476
+ self .validate_build_args ()
477
+ self .validate_module_compatibility ()
478
+
479
+
480
+ else :
481
+
482
+ self .print_help ()
483
+ sys .exit ()
484
+
485
+ def validate_build_args (self ):
486
+
487
+ interface = self .dispatch ['interface' ]
488
+ runner = self .dispatch ['runner' ]
489
+ crypter = self .dispatch ['crypter' ]
490
+ decrypter = self .dispatch ['decrypter' ]
491
+ ekeys = self .dispatch ['ekeys' ]
492
+ dkeys = self .dispatch ['dkeys' ]
493
+ executor = self .dispatch ['executor' ]
494
+ postmodules = self .dispatch ['postmodules' ]
495
+ premodules = self .dispatch ['premodules' ]
496
+ mutator = self .dispatch ['mutator' ]
497
+
498
+ shellcode = self .master_args .shellcode
499
+
500
+ if interface is None :
501
+ pnoselect ('interface' )
502
+
503
+ if runner is None :
504
+ pnoselect ('runner' )
505
+
506
+ if crypter is None :
507
+ pnoselect ('crypter' )
508
+
509
+ if decrypter is None :
510
+ pnoselect ('decrypter' )
511
+
512
+ if ekeys == []:
513
+ pnoselect ('ekeys' )
514
+
515
+ if dkeys == []:
516
+ pnoselect ('dkeys' )
517
+
518
+ if executor is None :
519
+ pnoselect ('executor' )
520
+
521
+ if mutator is None :
522
+ pnoselect ('mutator' )
523
+
524
+ if shellcode is None :
525
+ perror ('No shellcode was provided to DropEngine.' )
526
+ perror ('You must specify the path to your shellcode using the --input-file flag.' )
527
+ pexit ('Aborting.' )
528
+
529
+ if not os .path .exists (shellcode ):
530
+ perror ('The shellcode path you provided was invalid.' )
531
+ perror ('You must specify a valid path to your shellcode using the --input-file flag.' )
532
+ pexit ('Aborting.' )
533
+
534
+
535
+
480
536
def print_args (self ):
481
537
482
538
print (json .dumps (self .options , indent = 4 , sort_keys = True ))
@@ -485,6 +541,68 @@ def print_dispatch(self):
485
541
486
542
print (self .dispatch )
487
543
544
+ def vmc_iface (self , mod , iface , mtype ):
545
+
546
+ if iface .name not in mod .compatible_interfaces :
547
+ picompat (mod .name , iface .name , mtype )
548
+
549
+ def vmc_imodule (self , imodule , omodule , iface , mtype ):
550
+
551
+ if imodule .name not in omodule .compatible_imodules :
552
+ pcompat (imodule .name , omodule .name , mtype )
553
+
554
+ self .vmc_iface (imodule , iface , mtype )
555
+
556
+ def vmc_omodule (self , omodule , imodule , iface , mtype ):
557
+
558
+ if omodule .name not in imodule .compatible_omodules :
559
+ pcompat (omodule .name , imodule .name , mtype )
560
+
561
+ self .vmc_iface (omodule , iface , mtype )
562
+
563
+ def validate_module_compatibility (self ):
564
+
565
+ #print(json.dumps(self.options, indent=4, sort_keys=True))
566
+
567
+ interface = self .dispatch ['interface' ]
568
+ runner = self .dispatch ['runner' ]
569
+ crypter = self .dispatch ['crypter' ]
570
+ decrypter = self .dispatch ['decrypter' ]
571
+ ekeys = self .dispatch ['ekeys' ]
572
+ dkeys = self .dispatch ['dkeys' ]
573
+ executor = self .dispatch ['executor' ]
574
+ postmodules = self .dispatch ['postmodules' ]
575
+ premodules = self .dispatch ['premodules' ]
576
+
577
+ vmc_iface = self .vmc_iface
578
+ vmc_imodule = self .vmc_imodule
579
+ vmc_omodule = self .vmc_omodule
580
+
581
+ # validate crypter
582
+ vmc_imodule (crypter , decrypter , interface , 'crypter' )
583
+
584
+ # validate decrypter
585
+ vmc_omodule (decrypter , crypter , interface , 'decrypter' )
586
+
587
+ # validate ekeys and dkeys
588
+ for ekey ,dkey in zip (ekeys , dkeys ):
589
+ vmc_imodule (ekey , dkey , interface , 'ekeys' )
590
+ vmc_omodule (dkey , ekey , interface , 'dkeys' )
591
+
592
+ # validate executor
593
+ vmc_iface (executor , interface , 'executor' )
594
+
595
+ # validate postmodules
596
+ for post in postmodules :
597
+ vmc_iface (post , interface , 'postmodules' )
598
+
599
+ # validate premodules
600
+ for pre in premodules :
601
+ vmc_iface (pre , interface , 'premodules' )
602
+
603
+ # validate runner
604
+ vmc_iface (runner , interface , 'runner' )
605
+
488
606
@staticmethod
489
607
def add_hidden_help_method (parser ):
490
608
@@ -519,6 +637,7 @@ def add_arguments(parser):
519
637
type = str ,
520
638
required = False ,
521
639
default = None ,
640
+ choices = Dispatcher .get_choices ('./modules/interfaces' , 'MRunnerInterface' ),
522
641
help = 'Select interface' )
523
642
524
643
#modules_group.add_argument('--ekey',
@@ -655,16 +774,16 @@ def add_arguments(parser):
655
774
modes_group .add_argument ('--validate-modules' ,
656
775
dest = 'validate_modules' ,
657
776
action = 'store_true' ,
658
- help = 'Build a payload ' )
777
+ help = 'Validate the sanity of a custom module ' )
659
778
660
779
build_group = parser .add_argument_group ('Build' )
661
780
662
- build_group .add_argument ('--shellcode ' ,
781
+ build_group .add_argument ('--input-file' , '-i ' ,
663
782
dest = 'shellcode' ,
664
783
type = str ,
665
784
required = False ,
666
785
default = None ,
667
- help = 'Select shellcode' )
786
+ help = 'Specify path to input file containing shellcode' )
668
787
669
788
if __name__ == '__main__' :
670
789
0 commit comments