@@ -15,6 +15,7 @@ import (
1515 "github.com/vulncheck-oss/go-exploit/config"
1616 "github.com/vulncheck-oss/go-exploit/db"
1717 "github.com/vulncheck-oss/go-exploit/output"
18+ "github.com/vulncheck-oss/go-exploit/payload"
1819 "github.com/vulncheck-oss/go-exploit/protocol"
1920)
2021
@@ -482,7 +483,10 @@ func printDetails(conf *config.Config) {
482483 for _ , value := range conf .SupportedC2 {
483484 supportedC2Strings = append (supportedC2Strings , value .Name )
484485 }
485-
486+ supportedPayloadsStrings := make ([]string , 0 )
487+ for _ , value := range conf .SupportedPayloads {
488+ supportedPayloadsStrings = append (supportedPayloadsStrings , value .String ())
489+ }
486490 customFlags := make ([]CustomFlag , 0 )
487491 for key , value := range conf .StringFlagsMap {
488492 customFlags = append (customFlags , CustomFlag {
@@ -519,6 +523,7 @@ func printDetails(conf *config.Config) {
519523 "VersionScanner" , conf .Impl .VersionScanning ,
520524 "Exploitation" , conf .Impl .Exploitation ,
521525 "SupportedC2" , supportedC2Strings ,
526+ "SupportedPayloads" , supportedPayloadsStrings ,
522527 "Vendor" , conf .Vendor ,
523528 "Products" , conf .Products ,
524529 "CPE" , conf .CPE ,
@@ -548,6 +553,7 @@ func CodeExecutionCmdLineParse(conf *config.Config) bool {
548553 exploitFunctionality (conf )
549554 sslFlags (conf )
550555 c2Flags (& c2Selection , conf )
556+ addPayloadFlags (conf )
551557 detailsFlag := flag .Bool ("details" , false , "Print the implementation details for this exploit" )
552558
553559 flag .Usage = func () {
@@ -612,6 +618,7 @@ func InformationDisclosureCmdLineParse(conf *config.Config) bool {
612618 localHostFlags (conf )
613619 exploitFunctionality (conf )
614620 sslFlags (conf )
621+ addPayloadFlags (conf )
615622 detailsFlag := flag .Bool ("details" , false , "Print the implementation details for this exploit" )
616623
617624 flag .Usage = func () {
@@ -654,6 +661,7 @@ func WebShellCmdLineParse(conf *config.Config) bool {
654661 localHostFlags (conf )
655662 exploitFunctionality (conf )
656663 sslFlags (conf )
664+ addPayloadFlags (conf )
657665 detailsFlag := flag .Bool ("details" , false , "Print the implementation details for this exploit" )
658666
659667 flag .Usage = func () {
@@ -726,6 +734,7 @@ func FormatFileCmdLineParse(conf *config.Config) bool {
726734 localHostFlags (conf )
727735 exploitFunctionality (conf )
728736 c2Flags (& c2Selection , conf )
737+ addPayloadFlags (conf )
729738 detailsFlag := flag .Bool ("details" , false , "Print the implementation details for this exploit" )
730739 flag .StringVar (& templateFile , "in" , "" , "The file format template to work with" )
731740 flag .StringVar (& conf .FileFormatFilePath , "out" , "" , "The file to write the malicious file to" )
@@ -792,6 +801,7 @@ func LocalCmdLineParse(conf *config.Config) bool {
792801 localHostFlags (conf )
793802 exploitFunctionality (conf )
794803 c2Flags (& c2Selection , conf )
804+ addPayloadFlags (conf )
795805 detailsFlag := flag .Bool ("details" , false , "Print the implementation details for this exploit" )
796806
797807 flag .Usage = func () {
@@ -826,3 +836,83 @@ func LocalCmdLineParse(conf *config.Config) bool {
826836
827837 return handleLogOptions (logFile , frameworkLogLevel , exploitLogLevel )
828838}
839+
840+ func addDefaultPayloadFlags (conf * config.Config ) (string , string , map [payload .Type ]int , []string , []string ) {
841+ if len (conf .SupportedPayloads ) == 1 {
842+ conf .SupportedPayloads [0 ].Default = payload .Default
843+ }
844+ hasDefault := false
845+ defaultType := ""
846+ defaultArch := ""
847+ typeOptions := []string {}
848+ archOptions := []string {}
849+ count := map [payload.Type ]int {}
850+ for i , supported := range conf .SupportedPayloads {
851+ switch supported .Type {
852+ case payload .LinuxCommand ,
853+ payload .WindowsCommand ,
854+ payload .WindowsPowerShellCommand ,
855+ payload .MacCommand ,
856+ payload .GenericCommand :
857+ _ , exists := conf .StringFlagsMap ["command" ]
858+ if ! exists {
859+ conf .CreateStringFlag ("command" , "" , "Command to use for the exploit, an empty string will use the exploit default." )
860+ }
861+ case payload .LinuxELF ,
862+ payload .LinuxSO ,
863+ payload .WindowsEXE ,
864+ payload .WindowsDLL ,
865+ payload .Webshell :
866+ _ , exists := conf .StringFlagsMap ["payload" ]
867+ if ! exists {
868+ conf .CreateStringFlag ("payload" , "" , "Path to load custom payload from, an empty string will use the exploit default." )
869+ }
870+ case payload .UnspecifiedType :
871+ output .PrintFrameworkError ("Unspecified payload type used" )
872+ default :
873+ output .PrintFrameworkError ("Unexpected payload type used" )
874+ }
875+
876+ count [supported .Type ]++
877+ typeOptions = append (typeOptions , supported .Type .String ())
878+ archOptions = append (archOptions , supported .Arch .String ())
879+ if i == 0 && len (conf .SupportedPayloads ) == 1 {
880+ defaultType = supported .Type .String ()
881+ defaultArch = supported .Arch .String ()
882+
883+ continue
884+ }
885+ if hasDefault && supported .Default == payload .Default {
886+ output .PrintfFrameworkWarn ("Multiple default payloads selected, using the first and skipping: %s" , supported .Type .String ())
887+
888+ continue
889+ }
890+ if ! hasDefault && supported .Default == payload .Default {
891+ defaultType = supported .Type .String ()
892+ defaultArch = supported .Arch .String ()
893+ }
894+ }
895+
896+ return defaultType , defaultArch , count , typeOptions , archOptions
897+ }
898+
899+ // Adds default flags for payload types, this allows classes of payloads that are supported to
900+ // use globally defined command line flags without having to redefine them each exploit.
901+ func addPayloadFlags (conf * config.Config ) {
902+ if conf .PayloadFlags {
903+ defaultType , defaultArch , count , typeOptions , archOptions := addDefaultPayloadFlags (conf )
904+ if len (conf .SupportedPayloads ) > 1 {
905+ if defaultType == "" {
906+ output .PrintFrameworkError ("No default payload type was defined." )
907+ }
908+ conf .CreateStringFlag ("payload-type" , defaultType , "Payload type to use based on supported types: " + strings .Join (typeOptions , ", " ))
909+ for _ , v := range count {
910+ if v > 1 {
911+ conf .CreateStringFlag ("payload-arch" , defaultArch , "Payload architecture to use based on supported archs: " + strings .Join (archOptions , ", " ))
912+
913+ break
914+ }
915+ }
916+ }
917+ }
918+ }
0 commit comments