mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Fixed '--subnet' flag not adding hosts to scan
This commit is contained in:
parent
0c30d4dc3a
commit
dd829cd10e
4 changed files with 43 additions and 26 deletions
17
cmd/scan.go
17
cmd/scan.go
|
|
@ -78,26 +78,17 @@ var scanCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate a slice of all hosts to scan from subnets
|
// generate a slice of all hosts to scan from subnets
|
||||||
targetHosts = append(targetHosts, magellan.GenerateHostsWithSubnet(subnet, &subnetMask, ports, scheme)...)
|
subnetHosts := magellan.GenerateHostsWithSubnet(subnet, &subnetMask, ports, scheme)
|
||||||
}
|
targetHosts = append(targetHosts, subnetHosts...)
|
||||||
|
|
||||||
// convert everything into full addresses for scanning
|
|
||||||
for _, host := range hosts {
|
|
||||||
var targets []string
|
|
||||||
for _, port := range ports {
|
|
||||||
_ = port
|
|
||||||
targets = append(targets, host)
|
|
||||||
}
|
|
||||||
targetHosts = append(targetHosts, targets)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no target hosts, then there's nothing to do
|
// if there are no target hosts, then there's nothing to do
|
||||||
if len(targetHosts) <= 0 {
|
if len(targetHosts) <= 0 {
|
||||||
log.Warn().Msg("nothing to do (no target hosts)")
|
log.Warn().Msg("nothing to do (no valid target hosts)")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if len(targetHosts[0]) <= 0 {
|
if len(targetHosts[0]) <= 0 {
|
||||||
log.Warn().Msg("nothing to do (no target hosts)")
|
log.Warn().Msg("nothing to do (no valid target hosts)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
internal/cache/cache.go
vendored
4
internal/cache/cache.go
vendored
|
|
@ -1,6 +1,8 @@
|
||||||
package cache
|
package cache
|
||||||
|
|
||||||
import "database/sql/driver"
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
|
)
|
||||||
|
|
||||||
type Cache[T any] interface {
|
type Cache[T any] interface {
|
||||||
CreateIfNotExists(path string) (driver.Connector, error)
|
CreateIfNotExists(path string) (driver.Connector, error)
|
||||||
|
|
|
||||||
28
internal/cache/storage.go
vendored
Normal file
28
internal/cache/storage.go
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cache
|
||||||
|
|
||||||
|
import "github.com/google/uuid"
|
||||||
|
|
||||||
|
type Storage[T any] interface {
|
||||||
|
Save(id uuid.UUID, val T, varargs ...T) error
|
||||||
|
Get(id uuid.UUID) (T, error)
|
||||||
|
Update(id uuid.UUID, val T) error
|
||||||
|
Delete(id uuid.UUID) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type Compute struct{}
|
||||||
|
type BMC struct{}
|
||||||
|
|
||||||
|
type Node[T any] struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type NodeStorage struct {
|
||||||
|
Storage[Node[Compute]]
|
||||||
|
}
|
||||||
|
|
||||||
|
type BMCStorage struct {
|
||||||
|
Storage[Node[BMC]]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *NodeStorage) Save(id uuid.UUID, val Node[Compute], varargs ...Node[Compute]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -145,31 +145,27 @@ func FormatIPUrls(ips []string, ports []int, scheme string, verbose bool) [][]st
|
||||||
// format each positional arg as a complete URL
|
// format each positional arg as a complete URL
|
||||||
var formattedHosts [][]string
|
var formattedHosts [][]string
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
// if parsing completely fails, try to build new URL object
|
if scheme == "" {
|
||||||
|
scheme = "https"
|
||||||
|
}
|
||||||
|
// make an entirely new object since we're expecting just IPs
|
||||||
uri := &url.URL{
|
uri := &url.URL{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
Host: ip,
|
Host: ip,
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if scheme is set, if not set it with flag or default value ('https' if flag is not set)
|
|
||||||
if uri.Scheme == "" {
|
|
||||||
if scheme != "" {
|
|
||||||
uri.Scheme = scheme
|
|
||||||
} else {
|
|
||||||
// hardcoded assumption
|
|
||||||
uri.Scheme = "https"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.TrimSuffix(uri.Path, "/")
|
||||||
uri.Path = strings.ReplaceAll(uri.Path, "//", "/")
|
uri.Path = strings.ReplaceAll(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() == "" {
|
||||||
|
if len(ports) == 0 {
|
||||||
|
ports = append(ports, 443)
|
||||||
|
}
|
||||||
var tmp []string
|
var tmp []string
|
||||||
for _, port := range ports {
|
for _, port := range ports {
|
||||||
uri.Host = fmt.Sprintf("%s:%d", ip, port)
|
uri.Host += fmt.Sprintf(":%d", port)
|
||||||
tmp = append(tmp, uri.String())
|
tmp = append(tmp, uri.String())
|
||||||
}
|
}
|
||||||
formattedHosts = append(formattedHosts, tmp)
|
formattedHosts = append(formattedHosts, tmp)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue