Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically skip redundant host discovery #1061

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions v2/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ type Target struct {
func NewRunner(options *Options) (*Runner, error) {
options.configureOutput()

options.configureHostDiscovery()
// automatically disable host discovery when less than two ports for scan are provided
ports, err := ParsePorts(options)
if err != nil {
return nil, fmt.Errorf("could not parse ports: %s", err)
}

options.configureHostDiscovery(ports)

// default to ipv4 if no ipversion was specified
if len(options.IPVersion) == 0 {
Expand Down Expand Up @@ -131,10 +137,7 @@ func NewRunner(options *Options) (*Runner, error) {
}
runner.scanner = scanner

runner.scanner.Ports, err = ParsePorts(options)
if err != nil {
return nil, fmt.Errorf("could not parse ports: %s", err)
}
runner.scanner.Ports = ports

if options.EnableProgressBar {
defaultOptions := &clistats.DefaultOptions
Expand Down
8 changes: 7 additions & 1 deletion v2/pkg/runner/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/projectdiscovery/naabu/v2/pkg/port"
"github.com/projectdiscovery/naabu/v2/pkg/privileges"
"github.com/projectdiscovery/naabu/v2/pkg/scan"
fileutil "github.com/projectdiscovery/utils/file"
Expand Down Expand Up @@ -165,7 +166,12 @@ func (options *Options) configureOutput() {

// ConfigureHostDiscovery enables default probes if none is specified
// but host discovery option was requested
func (options *Options) configureHostDiscovery() {
func (options *Options) configureHostDiscovery(ports []*port.Port) {
// if less than two ports are specified as input, reduce time and scan directly
if len(ports) <= 2 {
gologger.Info().Msgf("Host discovery disabled: less than two ports were specified")
options.SkipHostDiscovery = true
}
if options.shouldDiscoverHosts() && !options.hasProbes() {
// if no options were defined enable
// - ICMP Echo Request
Expand Down
Loading