Class: BetterCap::Network::Protos::DHCP::Packet

Inherits:
Base
  • Object
show all
Defined in:
lib/bettercap/network/protos/dhcp.rb

Constant Summary

Constants inherited from Base

Base::TYPES

Instance Method Summary collapse

Methods inherited from Base

method_missing, offset, parse, size

Instance Method Details

#authenticationObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/bettercap/network/protos/dhcp.rb', line 183

def authentication
  # Thank you Wireshark BOOTP dissector!
  self.each_option( :Authentication ) do |_,data|
    auth = {}

    auth['Protocol'] = AUTH_PROTOCOLS[ data[0] ]

    if data[0] == 1
      auth['Delay Algorithm'] = 'HMAC_MD5'
    end

    auth['Replay Detection Method']    = 'Monotonically-increasing counter'
    auth['RDM Replay Detection Value'] = "0x" + data[3..10].map { |b| sprintf( "%02x", b ) }.join
    auth['Secret ID']                  = "0x" + data[11..14].map { |b| sprintf( "%02x", b ) }.join
    auth['HMAC MD5 Hash']              = data[15..data.size].map { |b| sprintf( "%02X", b ) }.join

    return auth
  end
end

#client_identifierObject



177
178
179
180
181
# File 'lib/bettercap/network/protos/dhcp.rb', line 177

def client_identifier
  self.each_option( :ClientIdentifier ) do |_,data|
    return data.pack('c*')
  end
end

#each_option(sym = nil) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/bettercap/network/protos/dhcp.rb', line 203

def each_option sym = nil
  offset = 0
  limit = self.dhcpoptions.size

  while offset < limit
    opt     = self.dhcpoptions[offset]
    break if opt == 0xFF
    offset += 1
    len     = self.dhcpoptions[offset]
    break if len.nil?
    offset += 1
    data    = self.dhcpoptions[offset..offset+len-1]
    offset += len

    if sym.nil? or OP_CONSTANTS[opt] == sym
      yield( OP_CONSTANTS[opt], data )
    end
  end
end

#typeObject



170
171
172
173
174
175
# File 'lib/bettercap/network/protos/dhcp.rb', line 170

def type
  self.each_option( :MessageType ) do |_,data|
    return OP_MESSAGETYPES[ data[0] ]
  end
  OP_MESSAGETYPES[ @op ]
end