Idiomatic nmap library for go developers
This library aims at providing idiomatic nmap bindings for go developers, in order to make it easier to write security audit tools using golang.
Nmap (Network Mapper) is a free and open-source network scanner created by Gordon Lyon. Nmap is used to discover hosts and services on a computer network by sending packets and analyzing the responses.
Nmap provides a number of features for probing computer networks, including host discovery and service and operating system detection. These features are extensible by scripts that provide more advanced service detection, vulnerability detection, and other features. Nmap can adapt to network conditions including latency and congestion during a scan.
Most pentest tools are currently written using Python and not Go, because it is easy to quickly write scripts, lots of libraries are available, and it's a simple language to use. However, for writing robust and reliable applications, Go is the better tool. It is statically compiled, has a static type system, much better performance, it is also a very simple language to use and goroutines are awesome... But I might be slighly biased, so feel free to disagree.
This library shells out to the nmap binary using Go's exec package and parses the XML output.
That means nmap must be installed and available on your PATH for this library to work.
Compatibility is confirmed with the current latest version of nmap, 7.98.
Some scan types require elevated privileges (for example, SYN scans, OS detection, or raw socket usage). If you enable those options, you may need to run your program with sudo or the appropriate capabilities for your platform.
[!TIP] For unprivileged runs, prefer connect scans (e.g.
-sT).
…The program above outputs:
Host "45.33.32.156":
Port 80/tcp open http
Port 443/tcp closed https
Port 843/tcp closed
Nmap done: 1 hosts up scanned in 0.42 seconds[!IMPORTANT] This relies on terminal escape sequences and only works when the process is attached to a TTY.
[!NOTE] Progress is not guaranteed to increase monotonically: nmap estimates time remaining and can revise that estimate, which may cause the reported percentage to go down.
…This example outputs the following:
……See the examples directory for more usage examples.
Cameradar already uses this library at its core to communicate with nmap, discover RTSP streams and access them remotely.
More examples:
No open issues yet, or sync has not completed.