packetgen

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2017 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package packetgen "PacketGen" is a Packet Generator library Current version: V1.0, Updates are coming soon

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EthernetPacketManipulator

type EthernetPacketManipulator interface {
	//Used to create an Ethernet layer
	AddEthernetLayer(srcMACstr string, dstMACstr string) error
	//Used to return Ethernet packet created
	GetEthernetPacket() layers.Ethernet
}

EthernetPacketManipulator interface is used to create/manipulate Ethernet packet

type IPPacketManipulator

type IPPacketManipulator interface {
	//Used to create an IP layer
	AddIPLayer(srcIPstr string, dstIPstr string) error
	//Used to return IP packet created
	GetIPPacket() layers.IPv4
	//Used to return IP checksum
	GetIPChecksum() uint16
}

IPPacketManipulator interface is used to create/manipulate IP packet

type Packet

type Packet struct {
	EthernetLayer *layers.Ethernet
	IPLayer       *layers.IPv4
	TCPLayer      *layers.TCP
}

Packet is a custom type which holds the packets and implements PacketManipulator

func (*Packet) AddEthernetLayer

func (p *Packet) AddEthernetLayer(srcMACstr string, dstMACstr string) error

AddEthernetLayer creates an Ethernet layer

func (*Packet) AddIPLayer

func (p *Packet) AddIPLayer(srcIPstr string, dstIPstr string) error

AddIPLayer creates an IP layer

func (*Packet) AddTCPLayer

func (p *Packet) AddTCPLayer(srcPort layers.TCPPort, dstPort layers.TCPPort) error

AddTCPLayer creates a TCP layer

func (*Packet) GetEthernetPacket

func (p *Packet) GetEthernetPacket() layers.Ethernet

GetEthernetPacket returns the ethernet layer created

func (*Packet) GetIPChecksum

func (p *Packet) GetIPChecksum() uint16

GetIPChecksum returns IP cheksum

func (*Packet) GetIPPacket

func (p *Packet) GetIPPacket() layers.IPv4

GetIPPacket returns IP checksum

func (*Packet) GetTCPAck

func (p *Packet) GetTCPAck() bool

GetTCPAck returns TCP ACK flag

func (*Packet) GetTCPAcknowledgementNumber

func (p *Packet) GetTCPAcknowledgementNumber() uint32

GetTCPAcknowledgementNumber returns TCP Acknowledgement number

func (*Packet) GetTCPChecksum

func (p *Packet) GetTCPChecksum() uint16

GetTCPChecksum returns TCP checksum

func (*Packet) GetTCPFin

func (p *Packet) GetTCPFin() bool

GetTCPFin returns TCP FIN flag

func (*Packet) GetTCPPacket

func (p *Packet) GetTCPPacket() layers.TCP

GetTCPPacket returns created TCP packet

func (*Packet) GetTCPSequenceNumber

func (p *Packet) GetTCPSequenceNumber() uint32

GetTCPSequenceNumber returns TCP Sequence number

func (*Packet) GetTCPSyn

func (p *Packet) GetTCPSyn() bool

GetTCPSyn returns TCP SYN flag

func (*Packet) GetTCPWindow

func (p *Packet) GetTCPWindow() uint16

GetTCPWindow returns TCP Window

func (*Packet) NewTCPPayload

func (p *Packet) NewTCPPayload(newPayload string) error

NewTCPPayload adds new payload to TCP layer

func (*Packet) SetTCPAck

func (p *Packet) SetTCPAck()

SetTCPAck changes the TCP ACK flag to true

func (*Packet) SetTCPAcknowledgementNumber

func (p *Packet) SetTCPAcknowledgementNumber(ackNum uint32) error

SetTCPAcknowledgementNumber changes TCP Acknowledgement number

func (*Packet) SetTCPSequenceNumber

func (p *Packet) SetTCPSequenceNumber(seqNum uint32) error

SetTCPSequenceNumber changes TCP sequence number

func (*Packet) SetTCPSyn

func (p *Packet) SetTCPSyn()

SetTCPSyn changes the TCP SYN flag to true

func (*Packet) SetTCPSynAck

func (p *Packet) SetTCPSynAck()

SetTCPSynAck changes the TCP SYN and ACK flag to true

func (*Packet) SetTCPWindow

func (p *Packet) SetTCPWindow(window uint16) error

SetTCPWindow changes the TCP window

func (*Packet) ToBytes

func (p *Packet) ToBytes() []byte

ToBytes creates a packet buffer and converts it into a complete packet with ethernet, IP and TCP (with options)

type PacketFlow

type PacketFlow struct {
	Flow []PacketManipulator
	// contains filtered or unexported fields
}

PacketFlow is a custom type which holds the packet attributes and the flow Implements PacketFlowManipulator interface

func (*PacketFlow) AppendPacket

func (p *PacketFlow) AppendPacket(pm PacketManipulator) int

AppendPacket adds the packet to Flow field of PacketFlowManipulator interface

func (*PacketFlow) GenerateTCPFlow

func (p *PacketFlow) GenerateTCPFlow(pt PacketFlowType) PacketFlowManipulator

GenerateTCPFlow returns an array of PacketFlowManipulator interface

func (*PacketFlow) GenerateTCPFlowPayload

func (p *PacketFlow) GenerateTCPFlowPayload(newPayload string) PacketFlowManipulator

GenerateTCPFlowPayload Coming soon...

func (*PacketFlow) GetAckPackets

func (p *PacketFlow) GetAckPackets() PacketFlowManipulator

GetAckPackets returns the Ack Packets

func (*PacketFlow) GetFirstAckPacket

func (p *PacketFlow) GetFirstAckPacket() PacketManipulator

GetFirstAckPacket return first Ack packet from the flow

func (*PacketFlow) GetFirstSynAckPacket

func (p *PacketFlow) GetFirstSynAckPacket() PacketManipulator

GetFirstSynAckPacket return first SynAck packet from the flow

func (*PacketFlow) GetFirstSynPacket

func (p *PacketFlow) GetFirstSynPacket() PacketManipulator

GetFirstSynPacket return first Syn packet from the flow

func (*PacketFlow) GetNthPacket

func (p *PacketFlow) GetNthPacket(index int) PacketManipulator

GetNthPacket returns the packet requested by the user from the array

func (*PacketFlow) GetNumPackets

func (p *PacketFlow) GetNumPackets() int

GetNumPackets returns an array of packets

func (*PacketFlow) GetSynAckPackets

func (p *PacketFlow) GetSynAckPackets() PacketFlowManipulator

GetSynAckPackets returns the SynAck packets

func (*PacketFlow) GetSynPackets

func (p *PacketFlow) GetSynPackets() PacketFlowManipulator

GetSynPackets returns the SYN packets

type PacketFlowManipulator

type PacketFlowManipulator interface {
	//Ued to create a flow of TCP packets
	GenerateTCPFlow(pt PacketFlowType) PacketFlowManipulator
	//Used to return first TCP Syn packet
	GetFirstSynPacket() PacketManipulator
	//Used to return first TCP SynAck packet
	GetFirstSynAckPacket() PacketManipulator
	//Used to return first TCP Ack packet
	GetFirstAckPacket() PacketManipulator
	//Used to return all the TCP Syn packets from the flow
	GetSynPackets() PacketFlowManipulator
	//Used to return all the TCP SynAck packets from the flow
	GetSynAckPackets() PacketFlowManipulator
	//Used to return all the TCP Ack packets from the flow
	GetAckPackets() PacketFlowManipulator
	//Used to return Nth packet from the flow
	GetNthPacket(index int) PacketManipulator
	//Used to return length of the flow
	GetNumPackets() int
	//Used to add a new packet to the flow
	AppendPacket(p PacketManipulator) int
}

PacketFlowManipulator is an interface for packet flow manipulations Used to create/manipulate packet flows

func NewTCPPacketFlow

func NewTCPPacketFlow(smac string, dmac string, sip string, dip string, sport layers.TCPPort, dport layers.TCPPort) PacketFlowManipulator

NewTCPPacketFlow returns PacketFlow struct which implements PacketFlowManipulator

type PacketFlowType

type PacketFlowType uint8

PacketFlowType type for different types of flows

const (
	//PacketFlowTypeGoodFlow returns a good flow
	PacketFlowTypeGoodFlow PacketFlowType = iota
)

type PacketHelper

type PacketHelper interface {
	ToBytes() []byte
}

PacketHelper interface is a helper for packets and packet flows Optional: not needed for actual usage

type PacketManipulator

PacketManipulator is an interface for packet manipulations Composition of Ethernet, IP and TCP Manipulator interface

func NewPacket

func NewPacket() PacketManipulator

NewPacket returns a packet strut which implements PacketManipulator

type TCPPacketManipulator

type TCPPacketManipulator interface {
	//Used to create a TCP layer
	AddTCPLayer(srcPort layers.TCPPort, dstPort layers.TCPPort) error
	//Used to return TCP packet
	GetTCPPacket() layers.TCP
	//Used to return TCP Sequence number
	GetTCPSequenceNumber() uint32
	//Used to return TCP Acknowledgement number number
	GetTCPAcknowledgementNumber() uint32
	//Used to return TCP window
	GetTCPWindow() uint16
	//Used to return TCP Syn flag
	GetTCPSyn() bool
	//Used to return TCP Ack flag
	GetTCPAck() bool
	//Used to return TCP Fin flag
	GetTCPFin() bool
	//Used to return TCP Checksum
	GetTCPChecksum() uint16
	//Used to set TCP Sequence number
	SetTCPSequenceNumber(seqNum uint32) error
	//Used to set TCP Acknowledgement number
	SetTCPAcknowledgementNumber(ackNum uint32) error
	//Used to set TCP Window
	SetTCPWindow(window uint16) error
	//Used to set TCP Syn flag to true
	SetTCPSyn()
	//Used to set TCP Syn and Ack flag to true
	SetTCPSynAck()
	//Used to set TCP Ack flag to true
	SetTCPAck()
	//Used to add TCP Payload
	NewTCPPayload(newPayload string) error
}

TCPPacketManipulator interface is used to create/manipulate TCP packet

Jump to

Keyboard shortcuts

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