(c *cli.Context)
| 136 | } |
| 137 | |
| 138 | func ParseCommonHTTPOptions(c *cli.Context) (libgobuster.HTTPOptions, error) { |
| 139 | var opts libgobuster.HTTPOptions |
| 140 | basic, err := ParseBasicHTTPOptions(c) |
| 141 | if err != nil { |
| 142 | return opts, err |
| 143 | } |
| 144 | opts.BasicHTTPOptions = basic |
| 145 | |
| 146 | urlInput := c.String("url") |
| 147 | if !strings.HasPrefix(urlInput, "http") { |
| 148 | // check to see if a port was specified |
| 149 | re := regexp.MustCompile(`^[^/]+:(\d+)`) |
| 150 | match := re.FindStringSubmatch(urlInput) |
| 151 | |
| 152 | if len(match) < 2 { |
| 153 | // no port, default to http on 80 |
| 154 | urlInput = fmt.Sprintf("http://%s", urlInput) |
| 155 | } else { |
| 156 | port, err2 := strconv.Atoi(match[1]) |
| 157 | switch { |
| 158 | case err2 != nil || (port != 80 && port != 443): |
| 159 | return opts, errors.New("url scheme not specified") |
| 160 | case port == 80: |
| 161 | urlInput = fmt.Sprintf("http://%s", urlInput) |
| 162 | default: |
| 163 | urlInput = fmt.Sprintf("https://%s", urlInput) |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if opts.URL, err = url.Parse(urlInput); err != nil { |
| 169 | return opts, fmt.Errorf("url %q is not valid: %w", urlInput, err) |
| 170 | } |
| 171 | |
| 172 | opts.Cookies = c.String("cookies") |
| 173 | opts.Username = c.String("username") |
| 174 | opts.Password = c.String("password") |
| 175 | |
| 176 | // Prompt for PW if not provided |
| 177 | if opts.Username != "" && opts.Password == "" { |
| 178 | fmt.Printf("[?] Auth Password: ") // nolint:forbidigo |
| 179 | // please don't remove the int cast here as it is sadly needed on windows :/ |
| 180 | passBytes, err := term.ReadPassword(int(syscall.Stdin)) //nolint:unconvert |
| 181 | // print a newline to simulate the newline that was entered |
| 182 | // this means that formatting/printing after doesn't look bad. |
| 183 | fmt.Println("") // nolint:forbidigo |
| 184 | if err != nil { |
| 185 | return opts, errors.New("username given but reading of password failed") |
| 186 | } |
| 187 | opts.Password = string(passBytes) |
| 188 | } |
| 189 | // if it's still empty bail out |
| 190 | if opts.Username != "" && opts.Password == "" { |
| 191 | return opts, errors.New("username was provided but password is missing") |
| 192 | } |
| 193 | |
| 194 | opts.FollowRedirect = c.Bool("follow-redirect") |
| 195 | opts.NoCanonicalizeHeaders = c.Bool("no-canonicalize-headers") |
nothing calls this directly
no test coverage detected