• Stars
    star
    914
  • Rank 49,973 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Idiomatic nmap library for go developers

nmap

PkgGoDev github.com/Ullaakut/nmap/v3 Coverage Status

This library aims at providing idiomatic nmap 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 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.

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

Simple example

package main

import (
    "context"
    "fmt"
    "log"
    "time"

    "github.com/Ullaakut/nmap/v3"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
	defer cancel()

	// 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"),
	)
	if err != nil {
		log.Fatalf("unable to create nmap scanner: %v", err)
	}

	result, warnings, err := scanner.Run()
	if len(*warnings) > 0 {
		log.Printf("run finished with warnings: %s\n", *warnings) // Warnings are non-critical errors from nmap.
	}
	if err != nil {
		log.Fatalf("unable to run nmap scan: %v", err)
	}

	// Use the results to print an example output
	for _, host := range result.Hosts {
		if len(host.Ports) == 0 || len(host.Addresses) == 0 {
			continue
		}

		fmt.Printf("Host %q:\n", host.Addresses[0])

		for _, port := range host.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 unknown
Host "31.13.81.36":
    Port 80/tcp open http
    Port 443/tcp open https
    Port 843/tcp open unknown
Host "216.58.215.110":
    Port 80/tcp open http
    Port 443/tcp open https
    Port 843/tcp filtered unknown
Nmap done: 3 hosts up scanned in 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

More Repositories

1

cameradar

Cameradar hacks its way into RTSP videosurveillance cameras
Go
3,998
star
2

Gorsair

Gorsair gives root access on remote docker containers that expose their APIs
Go
816
star
3

astronomer

A tool to detect illegitimate stars from bot accounts on GitHub projects
Go
439
star
4

camerattack

An attack tool designed to remotely disable CCTV camera streams (like in spy movies)
Go
303
star
5

RTSPAllTheThings

Deprecated RTSP media server -- Use github.com/aler9/rtsp-simple-server instead.
C++
272
star
6

disgo

๐Ÿ•บ๐ŸฝSimple output library for go CLIs.
Go
37
star
7

WebRTCCTV

WebRTCCTV is a signaling server & webapp able to stream from RTSP cameras using WebRTC
JavaScript
35
star
8

Hackerbeat

An Elastic Beats for indexing HackerNews posts
Go
17
star
9

GoneyPot

A golang CLI to setup honey pots https://en.wikipedia.org/wiki/Honeypot_(computing)
Go
15
star
10

astrolab

The server which receives and stores Astronomer trust reports, and provides an endpoint to generate GitHub badges.
Go
13
star
11

aoc19

Advent of code solutions for 2019
Go
11
star
12

ShittyRouterRebooter

My motherfucking router's firmware has a memory leak, I can't update the firmware and I don't have admin access on it. Only thing I can do is reboot it.
Shell
7
star
13

gonvey

Gonvey is a simple Go reverse-proxy (don't use it, this was just a coding challenge)
Go
7
star
14

gonut

Go
6
star
15

eagolint

The golang linter for keeping comments punctuated and double-space free. ๐Ÿฆ…
Go
5
star
16

3BP

Three body problem solver rendered in 2d in terminal
Go
5
star
17

IRC

A simple IRC server and a client. -- Don't use this.
C
5
star
18

Bloggo

The blogging CMS for go doggos
Go
5
star
19

FactoriHub

An application for sharing Factorio blueprints and map seeds.
Go
4
star
20

dockurn

Simple docker image to make running turnserver easier without limits
4
star
21

auto-invoice

Repository to automatically generate and send my invoices using the Toggl API and XLSX templates
Go
4
star
22

csvtojson

Go
2
star
23

dps-rosetta-docker

Dockerfile
2
star
24

hk-agent

The HK Agent is a piece of software that runs on your hosts. Its job is to faithfully collect events and metrics and offer basic monitoring and alarming features.
Go
2
star
25

aoc18

Go
2
star
26

Netfu-License-Server-Spoof

This server is a fake license checking service for the Netfu bot
Go
2
star
27

swarmctl-docker

Docker image that builds swarmctl and has it as its entrypoint. Remember to mount your docker socket.
Dockerfile
1
star