Skip to content

Commit 3b1ad87

Browse files
authored
check for root privileges warning (#137)
1 parent 1bef796 commit 3b1ad87

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

errors.go

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var (
1919
// ErrParseOutput means that nmap's output was not parsed successfully.
2020
ErrParseOutput = errors.New("unable to parse nmap output, see warnings for details")
2121

22+
// ErrRequiresRoot means this feature requires root privileges (e.g. OS detection)
23+
ErrRequiresRoot = errors.New("this feature requires root privileges")
24+
2225
// ErrResolveName means that Nmap could not resolve a name.
2326
ErrResolveName = errors.New("nmap could not resolve a name")
2427
)

nmap.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,18 @@ func choosePorts(result *Run, filter func(Port) bool) {
250250

251251
func (s *Scanner) processNmapResult(result *Run, warnings *[]string, stdout, stderr *bytes.Buffer, done chan error, doneProgress chan bool) error {
252252
// Wait for nmap to finish.
253-
var err = <-done
253+
var (
254+
errStatus = <-done
255+
err error
256+
)
254257
close(doneProgress)
255-
if err != nil {
256-
return err
257-
}
258-
259258
// Check stderr output.
260259
if err := checkStdErr(stderr, warnings); err != nil {
261260
return err
262261
}
262+
if errStatus != nil {
263+
return errStatus
264+
}
263265

264266
// Parse nmap xml output. Usually nmap always returns valid XML, even if there is a scan error.
265267
// Potentially available warnings are returned too, but probably not the reason for a broken XML.
@@ -310,6 +312,10 @@ func checkStdErr(stderr *bytes.Buffer, warnings *[]string) error {
310312
switch {
311313
case strings.Contains(warning, "Malloc Failed!"):
312314
return ErrMallocFailed
315+
case strings.Contains(warning, "requires root privileges."):
316+
return ErrRequiresRoot
317+
// TODO: Add cases for other known errors we might want to guard.
318+
default:
313319
}
314320
}
315321
return nil

0 commit comments

Comments
 (0)