5
5
"encoding/json"
6
6
"flag"
7
7
"fmt"
8
+ "io"
8
9
"net"
9
10
"os"
10
11
"strconv"
@@ -408,8 +409,25 @@ func dbFlags(conf *config.Config) {
408
409
flag .IntVar (& db .GlobalHTTPRespCacheLimit , "cacheMax" , 10 * (1024 * 1024 ), "The maximum size of an HTTP response that can be cached" )
409
410
}
410
411
411
- // handlue generic sounding c2 flags.
412
- func c2Flags (conf * config.Config ) {
412
+ // handle generic sounding c2 flags.
413
+ func c2Flags (c2Selection * string , conf * config.Config ) {
414
+ c2Default , _ := c2 .ImplToString (conf .SupportedC2 [0 ])
415
+ c2Available := "The C2 server implementation to use. Supported: "
416
+ for _ , value := range conf .SupportedC2 {
417
+ c2Name , ok := c2 .ImplToString (value )
418
+ if ok {
419
+ c2Available += "\n \t " + c2Name
420
+ }
421
+
422
+ // add the supported c2 flags, allowing for command line config of the backend
423
+ impl , success := c2 .GetInstance (value )
424
+ if success {
425
+ impl .CreateFlags ()
426
+ }
427
+ }
428
+ c2Available += "\n "
429
+ flag .StringVar (c2Selection , "c2" , c2Default , c2Available )
430
+
413
431
// flags unique to remote code execution
414
432
flag .IntVar (& conf .Bport , "bport" , 0 , "The port to attach the bind shell to" )
415
433
@@ -423,6 +441,31 @@ func c2Flags(conf *config.Config) {
423
441
flag .BoolVar (& conf .ThirdPartyC2Server , "o" , false , "Indicates if the reverse shell should be caught by an outside program (nc, openssl)" )
424
442
}
425
443
444
+ // loop through the c2 the exploit supports and find the one the user actually selected.
445
+ func validateC2Selection (c2Selection string , conf * config.Config ) bool {
446
+ c2Selected , ok := c2 .StringToImpl (c2Selection )
447
+ if ! ok {
448
+ output .PrintFrameworkError ("Provided an invalid c2 implementation" )
449
+
450
+ return false
451
+ }
452
+ // is this a supported c2?
453
+ foundSupported := false
454
+ for _ , value := range conf .SupportedC2 {
455
+ if c2Selected == value {
456
+ foundSupported = true
457
+ }
458
+ }
459
+ if ! foundSupported {
460
+ output .PrintFrameworkError ("The c2 you selected is not supported by this exploit." )
461
+
462
+ return false
463
+ }
464
+ conf .C2Type = c2Selected
465
+
466
+ return true
467
+ }
468
+
426
469
// Parses the command line arguments used by RCE exploits.
427
470
func CodeExecutionCmdLineParse (conf * config.Config ) bool {
428
471
var rhosts string
@@ -432,6 +475,7 @@ func CodeExecutionCmdLineParse(conf *config.Config) bool {
432
475
var frameworkLogLevel string
433
476
var exploitLogLevel string
434
477
var proxy string
478
+ var c2Selection string
435
479
436
480
dbFlags (conf )
437
481
proxyFlags (& proxy )
@@ -440,26 +484,7 @@ func CodeExecutionCmdLineParse(conf *config.Config) bool {
440
484
localHostFlags (conf )
441
485
exploitFunctionality (conf )
442
486
sslFlags (conf )
443
- c2Flags (conf )
444
-
445
- // c2 selection. defaults to the implementations first supported value
446
- var c2Selection string
447
- c2Default , _ := c2 .ImplToString (conf .SupportedC2 [0 ])
448
- c2Available := "The C2 server implementation to use. Supported: "
449
- for _ , value := range conf .SupportedC2 {
450
- c2Name , ok := c2 .ImplToString (value )
451
- if ok {
452
- c2Available += "\n \t " + c2Name
453
- }
454
-
455
- // add the supported c2 flags, allowing for command line config of the backend
456
- impl , success := c2 .GetInstance (value )
457
- if success {
458
- impl .CreateFlags ()
459
- }
460
- }
461
- c2Available += "\n "
462
- flag .StringVar (& c2Selection , "c2" , c2Default , c2Available )
487
+ c2Flags (& c2Selection , conf )
463
488
464
489
flag .Usage = func () {
465
490
// banner explaining what the software is
@@ -478,23 +503,7 @@ func CodeExecutionCmdLineParse(conf *config.Config) bool {
478
503
479
504
// validate a reverse shell or bind shell params are correctly specified
480
505
if conf .DoExploit {
481
- c2Selected , ok := c2 .StringToImpl (c2Selection )
482
- if ! ok {
483
- output .PrintFrameworkError ("Provided an invalid c2 implementation" )
484
- success = false
485
- }
486
- // is this a supported c2?
487
- foundSupported := false
488
- for _ , value := range conf .SupportedC2 {
489
- if c2Selected == value {
490
- foundSupported = true
491
- }
492
- }
493
- if ! foundSupported {
494
- output .PrintFrameworkError ("The c2 you selected is not supported by this exploit." )
495
- success = false
496
- }
497
- conf .C2Type = c2Selected
506
+ success = validateC2Selection (c2Selection , conf )
498
507
499
508
if rhostsFile == "-" {
500
509
// this is a pretty dirty check but c2 that use stdin can't be used after piping targets in
@@ -589,3 +598,132 @@ func WebShellCmdLineParse(conf *config.Config) bool {
589
598
return handleLogOptions (logFile , frameworkLogLevel , exploitLogLevel ) &&
590
599
commonValidate (conf , rhosts , rports , rhostsFile ) && handleRhostsOptions (conf , rhosts , rports , rhostsFile )
591
600
}
601
+
602
+ func loadFileFormatTemplate (templateFilePath string , conf * config.Config ) bool {
603
+ if len (templateFilePath ) == 0 {
604
+ // the user doesn't have to provide an -in. There are plenty of scenarios where I could imagine
605
+ // the template would be embedded in the exploit. That seems fine to me.
606
+ return true
607
+ }
608
+
609
+ fileTemplate , err := os .Open (templateFilePath )
610
+ if err != nil {
611
+ output .PrintfFrameworkError ("Failed to open the template file: %s" , err .Error ())
612
+
613
+ return false
614
+ }
615
+ defer fileTemplate .Close ()
616
+
617
+ content , err := io .ReadAll (fileTemplate )
618
+ if err != nil {
619
+ output .PrintfFrameworkError ("Failed to read the template file: %s" , err .Error ())
620
+
621
+ return false
622
+ }
623
+
624
+ conf .FileTemplateData = string (content )
625
+ if len (conf .FileTemplateData ) == 0 {
626
+ output .PrintfFrameworkError ("The template file was empty" )
627
+
628
+ return false
629
+ }
630
+
631
+ return true
632
+ }
633
+
634
+ // FileFormat doesn't handle any type of remote host configuration. FileFormat exploits just
635
+ // take an -in and and -out, where "in" is expected to be some type of template and "out" is
636
+ // the file to generate.
637
+ func FormatFileCmdLineParse (conf * config.Config ) bool {
638
+ var logFile string
639
+ var frameworkLogLevel string
640
+ var exploitLogLevel string
641
+ var templateFile string
642
+ var c2Selection string
643
+
644
+ loggingFlags (& logFile , & frameworkLogLevel , & exploitLogLevel )
645
+ localHostFlags (conf )
646
+ exploitFunctionality (conf )
647
+ c2Flags (& c2Selection , conf )
648
+ flag .StringVar (& templateFile , "in" , "" , "The file format template to work with" )
649
+ flag .StringVar (& conf .FileFormatFilePath , "out" , "" , "The file to write the malicious file to" )
650
+
651
+ flag .Usage = func () {
652
+ // banner explaining what the software is
653
+ fmt .Printf ("An exploit for %s %s that crafts a malicious file\n \n " , conf .Product , conf .CVE )
654
+
655
+ // print default usage information
656
+ flag .PrintDefaults ()
657
+
658
+ // usage examples
659
+ fmt .Println ("Usage example:" )
660
+ fmt .Println ("\t ./exploit -e -in <file> -out <file>" )
661
+ }
662
+ flag .Parse ()
663
+
664
+ if ! loadFileFormatTemplate (templateFile , conf ) {
665
+ return false
666
+ }
667
+ if len (conf .FileFormatFilePath ) == 0 {
668
+ output .PrintFrameworkError ("Must provide an -out parameter" )
669
+
670
+ return false
671
+ }
672
+ if ! conf .DoExploit {
673
+ output .PrintFrameworkError ("Exploitation must be invoked for file format exploits" )
674
+
675
+ return false
676
+ }
677
+ if conf .DoVerify || conf .DoVersionCheck {
678
+ output .PrintFrameworkError ("Verification and version checking are disabled for file format exploits" )
679
+
680
+ return false
681
+ }
682
+ if ! validateC2Selection (c2Selection , conf ) {
683
+ return false
684
+ }
685
+ if ! conf .ThirdPartyC2Server && (conf .Lport == 0 || len (conf .Lhost ) == 0 ) {
686
+ output .PrintFrameworkError ("Missing exploitation options (-Lhost or -Lport)" )
687
+
688
+ return false
689
+ }
690
+
691
+ return handleLogOptions (logFile , frameworkLogLevel , exploitLogLevel )
692
+ }
693
+
694
+ func LocalCmdLineParse (conf * config.Config ) bool {
695
+ var logFile string
696
+ var frameworkLogLevel string
697
+ var exploitLogLevel string
698
+ var c2Selection string
699
+
700
+ loggingFlags (& logFile , & frameworkLogLevel , & exploitLogLevel )
701
+ localHostFlags (conf )
702
+ exploitFunctionality (conf )
703
+ c2Flags (& c2Selection , conf )
704
+
705
+ flag .Usage = func () {
706
+ // banner explaining what the software is
707
+ fmt .Printf ("An exploit for %s %s that exploits a local vulnerability\n \n " , conf .Product , conf .CVE )
708
+
709
+ // print default usage information
710
+ flag .PrintDefaults ()
711
+
712
+ // usage examples
713
+ fmt .Println ("Usage example:" )
714
+ fmt .Println ("\t ./exploit -e" )
715
+ }
716
+ flag .Parse ()
717
+
718
+ if ! validateC2Selection (c2Selection , conf ) {
719
+ return false
720
+ }
721
+
722
+ if ! conf .ThirdPartyC2Server && (conf .Lport == 0 || len (conf .Lhost ) == 0 ) {
723
+ output .PrintFrameworkError ("Missing exploitation options (-Lhost or -Lport)" )
724
+
725
+ return false
726
+ }
727
+
728
+ return handleLogOptions (logFile , frameworkLogLevel , exploitLogLevel )
729
+ }
0 commit comments