|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + |
| 6 | + path "github.com/Method-Security/methodwebtest/internal/wordpress/path" |
| 7 | + "github.com/spf13/cobra" |
| 8 | +) |
| 9 | + |
| 10 | +// InitWordpressCommand initializes the apache command for the methodwebtest CLI. |
| 11 | +func (a *MethodWebTest) InitWordpressCommand() { |
| 12 | + wordpressCmd := &cobra.Command{ |
| 13 | + Use: "wordpress", |
| 14 | + Short: "Perform wordpress specific injection tests against a target", |
| 15 | + Long: `Perform wordpress specific injection tests against a target`, |
| 16 | + } |
| 17 | + |
| 18 | + wordpressCmd.PersistentFlags().StringSlice("targets", []string{}, "The URL of target") |
| 19 | + wordpressCmd.PersistentFlags().Int("timeout", 30, "Timeout per request (seconds)") |
| 20 | + wordpressCmd.PersistentFlags().Int("sleep", 0, "Sleep time between requests (seconds)") |
| 21 | + wordpressCmd.PersistentFlags().Int("retries", 0, "Number of attempts per credential pair") |
| 22 | + |
| 23 | + // pathCmd holds the subcommands for path injection tests |
| 24 | + pathCmd := &cobra.Command{ |
| 25 | + Use: "path", |
| 26 | + Short: "Perform path injection tests against a target", |
| 27 | + Long: `Perform path injection tests against a target`, |
| 28 | + } |
| 29 | + |
| 30 | + traversalCmd := &cobra.Command{ |
| 31 | + Use: "traversal", |
| 32 | + Short: "Perform a Wordpress specific path traversal for common file locations", |
| 33 | + Long: `Perform a Wordpress specific path traversal for common file locations`, |
| 34 | + Run: func(cmd *cobra.Command, args []string) { |
| 35 | + defer a.OutputSignal.PanicHandler(cmd.Context()) |
| 36 | + |
| 37 | + // Target flags |
| 38 | + targets, err := cmd.Flags().GetStringSlice("targets") |
| 39 | + if err != nil { |
| 40 | + a.OutputSignal.AddError(err) |
| 41 | + return |
| 42 | + } |
| 43 | + if len(targets) == 0 { |
| 44 | + a.OutputSignal.AddError(errors.New("no targets provided")) |
| 45 | + return |
| 46 | + } |
| 47 | + |
| 48 | + // Configuration flags |
| 49 | + responseCodes, err := cmd.Flags().GetString("responsecodes") |
| 50 | + if err != nil { |
| 51 | + a.OutputSignal.AddError(err) |
| 52 | + return |
| 53 | + } |
| 54 | + ignoreBase, err := cmd.Flags().GetBool("ignorebasecontentmatch") |
| 55 | + if err != nil { |
| 56 | + a.OutputSignal.AddError(err) |
| 57 | + return |
| 58 | + } |
| 59 | + timeout, err := cmd.Flags().GetInt("timeout") |
| 60 | + if err != nil { |
| 61 | + a.OutputSignal.AddError(err) |
| 62 | + return |
| 63 | + } |
| 64 | + sleep, err := cmd.Flags().GetInt("sleep") |
| 65 | + if err != nil { |
| 66 | + a.OutputSignal.AddError(err) |
| 67 | + return |
| 68 | + } |
| 69 | + retries, err := cmd.Flags().GetInt("retries") |
| 70 | + if err != nil { |
| 71 | + a.OutputSignal.AddError(err) |
| 72 | + return |
| 73 | + } |
| 74 | + successfulOnly, err := cmd.Flags().GetBool("successfulonly") |
| 75 | + if err != nil { |
| 76 | + a.OutputSignal.AddError(err) |
| 77 | + return |
| 78 | + } |
| 79 | + threshold, err := cmd.Flags().GetFloat64("threshold") |
| 80 | + if err != nil { |
| 81 | + a.OutputSignal.AddError(err) |
| 82 | + return |
| 83 | + } |
| 84 | + |
| 85 | + // Load configuration |
| 86 | + config := LoadPathTraversalConfig(targets, []string{}, []string{}, "", responseCodes, ignoreBase, timeout, sleep, retries, successfulOnly, threshold, nil) |
| 87 | + |
| 88 | + // Generate report |
| 89 | + report := path.PerformWordpressPathTraversal(cmd.Context(), config) |
| 90 | + if len(report.Errors) > 0 { |
| 91 | + a.OutputSignal.Status = 1 |
| 92 | + } |
| 93 | + a.OutputSignal.Content = report |
| 94 | + }, |
| 95 | + } |
| 96 | + |
| 97 | + traversalCmd.Flags().String("responsecodes", "200-299", "Response codes to consider as valid responses") |
| 98 | + traversalCmd.Flags().Bool("ignorebasecontentmatch", true, "Ignores valid responses with identical size and word length to the base path, typically signifying a web backend redirect") |
| 99 | + traversalCmd.Flags().Bool("successfulonly", false, "Only show successful attempts") |
| 100 | + traversalCmd.Flags().Float64("threshold", 0.10, "Threshold for a negitive finding that represents the percentage difference between the size of the response body in question and the baseline response (0.0 is an exact match, with .05 being a 5 percent difference)") |
| 101 | + |
| 102 | + pathCmd.AddCommand(traversalCmd) |
| 103 | + |
| 104 | + wordpressCmd.AddCommand(pathCmd) |
| 105 | + |
| 106 | + a.RootCmd.AddCommand(wordpressCmd) |
| 107 | +} |
0 commit comments