Changed order of adding default ports to add host correctly

This commit is contained in:
David Allen 2024-08-07 19:57:37 -06:00
parent 3d6daa757a
commit 4cc3f7f7ac
Signed by: towk
GPG key ID: 793B2924A49B3A3F
2 changed files with 10 additions and 9 deletions

View file

@ -63,6 +63,14 @@ var scanCmd = &cobra.Command{
// assumes subnet without CIDR has a subnet-mask of 255.255.0.0 // 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", " 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) { 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 // format and combine flag and positional args
targetHosts = append(targetHosts, util.FormatHostUrls(args, ports, scheme, verbose)...) targetHosts = append(targetHosts, util.FormatHostUrls(args, ports, scheme, verbose)...)
targetHosts = append(targetHosts, util.FormatHostUrls(hosts, 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 // show the parameters going into the scan
if debug { if debug {
combinedTargetHosts := []string{} combinedTargetHosts := []string{}
@ -133,6 +133,7 @@ var scanCmd = &cobra.Command{
} }
// scan and store scanned data in cache // scan and store scanned data in cache
fmt.Printf("targets: %v\n", targetHosts)
foundAssets := magellan.ScanForAssets(&magellan.ScanParams{ foundAssets := magellan.ScanForAssets(&magellan.ScanParams{
TargetHosts: targetHosts, TargetHosts: targetHosts,
Scheme: scheme, Scheme: scheme,

View file

@ -155,8 +155,8 @@ func FormatIPUrls(ips []string, ports []int, scheme string, verbose bool) [][]st
} }
// tidy up slashes and update arg with new value // tidy up slashes and update arg with new value
uri.Path = strings.TrimSuffix(uri.Path, "/")
uri.Path = strings.ReplaceAll(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 // for hosts with unspecified ports, add ports to scan from flag
if uri.Port() == "" { if uri.Port() == "" {