Skip to content

edoermini/gonmap

Repository files navigation

gonmap

import "github.com/edoermini/gonmap"

Package gonmap provides an efficient and simple API for nmap

For every scan it's necessary create a scan with:

scan := NewScan()

and populate it with related functions.

A simple main example:

package main

import (
	"log"
	"fmt"

	gonmap "github.com/edoermini/gonmap"
)

func main() {
	scan := gonmap.NewScan()

	if err := scan.AddHost("github.com"); err != nil {
		log.Fatal(err)
	}

	if err := scan.AddPort(80); err != nil {
		log.Fatal(err)
	}

	ret, err := scan.TCPScan()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(ret.Hosts[0].PortList.Port[0].ID)
}

Index

type Address

Address contains info about address (ipv4, ipv6)

type Address struct {
    Value string `xml:"addr,attr" json:"value"`
    Type  string `xml:"addrtype,attr" json:"type"`
}

type Elem

Elem contains a part of script result

type Elem struct {
    Key   string `xml:"key,attr" json:"key"`
    Value string `xml:",chardata" json:"value"`
}

type Host

Host contains all info about a specific host

type Host struct {
    Status   HostStatus `xml:"status" json:"status"`
    Address  Address    `xml:"address" json:"address"`
    PortList Port       `xml:"ports" json:"ports"`
    OsInfo   OsInfo     `xml:"os" json:"osinfo"`
}

HostDiscovery contains all methods that implement an host discovery scan

type HostDiscovery interface {
    SYNDiscovery()
    ACKDiscovery()
    UDPDiscovery()
    SCTPDiscovery()
}

HostStatus contains status of specific host

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

type NmapRun

NmapRun is the root of every scan result

type NmapRun struct {
    Info  ScanInfo `xml:"scaninfo" json:"scaninfo"`
    Hosts []Host   `xml:"host" json:"hosts"`
}

type OsInfo

OsInfo contains all os detection matches

type OsInfo struct {
    OsMatch []OsMatch `xml:"osmatch" json:"osmatch"`
}

type OsMatch

OsMatch contains info about an os detection match

type OsMatch struct {
    Name     string `xml:"name,attr" json:"name"`
    Accuracy string `xml:"accuracy,attr" json:"accuracy"`
}

type Port

Port contains all port checked in scan

type Port struct {
    Port []PortInfo `xml:"port" json:"ports"`
}

PortInfo contains info about a specific port

type PortInfo struct {
    ID       int       `xml:"portid,attr" json:"id"`
    Protocol string    `xml:"protocol,attr" json:"protocol"`
    Status   PortState `xml:"state" json:"status"`
    Service  Service   `xml:"service" json:"service"`
    Scripts  []Script  `xml:"script" json:"scripts"`
}

PortState contains status of specific port

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

type Scan

Scan contains basic scan information like hosts, ports, performance of scan and a flag for service version scan. Is the base for every scan type

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

func NewScan

func NewScan() Scan

NewScan returns a new Scan with default values

func (Scan) ACKDiscovery

func (s Scan) ACKDiscovery() (NmapRun, error)

ACKDiscovery makes a TCP ACK discovery

func (Scan) ACKScan

func (s Scan) ACKScan() (NmapRun, error)

ACKScan are used to determine whether a particular port is filtered or not. Flag: -sA

func (*Scan) AddHost

func (s *Scan) AddHost(h string) error

AddHost adds given host to scan if it's a valid host and returns error otherwise

func (*Scan) AddHosts

func (s *Scan) AddHosts(hosts []string) error

AddHosts adds all given hosts to scan if all hosts are valid and returns error otherwise

func (*Scan) AddPort

func (s *Scan) AddPort(p int) error

AddPort adds given port to scan if is a valid port and returns error otherwise

func (*Scan) AddPortRange

func (s *Scan) AddPortRange(min int, max int) error

AddPortRange adds ports from min to max if min and max are valid bounds and returns error otherwise

func (*Scan) AddPorts

func (s *Scan) AddPorts(ports []int) error

AddPorts adds all given ports to scan if all ports are valid and returns error otherwise

func (*Scan) AddScript

func (s *Scan) AddScript(script string) error

AddScript adds given script to scan

func (*Scan) AddScripts

func (s *Scan) AddScripts(scripts []string) error

AddScripts adds all given scripts to scan

func (*Scan) AddTopPorts

func (s *Scan) AddTopPorts(n int) error

AddTopPorts adds top n ports to scan

func (Scan) AggressiveScan

func (s Scan) AggressiveScan() (NmapRun, error)

AggressiveScan makes a scan with version scan (-sV), os detection (-O), script scanning (-sC) and traceroute

func (Scan) FINScan

func (s Scan) FINScan() (NmapRun, error)

FINScan is like SYN scan, but sends a TCP FIN packet instead. Flag: -sF

func (Scan) GetHosts

func (s Scan) GetHosts() []string

GetHosts returns hosts set

func (Scan) GetOsDetection

func (s Scan) GetOsDetection() bool

GetOsDetection returns os detection choise

func (Scan) GetPerformance

func (s Scan) GetPerformance() int

GetPerformance returns performance

func (Scan) GetPorts

func (s Scan) GetPorts() []int

GetPorts returns ports set

func (Scan) GetRunScript

func (s Scan) GetRunScript() bool

GetRunScript returns script running choise

func (Scan) GetScripts

func (s Scan) GetScripts() []string

GetScripts returns scripts set

func (Scan) HasHost

func (s Scan) HasHost(h string) bool

HasHost checks if scan has given host

func (Scan) HasPort

func (s Scan) HasPort(p int) bool

HasPort checks if scan has given port

func (Scan) HasScript

func (s Scan) HasScript(script string) bool

HasScript checks if scan has given script

func (Scan) IDLEScan

func (s Scan) IDLEScan(zombie string) (NmapRun, error)

IDLEScan is the stealthiest of all scans as the packets are bounced off an external host. Flag: -sI

func (Scan) IsEqual

func (s Scan) IsEqual(s1 Scan) bool

IsEqual cheks if two scans are equal

func (Scan) MaimonScan

func (s Scan) MaimonScan() (NmapRun, error)

MaimonScan is exactly the same as NULL, FIN, and Xmas scan, except that the probe is FIN/ACK. Flag: -sM

func (Scan) NULLScan

func (s Scan) NULLScan() (NmapRun, error)

NULLScan are extremely stealthy scan and what they do is as the name suggests — they set all the header fields to null. Flag: -sN

func (*Scan) RunScripts

func (s *Scan) RunScripts(choise bool)

RunScripts sets scripts running if choise is true. Setting this true without adding scripts it's equivalent to a scan with default scripts. Flag: -sC

func (Scan) SCTPDiscovery

func (s Scan) SCTPDiscovery() (NmapRun, error)

SCTPDiscovery makes an SCTP discovery

func (Scan) SYNDiscovery

func (s Scan) SYNDiscovery() (NmapRun, error)

SYNDiscovery makes a TCP SYN discovery

func (Scan) SYNScan

func (s Scan) SYNScan() (NmapRun, error)

SYNScan is another form of TCP scan. The difference is unlike a normal TCP scan, nmap itself crafts a syn packet, which is the first packet that is sent to establish a TCP connection. Flag: -sS

func (*Scan) SetOsDetection

func (s *Scan) SetOsDetection(choise bool)

SetOsDetection sets operative system detection flag if choise is true. Nmap flag: -O

func (*Scan) SetPerformance

func (s *Scan) SetPerformance(performance int) error

SetPerformance sets scan performance if performance parameter is an integer between 0 and 5

func (*Scan) SetVersionScan

func (s *Scan) SetVersionScan(choise bool)

SetVersionScan sets service version scan. Nmap flag: -sV

func (Scan) String

func (s Scan) String() string

func (Scan) TCPScan

func (s Scan) TCPScan() (NmapRun, error)

TCPScan is generally used to check and complete a three-way handshake between you and a chosen target system. Flag: -sT

func (Scan) UDPDiscovery

func (s Scan) UDPDiscovery() (NmapRun, error)

UDPDiscovery makes an UDP discovery

func (Scan) UDPScan

func (s Scan) UDPScan() (NmapRun, error)

UDPScan are used to check whether there is any UDP port up and listening for incoming requests on the target machine. Flag: -sU

func (Scan) WindowScan

func (s Scan) WindowScan() (NmapRun, error)

WindowScan is exactly the same as ACK scan except that it exploits an implementation detail of certain systems to differentiate open ports from closed ones, rather than always printing unfiltered when a RST is returned. Flag: -sW

func (Scan) XmasScan

func (s Scan) XmasScan() (NmapRun, error)

XmasScan is just like null scans, these are also stealthy in nature. Flag -sX

ScanInfo contains info about the scan

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

ScanTecnique contains all methods that implement a scan tecnique

type ScanTecnique interface {
    TCPScan()
    UDPScan()
    SYNScan()
    ACKScan()
    FINScan()
    NULLScan()
    XmasScan()
    WindowScan()
    MaimonScan()
    IDLEScan()
}

type Script

Script contains info about a specific script launched against a specific port

type Script struct {
    ID     string  `xml:"id,attr" json:"id"`
    Output string  `xml:"output,attr" json:"output"`
    Elems  []Elem  `xml:"elem" json:"elems"`
    Tables []Table `xml:"table" json:"tables"`
}

type Service

Service contains info about service served in a specific port

type Service struct {
    Name    string `xml:"name,attr" json:"name"`
    Version string `xml:"product,attr" json:"version"`
}

type Table

Table contains a group of elems of a specific script

type Table struct {
    Key   string `xml:"key,attr" json:"key"`
    Elems []Elem `xml:"elem" json:"elems"`
}

Generated by gomarkdoc