nmap: Idiomatic nmap bindings for go developers

nmap

This library aims at providing idiomatic nmap bindings for go developers, to make it easier to write security audit tools using golang.

nmap go programming

What is nmap

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 many 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.

Why use go for penetration testing

Most pen test 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 slightly biased, so feel free to disagree.

Supported features

  •  All of nmap‘s native options.
  •  Additional idiomatic go filters for filtering hosts and ports.
  •  Helpful enums for nmap commands. (time templates, os families, port states, etc.)
  •  Complete documentation of each option, mostly insipred from nmap’s documentation.
  •  Run a nmap scan asynchronously.
  •  Scan progress can be piped through a channel.
  •  Write the nmap output to a given file while also parsing it to the struct.
  •  Stream the nmap output to an io.Writer interface while also parsing it to the struct.
  •  Functionality to show local interfaces and routes.

Example

[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”package%20main%0A%0Aimport%20(%0A%20%20%20%20%22context%22%0A%20%20%20%20%22fmt%22%0A%20%20%20%20%22log%22%0A%20%20%20%20%22time%22%0A%0A%20%20%20%20%22github.com%2FUllaakut%2Fnmap%22%0A)%0A%0Afunc%20main()%20%7B%0A%20%20%20%20ctx%2C%20cancel%20%3A%3D%20context.WithTimeout(context.Background()%2C%205*time.Minute)%0A%20%20%20%20defer%20cancel()%0A%0A%20%20%20%20%2F%2F%20Equivalent%20to%20%60%2Fusr%2Flocal%2Fbin%2Fnmap%20-p%2080%2C443%2C843%20google.com%20facebook.com%20youtube.com%60%2C%0A%20%20%20%20%2F%2F%20with%20a%205%20minute%20timeout.%0A%20%20%20%20scanner%2C%20err%20%3A%3D%20nmap.NewScanner(%0A%20%20%20%20%20%20%20%20nmap.WithTargets(%22google.com%22%2C%20%22facebook.com%22%2C%20%22youtube.com%22)%2C%0A%20%20%20%20%20%20%20%20nmap.WithPorts(%2280%2C443%2C843%22)%2C%0A%20%20%20%20%20%20%20%20nmap.WithContext(ctx)%2C%0A%20%20%20%20)%0A%20%20%20%20if%20err%20!%3D%20nil%20%7B%0A%20%20%20%20%20%20%20%20log.Fatalf(%22unable%20to%20create%20nmap%20scanner%3A%20%25v%22%2C%20err)%0A%20%20%20%20%7D%0A%0A%20%20%20%20result%2C%20err%20%3A%3D%20scanner.Run()%0A%20%20%20%20if%20err%20!%3D%20nil%20%7B%0A%20%20%20%20%20%20%20%20log.Fatalf(%22unable%20to%20run%20nmap%20scan%3A%20%25v%22%2C%20err)%0A%20%20%20%20%7D%0A%0A%20%20%20%20%2F%2F%20Use%20the%20results%20to%20print%20an%20example%20output%0A%20%20%20%20for%20_%2C%20host%20%3A%3D%20range%20result.Hosts%20%7B%0A%20%20%20%20%20%20%20%20if%20len(host.Ports)%20%3D%3D%200%20%7C%7C%20len(host.Addresses)%20%3D%3D%200%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20fmt.Printf(%22Host%20%25q%3A%5Cn%22%2C%20host.Addresses%5B0%5D)%0A%0A%20%20%20%20%20%20%20%20for%20_%2C%20port%20%3A%3D%20range%20host.Ports%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20fmt.Printf(%22%5CtPort%20%25d%2F%25s%20%25s%20%25s%5Cn%22%2C%20port.ID%2C%20port.Protocol%2C%20port.State%2C%20port.Service.Name)%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%0A%20%20%20%20fmt.Printf(%22Nmap%20done%3A%20%25d%20hosts%20up%20scanned%20in%20%253f%20seconds%5Cn%22%2C%20len(result.Hosts)%2C%20result.Stats.Finished.Elapsed)%0A%7D”/]

Download

Copyright (c) 2019 Ullaakut

Support Our Threat Intelligence

If you find our technology report and cybersecurity news helpful, consider supporting our work.

Crypto QR Code
USDT (TRC20):
TN8BdV8cp4T1Cd28gK9qTAnZknzzuwyUtm
USDT (ERC20):
0x3725e1a7d3bc5765499fa6aaafe307fabcd75bce