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, inherited, #initialize, load_by_names, load_custom

Constructor Details

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

Instance Method Details

#on_packet(pkt) ⇒ Object


17
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
# File 'lib/bettercap/sniffer/parsers/dhcp.rb', line 17

def on_packet( pkt )
  begin
    if pkt.udp_dst == 67 or pkt.udp_dst == 68
      packet = Network::Protos::DHCP::Packet.parse( pkt.payload )
      unless 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 )
      end
    end
  rescue; end
end