Skip to content

Instantly share code, notes, and snippets.

@leonjza
Last active March 16, 2022 14:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save leonjza/bb977e98eac9565fae2aa177e498d9b8 to your computer and use it in GitHub Desktop.
Save leonjza/bb977e98eac9565fae2aa177e498d9b8 to your computer and use it in GitHub Desktop.
goness - A golang Nessus XML parser for use in your shell pipeline

goness

A golang Nessus XML parser for use in your shell pipeline

examples

Just searching for "MS15":

$ goness -f exported_download.nessus | grep "MS15"
MS15-034: Vulnerability in HTTP.sys Could Allow Remote Code Execution (3042553) (uncredentialed check)|www|10.1.1.1:80

Getting all hosts with NULL ciphers:

$ goness -f exported_download.nessus | grep -i "ssl null" | cut -d"|" -f 3 | sort | uniq
10.1.1.10:50001
10.1.1.11:50003

installation

Save the main.go and either run it directly, build it and run the binary or install it.

go run main.go  // just run it
go build -o goness && ./goness // build an executable and run it
go install  // build and install the executable in your $GOPATH/bin directory
package main
import (
"encoding/xml"
"flag"
"fmt"
"os"
)
type reportHost struct {
HostName string `xml:"name,attr"`
ReportItems []reportItem `xml:"ReportItem"`
}
type reportItem struct {
PluginName string `xml:"pluginName,attr"`
ServiceName string `xml:"svc_name,attr"`
Port int `xml:"port,attr"`
}
const version = "0.1"
func banner() {
fmt.Printf("goness - v%s\n", version)
fmt.Printf(" A golang Nessus XML parser for use in your shell pipeline.\n\n")
}
func main() {
var fileType string
const (
defaultFile = ""
usage = "The Nessus XML file to parse"
)
// flags
flag.StringVar(&fileType, "file", defaultFile, usage)
flag.StringVar(&fileType, "f", defaultFile, usage+" (shorthand)")
flag.Parse()
if fileType == "" {
banner()
flag.PrintDefaults()
return
}
file, err := os.Open(fileType)
if err != nil {
banner()
fmt.Println("Error opening source XML file: ", err)
return
}
// close the xml when we are done
defer file.Close()
decoder := xml.NewDecoder(file)
for {
token, err := decoder.Token()
if err != nil {
break
}
if token == nil {
break
}
switch element := token.(type) {
case xml.StartElement:
tagName := element.Name.Local
// Read the ReportHosts from the XML
if tagName == "ReportHost" {
var host reportHost
decoder.DecodeElement(&host, &element)
for _, item := range host.ReportItems {
fmt.Printf("%s|%s|%s:%d\n", item.PluginName, item.ServiceName, host.HostName, item.Port)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment