packetgen

package
v0.0.0-...-b89fbfb Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: MIT Imports: 6 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

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

func BuildNetworkLayer

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

func BuildPayload

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

func BuildTransportLayer

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

func OpenRawConnection

func OpenRawConnection(c ConnectionConfig) (*ipv6.PacketConn, error)

OpenRawConnection opens a raw ip network connection based on the provided config use ipv6 as it also supports ipv4

func Serialize

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

func SerializeLayers

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

Types

type ConnectionConfig

type ConnectionConfig struct {
	Name    string
	Address string
}

ConnectionConfig describes which network to use when sending packets

type DNSPacketConfig

type DNSPacketConfig struct {
	ID      uint16
	Qr      bool
	OpCode  uint8 `mapstructure:"code"`
	QDCount uint16
}

type EthernetPacketConfig

type EthernetPacketConfig struct {
	SrcMAC string `mapstructure:"src_mac"`
	DstMAC string `mapstructure:"dst_mac"`
}

EthernetPacketConfig describes ethernet layer configuration

type ICMPV4PacketConfig

type ICMPV4PacketConfig struct {
	TypeCode uint16 `mapstructure:"code"`
	ID       uint16
	Seq      uint16
}

type IPPacketConfig

type IPPacketConfig struct {
	SrcIP        string `mapstructure:"src_ip"`
	DstIP        string `mapstructure:"dst_ip"`
	NextProtocol *int   `mapstructure:"next"`
}

IPPacketConfig describes ip layer configuration

type LayerConfig

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

type Packet

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

func (Packet) IP

func (p Packet) IP() net.IP

func (Packet) Serialize

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

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 `mapstructure:"src_port,string"`
	DstPort int `mapstructure:"dst_port,string"`
	Seq     uint32
	Ack     uint32
	Window  uint16
	Urgent  uint16
	Flags   TCPFlagsConfig
}

TCPPacketConfig describes tcp layer configuration

type UDPPacketConfig

type UDPPacketConfig struct {
	SrcPort int `mapstructure:"src_port,string"`
	DstPort int `mapstructure:"dst_port,string"`
}

UDPPacketConfig describes udp layer configuration

Jump to

Keyboard shortcuts

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