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

    View Source
    var PacketFlowTemplate1 [][]byte

      PacketFlowTemplate1 is a good hardcoded template

      View Source
      var PacketFlowTemplate2 [][]byte

        PacketFlowTemplate2 has a two complete TCP flow

        View Source
        var PacketFlowTemplate3 [][]byte

          PacketFlowTemplate3 has a two intervened TCP flows

          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 {
              	// contains filtered or unexported fields
              }

                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) AddPacket

                    func (p *Packet) AddPacket(packet gopacket.Packet)

                      AddPacket is a helper method to add the packet from the template to the struct internal struct field

                      func (*Packet) AddTCPLayer

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

                        AddTCPLayer creates a TCP layer

                        func (*Packet) DecodePacket

                        func (p *Packet) DecodePacket() PacketManipulator

                          DecodePacket returns decoded packet which implements PacketManipulator

                          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) SetTCPCwr

                                                      func (p *Packet) SetTCPCwr()

                                                        SetTCPCwr changes the TCP CWR flag to true

                                                        func (*Packet) SetTCPEce

                                                        func (p *Packet) SetTCPEce()

                                                          SetTCPEce changes the TCP ECE flag to true

                                                          func (*Packet) SetTCPFin

                                                          func (p *Packet) SetTCPFin()

                                                            SetTCPFin changes the TCP FIN flag to true

                                                            func (*Packet) SetTCPPsh

                                                            func (p *Packet) SetTCPPsh()

                                                              SetTCPPsh changes the TCP PSH flag to true

                                                              func (*Packet) SetTCPRst

                                                              func (p *Packet) SetTCPRst()

                                                                SetTCPRst changes the TCP RST flag to true

                                                                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) SetTCPUrg

                                                                      func (p *Packet) SetTCPUrg()

                                                                        SetTCPUrg changes the TCP URG 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 {
                                                                            	// 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

                                                                                                    func (*PacketFlow) GetUptoFirstAckPacket

                                                                                                    func (p *PacketFlow) GetUptoFirstAckPacket() PacketFlowManipulator

                                                                                                      GetUptoFirstAckPacket will return packets upto first Ack packet

                                                                                                      func (*PacketFlow) GetUptoFirstSynAckPacket

                                                                                                      func (p *PacketFlow) GetUptoFirstSynAckPacket() PacketFlowManipulator

                                                                                                        GetUptoFirstSynAckPacket will return packets upto first SynAck packet

                                                                                                        type PacketFlowManipulator

                                                                                                        type PacketFlowManipulator interface {
                                                                                                        	//Used 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 all the packets upto first TCP SynAck packet from the flow
                                                                                                        	GetUptoFirstSynAckPacket() PacketFlowManipulator
                                                                                                        	//Used to return all the packets upto first TCP Ack packet from the flow
                                                                                                        	GetUptoFirstAckPacket() 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 NewPacketFlow

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

                                                                                                            NewPacketFlow returns PacketFlow struct which implements PacketFlowManipulator

                                                                                                            func NewTemplateFlow

                                                                                                            func NewTemplateFlow() PacketFlowManipulator

                                                                                                              NewTemplateFlow will return flow of packets which implements PacketManipulator

                                                                                                              type PacketFlowType

                                                                                                              type PacketFlowType uint8

                                                                                                                PacketFlowType type for different types of flows

                                                                                                                const (
                                                                                                                	//PacketFlowTypeGenerateGoodFlow is used to generate a good floe
                                                                                                                	PacketFlowTypeGenerateGoodFlow PacketFlowType = iota
                                                                                                                	//PacketFlowTypeGoodFlowTemplate will have a good flow from a hardcoded template
                                                                                                                	PacketFlowTypeGoodFlowTemplate
                                                                                                                	//PacketFlowTypeMultipleGoodFlow will have two flows
                                                                                                                	PacketFlowTypeMultipleGoodFlow
                                                                                                                	//PacketFlowTypeMultipleIntervenedFlow will have two flows intervened to eachothers
                                                                                                                	PacketFlowTypeMultipleIntervenedFlow
                                                                                                                )

                                                                                                                type PacketHelper

                                                                                                                type PacketHelper interface {
                                                                                                                	ToBytes() []byte
                                                                                                                	AddPacket(packet gopacket.Packet)
                                                                                                                	DecodePacket() PacketManipulator
                                                                                                                }

                                                                                                                  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 set TCP Cwr flag to true
                                                                                                                      	SetTCPCwr()
                                                                                                                      	//Used to set TCP Ece flag to true
                                                                                                                      	SetTCPEce()
                                                                                                                      	//Used to set TCP Urg flag to true
                                                                                                                      	SetTCPUrg()
                                                                                                                      	//Used to set TCP Psh flag to true
                                                                                                                      	SetTCPPsh()
                                                                                                                      	//Used to set TCP Rst flag to true
                                                                                                                      	SetTCPRst()
                                                                                                                      	//Used to set TCP Fin flag to true
                                                                                                                      	SetTCPFin()
                                                                                                                      	//Used to add TCP Payload
                                                                                                                      	NewTCPPayload(newPayload string) error
                                                                                                                      }

                                                                                                                        TCPPacketManipulator interface is used to create/manipulate TCP packet