PacketGen wiki
  • Introduction
  • Getting Started
    • Interactive Console
    • PacketGen Structure
  • Supported Protocols
  • Protocols
    • TCP IP
    • SNMP
    • WiFi
    • HTTP
    • ICMP
    • ICMPv6
    • IPv6
    • UDP
    • OSPFv2
  • Advanced Use
    • Create Custom Protocol
Powered by GitBook
On this page
  • Quick access to PacketGen methods
  • local configuration
  • Utils
  1. Getting Started

Interactive Console

PreviousGetting StartedNextPacketGen Structure

Last updated 6 years ago

PacketGen provides an interactive console: pgconsole. It may be used to quickly write and test some pieces of code.

pgconsole uses IRB, or Pry if it is installed. It includes class methods and ones to simplify access to them.

Quick access to PacketGen methods

gen, parse, capture, read and write are quickly accessible:

pg> pkt = gen('Eth', src: '00:00:00:00:00:01', dst: '00:00:00:00:00:02')
=> -- PacketGen::Packet -------------------------------------------------
---- PacketGen::Header::Eth ------------------------------------------
           MacAddr          dst: 00:00:00:00:00:02
           MacAddr          src: 00:00:00:00:00:01
             Int16    ethertype: 0          (0x0000)
pg>
pg> parse(pkt.to_s, first_header: 'Eth')
=> -- PacketGen::Packet -------------------------------------------------
---- PacketGen::Header::Eth ------------------------------------------
           MacAddr          dst: 00:00:00:00:00:02
           MacAddr          src: 00:00:00:00:00:01
             Int16    ethertype: 0          (0x0000)
pg> write 'packet.pcapng', [pkt]
pg> pkts = read('packet.pcapng')
=> [-- PacketGen::Packet -------------------------------------------------
---- PacketGen::Header::Eth ------------------------------------------
           MacAddr          dst: 00:00:00:00:00:02
           MacAddr          src: 00:00:00:00:00:01
             Int16    ethertype: 0          (0x0000)
]
pg>
pg> capture { |pkt| p pkt }

local configuration

$ pgconsole
pg> config.default_iface
=> "eth0"
pg> config.hwaddr
=> "7a:fb:fc:fd:fe:ff"
pg> config.ipaddr
=> "192.168.0.2"
pg> config.ip6addr
=> ["fe80::e255:ffff:275c:9bee%eth0"]
pg> config.ipaddr('lo')
=> "127.0.0.1"

This local configuration may be used to forge packets:

pg> pkt = gen('IP', src: config.ipaddr, dst: '8.8.8.8')
pg> pkt.calc
pg> pkt.to_w
=> 20

Utils

To ease tests, Methods from PacketGen::Utils module are quickly accessible from pgconsole:

pg> PacketGen::Utils.arp '192.168.0.1'
=> "aa:bb:cc:dd:ee:ff"
pg> arp '192.168.0.1'
=> "aa:bb:cc:dd:ee:ff"

Utils methods are:

  • to get MAC address for given IP address,

  • to do ARP spoofing.

pgconsole provides quick access to local network configuration through config, a object:

to do a Man-In-The-Middle attack (on local network only).

PacketGen
PacketGen::Utils
PacketGen::Config
arp
arp_spoof
mitm