|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + |
| 6 | + "github.com/rsteube/carapace" |
| 7 | + "github.com/rsteube/carapace-bin/pkg/actions/net" |
| 8 | + "github.com/rsteube/carapace-bin/pkg/actions/tools/mitmproxy" |
| 9 | + "github.com/spf13/cobra" |
| 10 | +) |
| 11 | + |
| 12 | +var rootCmd = &cobra.Command{ |
| 13 | + Use: "mitmproxy", |
| 14 | + Short: "interactive, SSL/TLS-capable intercepting proxy", |
| 15 | + Long: "https://mitmproxy.org/", |
| 16 | + Run: func(cmd *cobra.Command, args []string) {}, |
| 17 | +} |
| 18 | + |
| 19 | +func Execute() error { |
| 20 | + return rootCmd.Execute() |
| 21 | +} |
| 22 | +func init() { |
| 23 | + carapace.Gen(rootCmd).Standalone() |
| 24 | + |
| 25 | + rootCmd.Flags().StringArray("allow-hosts", []string{}, "Opposite of --ignore-hosts") |
| 26 | + rootCmd.Flags().Bool("anticache", false, "Strip out request headers that might cause the server to return 304-not-modified") |
| 27 | + rootCmd.Flags().Bool("anticomp", false, "Try to convince servers to send us un-compressed data") |
| 28 | + rootCmd.Flags().String("cert-passphrase", "", "Passphrase for decrypting the private key provided in the --cert option") |
| 29 | + rootCmd.Flags().String("certs", "", "SSL certificates of the form \"[domain=]path\"") |
| 30 | + rootCmd.Flags().StringP("client-replay", "C", "", "Replay client requests from a saved file") |
| 31 | + rootCmd.Flags().Bool("commands", false, "Show all commands and their signatures") |
| 32 | + rootCmd.Flags().String("console-layout", "", "Console layout") |
| 33 | + rootCmd.Flags().Bool("console-layout-headers", false, "Show layout component headers") |
| 34 | + rootCmd.Flags().BoolP("help", "h", false, "show this help message and exit") |
| 35 | + rootCmd.Flags().Bool("http2", false, "Enable HTTP/2 support") |
| 36 | + rootCmd.Flags().StringArray("ignore-hosts", []string{}, "Ignore host and forward all traffic without processing it") |
| 37 | + rootCmd.Flags().String("intercept", "", "Intercept filter expression") |
| 38 | + rootCmd.Flags().String("key-size", "", "TLS key size for certificates and CA") |
| 39 | + rootCmd.Flags().String("listen-host", "", "Address to bind proxy to") |
| 40 | + rootCmd.Flags().StringP("listen-port", "p", "", "Proxy service port") |
| 41 | + rootCmd.Flags().String("map-local", "", "Map remote resources to a local file") |
| 42 | + rootCmd.Flags().StringP("map-remote", "M", "", "Map remote resources to another remote URL") |
| 43 | + rootCmd.Flags().StringP("mode", "m", "", "Set mode") |
| 44 | + rootCmd.Flags().StringP("modify-body", "B", "", "Replacement pattern") |
| 45 | + rootCmd.Flags().StringP("modify-headers", "H", "", "Header modify pattern") |
| 46 | + rootCmd.Flags().Bool("no-anticache", false, "Do not strip out request headers that might cause the server to return 304-not-modified") |
| 47 | + rootCmd.Flags().Bool("no-anticomp", false, "Do not try to convince servers to send us un-compressed data") |
| 48 | + rootCmd.Flags().Bool("no-console-layout-headers", false, "Do not show layout component headers") |
| 49 | + rootCmd.Flags().Bool("no-http2", false, "Disable HTTP/2 support") |
| 50 | + rootCmd.Flags().Bool("no-rawtcp", false, "Disable raw TCP connections") |
| 51 | + rootCmd.Flags().BoolP("no-server", "n", false, "Do not start a proxy server") |
| 52 | + rootCmd.Flags().Bool("no-server-replay-kill-extra", false, "Do not kill extra requests during replay") |
| 53 | + rootCmd.Flags().Bool("no-server-replay-nopop", false, "Remove flows from server replay state after use") |
| 54 | + rootCmd.Flags().Bool("no-server-replay-refresh", false, "") |
| 55 | + rootCmd.Flags().Bool("no-showhost", false, "Do not use the Host header to construct URLs for display") |
| 56 | + rootCmd.Flags().Bool("no-ssl-insecure", false, "Verify upstream server SSL/TLS certificates") |
| 57 | + rootCmd.Flags().Bool("options", false, "Show all options and their default values") |
| 58 | + rootCmd.Flags().String("proxyauth", "", "Require proxy authentication") |
| 59 | + rootCmd.Flags().BoolP("quiet", "q", false, "Quiet") |
| 60 | + rootCmd.Flags().Bool("rawtcp", false, "Enable raw TCP connections") |
| 61 | + rootCmd.Flags().StringP("rfile", "r", "", "Read flows from file") |
| 62 | + rootCmd.Flags().StringP("save-stream-file", "w", "", "Stream flows to file as they arrive") |
| 63 | + rootCmd.Flags().StringArrayP("scripts", "s", []string{}, "Execute a script") |
| 64 | + rootCmd.Flags().Bool("server", false, "Start a proxy server") |
| 65 | + rootCmd.Flags().StringP("server-replay", "S", "", "Replay server responses from a saved file") |
| 66 | + rootCmd.Flags().Bool("server-replay-kill-extra", false, "Kill extra requests during replay") |
| 67 | + rootCmd.Flags().Bool("server-replay-nopop", false, "Don't remove flows from server replay state after use") |
| 68 | + rootCmd.Flags().Bool("server-replay-refresh", false, "Refresh server replay responses by adjusting date, expires and last-modified headers") |
| 69 | + rootCmd.Flags().StringArray("set", []string{}, "Set an option") |
| 70 | + rootCmd.Flags().Bool("showhost", false, "Use the Host header to construct URLs for display") |
| 71 | + rootCmd.Flags().BoolP("ssl-insecure", "k", false, "Do not verify upstream server SSL/TLS certificates") |
| 72 | + rootCmd.Flags().String("stickyauth", "", "Set sticky auth filter") |
| 73 | + rootCmd.Flags().String("stickycookie", "", "Set sticky cookie filter") |
| 74 | + rootCmd.Flags().String("tcp-hosts", "", "Generic TCP SSL proxy mode for all hosts that match the pattern") |
| 75 | + rootCmd.Flags().String("upstream-auth", "", "Add HTTP Basic authentication to upstream proxy and reverse proxy requests") |
| 76 | + rootCmd.Flags().BoolP("verbose", "v", false, "Increase log verbosity") |
| 77 | + rootCmd.Flags().Bool("version", false, "show version number and exit") |
| 78 | + rootCmd.Flags().String("view-filter", "", "Limit the view to matching flows") |
| 79 | + |
| 80 | + // TODO complete flag completions |
| 81 | + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ |
| 82 | + "certs": carapace.ActionMultiParts("=", func(c carapace.Context) carapace.Action { |
| 83 | + if len(c.Parts) < 2 { |
| 84 | + return carapace.ActionFiles() |
| 85 | + } |
| 86 | + return carapace.ActionValues() |
| 87 | + }), |
| 88 | + "client-replay": carapace.ActionFiles(), |
| 89 | + "console-layout": mitmproxy.ActionConsoleLayouts(), |
| 90 | + "listen-port": net.ActionPorts(), |
| 91 | + "mode": mitmproxy.ActionModes(), |
| 92 | + "modify-body": mitmproxy.ActionModifyBodyPattern(), |
| 93 | + "modify-headers": mitmproxy.ActionModifyHeaderPattern(), |
| 94 | + "rfile": carapace.ActionFiles(), |
| 95 | + "save-stream-file": mitmproxy.ActionAppendableFiles(), |
| 96 | + "scripts": carapace.ActionFiles(), |
| 97 | + "server-replay": carapace.ActionFiles(), |
| 98 | + "set": carapace.ActionCallback(func(c carapace.Context) carapace.Action { |
| 99 | + if splitted := strings.SplitN(c.CallbackValue, "=", 2); len(splitted) > 1 { |
| 100 | + c.CallbackValue = splitted[1] |
| 101 | + return mitmproxy.ActionOptionValues(splitted[0]).Invoke(c).Prefix(splitted[0] + "=").ToA().NoSpace() |
| 102 | + } |
| 103 | + return mitmproxy.ActionOptionNames().NoSpace() |
| 104 | + }), |
| 105 | + }) |
| 106 | +} |
0 commit comments