Skip to content

Commit

Permalink
check for root privileges warning (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymet authored Jan 5, 2025
1 parent 1bef796 commit 3b1ad87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var (
// ErrParseOutput means that nmap's output was not parsed successfully.
ErrParseOutput = errors.New("unable to parse nmap output, see warnings for details")

// ErrRequiresRoot means this feature requires root privileges (e.g. OS detection)
ErrRequiresRoot = errors.New("this feature requires root privileges")

// ErrResolveName means that Nmap could not resolve a name.
ErrResolveName = errors.New("nmap could not resolve a name")
)
16 changes: 11 additions & 5 deletions nmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,18 @@ func choosePorts(result *Run, filter func(Port) bool) {

func (s *Scanner) processNmapResult(result *Run, warnings *[]string, stdout, stderr *bytes.Buffer, done chan error, doneProgress chan bool) error {
// Wait for nmap to finish.
var err = <-done
var (
errStatus = <-done
err error
)
close(doneProgress)
if err != nil {
return err
}

// Check stderr output.
if err := checkStdErr(stderr, warnings); err != nil {
return err
}
if errStatus != nil {
return errStatus
}

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

0 comments on commit 3b1ad87

Please sign in to comment.