Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Idiomatic nmap library for go developers

License

NotificationsYou must be signed in to change notification settings

Ullaakut/nmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PkgGoDev github.com/Ullaakut/nmap/v3Coverage Status

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

What is nmap

Nmap (Network Mapper) is a free and open-source network scanner created byGordon 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.

Why use go for penetration testing

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.

Supported features

  • All ofnmap's native options.
  • Additionalidiomatic 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 anio.Writer interface while also parsing it to the struct.
  • Functionality to show local interfaces and routes.

Simple example

package mainimport ("context""fmt""log""time""github.com/Ullaakut/nmap/v3")funcmain() {ctx,cancel:=context.WithTimeout(context.Background(),5*time.Minute)defercancel()// Equivalent to `/usr/local/bin/nmap -p 80,443,843 google.com facebook.com youtube.com`,// with a 5-minute timeout.scanner,err:=nmap.NewScanner(ctx,nmap.WithTargets("google.com","facebook.com","youtube.com"),nmap.WithPorts("80,443,843"),)iferr!=nil {log.Fatalf("unable to create nmap scanner: %v",err)}result,warnings,err:=scanner.Run()iflen(*warnings)>0 {log.Printf("run finished with warnings: %s\n",*warnings)// Warnings are non-critical errors from nmap.}iferr!=nil {log.Fatalf("unable to run nmap scan: %v",err)}// Use the results to print an example outputfor_,host:=rangeresult.Hosts {iflen(host.Ports)==0||len(host.Addresses)==0 {continue}fmt.Printf("Host %q:\n",host.Addresses[0])for_,port:=rangehost.Ports {fmt.Printf("\tPort %d/%s %s %s\n",port.ID,port.Protocol,port.State,port.Service.Name)}}fmt.Printf("Nmap done: %d hosts up scanned in %.2f seconds\n",len(result.Hosts),result.Stats.Finished.Elapsed)}

The program above outputs:

Host"172.217.16.46":    Port 80/tcp open http    Port 443/tcp open https    Port 843/tcp filtered unknownHost"31.13.81.36":    Port 80/tcp open http    Port 443/tcp open https    Port 843/tcp open unknownHost"216.58.215.110":    Port 80/tcp open http    Port 443/tcp open https    Port 843/tcp filtered unknownNmap done: 3 hosts up scannedin 1.29 seconds

Advanced example

Cameradar already uses this library at its core to communicate with nmap, discover RTSP streams and access them remotely.

More examples:

External resources


[8]ページ先頭

©2009-2025 Movatter.jp