Class: BetterCap::Parsers::DHCP

Inherits:
Base
  • Object
show all
Defined in:
lib/bettercap/sniffer/parsers/dhcp.rb

Overview

DHCP packets and authentication parser.

Instance Method Summary collapse

Methods inherited from Base

available, from_cmdline, from_exclusion_list, inherited, #initialize, load_by_names, load_custom, #match_port?

Constructor Details

This class inherits a constructor from BetterCap::Parsers::Base

Instance Method Details

#on_packet(pkt) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bettercap/sniffer/parsers/dhcp.rb', line 18

def on_packet( pkt )
  return unless (pkt.udp_dst == 67 || pkt.udp_dst == 68)

  packet = Network::Protos::DHCP::Packet.parse( pkt.payload )

  return if packet.nil?

  auth = packet.authentication
  cid  = auth.nil?? nil : packet.client_identifier
  msg  = "[#{packet.type.yellow}] #{'Transaction-ID'.green}=#{sprintf( "0x%X", packet.xid ).yellow}"

  unless cid.nil?
    msg += " #{'Client-ID'.green}='#{cid.yellow}'"
  end

  unless auth.nil?
    msg += "\n#{'AUTHENTICATION'.green}:\n\n"
    auth.each do |k,v|
      msg += "  #{k.blue} : #{v.yellow}\n"
    end
    msg += "\n"
  end

  StreamLogger.log_raw( pkt, 'DHCP', msg )
rescue
end