Skip to content

Commit

Permalink
Fixing the missing port issue with Nessus (#191)
Browse files Browse the repository at this point in the history
* Fixing Nessus missing ports issue

Fixing the issue where some ports where missing when importing a Nessus scan.

* Fixing typo
  • Loading branch information
quentinpraz authored Oct 29, 2023
1 parent 6cda5a5 commit d802cd4
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions cmd/nessus.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func getNessusURLs() (urls []string, err error) {
decoder := xml.NewDecoder(nessusFile)

// Unique maps to cut down on dupliation within nessus files
var nessusIPsMap = make(map[string]int)
var nessusHostsMap = make(map[string]int)
var nessusIPsMap = make(map[string][]int)
var nessusHostsMap = make(map[string][]int)

for {
token, err := decoder.Token()
Expand Down Expand Up @@ -232,12 +232,12 @@ func getNessusURLs() (urls []string, err error) {
// add the hostnames if the option has been set
if options.NmapScanHostnames {
if fqdn != "" {
nessusHostsMap[fqdn] = item.Port
nessusHostsMap[fqdn] = removeDuplicatedPorts(append(nessusHostsMap[fqdn], item.Port))
}
}
// checking for empty ip. It should always be set, but you never know
if ip != "" {
nessusIPsMap[ip] = item.Port
nessusIPsMap[ip] = removeDuplicatedPorts(append(nessusIPsMap[ip], item.Port))
}

log.Debug().Str("target", ip).Str("service", item.ServiceName).Int("port", item.Port).
Expand All @@ -261,15 +261,32 @@ func getNessusURLs() (urls []string, err error) {
}

// buildURI will build urls taking the http/https options int account
func buildURL(hostname string, port int) (r []string) {
func buildURL(hostname string, port []int) (r []string) {

if !options.NoHTTP {
r = append(r, fmt.Sprintf(`http://%s:%d`, hostname, port))
}
for _, v := range port {
if !options.NoHTTP {
r = append(r, fmt.Sprintf(`http://%s:%d`, hostname, v))
}

if !options.NoHTTPS {
r = append(r, fmt.Sprintf(`https://%s:%d`, hostname, port))
if !options.NoHTTPS {
r = append(r, fmt.Sprintf(`https://%s:%d`, hostname, v))
}
}

return r
}

// removeDuplicatedPort removes duplicated ports
func removeDuplicatedPorts(port []int) []int {
uniqueMap := make(map[int]bool)
uniqueList := []int{}

for _, item := range port {
if _, ok := uniqueMap[item]; !ok {
uniqueMap[item] = true
uniqueList = append(uniqueList, item)
}
}

return uniqueList
}

0 comments on commit d802cd4

Please sign in to comment.