scan

package
v2.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 33 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DeadlineSec      = 10
	ProtocolICMP     = 1
	ProtocolIPv6ICMP = 58
)

Some constants

View Source
const (
	IPv4 = "4"
	IPv6 = "6"
)

Variables

View Source
var (
	ListenHandlers   []*ListenHandler
	NetworkInterface string

	PkgRouter routing.Router

	ArpRequestAsync  func(ip string)
	InitScanner      func(s *Scanner) error
	NumberOfHandlers = 1
)

Functions

func ACKPort

func ACKPort(listenHandler *ListenHandler, dstIP string, port int, timeout time.Duration) (bool, error)

ACKPort sends an ACK packet to a port

func CleanupHandlersUnix

func CleanupHandlersUnix()

CleanupHandlers for all interfaces

func EthernetWriteWorker

func EthernetWriteWorker()

EthernetWriteWorker writes packet to the network layer

func GetInterfaceFromIP

func GetInterfaceFromIP(ip net.IP) (*net.Interface, error)

GetInterfaceFromIP gets the name of the network interface from local ip address

func ICMPWriteWorker

func ICMPWriteWorker()

ICMPWriteWorker writes packet to the network layer

func ParseTimestamp

func ParseTimestamp(_ int, b []byte) (icmp.MessageBody, error)

ParseTimestamp to MessageBody structure

func PingIcmpAddressMaskRequestAsync

func PingIcmpAddressMaskRequestAsync(ip string)

PingIcmpAddressMaskRequestAsync asynchronous to the target ip address - ipv4 only

func PingIcmpEchoRequest

func PingIcmpEchoRequest(ip string, timeout time.Duration) bool

PingIcmpEchoRequest synchronous to the target ip address

func PingIcmpEchoRequestAsync

func PingIcmpEchoRequestAsync(ip string)

PingIcmpEchoRequestAsync asynchronous to the target ip address

func PingIcmpTimestampRequest

func PingIcmpTimestampRequest(ip string, timeout time.Duration) bool

PingIcmpTimestampRequest synchronous to the target ip address

func PingIcmpTimestampRequestAsync

func PingIcmpTimestampRequestAsync(ip string)

PingIcmpTimestampRequestAsync synchronous to the target ip address - ipv4 only

func PingNdpRequestAsync

func PingNdpRequestAsync(ip string)

PingNdpRequestAsync asynchronous to the target ip address

func SendAsyncPkg

func SendAsyncPkg(listenHandler *ListenHandler, ip string, p *port.Port, pkgFlag PkgFlag)

SendAsyncPkg sends a single packet to a port

func SetupHandler

func SetupHandler(interfaceName string) error

func SetupHandlerUnix

func SetupHandlerUnix(interfaceName, bpfFilter string, protocols ...protocol.Protocol) error

SetupHandlerUnix on unix OS

func SetupHandlers

func SetupHandlers() error

func ToString

func ToString(ip net.IP) string

func TransportReadWorker

func TransportReadWorker()

func TransportWriteWorker

func TransportWriteWorker()

TCPWriteWorker that sends out TCP|UDP packets

func WhatsMyIP

func WhatsMyIP() (string, error)

WhatsMyIP attempts to obtain the external ip through public api

Types

type AddressMask

type AddressMask struct {
	ID          int
	Seq         int
	AddressMask uint32
}

AddressMask ICMP structure

func (*AddressMask) Len

func (a *AddressMask) Len(_ int) int

Len returns default timestamp length

func (*AddressMask) Marshal

func (a *AddressMask) Marshal(_ int) ([]byte, error)

Marshal the address mask structure

type Handlers

type Handlers struct {
	InterfaceHandle   map[string]*pcap.Handle
	TransportActive   []*pcap.Handle
	LoopbackHandlers  []*pcap.Handle
	TransportInactive []*pcap.InactiveHandle
	EthernetActive    []*pcap.Handle
	EthernetInactive  []*pcap.InactiveHandle
}

Handlers contains the list of pcap handlers

type ListenHandler

type ListenHandler struct {
	Busy                                   bool
	Phase                                  *Phase
	SourceHW                               net.HardwareAddr
	SourceIp4                              net.IP
	SourceIP6                              net.IP
	Port                                   int
	TcpConn4, UdpConn4, TcpConn6, UdpConn6 *net.IPConn
	TcpChan, UdpChan, HostDiscoveryChan    chan *PkgResult
}

func Acquire

func Acquire(options *Options) (*ListenHandler, error)

func NewListenHandler

func NewListenHandler() *ListenHandler

func (*ListenHandler) ICMPReadWorker4

func (l *ListenHandler) ICMPReadWorker4()

ICMPReadWorker4 reads packets from the network layer

func (*ListenHandler) ICMPReadWorker6

func (l *ListenHandler) ICMPReadWorker6()

ICMPReadWorker6 reads packets from the network layer

func (*ListenHandler) Release

func (l *ListenHandler) Release()

func (*ListenHandler) TcpReadWorker4

func (l *ListenHandler) TcpReadWorker4()

func (*ListenHandler) TcpReadWorker6

func (l *ListenHandler) TcpReadWorker6()

func (*ListenHandler) UdpReadWorker4

func (l *ListenHandler) UdpReadWorker4()

func (*ListenHandler) UdpReadWorker6

func (l *ListenHandler) UdpReadWorker6()

type Options

type Options struct {
	Timeout       time.Duration
	Retries       int
	Rate          int
	PortThreshold int
	ExcludeCdn    bool
	OutputCdn     bool
	ExcludedIps   []string
	Proxy         string
	ProxyAuth     string
	Stream        bool
	OnReceive     result.ResultFn
	ScanType      string
}

Options of the scan

type Phase

type Phase struct {
	sync.RWMutex
	State
}

func (*Phase) Is

func (phase *Phase) Is(state State) bool

func (*Phase) Set

func (phase *Phase) Set(state State)

type Ping

type Ping struct {
	Type    PingResultType
	Latency time.Duration
	Error   error
	Host    string
}

Ping contains the results for ping on a single host

type PingResult

type PingResult struct {
	Hosts []Ping
}

PingResult contains the results for the Ping request

func PingHosts

func PingHosts(addresses []string) (*PingResult, error)

PingHosts pings the addresses given and returns the latencies of each host If the address returns an error, that address is marked as unusable.

func (*PingResult) GetFastestHost

func (p *PingResult) GetFastestHost() (Ping, error)

GetFastestHost gets the fastest host from the ping responses

type PingResultType

type PingResultType int

PingResultType contains the type of result for ping request on an address

const (
	HostInactive PingResultType = iota
	HostActive
)

Type of ping responses

type PkgFlag

type PkgFlag int

PkgFlag represent the TCP packet flag

const (
	Syn PkgFlag = iota
	Ack
	IcmpEchoRequest
	IcmpTimestampRequest
	IcmpAddressMaskRequest
	Arp
	Ndp
)

type PkgResult

type PkgResult struct {
	// contains filtered or unexported fields
}

PkgResult contains the results of sending TCP packages

type PkgSend

type PkgSend struct {
	ListenHandler *ListenHandler

	SourceIP string
	// contains filtered or unexported fields
}

PkgSend is a TCP package

type Scanner

type Scanner struct {
	Ports    []*port.Port
	IPRanger *ipranger.IPRanger

	HostDiscoveryResults *result.Result
	ScanResults          *result.Result
	NetworkInterface     *net.Interface

	ListenHandler *ListenHandler
	OnReceive     result.ResultFn
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(options *Options) (*Scanner, error)

NewScanner creates a new full port scanner that scans all ports using SYN packets.

func (*Scanner) CdnCheck

func (s *Scanner) CdnCheck(ip string) (bool, string, error)

CdnCheck verifies if the given ip is part of Cdn/WAF ranges

func (*Scanner) Close

func (s *Scanner) Close()

Close the scanner and terminate all workers

func (*Scanner) ConnectPort

func (s *Scanner) ConnectPort(host string, p *port.Port, timeout time.Duration) (bool, error)

ConnectPort a single host and port

func (*Scanner) ConnectVerify

func (s *Scanner) ConnectVerify(host string, ports []*port.Port) []*port.Port

ConnectVerify is used to verify if ports are accurate using a connect request

func (*Scanner) EnqueueEthernet

func (s *Scanner) EnqueueEthernet(ip string, pkgtype PkgFlag)

EnqueueEthernet outgoing Ethernet packets

func (*Scanner) EnqueueICMP

func (s *Scanner) EnqueueICMP(ip string, pkgtype PkgFlag)

EnqueueICMP outgoing ICMP packets

func (*Scanner) EnqueueTCP

func (s *Scanner) EnqueueTCP(ip string, pkgtype PkgFlag, ports ...*port.Port)

EnqueueTCP outgoing TCP packets

func (*Scanner) EnqueueUDP

func (s *Scanner) EnqueueUDP(ip string, ports ...*port.Port)

EnqueueTCP outgoing TCP packets

func (*Scanner) ICMPResultWorker

func (s *Scanner) ICMPResultWorker(ctx context.Context)

ICMPResultWorker handles ICMP responses (used only during probes)

func (*Scanner) ScanSyn

func (s *Scanner) ScanSyn(ip string)

ScanSyn a target ip

func (*Scanner) StartWorkers

func (s *Scanner) StartWorkers(ctx context.Context)

StartWorkers of the scanner

func (*Scanner) TCPResultWorker

func (s *Scanner) TCPResultWorker(ctx context.Context)

TCPResultWorker handles probes and scan results

func (*Scanner) UDPResultWorker

func (s *Scanner) UDPResultWorker(ctx context.Context)

UDPResultWorker handles probes and scan results

type State

type State int

State determines the internal scan state

const (
	Init State = iota
	HostDiscovery
	Scan
	Done
	Guard
)

type TCPSequencer

type TCPSequencer struct {
	// contains filtered or unexported fields
}

TCPSequencer generates linear TCP sequence numbers that wrap around after reaching their maximum value.

According to specs, this is the correct way to approach TCP sequence number since linearity will be guaranteed by the wrapping around to initial 0.

func NewTCPSequencer

func NewTCPSequencer() *TCPSequencer

NewTCPSequencer creates a new linear tcp sequenc enumber generator

func (*TCPSequencer) Next

func (t *TCPSequencer) Next() uint32

Next returns the next number in the sequence of tcp sequence numbers

type Timestamp

type Timestamp struct {
	ID                int
	Seq               int
	OriginTimestamp   uint32
	ReceiveTimestamp  uint32
	TransmitTimestamp uint32
}

Timestamp ICMP structure

func (*Timestamp) Len

func (t *Timestamp) Len(_ int) int

Len returns default timestamp length

func (*Timestamp) Marshal

func (t *Timestamp) Marshal(_ int) ([]byte, error)

Marshal the timestamp structure

Jump to

Keyboard shortcuts

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