Skip to content

Commit

Permalink
Changed order of adding default ports to add host correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
davidallendj committed Aug 8, 2024
1 parent 3d6daa7 commit 4cc3f7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() == "" {
Expand Down

0 comments on commit 4cc3f7f

Please sign in to comment.