Documentation
¶
Index ¶
- Constants
- func CheckDLL() error
- func GetBuffer(size int) []byte
- func GetMarshalBuffer(size int) (..., bool)
- func HelperCompileFilter(filter string) (bool, int)
- func HelperEvalFilter(packet *Packet, filter string) (bool, error)
- func HelperFormatIPv4Address(addr uint32) (string, error)
- func HelperFormatIPv6Address(addr [4]uint32) (string, error)
- func HelperHashPacket(packet []byte, seed uint64) (uint64, error)
- func HelperHtonIPv6Address(inAddr [4]uint32) [4]uint32
- func HelperHtonl(x uint32) uint32
- func HelperHtonll(x uint64) uint64
- func HelperHtons(x uint16) uint16
- func HelperNtohIPv6Address(inAddr [4]uint32) [4]uint32
- func HelperNtohl(x uint32) uint32
- func HelperNtohll(x uint64) uint64
- func HelperNtohs(x uint16) uint16
- func HelperParseIPv4Address(addrStr string) (uint32, error)
- func HelperParseIPv6Address(addrStr string) ([4]uint32, error)
- func IsDLLLoaded() bool
- func LoadDLL(path64, path32 string) error
- func ProcessPacketBatch(packets []*Packet)
- func PutBuffer(buf []byte)
- func PutMarshalBuffer(buf ..., pooled bool)
- func UnloadDLL() error
- type Direction
- type Flags
- type Layer
- type Option
- type Packet
- func (p *Packet) CalcNewChecksum(wd *WinDivertHandle)
- func (p *Packet) Direction() Direction
- func (p *Packet) DstIP() net.IP
- func (p *Packet) DstPort() (uint16, error)
- func (p *Packet) EvalFilter(filter string) (bool, error)
- func (p *Packet) IpVersion() int
- func (p *Packet) MarshalBinary() ([]byte, error)
- func (p *Packet) NextHeaderProtocolName() string
- func (p *Packet) NextHeaderType() uint8
- func (p *Packet) ParseHeaders()
- func (p *Packet) Release()
- func (p *Packet) Reset()
- func (p *Packet) Send(wd *WinDivertHandle) (uint, error)
- func (p *Packet) SetDstIP(ip net.IP)
- func (p *Packet) SetDstPort(port uint16) error
- func (p *Packet) SetSrcIP(ip net.IP)
- func (p *Packet) SetSrcPort(port uint16) error
- func (p *Packet) SrcIP() net.IP
- func (p *Packet) SrcPort() (uint16, error)
- func (p *Packet) String() string
- func (p *Packet) UnmarshalBinary(data []byte) error
- func (p *Packet) VerifyParsed()
- type ParsedPacket
- type WinDivertAddress
- func (w *WinDivertAddress) Direction() Direction
- func (w *WinDivertAddress) GetFlags() uint8
- func (w *WinDivertAddress) GetLayer() uint8
- func (w *WinDivertAddress) Impostor() bool
- func (w *WinDivertAddress) Loopback() bool
- func (w *WinDivertAddress) MarshalBinary() ([]byte, error)
- func (w *WinDivertAddress) PseudoIPChecksum() bool
- func (w *WinDivertAddress) PseudoTCPChecksum() bool
- func (w *WinDivertAddress) PseudoUDPChecksum() bool
- func (w *WinDivertAddress) SetFlags(flags uint8)
- func (w *WinDivertAddress) SetLayer(layer uint8)
- func (w *WinDivertAddress) Size() int
- func (w *WinDivertAddress) String() string
- func (w *WinDivertAddress) UnmarshalBinary(data []byte) error
- type WinDivertHandle
- func (wd *WinDivertHandle) Close() error
- func (wd *WinDivertHandle) GetParam(param uint) (uint64, error)
- func (wd *WinDivertHandle) HelperCalcChecksum(packet *Packet) error
- func (wd *WinDivertHandle) Packets(ctx context.Context) (<-chan *Packet, error)
- func (wd *WinDivertHandle) Recv() (*Packet, error)
- func (wd *WinDivertHandle) RecvBatch(maxPackets int) ([]*Packet, error)
- func (wd *WinDivertHandle) RecvEx(packet []byte, addr *WinDivertAddress, flags uint64, ...) (uint, error)
- func (wd *WinDivertHandle) Send(packet *Packet) (uint, error)
- func (wd *WinDivertHandle) SendEx(packet []byte, addr *WinDivertAddress, flags uint64, ...) (uint, error)
- func (wd *WinDivertHandle) SetParam(param uint, value uint64) error
- func (wd *WinDivertHandle) Shutdown(how uint) error
- type WinDivertHandleConfig
Constants ¶
const ( PacketBufferSize = 2048 PacketChanCapacity = 256 WinDivertDirectionOutbound Direction = false WinDivertDirectionInbound Direction = true )
const ( WinDivertFlagSniff uint8 = 1 << iota WinDivertFlagDrop uint8 = 1 << iota WinDivertFlagDebug uint8 = 1 << iota )
const (
MaxPacketSize = 65535
)
Variables ¶
This section is empty.
Functions ¶
func CheckDLL ¶
func CheckDLL() error
CheckDLL verifies that the WinDivert driver is installed and accessible
func GetMarshalBuffer ¶ added in v1.0.1
func GetMarshalBuffer(size int) (*struct { buf []byte hdr [header.MarshalHeaderSize]byte addr [header.AddressSize]byte }, bool)
GetMarshalBuffer returns a buffer for marshal operations
func HelperCompileFilter ¶
Take the given filter and check if it contains any error https://reqrypt.org/windivert-doc.html#divert_helper_check_filter
func HelperEvalFilter ¶
Take a packet and compare it with the given filter Returns true if the packet matches the filter https://reqrypt.org/windivert-doc.html#divert_helper_eval_filter
func HelperFormatIPv4Address ¶
HelperFormatIPv4Address formats an IPv4 address as a string
func HelperFormatIPv6Address ¶
HelperFormatIPv6Address formats an IPv6 address as a string
func HelperHashPacket ¶
HelperHashPacket calculates a 64-bit hash of the packet
func HelperHtonIPv6Address ¶
func HelperHtonl ¶
func HelperHtonll ¶
func HelperHtons ¶
func HelperNtohIPv6Address ¶
func HelperNtohl ¶
func HelperNtohll ¶
func HelperParseIPv4Address ¶
HelperParseIPv4Address parses an IPv4 address string
func HelperParseIPv6Address ¶
HelperParseIPv6Address parses an IPv6 address string
func ProcessPacketBatch ¶ added in v1.0.1
func ProcessPacketBatch(packets []*Packet)
Process multiple packets at once
func PutBuffer ¶ added in v1.0.1
func PutBuffer(buf []byte)
PutBuffer with optimized size class lookup
func PutMarshalBuffer ¶ added in v1.0.1
func PutMarshalBuffer(buf *struct {
buf []byte
hdr [header.MarshalHeaderSize]byte
addr [header.AddressSize]byte
}, pooled bool)
PutMarshalBuffer returns a marshal buffer to the pool
Types ¶
type Flags ¶
type Flags uint64
const ( // Packet sniffing mode - packets will continue to their destination FlagSniff Flags = 0x0001 // Packet dropping mode - matching packets will be dropped FlagDrop Flags = 0x0002 // Receive-only mode - packets can only be read, not injected FlagRecvOnly Flags = 0x0004 FlagReadOnly = FlagRecvOnly // Alias for FlagRecvOnly // Send-only mode - packets can only be injected, not read FlagSendOnly Flags = 0x0008 FlagWriteOnly = FlagSendOnly // Alias for FlagSendOnly // Skip driver installation check FlagNoInstall Flags = 0x0010 // Handle IP fragments FlagFragments Flags = 0x0020 )
type Option ¶
type Option func(*WinDivertHandleConfig)
Option is a function that configures a WinDivertHandle
func WithPriority ¶
WithPriority sets the priority for the WinDivertHandle
type Packet ¶
type Packet struct {
Raw []byte
Addr *WinDivertAddress
PacketLen uint
IpHdr header.IPHeader
NextHeader header.ProtocolHeader
// contains filtered or unexported fields
}
Represents a packet
func GetPacket ¶ added in v1.0.1
func GetPacket() *Packet
Add helper method to get a packet from pool
func (*Packet) CalcNewChecksum ¶
func (p *Packet) CalcNewChecksum(wd *WinDivertHandle)
Recalculate the packet's checksum Shortcut for WinDivertHelperCalcChecksum
func (*Packet) Direction ¶
Returns the Direction of the packet WinDivertDirectionInbound (true) for inbound Packets WinDivertDirectionOutbound (false) for outbound packets Shortcut for Addr.Direction()
func (*Packet) DstPort ¶
Returns the destination port of the packet Shortcut for NextHeader.DstPort()
func (*Packet) EvalFilter ¶
Check the packet with the filter Returns true if the packet matches the filter
func (*Packet) MarshalBinary ¶ added in v1.0.1
MarshalBinary implements the encoding.BinaryMarshaler interface
func (*Packet) NextHeaderProtocolName ¶
Returns the name of the protocol
func (*Packet) NextHeaderType ¶
Returns the IP Protocol number of the next Header https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
func (*Packet) Release ¶ added in v1.0.1
func (p *Packet) Release()
Add helper method to return packet to pool
func (*Packet) Reset ¶ added in v1.0.1
func (p *Packet) Reset()
Reset resets the packet to its zero state for reuse
func (*Packet) Send ¶
func (p *Packet) Send(wd *WinDivertHandle) (uint, error)
Inject the packet on the Network Stack If the packet has been modified calls WinDivertHelperCalcChecksum to get a new checksum
func (*Packet) SetDstPort ¶
Sets the destination port of the packet Shortcut for NextHeader.SetDstPort()
func (*Packet) SetSrcPort ¶
Sets the source port of the packet Shortcut for NextHeader.SetSrcPort()
func (*Packet) UnmarshalBinary ¶ added in v1.0.1
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface
func (*Packet) VerifyParsed ¶
func (p *Packet) VerifyParsed()
Check if the headers have already been parsed and call ParseHeaders() if not
type ParsedPacket ¶
type ParsedPacket struct {
Raw []byte
IPv4 *header.IPv4Header
IPv6 *header.IPv6Header
ICMP *header.ICMPv4Header
ICMPv6 *header.ICMPv6Header
TCP *header.TCPHeader
UDP *header.UDPHeader
}
ParsedPacket represents a parsed network packet
func HelperParsePacket ¶
func HelperParsePacket(packet []byte) (*ParsedPacket, error)
HelperParsePacket parses a raw packet into its components
type WinDivertAddress ¶
type WinDivertAddress struct {
Timestamp int64
IfIdx uint32
SubIfIdx uint32
Flags uint8
Reserved1 uint8
Reserved2 uint16
Reserved3 uint32
}
Represents a WinDivertAddress struct See : https://reqrypt.org/windivert-doc.html#divert_address
func NewWinDivertAddress ¶ added in v1.0.1
func NewWinDivertAddress() *WinDivertAddress
NewWinDivertAddress creates a new WinDivertAddress with default values
func (*WinDivertAddress) Direction ¶
func (w *WinDivertAddress) Direction() Direction
Returns the direction of the packet WinDivertDirectionInbound (true) for inbounds packets WinDivertDirectionOutbounds (false) for outbounds packets
func (*WinDivertAddress) GetFlags ¶
func (w *WinDivertAddress) GetFlags() uint8
func (*WinDivertAddress) GetLayer ¶
func (w *WinDivertAddress) GetLayer() uint8
func (*WinDivertAddress) Impostor ¶
func (w *WinDivertAddress) Impostor() bool
Returns true if the packet is an impostor
func (*WinDivertAddress) Loopback ¶
func (w *WinDivertAddress) Loopback() bool
Returns true if the packet is a loopback packet
func (*WinDivertAddress) MarshalBinary ¶ added in v1.0.1
func (w *WinDivertAddress) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface
func (*WinDivertAddress) PseudoIPChecksum ¶
func (w *WinDivertAddress) PseudoIPChecksum() bool
Returns true if the packet uses a pseudo IP checksum
func (*WinDivertAddress) PseudoTCPChecksum ¶
func (w *WinDivertAddress) PseudoTCPChecksum() bool
Returns true if the packet uses a pseudo TCP checksum
func (*WinDivertAddress) PseudoUDPChecksum ¶
func (w *WinDivertAddress) PseudoUDPChecksum() bool
Returns true if the packet uses a pseudo UDP checksum
func (*WinDivertAddress) SetFlags ¶
func (w *WinDivertAddress) SetFlags(flags uint8)
Add helper methods to handle flags through Flags field
func (*WinDivertAddress) SetLayer ¶
func (w *WinDivertAddress) SetLayer(layer uint8)
func (*WinDivertAddress) Size ¶ added in v1.0.1
func (w *WinDivertAddress) Size() int
Size returns the binary size of WinDivertAddress
func (*WinDivertAddress) String ¶
func (w *WinDivertAddress) String() string
func (*WinDivertAddress) UnmarshalBinary ¶ added in v1.0.1
func (w *WinDivertAddress) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface
type WinDivertHandle ¶
type WinDivertHandle struct {
// contains filtered or unexported fields
}
Used to call WinDivert's functions
func NewWinDivertHandle ¶
func NewWinDivertHandle(filter string, opts ...Option) (*WinDivertHandle, error)
NewWinDivertHandle creates a new WinDivertHandle with the given filter and options
func (*WinDivertHandle) Close ¶
func (wd *WinDivertHandle) Close() error
Close the Handle See https://reqrypt.org/windivert-doc.html#divert_close
func (*WinDivertHandle) GetParam ¶
func (wd *WinDivertHandle) GetParam(param uint) (uint64, error)
GetParam gets a WinDivert parameter
func (*WinDivertHandle) HelperCalcChecksum ¶
func (wd *WinDivertHandle) HelperCalcChecksum(packet *Packet) error
Calls WinDivertHelperCalcChecksum to calculate the packet's checksum
func (*WinDivertHandle) Packets ¶
func (wd *WinDivertHandle) Packets(ctx context.Context) (<-chan *Packet, error)
Create a new channel that will be used to pass captured packets and returns it calls recvLoop to maintain a loop
func (*WinDivertHandle) Recv ¶
func (wd *WinDivertHandle) Recv() (*Packet, error)
Recv receives a packet from the network stack
func (*WinDivertHandle) RecvBatch ¶
func (wd *WinDivertHandle) RecvBatch(maxPackets int) ([]*Packet, error)
RecvBatch receives multiple packets in a single call for better performance
func (*WinDivertHandle) RecvEx ¶
func (wd *WinDivertHandle) RecvEx(packet []byte, addr *WinDivertAddress, flags uint64, overlapped *windows.Overlapped) (uint, error)
RecvEx receives a packet with extended options
func (*WinDivertHandle) Send ¶
func (wd *WinDivertHandle) Send(packet *Packet) (uint, error)
Send injects a packet into the network stack
func (*WinDivertHandle) SendEx ¶
func (wd *WinDivertHandle) SendEx(packet []byte, addr *WinDivertAddress, flags uint64, overlapped *windows.Overlapped) (uint, error)
SendEx sends a packet with extended options
func (*WinDivertHandle) SetParam ¶
func (wd *WinDivertHandle) SetParam(param uint, value uint64) error
SetParam sets a WinDivert parameter
func (*WinDivertHandle) Shutdown ¶
func (wd *WinDivertHandle) Shutdown(how uint) error
Shutdown shuts down the handle
type WinDivertHandleConfig ¶
type WinDivertHandleConfig struct {
// contains filtered or unexported fields
}
WinDivertHandleConfig holds configuration for WinDivertHandle