scanner

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout      int = 1
	NumberOfScans       int = 2
	DefaultBackoffLimit int = 3
	UDPMaxBufferSize    int = 1500
	DefaultDelayRetry   int = 15
	IncDelayRetry       int = 5
	LastPort            int = 65535
)

Variables

View Source
var (
	ErrAtLeastOneProtocolMustBeUsed   = errors.New("use at least one protocol tpc/udp")
	ErrHostUnavailable                = errors.New("host can not be pinged")
	ErrICMPResponseDontMatchEchoReply = errors.New("host did not response with echo reply")
	ErrSynTimedOut                    = errors.New("syn scan timed out")
)
View Source
var DefaultConfig = Config{
	Timeout:      DefaultTimeout,
	BackoffLimit: DefaultBackoffLimit,
	DelayRetry:   DefaultDelayRetry,
	TCP:          true,
	UDP:          false,
	SYN:          false,
	Ping:         false,
}

Functions

func GetFreePort

func GetFreePort() (uint16, error)

func GetLocalIP

func GetLocalIP() (string, string)

func PortToService

func PortToService(descriptivePort string) string

Types

type Config

type Config struct {
	// scan timeout in milliseconds
	Timeout int
	// number scan retries
	BackoffLimit int
	// Time until a scan is attempted again
	DelayRetry int
	// enable tcp scan
	TCP bool
	// enable udp scan
	UDP bool
	// enable half open connection scan
	SYN bool
	// enable ping before scanning
	Ping bool
}

type ReadPacket

type ReadPacket struct {
	TCPPacket []byte
	Err       error
}

type ScanExecutor

type ScanExecutor interface {
	PingHost(host string) (*ping.Stats, error)
	SynScan(ip string, port string) (*ScanResult, error)
	UDPScan(ip, port string) (*ScanResult, error)
	TCPScan(ip, port string) (*ScanResult, error)
	Scan(host string, ports []string) ([]*ScanResult, *Stats, []error)
	VanillaScan(host string) ([]*ScanResult, *Stats, []error)
	SweepScan(hosts []string, port string) ([]*SweepScanResult, float64)
}

func NewScanExecutor

func NewScanExecutor(c *Config, privilegedPing bool) ScanExecutor

type ScanResult

type ScanResult struct {
	// Rtt(round trip) of a single scan in seconds
	Rtt float64
	// service name
	Service string
	// service port
	Port string
	// scan state
	// open when host is ready to accept connection
	// filtered when host did not return a response/timed out
	// closed when the host returns icmp type 3 code 13(dst unreachable) or RST packet
	State State
}

type ScanType

type ScanType string
const (
	TCP ScanType = "tcp"
	UDP ScanType = "udp"
	SYN ScanType = "syn"
)

type Scanner

type Scanner struct {
	Cfg *Config
	Pg  ping.Pinger
}

func (*Scanner) PingHost

func (s *Scanner) PingHost(host string) (*ping.Stats, error)

PingHost resolves host and ping it

func (*Scanner) Scan

func (s *Scanner) Scan(host string,
	ports []string,
) ([]*ScanResult, *Stats, []error)

Scan scans all the provided ports(tcp,udp and syn if enabled) on the provided host.

func (*Scanner) SweepScan

func (s *Scanner) SweepScan(hosts []string,
	port string,
) ([]*SweepScanResult, float64)

SweepScan scans port (TCP, UDP and SYN if enabled) on each host from the provided host list.

func (*Scanner) SynScan

func (s *Scanner) SynScan(ip, port string) (*ScanResult, error)

SynScan performs a TCP half-open connection scan.

func (*Scanner) TCPScan

func (s *Scanner) TCPScan(ip, port string) (*ScanResult, error)

TCPScan performs a single tcp scan

func (*Scanner) UDPScan

func (s *Scanner) UDPScan(ip, port string) (*ScanResult, error)

UDPScan performs a single udp scan

func (*Scanner) VanillaScan

func (s *Scanner) VanillaScan(host string) (
	[]*ScanResult, *Stats, []error,
)

VanillaScan scans 0-65535 ports(tcp,udp and syn if enabled).

type State

type State string
const (
	Open     State = "open"
	Filtered State = "filtered"
	Closed   State = "closed"
)

type Stats

type Stats struct {
	DNS  *dns.DNSInfo
	Ping *ping.Stats
	Rtt  float64
}

type SweepScanResult

type SweepScanResult struct {
	Host        string
	IP          string
	Stats       *Stats
	ScanResults []*ScanResult
	Errs        []error
}

Jump to

Keyboard shortcuts

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