Documentation
¶
Overview ¶
Package nmap is a wrapper library for nmap.
Why ¶
NMap is a great tool, but it's very hard to script when using Go. This project is meant to make life easier when doing network scanning in Go. The package is meant to be very easy to use, and extremely intuitive to learn.
Install ¶
You will need to have the binary `nmap` installed on your computer, so visit their website http://nmap.org and install nmap.
For macos, you can install nmap by using Homebrew ¶
for Linux systems, use your package manager to install nmap.
For Windows, visit http://nmap.org
Index ¶
- Variables
- type DisallowedFlagError
- type Element
- type Host
- type Hostname
- type Port
- type Scan
- func (s Scan) AddFlags(flags ...string) Scan
- func (s Scan) AddHosts(hosts ...string) Scan
- func (s Scan) AddPortRange(lPort, hPort uint16) Scan
- func (s Scan) AddPorts(ports ...uint16) Scan
- func (s Scan) AddTCPPorts(ports ...uint16) Scan
- func (s Scan) AddUDPPorts(ports ...uint16) Scan
- func (s Scan) CreateNmapArgs() ([]string, error)
- func (s Scan) GetHost(hostTarget string) (target Host, exists bool)
- func (s Scan) Intense() Scan
- func (s Scan) IntenseAllTCPPorts() Scan
- func (s Scan) Ping() Scan
- func (s Scan) Quick() Scan
- func (s Scan) Run() (output Scan, err error)
- func (s Scan) SetFlags(flags ...string) Scan
- func (s Scan) SetHosts(hosts ...string) Scan
- func (s Scan) SetPorts(ports ...uint16) Scan
- func (s Scan) SetTCPPorts(ports ...uint16) Scan
- func (s Scan) SetUDPPorts(ports ...uint16) Scan
- func (s Scan) ToString() (out string)
- type Script
- Bugs
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DisallowedFlags = []string{"-oN", "-oX", "-oG", "-oA"}
DisallowedFlags is a list of flags that will break the nmap library's ability to parse the output
Functions ¶
This section is empty.
Types ¶
type DisallowedFlagError ¶
type DisallowedFlagError struct {
Flag string
}
DisallowedFlagError is thrown when a disallowed flag is used. A list of disallowed flags can be seen in the `DisallowedFlags` variable
func (*DisallowedFlagError) Error ¶
func (f *DisallowedFlagError) Error() string
Error returns the flag string
type Host ¶
type Host struct { State string Address string AddressType string Hostnames []Hostname Ports []Port // contains filtered or unexported fields }
Host declares host information
func (Host) Diff ¶
Diff gets the difference between the the target host and the argument host. The first returned value is the added ports and the second returned value is the removed ports.
Example ¶
// Scan maxh.io one scan, _ := Init().AddHosts("maxh.io").Run() firstHost, _ := scan.GetHost("maxh.io") // Wait 100 seconds time.Sleep(100 * time.Second) // Rescan maxh.io scan, _ = scan.Run() secondHost, _ := scan.GetHost("maxh.io") // Get list of added and removed ports added, removed := firstHost.Diff(secondHost) fmt.Println(added, removed)
Output:
type Port ¶
type Port struct { Protocol string // ID is the port number ID uint32 State string Service string Method string Scripts []Script }
Port represents nmap port information
type Scan ¶
type Scan struct { DisplayArgs string Hosts map[string]Host // contains filtered or unexported fields }
Scan holds one nmap scan. It can be rescanned, diff'ed, and parsed for hosts
func Init ¶
func Init() Scan
Init initializes a scan object. This is the easiest way to create a Scan object. If you are trying to create a Scan object by hand, make sure to instantiate the Hosts map
func (Scan) AddFlags ¶
AddFlags adds a list of flags to be used by nmap. Seperate flags by new arguments. The order of the flag is kept, so when using flags that require file names, seperate it by using multiple arguments.
Use the DisallowedFlags variable to guide you on which flags are not allowed to be used.
func (Scan) AddPortRange ¶
AddPortRange adds a list of ports where the first argument is the low bound (inclusive) on the range and the second argument is the upper bound (exclusive)
E.x. AddPortRange(0, 1025) adds ports 1-1024 to the list TODO(t94j0): Make into actual nmap ranges. (-p1-1024)
func (Scan) AddTCPPorts ¶
AddTCPPorts adds TCP-only ports. Similar to using `-pT:<port1>,<port2>...`
func (Scan) AddUDPPorts ¶
AddUDPPorts adds UDP-only ports. Similar to using `-pU:<port1>,<port2>...`
func (Scan) CreateNmapArgs ¶
CreateNmapArgs takes a Scan object and returns a list of strings that map to arguments for an nmap scan.
func (Scan) GetHost ¶
GetHost will get a specified host by either hostname or ip. The first return value is the host, if it was found. The second return value is the wether the host was found or not
Example ¶
// All online hosts are added to the `scan` object scan, _ := Init().AddPorts(80).AddHosts("example.com").Run() // GetHost allows you to select one host from the list targetHost, _ := scan.GetHost("93.184.216.34") fmt.Println(targetHost.ToString()) // It also searches hostnames targetHost, _ = scan.GetHost("maxh.io") fmt.Println(targetHost.ToString())
Output:
func (Scan) Intense ¶
Intense sets the options to use an "intense" scan. These are the same options as used in Zenmap's intense scan.
Example ¶
scan, _ := Init().AddHosts("localhost").Intense().Run() fmt.Println(scan.ToString())
Output:
func (Scan) IntenseAllTCPPorts ¶
IntenseAllTCPPorts does an intense scan, but adds all TCP ports
func (Scan) Run ¶
Run is used to scan hosts. The Scan object should be configured using specified Add* Set* functions.
BUG(t94j0): The scan will sometimes segfault and theres no reason why
Example ¶
scan, _ := Init(). AddHosts("maxh.io", "192.168.0.1"). AddPorts(80, 445). AddFlags("-A"). Run() fmt.Println(scan.ToString())
Output:
func (Scan) SetTCPPorts ¶
SetTCPPorts sets which TCP-only ports are used to scan
func (Scan) SetUDPPorts ¶
SetUDPPort sets which TCP-only ports are used to scan
Notes ¶
Bugs ¶
The scan will sometimes segfault and theres no reason why