diff --git a/cmd/scan.go b/cmd/scan.go index e48173c..3e9a9d0 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -63,6 +63,14 @@ var scanCmd = &cobra.Command{ // assumes subnet without CIDR has a subnet-mask of 255.255.0.0 " magellan scan --subnet 10.0.0.0/24 --subnet 172.16.0.0 --subnet-mask 255.255.0.0 --cache ./assets.db", Run: func(cmd *cobra.Command, args []string) { + // add default ports for hosts if none are specified with flag + if len(ports) == 0 { + if debug { + log.Debug().Msg("adding default ports") + } + ports = magellan.GetDefaultPorts() + } + // format and combine flag and positional args targetHosts = append(targetHosts, util.FormatHostUrls(args, ports, scheme, verbose)...) targetHosts = append(targetHosts, util.FormatHostUrls(hosts, ports, scheme, verbose)...) @@ -93,14 +101,6 @@ var scanCmd = &cobra.Command{ } } - // add default ports for hosts if none are specified with flag - if len(ports) == 0 { - if debug { - log.Debug().Msg("adding default ports") - } - ports = magellan.GetDefaultPorts() - } - // show the parameters going into the scan if debug { combinedTargetHosts := []string{} @@ -133,6 +133,7 @@ var scanCmd = &cobra.Command{ } // scan and store scanned data in cache + fmt.Printf("targets: %v\n", targetHosts) foundAssets := magellan.ScanForAssets(&magellan.ScanParams{ TargetHosts: targetHosts, Scheme: scheme, diff --git a/internal/util/net.go b/internal/util/net.go index 50bbbfa..76749aa 100644 --- a/internal/util/net.go +++ b/internal/util/net.go @@ -155,8 +155,8 @@ func FormatIPUrls(ips []string, ports []int, scheme string, verbose bool) [][]st } // tidy up slashes and update arg with new value - uri.Path = strings.TrimSuffix(uri.Path, "/") uri.Path = strings.ReplaceAll(uri.Path, "//", "/") + uri.Path = strings.TrimSuffix(uri.Path, "/") // for hosts with unspecified ports, add ports to scan from flag if uri.Port() == "" {