Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
praetorian-thendrickson committed Jan 12, 2023
1 parent 291db65 commit a170c47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
21 changes: 1 addition & 20 deletions pkg/scan/scan_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,13 @@ func UDPScan(targets []plugins.Target, config Config) ([]plugins.Service, error)
// ScanTargets fingerprints service(s) running given a list of targets.
func ScanTargets(targets []plugins.Target, config Config) ([]plugins.Service, error) {
var results []plugins.Service
unidentifiedServices := make([]plugins.Target, 0)

if config.UDP {
return UDPScan(targets, config)
}

for _, target := range targets {
result, err := config.simpleScanTarget(target, true)
if err == nil && result != nil {
results = append(results, *result)
} else {
unidentifiedServices = append(unidentifiedServices, target)
}
if config.Verbose && err != nil {
log.Printf("%s\n", err)
}
}

// done with fastlane mode, return
if config.FastMode {
return results, nil
}

// slow lane scanning
for _, target := range unidentifiedServices {
result, err := config.simpleScanTarget(target, false)
result, err := config.SimpleScanTarget(target)
if err == nil && result != nil {
results = append(results, *result)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/scan/simple_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *Config) UDPScanTarget(target plugins.Target) (*plugins.Service, error)
// only attempts to fingerprint services by mapping them to their default port.
// The slow lane isn't as focused on performance and instead tries to be as
// accurate as possible.
func (c *Config) simpleScanTarget(target plugins.Target, fastMode bool) (*plugins.Service, error) {
func (c *Config) SimpleScanTarget(target plugins.Target) (*plugins.Service, error) {
ip := target.Address.Addr().String()
port := target.Address.Port()

Expand All @@ -93,7 +93,7 @@ func (c *Config) simpleScanTarget(target plugins.Target, fastMode bool) (*plugin
//
// If the port has multiple default mappings we only run the first one
// so in some cases we still bail out to the slow path.
if fastMode {
if c.FastMode {
for _, plugin := range sortedTCPPlugins {
if plugin.PortPriority(port) {
conn, err := DialTCP(ip, port)
Expand Down Expand Up @@ -128,7 +128,7 @@ func (c *Config) simpleScanTarget(target plugins.Target, fastMode bool) (*plugin
// itself as being the one of the default services
// associated with this port. In slow, mode we need to
// run every registered plugin.
if plugin.PortPriority(port) || !fastMode {
if plugin.PortPriority(port) || !c.FastMode {
// Invoke the plugin and return the discovered service event if
// we are successful
result, err := simplePluginRunner(tlsConn, target, c, plugin)
Expand All @@ -155,7 +155,7 @@ func (c *Config) simpleScanTarget(target plugins.Target, fastMode bool) (*plugin
// If we fail to fingerprint the service in fast lane we just bail out to the
// slow lane. However, in the slow lane we want to also try the TCP plugins
// just to be safe.
if fastMode {
if c.FastMode {
return nil, nil
}
}
Expand All @@ -164,7 +164,7 @@ func (c *Config) simpleScanTarget(target plugins.Target, fastMode bool) (*plugin
// In fast mode we only run the corresponding TCP port plugin if it is
// associated with the default port for the service. Within the slow path
// we run every plugin regardless of the default port mapping.
if plugin.PortPriority(port) || !fastMode {
if plugin.PortPriority(port) || !c.FastMode {
conn, err := DialTCP(ip, port)
if err != nil {
return nil, fmt.Errorf("unable to connect, err = %w", err)
Expand Down

0 comments on commit a170c47

Please sign in to comment.