Class: Rex::Post::Meterpreter::Extensions::Lanattacks::Dhcp::Dhcp

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb

Overview

DHCP Server functionality

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Dhcp

Returns a new instance of Dhcp.



19
20
21
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 19

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



74
75
76
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 74

def client
  @client
end

Instance Method Details

#load_options(datastore) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 41

def load_options(datastore)
  # TODO: change this so that all of the options are set in a single
  # payload rather than firing off lots of calls separately
  datastore.each do |name, value|
    if Regexp.new('DHCPIPSTART|DHCPIPEND|NETMASK|ROUTER|DNSSERVER|BROADCAST|'+
        'SERVEONCE|PXE|HOSTNAME|HOSTSTART|FILENAME|PXECONF|SRVHOST') =~ name
      set_option(name, value)
    end
  end
end

#logObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 57

def log
  response = client.send_request(Packet.create_request(COMMAND_ID_LANATTACKS_DHCP_LOG))
  entries = []
  if( response.result == 0 )
    log = response.get_tlv_value( TLV_TYPE_LANATTACKS_RAW )
    while log.length > 0
      mac = log.slice!(0..5)
      ip = log.slice!(0..3)
      entries << {
       :mac => mac,
       :ip  => ip
      }
    end
  end
  entries
end

#resetObject



28
29
30
31
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 28

def reset
  client.send_request(Packet.create_request(COMMAND_ID_LANATTACKS_RESET_DHCP))
  true
end

#set_option(name, value) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 33

def set_option(name, value)
  request = Packet.create_request(COMMAND_ID_LANATTACKS_SET_DHCP_OPTION)
  request.add_tlv(TLV_TYPE_LANATTACKS_OPTION_NAME, name)
  request.add_tlv(TLV_TYPE_LANATTACKS_OPTION, value)
  client.send_request(request)
  true
end

#startObject



23
24
25
26
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 23

def start
  client.send_request(Packet.create_request(COMMAND_ID_LANATTACKS_START_DHCP))
  true
end

#stopObject



52
53
54
55
# File 'lib/rex/post/meterpreter/extensions/lanattacks/dhcp/dhcp.rb', line 52

def stop
  client.send_request(Packet.create_request(COMMAND_ID_LANATTACKS_STOP_DHCP))
  true
end