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

Fixing the missing port issue with Nessus #191

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Changes from 1 commit
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
Next Next commit
Fixing Nessus missing ports issue
Fixing the issue where some ports where missing when importing a Nessus scan.
  • Loading branch information
quentinpraz authored Jul 14, 2023
commit 631dc53f61b47797557b9ec6be34e6b180118cb2
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[ip] = removeDuplicatedPorts(append(nessusHostsMap[ip], 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
}