@@ -837,91 +837,70 @@ func LocalCmdLineParse(conf *config.Config) bool {
837837 return handleLogOptions (logFile , frameworkLogLevel , exploitLogLevel )
838838}
839839
840- // Adds default flags for payload types, this allows classes of payloads that are supported to
841- // use globally defined command line flags without having to redifine them each exploit.
842- func addPayloadFlags (conf * config.Config ) {
843- if conf .PayloadFlags {
844- if len (conf .SupportedPayloads ) == 1 {
845- conf .SupportedPayloads [0 ].Default = payload .Default
846- }
847- hasDefault := false
848- defaultType := ""
849- defaultArch := ""
850- typeOptions := []string {}
851- archOptions := []string {}
852- count := map [payload.Types ]int {}
853- for i , supported := range conf .SupportedPayloads {
854- switch supported .Types {
855- case payload .LinuxCommand :
856- _ , exists := conf .StringFlagsMap ["command" ]
857- if ! exists {
858- conf .CreateStringFlag ("command" , "" , "Command to use for the exploit, an empty string will use the exploit default." )
859- }
860- case payload .WindowsCommand :
861- _ , exists := conf .StringFlagsMap ["command" ]
862- if ! exists {
863- conf .CreateStringFlag ("command" , "" , "Command to use for the exploit, an empty string will use the exploit default." )
864- }
865- case payload .MacCommand :
866- _ , exists := conf .StringFlagsMap ["command" ]
867- if ! exists {
868- conf .CreateStringFlag ("command" , "" , "Command to use for the exploit, an empty string will use the exploit default." )
869- }
870- case payload .GenericCommand :
871- _ , exists := conf .StringFlagsMap ["command" ]
872- if ! exists {
873- conf .CreateStringFlag ("command" , "" , "Command to use for the exploit, an empty string will use the exploit default." )
874- }
875- case payload .LinuxELF :
876- _ , exists := conf .StringFlagsMap ["payload" ]
877- if ! exists {
878- conf .CreateStringFlag ("payload" , "" , "Path to load custom payload from, an empty string will use the exploit default." )
879- }
880- case payload .LinuxSO :
881- _ , exists := conf .StringFlagsMap ["payload" ]
882- if ! exists {
883- conf .CreateStringFlag ("payload" , "" , "Path to load custom payload from, an empty string will use the exploit default." )
884- }
885- case payload .WindowsEXE :
886- _ , exists := conf .StringFlagsMap ["payload" ]
887- if ! exists {
888- conf .CreateStringFlag ("payload" , "" , "Path to load custom payload from, an empty string will use the exploit default." )
889- }
890-
891- case payload .WindowsDLL :
892- _ , exists := conf .StringFlagsMap ["payload" ]
893- if ! exists {
894- conf .CreateStringFlag ("payload" , "" , "Path to load custom payload from, an empty string will use the exploit default." )
895- }
896- case payload .Webshell :
897- _ , exists := conf .StringFlagsMap ["payload" ]
898- if ! exists {
899- conf .CreateStringFlag ("payload" , "" , "Path to load custom payload from, an empty string will use the exploit default." )
900- }
901- default :
902- output .PrintFrameworkError ("Unexpected payload type used" )
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." )
903860 }
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+ }
904875
905- count [supported .Types ]++
906- typeOptions = append (typeOptions , supported .Types .String ())
907- archOptions = append (archOptions , supported .Arch .String ())
908- if i == 0 && len (conf .SupportedPayloads ) == 1 {
909- defaultType = supported .Types .String ()
910- defaultArch = supported .Arch .String ()
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 ()
911882
912- continue
913- }
914- if hasDefault && supported .Default == payload .Default {
915- output .PrintfFrameworkWarn ("Multiple default payloads selected, using the first and skipping: %s" , supported .Types .String ())
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 ())
916887
917- continue
918- }
919- if ! hasDefault && supported .Default == payload .Default {
920- defaultType = supported .Types .String ()
921- defaultArch = supported .Arch .String ()
922- }
888+ continue
889+ }
890+ if ! hasDefault && supported .Default == payload .Default {
891+ defaultType = supported .Type .String ()
892+ defaultArch = supported .Arch .String ()
923893 }
894+ }
895+
896+ return defaultType , defaultArch , count , typeOptions , archOptions
897+ }
924898
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 redifine them each exploit.
901+ func addPayloadFlags (conf * config.Config ) {
902+ if conf .PayloadFlags {
903+ defaultType , defaultArch , count , typeOptions , archOptions := addDefaultPayloadFlags (conf )
925904 if len (conf .SupportedPayloads ) > 1 {
926905 if defaultType == "" {
927906 output .PrintFrameworkError ("No default payload type was defined." )
0 commit comments