Skip to content

Commit 33c0f37

Browse files
committed
fix: use correct log levels in UDP probe warnings
gologger.Info().Label("WRN") is a hack that suppresses warnings in -silent mode and breaks standard log-level semantics. Replace both occurrences with gologger.Warning(), demote the probe-load progress message to Debug, and add a ValidateOptions check that warns when -uP is used without any u: ports in the scan target. Follows up on #1689.
1 parent cf5563f commit 33c0f37

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

pkg/runner/options.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"strings"
78
"time"
89

910
"github.com/projectdiscovery/naabu/v2/pkg/privileges"
@@ -406,6 +407,25 @@ func (options *Options) shouldUseRawPackets() bool {
406407
return isOSSupported() && privileges.IsPrivileged && options.ScanType == SynScan && scan.PkgRouter != nil
407408
}
408409

410+
// hasUDPPorts reports whether the user's port specification includes at least
411+
// one UDP port (i.e. a segment starting with "u:"). This is used at validation
412+
// time, before ParsePorts has expanded the port list, so we inspect the raw
413+
// strings rather than the parsed []*port.Port slice.
414+
func (options *Options) hasUDPPorts() bool {
415+
// Check inline -p flag
416+
if strings.Contains(options.Ports, "u:") {
417+
return true
418+
}
419+
// Check -pf (ports file) entries — each element may itself be a
420+
// comma-separated list, so we search for the "u:" prefix in the joined string.
421+
for _, pf := range options.PortsFile {
422+
if strings.Contains(pf, "u:") {
423+
return true
424+
}
425+
}
426+
return false
427+
}
428+
409429
func (options *Options) ShouldScanIPv4() bool {
410430
return sliceutil.Contains(options.IPVersion, "4")
411431
}

pkg/runner/udp_probes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (r *Runner) loadProbeDB(path string) (*fingerprint.ProbeDB, error) {
1717
if err != nil {
1818
return nil, err
1919
}
20-
gologger.Info().Msgf("Loaded %d probes from %s", len(db.Probes), path)
20+
gologger.Debug().Msgf("Loaded %d probes from %s", len(db.Probes), path)
2121
r.probeDB = db
2222
return db, nil
2323
}
@@ -59,13 +59,13 @@ func (r *Runner) initUDPProbes() {
5959
probeFile = fingerprint.LocateNmapProbes()
6060
}
6161
if probeFile == "" {
62-
gologger.Info().Label("WRN").Msgf("could not find nmap-service-probes, -uP has nothing to send. Install nmap or specify the path with --sV-probes")
62+
gologger.Warning().Msgf("could not find nmap-service-probes, -uP has nothing to send. Install nmap or specify the path with --sV-probes")
6363
r.options.UDPProbes = false
6464
return
6565
}
6666
db, err := r.loadProbeDB(probeFile)
6767
if err != nil {
68-
gologger.Info().Label("WRN").Msgf("could not load service probes from %s for -uP: %s", probeFile, err)
68+
gologger.Warning().Msgf("could not load service probes from %s for -uP: %s", probeFile, err)
6969
r.options.UDPProbes = false
7070
return
7171
}

pkg/runner/validate.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ func (options *Options) ValidateOptions() error {
178178
if options.PredictionThreshold < 0 || options.PredictionThreshold > 100 {
179179
return errors.New("prediction threshold must be between 0 and 100")
180180
}
181+
// Warn when -uP is set but the port list contains no UDP ports: the
182+
// feature will load the probe database but never send any probes,
183+
// which is misleading for the user. We check the raw Ports string and
184+
// PortsFile because ParsePorts has not run yet at validation time. The
185+
// heuristic is: unless the user passed at least one "u:" segment, no
186+
// UDP port will be scanned.
187+
if options.UDPProbes && !options.hasUDPPorts() {
188+
gologger.Warning().Msgf("-uP (UDP probes) is enabled but no UDP ports were specified. " +
189+
"Add UDP ports with -p u:53,u:123 or similar. Without UDP ports -uP has no effect.")
190+
}
181191

182192
return nil
183193
}

0 commit comments

Comments
 (0)