formatter

package
v2.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DotOpenPortColor defines default color of the opened port
	DotOpenPortColor = "#228B22"
	// DotFilteredPortColor defines default color of the filtered port
	DotFilteredPortColor = "#FFAE00"
	// DotClosedPortColor defies default color of the closed port
	DotClosedPortColor = "#DC143C"
	// DotDefaultColor defines default color of various elements (lines, boxes)
	DotDefaultColor = "gray"

	// DotFontStyle default font style
	DotFontStyle = "monospace"

	// DotLayout is a type of layout used in Graphviz (dot by default is the most fitting)
	DotLayout = "dot"
)

Variables

View Source
var DotDefaultOptions = map[string]string{
	"default_font":  DotFontStyle,
	"layout":        DotLayout,
	"color_default": DotDefaultColor,
}

DotDefaultOptions is a config map that is used in Graphviz template

View Source
var DotTemplate string

DotTemplate variable is used to store contents of graphviz template

View Source
var HTMLSimpleTemplate string

HTMLSimpleTemplate variable is used to store embedded HTML template content

View Source
var MarkdownTemplate string

MarkdownTemplate variable is used to store markdown.tmpl embed file contents

View Source
var SqliteDDL string

SqliteDDL contains database schema definition

Functions

func TemplateContent

func TemplateContent(f Formatter, c *Config) (string, error)

TemplateContent reads customly provided template content or fails with error

Types

type CSVFormatter

type CSVFormatter struct {
	// contains filtered or unexported fields
}

CSVFormatter is struct defined for CSV Output use-case

func (*CSVFormatter) Format

func (f *CSVFormatter) Format(td *TemplateData, templateContent string) (err error)

Format the data to CSV and output it to appropriate io.Writer

type CSVOutputOptions

type CSVOutputOptions struct {
	// The hosts that are down won't be displayed
	SkipDownHosts bool
}

CSVOutputOptions store option related only to CSV conversion/formatting

type Config

type Config struct {
	Writer          io.WriteCloser
	OutputFormat    OutputFormat
	InputFileConfig InputFileConfig
	OutputFile      OutputFile
	OutputOptions   OutputOptions
	ShowVersion     bool
	TemplatePath    string
	CustomOptions   []string
	CurrentVersion  string
}

Config defines main application configs (requirements from user), like: where output will be delivered, desired output format, input file path, output file path and different output options

func (*Config) CustomOptionsMap

func (c *Config) CustomOptionsMap() map[string]string

CustomOptionsMap returns custom options provided in the CLI

type Debugging

type Debugging struct {
	Level int `xml:"level,attr"`
}

Debugging defines level of debug during NMAP execution

type Distance

type Distance struct {
	Value int `xml:"value,attr"`
}

Distance describes amount of hops to the target

type DotFormatter

type DotFormatter struct {
	// contains filtered or unexported fields
}

DotFormatter is used to create Graphviz (dot) format

func (*DotFormatter) Format

func (f *DotFormatter) Format(td *TemplateData, templateContent string) (err error)

Format the data and output it to appropriate io.Writer

type DotTemplateData

type DotTemplateData struct {
	NMAPRun   *NMAPRun
	Constants map[string]string
}

DotTemplateData is a custom TemplateData struct that is used by DotFormatter

type ExtraPorts

type ExtraPorts struct {
	State string `xml:"state,attr"`
	Count int    `xml:"count,attr"`
}

ExtraPorts contains information about certain amount of ports that were (for example) filtered

type Finished

type Finished struct {
	Time    int     `xml:"time,attr"`
	TimeStr string  `xml:"timestr,attr"`
	Elapsed float64 `xml:"elapsed,attr"`
	Summary string  `xml:"summary,attr"`
	Exit    string  `xml:"exit,attr"`
}

Finished is part of `RunStats` struct, it has all information related to the time (started, how much time it took) and summary incl. exit status code

type Formatter

type Formatter interface {
	// Format the data and output it to appropriate io.Writer
	Format(td *TemplateData, templateContent string) error
	// contains filtered or unexported methods
}

Formatter interface describes only one function `Format()` that is responsible for data "formatting"

func New

func New(config *Config) Formatter

New returns new instance of formatter the exact struct of formatter would depend on provided config

type HTMLFormatter

type HTMLFormatter struct {
	// contains filtered or unexported fields
}

HTMLFormatter is struct defined for HTML Output use-case

func (*HTMLFormatter) Format

func (f *HTMLFormatter) Format(td *TemplateData, templateContent string) error

Format the data and output it to appropriate io.Writer

type HTMLOutputOptions

type HTMLOutputOptions struct {
	// SkipDownHosts skips hosts that are down (including TOC)
	SkipDownHosts bool
	// SkipSummary skips general summary for HTML
	SkipSummary bool
	// SkipTraceroute skips traceroute information for HTML
	SkipTraceroute bool
	// SkipMetrics skips metrics related data for HTML
	SkipMetrics bool
	// SkipPortScripts skips port scripts information for HTML
	SkipPortScripts bool
	// DarkMode sets a style to be mostly in dark colours, if false, light colours would be used
	DarkMode bool
	// FloatingContentsTable is an option to make contents table float on the side of the page
	FloatingContentsTable bool
}

HTMLOutputOptions stores options related only to HTML conversion/formatting

type Hop

type Hop struct {
	TTL    int    `xml:"ttl,attr"`
	IPAddr string `xml:"ipaddr,attr"`
	RTT    RTT    `xml:"rtt,attr"`
	Host   string `xml:"host,attr"`
}

Hop struct contains information about HOP record with time to live, host name, IP

type Host

type Host struct {
	StartTime     int           `xml:"starttime,attr"`
	EndTime       int           `xml:"endtime,attr"`
	Port          []Port        `xml:"ports>port"`
	HostAddress   []HostAddress `xml:"address"`
	HostNames     HostNames     `xml:"hostnames"`
	Status        HostStatus    `xml:"status"`
	OS            OS            `xml:"os"`
	Trace         Trace         `xml:"trace"`
	Uptime        Uptime        `xml:"uptime"`
	Distance      Distance      `xml:"distance"`
	TCPSequence   TCPSequence   `xml:"tcpsequence"`
	IPIDSequence  IPIDSequence  `xml:"ipidsequence"`
	TCPTSSequence TCPTSSequence `xml:"tcptssequence"`
}

Host describes host related entry (`host` node)

func (*Host) JoinedAddresses

func (h *Host) JoinedAddresses(delimiter string) string

JoinedAddresses joins all possible host addresses with a delimiter string

func (*Host) JoinedHostNames added in v2.1.0

func (h *Host) JoinedHostNames(delimiter string) string

JoinedHostNames returns a joined string of host names with a provided delimiter

type HostAddress

type HostAddress struct {
	Address     string `xml:"addr,attr"`
	AddressType string `xml:"addrtype,attr"`
	Vendor      string `xml:"vendor,attr"`
}

HostAddress struct contains the host address (IP) and type of it.

type HostName

type HostName struct {
	Name string `xml:"name,attr"`
	Type string `xml:"type,attr"`
}

HostName defines the name of the host and type of DNS record (like PTR for example)

type HostNames

type HostNames struct {
	HostName []HostName `xml:"hostname"`
}

HostNames struct contains list of hostnames (domains) that this host has

type HostRepository added in v2.1.0

type HostRepository struct {
	// contains filtered or unexported fields
}

HostRepository main responsibility is to populated database with host related data

type HostStatus

type HostStatus struct {
	State  string `xml:"state,attr"`
	Reason string `xml:"reason,attr"`
}

HostStatus describes the state (up or down) of the host and the reason

type IPIDSequence

type IPIDSequence struct {
	Class  string `xml:"class,attr"`
	Values string `xml:"values,attr"`
}

IPIDSequence describes all information related to `<ipidsequence>` node

type InputFile

type InputFile string

InputFile describes input file (nmap XML full path)

type InputFileConfig

type InputFileConfig struct {
	Path    string
	IsStdin bool
	Source  io.ReadCloser
}

InputFileConfig stores all options related to nmap XML (path, is content is taken from stdin and io reader)

func (*InputFileConfig) ExistsOpen

func (i *InputFileConfig) ExistsOpen() error

ExistsOpen tries to open a file for reading, returning an error if it fails

type JSONFormatter

type JSONFormatter struct {
	// contains filtered or unexported fields
}

JSONFormatter is struct defined for JSON Output use-case

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(td *TemplateData, templateContent string) (err error)

Format the data and output it to appropriate io.Writer

type JSONOutputOptions

type JSONOutputOptions struct {
	// PrettyPrint defines if JSON output would be pretty-printed (human-readable) or not (machine readable)
	PrettyPrint bool
}

JSONOutputOptions store option related only to JSON conversion/formatting

type MainWorkflow

type MainWorkflow struct {
	Config *Config
}

MainWorkflow is main workflow implementation struct

func (*MainWorkflow) Execute

func (w *MainWorkflow) Execute() (err error)

Execute is the core of the application which executes required steps one-by-one to achieve formatting from input -> output.

func (*MainWorkflow) SetConfig

func (w *MainWorkflow) SetConfig(c *Config)

SetConfig is a simple setter-function that sets the configuration

func (*MainWorkflow) SetInputFile

func (w *MainWorkflow) SetInputFile()

SetInputFile sets an input file (file descriptor) in the config

func (*MainWorkflow) SetOutputFile

func (w *MainWorkflow) SetOutputFile()

SetOutputFile sets output file (file descriptor) depending on config and returns error if there is output file reading issue

type MarkdownFormatter

type MarkdownFormatter struct {
	// contains filtered or unexported fields
}

MarkdownFormatter is a formatter struct used to deliver markdown file format

func (*MarkdownFormatter) Format

func (f *MarkdownFormatter) Format(td *TemplateData, templateContent string) (err error)

Format the data and output it to appropriate io.Writer

type MarkdownOutputOptions

type MarkdownOutputOptions struct {
	// SkipDownHosts skips hosts that are down (including TOC)
	SkipDownHosts bool
	// SkipSummary skips general summary for Markdown
	SkipSummary bool
	// SkipPortScripts skips port scripts information for Markdown
	SkipPortScripts bool
	// SkipTraceroute skips traceroute information for Markdown
	SkipTraceroute bool
	// SkipMetrics skips metrics related data for Markdown
	SkipMetrics bool
}

MarkdownOutputOptions stores options related only to Markdown conversion/formatting

type NMAPRun

type NMAPRun struct {
	Scanner   string    `xml:"scanner,attr"`
	Args      string    `xml:"args,attr"`
	Start     int       `xml:"start,attr"`
	StartStr  string    `xml:"startstr,attr"`
	Version   string    `xml:"version,attr"`
	ScanInfo  ScanInfo  `xml:"scaninfo"`
	Host      []Host    `xml:"host"`
	Verbose   Verbose   `xml:"verbose"`
	Debugging Debugging `xml:"debugging"`
	RunStats  RunStats  `xml:"runstats"`
}

NMAPRun represents main `<nmaprun>“ node which contains meta-information about the scan For example: scanner, what arguments used during scan, nmap version, verbosity level, et cetera Main information about scanned hosts is in the `host` node

func (*NMAPRun) AllHops

func (n *NMAPRun) AllHops() map[string]Hop

AllHops is getting all possible hops that occurred during the scan and merges them uniquely into one map

type OS

type OS struct {
	OSPortUsed []OSPortUsed `xml:"portused"`
	OSClass    []OSClass    `xml:"osclass"`
	OSMatch    []OSMatch    `xml:"osmatch"`
}

OS describes all information about underlying operating system that this host operates

type OSClass

type OSClass struct {
	Type     string   `xml:"type,attr"`
	Vendor   string   `xml:"vendor,attr"`
	OSFamily string   `xml:"osfamily,attr"`
	OSGen    string   `xml:"osgen,attr"`
	Accuracy string   `xml:"accuracy,attr"`
	CPE      []string `xml:"cpe"`
}

OSClass contains all information about operating system family

type OSMatch

type OSMatch struct {
	Name     string `xml:"name,attr"`
	Accuracy string `xml:"accuracy,attr"`
	Line     string `xml:"line,attr"`
}

OSMatch is a record of OS that matched with certain accuracy

type OSPortUsed

type OSPortUsed struct {
	State    string `xml:"state,attr"`
	Protocol string `xml:"proto,attr"`
	PortID   int    `xml:"portid,attr"`
}

OSPortUsed defines which ports were used for OS detection

type OSRepository added in v2.1.0

type OSRepository struct {
	// contains filtered or unexported fields
}

OSRepository is responsible for populating database with OS related data on the scanned host

type OutputFile

type OutputFile string

OutputFile describes output file name (full path)

type OutputFormat

type OutputFormat string

OutputFormat is a resulting type of file that is converted/formatted from XML to HTML (for example)

const (
	// HTMLOutput constant defines OutputFormat is HyperText Markup Language which can be viewed using browsers
	HTMLOutput OutputFormat = "html"
	// CSVOutput constant defines OutputFormat for Comma-Separated Values CSV file which is viewed most of the time in Excel
	CSVOutput OutputFormat = "csv"
	// MarkdownOutput constant defines OutputFormat for Markdown, which is handy and easy format to read-write
	MarkdownOutput OutputFormat = "md"
	// JSONOutput constant defines OutputFormat for JavaScript Object Notation, which is more useful for machine-related operations (parsing)
	JSONOutput OutputFormat = "json"
	// DotOutput constant defined OutputFormat for Dot (Graphviz), which can be used to generate various graphs
	DotOutput OutputFormat = "dot"
	// SqliteOutput constant defines OutputFormat for sqlite file, which can be used to generate sqlite embedded databases
	SqliteOutput OutputFormat = "sqlite"
)

func (OutputFormat) IsValid

func (of OutputFormat) IsValid() bool

IsValid checks whether requested output format is valid

type OutputOptions

type OutputOptions struct {
	HTMLOptions         HTMLOutputOptions
	MarkdownOptions     MarkdownOutputOptions
	JSONOptions         JSONOutputOptions
	CSVOptions          CSVOutputOptions
	SqliteOutputOptions SqliteOutputOptions
}

OutputOptions describes various output options for nmap formatter

type Port

type Port struct {
	Protocol string      `xml:"protocol,attr"`
	PortID   int         `xml:"portid,attr"`
	State    PortState   `xml:"state"`
	Service  PortService `xml:"service"`
	Script   []Script    `xml:"script"`
}

Port record contains main information about port that was scanned

type PortRepository added in v2.1.0

type PortRepository struct {
	// contains filtered or unexported fields
}

PortRepository is responsible for populating database with a data related to ports

type PortService

type PortService struct {
	Name      string   `xml:"name,attr"`
	Product   string   `xml:"product,attr"`
	Version   string   `xml:"version,attr"`
	ExtraInfo string   `xml:"extrainfo,attr"`
	Method    string   `xml:"method,attr"`
	Conf      string   `xml:"conf,attr"`
	CPE       []string `xml:"cpe"`
}

PortService struct contains information about the service that is located on certain port

type PortState

type PortState struct {
	State     string `xml:"state,attr"`
	Reason    string `xml:"reason,attr"`
	ReasonTTL string `xml:"reason_ttl,attr"`
}

PortState describes information about the port state and why it's state was defined that way

type RTT

type RTT float64

RTT is a separate type that is located in Hop struct

func (*RTT) UnmarshalXMLAttr

func (r *RTT) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr is a separate function that attempts to parse RTT float value if it fails to do so, it sets the value to 0.0

type RunStats

type RunStats struct {
	Finished Finished  `xml:"finished"`
	Hosts    StatHosts `xml:"hosts"`
}

RunStats contains other nodes that refer to statistics of the scan

type ScanInfo

type ScanInfo struct {
	Type        string `xml:"type,attr"`
	Protocol    string `xml:"protocol,attr"`
	NumServices int    `xml:"numservices,attr"`
	Services    string `xml:"services,attr"`
}

ScanInfo shows what type of scan it was and number of services covered

type ScanRepository added in v2.1.0

type ScanRepository struct {
	// contains filtered or unexported fields
}

ScanRepository main function is to make a first step populating sqlite database with values

type Script

type Script struct {
	ID     string `xml:"id,attr"`
	Output string `xml:"output,attr"`
}

Script defines a script ID and script output (result)

type SqliteDB added in v2.1.0

type SqliteDB struct {
	// contains filtered or unexported fields
}

SqliteDB holds sqlite connection and transaction and performs main database function - preparation, population and finishing data migration

func NewSqliteDB added in v2.1.0

func NewSqliteDB(c *Config) (*SqliteDB, error)

NewSqliteDB attempts to create new instance of SqliteDB struct and attempts to make a connection to the database, once it's successful it assigns variables to a ScanRepository struct and returns a pointer

type SqliteFormatter added in v2.1.0

type SqliteFormatter struct {
	// contains filtered or unexported fields
}

SqliteFormatter is a main struct to handle output for Sqlite

func (*SqliteFormatter) Format added in v2.1.0

func (f *SqliteFormatter) Format(td *TemplateData, templateContent string) error

Format the data to sqlite format and insert it into appropriate output (Sqlite DSN)

type SqliteOutputOptions added in v2.1.0

type SqliteOutputOptions struct {
	// DSN is a Data Source Name to sqlite embedded database, by default it's empty which results in stdout output,
	// however, if both DSN and OutputFile provided, OutputFile option takes preference over SqliteOutputOptions.DSN
	DSN string
	// ScanIdentifier is a unique string passed by the user to identify unique scans. If it's empty, it's generated automatically
	ScanIdentifier string
}

SqliteOutputOptions store options related to SQLite database formatting

type StatHosts

type StatHosts struct {
	Up    int `xml:"up,attr"`
	Down  int `xml:"down,attr"`
	Total int `xml:"total,attr"`
}

StatHosts contains statistics about hosts that are up or down

type TCPSequence

type TCPSequence struct {
	Index      string `xml:"index,attr"`
	Difficulty string `xml:"difficulty,attr"`
	Values     string `xml:"values,attr"`
}

TCPSequence describes all information related to `<tcpsequence>`

type TCPTSSequence

type TCPTSSequence struct {
	Class  string `xml:"class,attr"`
	Values string `xml:"values,attr"`
}

TCPTSSequence describes all information related to `<tcptssequence>` node

type TemplateData

type TemplateData struct {
	NMAPRun       NMAPRun
	OutputOptions OutputOptions
	CustomOptions map[string]string
}

TemplateData is a struct that is used in the template, where NMAPRun is containing all parsed data from XML & OutputOptions contain all the information about certain output preferences.

type Trace

type Trace struct {
	Port     int    `xml:"port,attr"`
	Protocol string `xml:"proto,attr"`
	Hops     []Hop  `xml:"hop"`
}

Trace struct contains trace information with hops

type Uptime

type Uptime struct {
	Seconds  int    `xml:"seconds,attr"`
	LastBoot string `xml:"lastboot,attr"`
}

Uptime shows the information about host uptime

type Verbose

type Verbose struct {
	Level int `xml:"level,attr"`
}

Verbose defines verbosity level that was configured during NMAP execution

type Workflow

type Workflow interface {
	Execute() (err error)
	SetConfig(c *Config)
	SetInputFile()
	SetOutputFile()
}

Workflow interface that describes the main functions that are used in nmap-formatter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL