Interactive Console

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 PacketGen class methods and PacketGen::Utils 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 provides quick access to local network configuration through config, a PacketGen::Config object:

$ 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:

  • arp

    to get MAC address for given IP address,

  • arp_spoof

    to do ARP spoofing.

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

Last updated