dhcp4_spoofer

package
v0.0.0-...-88cdd03 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

package dhcp4_spoofer implements a dhcp server designed to operate as a secondary dhcp server on the same lan.

It allows the segmentation of the LAN into two distintict subnets, one used for hosts not captured, and a more confined subnet for hosts in capture state.

Captured hosts will have a specific subnet with the default router set to us so that all captured host traffic is directed to us.

It may also be set to attack the primary DHCP host to exhaust entries.

The original implementation used Richard Burton's dhcp4 package (see: https://github.com/krolaw/dhcp4) for processing of dhcp packets but current versions use our own packet package.

Index

Constants

This section is empty.

Variables

View Source
var LeaseFilename = "./dhcpleases.yaml"
View Source
var Logger = fastlog.New(module)

Functions

This section is empty.

Types

type Config

type Config struct {
	// ClientConn    net.PacketConn
	Mode          Mode
	NetfilterIP   netip.Prefix
	DNSServer     netip.Addr
	LeaseFilename string
}

Config contains configuration overrides

func (Config) New

func (config Config) New(session *packet.Session) (h *Handler, err error)

New accepts a configuration structure and return a dhcp handler with two internal subnets.

type Handler

type Handler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Handler is the main dhcp4 handler

func New

func New(session *packet.Session) (handler *Handler, err error)

New returns a dhcp handler with two internal subnets.

func (*Handler) Close

func (h *Handler) Close() error

Close free up internal resouces.

func (*Handler) MinuteTicker

func (h *Handler) MinuteTicker(now time.Time) error

MinuteTicker perform checks and free leases as required.

func (*Handler) Mode

func (h *Handler) Mode() Mode

Mode returns the current mode

func (*Handler) PrintTable

func (h *Handler) PrintTable()

PrintTable is a helper function to print the table to stdout

func (*Handler) ProcessPacket

func (h *Handler) ProcessPacket(frame packet.Frame) error

ProcessPacket handles a DHCP4 packet performing DHCP4 spoofing and segmentation to keep captured hosts on a different subnet.

func (*Handler) SendDiscoverPacket

func (h *Handler) SendDiscoverPacket(chAddr net.HardwareAddr, ciAddr netip.Addr, xid []byte, name string) (err error)

SendDiscoverPacket send a DHCP discover packet to target

func (*Handler) SetMode

func (h *Handler) SetMode(mode Mode)

SetMode changes the operating mode

func (*Handler) StartHunt

func (h *Handler) StartHunt(addr packet.Addr) error

StartHunt will start the process to capture the client DHCP negotiation

func (*Handler) StopHunt

func (h *Handler) StopHunt(addr packet.Addr) error

StopHunt will end the capture process

type Lease

type Lease struct {
	ClientID    []byte `yaml:",omitempty"`
	State       State
	Addr        packet.Addr
	IPOffer     netip.Addr `yaml:",omitempty"`
	OfferExpiry time.Time  `yaml:",omitempty"`
	XID         []byte     `yaml:",omitempty"`
	Count       int        `yaml:"-"` // a counter to check for repeat packets
	Name        string

	DHCPExpiry time.Time `yaml:",omitempty"`
	// contains filtered or unexported fields
}

Lease stores a client lease

func (Lease) FastLog

func (l Lease) FastLog(line *fastlog.Line) *fastlog.Line

func (Lease) String

func (l Lease) String() string

type Mode

type Mode int32
const (
	ModePrimaryServer       Mode = iota + 1 // sets the server to operate as the single DHCP on the LAN
	ModeSecondaryServer                     // sets the server to operate as a secondary DHCP on the LAN; will attack the primary
	ModeSecondaryServerNice                 // sets the server to operate nice; i.e. will attack captured entries only
)

Mode type for operational mode: Primary or Secondary server

type State

type State int

State defines a type for lease state

const (
	StateFree      State = 0
	StateDiscover  State = 1
	StateAllocated State = 2
)

lease state constants

func (State) String

func (e State) String() string

type SubnetConfig

type SubnetConfig struct {
	LAN        netip.Prefix     // lan address & netmask
	DefaultGW  netip.Addr       // Default Gateway for subnet
	DHCPServer netip.Addr       // DHCP server ID
	DNSServer  netip.Addr       // DNS server IP
	FirstIP    netip.Addr       // First IP in range
	Duration   time.Duration    // lease duration
	Stage      packet.HuntStage // Default stage for subnet
	ID         string           // Used for logging
}

SubnetConfig hold configuration values for the subnet

DefaultGW must be accessible in the subnet example: lan 192.168.0.0/24, gw 192.168.0.1

lan 192.168.0.128/25, gw 192.168.0.129

Jump to

Keyboard shortcuts

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