ns

package module
Version: v0.0.0-...-4fc9008 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2018 License: MIT Imports: 9 Imported by: 1

README

ns - Network Scanner

ns is a wrapper for nmap, parsing and storing the (nmap) output in a mysql database.

go report card Build Status MIT license GoDoc

Setup

  1. create a database for storing the results
CREATE DATABASE `ns`;
  1. add your database login/password (and database name) to config.yml file
database:
  login: 'DB_LOGIN'
  password: 'DB_PASSWORD'
  host: '127.0.0.1'
  port: '3306'
  name: 'ns'
  ...
  1. build it
make

if not using upx run

make build

Usage

ns uses nmap for scanning. In theory, all nmap arguments/parameters should work.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	gorm.Model
	HostID   int
	Addr     string `xml:"addr,attr" gorm:"unique_index:idx_addr_type_vendor"`
	AddrType string `xml:"addrtype,attr" gorm:"unique_index:idx_addr_type_vendor"`
	Vendor   string `xml:"vendor,attr" gorm:"unique_index:idx_addr_type_vendor"`
}

Address ...

<address addr="127.0.0.1" addrtype="ipv4"/>

type CPE

type CPE struct {
	gorm.Model
	Value string `xml:",chardata"`
}

CPE ...

<cpe>cpe:/a:igor_sysoev:nginx:1.13.12</cpe>

type Element

type Element struct {
	gorm.Model
	ScriptID int
	Key      string `xml:"key,attr"`
	Elem     string `xml:",chardata" sql:"type:text"`
}

Element ...

<elem key="type">ssh-rsa</elem>

type Hop

type Hop struct {
	gorm.Model
	TraceID int
	TTL     int     `xml:"ttl,attr"`
	IPAddr  string  `xml:"ipaddr,attr"`
	RTT     float32 `xml:"rtt,attr"`
	Host    string  `xml:"host,attr"`
}

Hop ...

<hop ttl="1" ipaddr="127.0.0.1" rtt="0.34"/>

type Host

type Host struct {
	gorm.Model
	Starttime int    `xml:"starttime,attr"`
	Endtime   int    `xml:"endtime,attr"`
	Status    Status `xml:"status"`
	StatusID  int
	Addresses []Address  `xml:"address"`
	Hostnames []Hostname `xml:"hostnames>hostname"`
	Ports     []Port     `xml:"ports>port"`
	OS        OS         `xml:"os"`
	OSID      int
	Times     Times `xml:"times"`
	TimesID   int
	Trace     Trace `xml:"trace"`
	TraceID   int
	LastSeen  time.Time
}

Host holds all information about detected hosts

<host starttime="..." endtime="...">....</host>

func (*Host) BeforeCreate

func (h *Host) BeforeCreate(scope *gorm.Scope) error

BeforeCreate sets the created_at, updated_at and last_seen date on the Host struct. This function is triggered by gorm

func (*Host) BeforeUpdate

func (h *Host) BeforeUpdate(scope *gorm.Scope) error

BeforeUpdate updates updated_at and last_seen date on the Host struct. This function is triggered by gorm

type Hostname

type Hostname struct {
	gorm.Model
	HostID int
	Name   string `xml:"name,attr"`
	Type   string `xml:"type,attr"`
}

Hostname ...

type OS

type OS struct {
	gorm.Model
	Portused        []Portused    `xml:"portused"`
	OSMatch         []OSMatch     `xml:"osmatch"`
	OSFingerprint   OSFingerprint `xml:"osfingerprint"`
	OSFingerprintID int
}

OS ...

<os>...</os>

type OSClass

type OSClass struct {
	gorm.Model
	OSMatchID int
	Type      string `xml:"type,attr"`
	Vendor    string `xml:"vendor,attr"`
	OSFamily  string `xml:"osfamily,attr"`
	Accuracy  int    `xml:"accuracy,attr"`
	CPE       []CPE  `xml:"cpe"`
}

OSClass ...

<osclass type="general purpose" vendor="Linux" osfamily="Linux" osgen="4.X" accuracy="100">...</osclass>

type OSFingerprint

type OSFingerprint struct {
	gorm.Model
	Fingerprint string `xml:"fingerprint,attr" sql:"type:text"`
}

OSFingerprint ...

type OSMatch

type OSMatch struct {
	gorm.Model
	OSID     int
	Name     string    `xml:"name,attr"`
	Accuracy int       `xml:"accuracy,attr"`
	Line     int       `xml:"line,attr"`
	OSClass  []OSClass `xml:"osclass"`
}

OSMatch ...

<osmatch name="Linux 3.12 - 4.10" accuracy="100" line="63515">...</osmatch>

type Port

type Port struct {
	gorm.Model
	HostID    int
	Protocol  string `xml:"protocol,attr"`
	PortID    int    `xml:"portid,attr"`
	State     State  `xml:"state"`
	StateID   int
	Service   Service `xml:"service"`
	ServiceID int
	Scripts   []Script `xml:"script"`
}

Port ...

<port protocol="tcp" portid="22">...</port>

type Portused

type Portused struct {
	gorm.Model
	OSID     int
	State    string `xml:"state,attr"`
	Protocol string `xml:"proto,attr"`
	PortID   int    `xml:"portid,attr"`
}

Portused ...

<portused state="open" proto="tcp" portid="22"/>

type Result

type Result struct {
	Scanner string  `xml:"scanner,attr"` // Information about the used scanner
	Args    string  `xml:"args,attr"`    // The whole command including arguments
	Start   uint32  `xml:"start,attr"`   // Starttime
	Hosts   []*Host `xml:"host"`         // Slice of hosts
}

Result ...

func ParseXML

func ParseXML(xmlFile string) (result Result, err error)

ParseXML reads the passed xml file and unmarshals the content to a Result struct

type Scanner

type Scanner struct {
	ForwardOutput bool
}

Scanner struct for some configuration

func (*Scanner) Query

func (s *Scanner) Query(args ...string) (result Result, err error)

Query executes the nmap command with an additional -oX param for XML output After execution, the XML is parsed to a Result struct and removed.

type Script

type Script struct {
	gorm.Model
	PortID   int
	ScriptID string    `xml:"id,attr"`
	Output   string    `xml:"output,attr" sql:"type:text"`
	Elements []Element `xml:"elem"`
}

Script ...

<script id="ssh-hostkey" output="&#xa;  .....">...</script>

type Service

type Service struct {
	gorm.Model
	Name    string `xml:"name,attr"`
	Product string `xml:"product,attr"`
	Version string `xml:"version,attr"`
	Method  string `xml:"method,attr"`
	Conf    int    `xml:"conf,attr"`
	CPE     []*CPE `xml:"cpe"`
}

Service ...

<service name="http" product="nginx" version="1.13.12" method="probed" conf="10">...</service>

type State

type State struct {
	gorm.Model
	State     string `xml:"state,attr"`
	Reason    string `xml:"reason,attr"`
	ReasonTTL int    `xml:"reason_ttl,attr"`
}

State ...

<state state="open" reason="syn-ack" reason_ttl="64"/>

type Status

type Status struct {
	gorm.Model
	State     string `xml:"state,attr"`
	Reason    string `xml:"reason,attr"`
	ReasonTTL int    `xml:"reason_ttl,attr"`
}

Status holds information about its Hosts status

<status state="up" reason="localhost-response" reason_ttl="0"/>

type Times

type Times struct {
	gorm.Model
	SRTT   int `xml:"srtt,attr"`
	RTTVar int `xml:"rttvar,attr"`
	TO     int `xml:"to,attr"`
}

Times ...

<times srtt="27" rttvar="3" to="100000"/>

type Trace

type Trace struct {
	gorm.Model
	Hops []*Hop `xml:"hop"`
}

Trace ...

<trace>...</trace>

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL