packetgen

package
v0.9.23 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package packetgen [allows sending customized tcp/udp traffic. Inspired by https://github.com/bilalcaliskan/syn-flood]

Index

Constants

View Source
const (
	TCPHeaderSize = 25 // 20 for header + at least 5 for options
	UDPHeaderSize = 8
	IPHeaderSize  = 20
)

Common protocol header sizes to help with metrics

Variables

This section is empty.

Functions

func BuildLinkLayer added in v0.8.0

func BuildLinkLayer(c LayerConfig) (gopacket.LinkLayer, error)

func BuildNetworkLayer added in v0.8.0

func BuildNetworkLayer(c LayerConfig) (gopacket.NetworkLayer, error)

func BuildPayload added in v0.8.0

func BuildPayload(c LayerConfig) (gopacket.Layer, error)

func BuildTransportLayer added in v0.8.0

func BuildTransportLayer(c LayerConfig, network gopacket.NetworkLayer) (gopacket.TransportLayer, error)

func Serialize added in v0.8.0

func Serialize(payloadBuf gopacket.SerializeBuffer, layer gopacket.Layer) error

func SerializeLayers added in v0.8.0

func SerializeLayers(payloadBuf gopacket.SerializeBuffer, layers ...gopacket.Layer) error

Types

type Connection added in v0.8.15

type Connection interface {
	Write(Packet) (int, error)
	Read([]byte) (int, error)
	Close() error
	Target() string
}

func OpenConnection added in v0.8.15

func OpenConnection(ctx context.Context, c ConnectionConfig) (Connection, error)

type ConnectionConfig added in v0.8.0

type ConnectionConfig struct {
	Type  string
	Args  map[string]any
	Proxy *utils.ProxyParams
}

ConnectionConfig describes which network to use when sending packets

type DNSPacketConfig added in v0.8.0

type DNSPacketConfig struct {
	ID     uint16
	Qr     bool
	OpCode uint8

	AA bool  // Authoritative answer
	TC bool  // Truncated
	RD bool  // Recursion desired
	RA bool  // Recursion available
	Z  uint8 // Reserved for future use

	ResponseCode uint8
	QDCount      *uint16 // Number of questions to expect

	// Entries
	Questions []DNSQuestion
}

type DNSQuestion added in v0.8.21

type DNSQuestion struct {
	Name  string
	Type  layers.DNSType
	Class layers.DNSClass
}

DNSQuestion wraps a single request (question) within a DNS query.

type EthernetPacketConfig

type EthernetPacketConfig struct {
	SrcMAC string
	DstMAC string
}

EthernetPacketConfig describes ethernet layer configuration

type ICMPV4PacketConfig added in v0.8.0

type ICMPV4PacketConfig struct {
	TypeCode uint16
	ID       uint16
	Seq      uint16
}

type IPPacketConfig

type IPPacketConfig struct {
	SrcIP        string
	DstIP        string
	NextProtocol *int
	TTL          uint8
}

IPPacketConfig describes ip layer configuration

type LayerConfig added in v0.8.0

type LayerConfig struct {
	Type string
	Data map[string]any
}

type Packet added in v0.8.0

type Packet struct {
	Link      gopacket.LinkLayer
	Network   gopacket.NetworkLayer
	Transport gopacket.TransportLayer
	Payload   gopacket.Layer
}

func (Packet) IP added in v0.8.0

func (p Packet) IP() net.IP

func (Packet) Serialize added in v0.8.0

func (p Packet) Serialize(payloadBuf gopacket.SerializeBuffer) (err error)

type PacketConfig

type PacketConfig struct {
	Link      LayerConfig
	Network   LayerConfig
	Transport LayerConfig
	Payload   LayerConfig
}

func (PacketConfig) Build added in v0.8.0

func (c PacketConfig) Build() (result Packet, err error)

type TCPFlagsConfig

type TCPFlagsConfig struct {
	SYN bool
	ACK bool
	FIN bool
	RST bool
	PSH bool
	URG bool
	ECE bool
	CWR bool
	NS  bool
}

TCPFlagsConfig stores flags to be set on tcp layer

type TCPPacketConfig

type TCPPacketConfig struct {
	SrcPort int
	DstPort int
	Seq     uint32
	Ack     uint32
	Window  uint16
	Urgent  uint16
	Flags   TCPFlagsConfig
}

TCPPacketConfig describes tcp layer configuration

type UDPPacketConfig

type UDPPacketConfig struct {
	SrcPort int
	DstPort int
}

UDPPacketConfig describes udp layer configuration

Jump to

Keyboard shortcuts

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