scan

package
v0.0.0-...-74ba35b Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	ListenHandlers   []*ListenHandler
	NetworkInterface string

	PkgRouter routing.Router

	NumberOfHandlers = 1
)

Functions

func CleanupHandlersUnix

func CleanupHandlersUnix()

CleanupHandlers for all interfaces

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 Handlers

type Handlers struct {
	InterfaceHandle   map[string]*pcap.Handle
	TransportActive   []*pcap.Handle
	LoopbackHandlers  []*pcap.Handle
	TransportInactive []*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                       chan *PkgResult
}

func Acquire

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

func NewListenHandler

func NewListenHandler() *ListenHandler

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
	Rate      int
	OnReceive result.ResultCallback
	ScanType  string
	Proxy     string
	ProxyAuth 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 PkgFlag

type PkgFlag int

PkgFlag represent the TCP packet flag

const (
	Syn PkgFlag = iota
	Ack
)

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.ResultCallback
	// 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) 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) 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) 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
	Scan
	Done
)

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

Jump to

Keyboard shortcuts

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