@@ -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,104 @@ func LocalCmdLineParse(conf *config.Config) bool {
826836
827837 return handleLogOptions (logFile , frameworkLogLevel , exploitLogLevel )
828838}
839+
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" )
903+ }
904+
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 ()
911+
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 ())
916+
917+ continue
918+ }
919+ if ! hasDefault && supported .Default == payload .Default {
920+ defaultType = supported .Types .String ()
921+ defaultArch = supported .Arch .String ()
922+ }
923+ }
924+
925+ if len (conf .SupportedPayloads ) > 1 {
926+ if defaultType == "" {
927+ output .PrintFrameworkError ("No default payload type was defined." )
928+ }
929+ conf .CreateStringFlag ("payload-type" , defaultType , "Payload type to use based on supported types: " + strings .Join (typeOptions , ", " ))
930+ for _ , v := range count {
931+ if v > 1 {
932+ conf .CreateStringFlag ("payload-arch" , defaultArch , "Payload architecture to use based on supported archs: " + strings .Join (archOptions , ", " ))
933+
934+ break
935+ }
936+ }
937+ }
938+ }
939+ }
0 commit comments