Class: Rex::Post::Meterpreter::Ui::Console::CommandDispatcher::Lanattacks::Dhcp

Inherits:
Object
  • Object
show all
Includes:
Extensions::Lanattacks, Rex::Post::Meterpreter::Ui::Console::CommandDispatcher
Defined in:
lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb

Overview

The DHCP portion of the lanattacks extension.

Constant Summary collapse

Klass =
Console::CommandDispatcher::Lanattacks::Dhcp
@@dhcp_start_opts =
Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])
@@dhcp_stop_opts =
Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])
@@dhcp_reset_opts =
Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])
@@dhcp_set_option_opts =
Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])
@@dhcp_set_option_valid_options =
[
  "BROADCAST", "DHCPIPEND", "DHCPIPSTART", "DNSSERVER",
  "FILENAME", "HOSTNAME", "HOSTSTART", "NETMASK",
  "PXE", "PXECONF", "ROUTER", "SERVEONCE", "SRVHOST"
]
@@dhcp_load_options_opts =
Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])
@@dhcp_log_opts =
Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])

Constants included from Extensions::Lanattacks

Extensions::Lanattacks::COMMAND_ID_LANATTACKS_ADD_TFTP_FILE, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_DHCP_LOG, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_RESET_DHCP, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_RESET_TFTP, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_SET_DHCP_OPTION, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_START_DHCP, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_START_TFTP, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_STOP_DHCP, Extensions::Lanattacks::COMMAND_ID_LANATTACKS_STOP_TFTP, Extensions::Lanattacks::EXTENSION_ID_LANATTACKS, Extensions::Lanattacks::TLV_TYPE_LANATTACKS_OPTION, Extensions::Lanattacks::TLV_TYPE_LANATTACKS_OPTION_NAME, Extensions::Lanattacks::TLV_TYPE_LANATTACKS_RAW, Extensions::Lanattacks::TLV_TYPE_LANATTACKS_UINT

Instance Attribute Summary

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Rex::Post::Meterpreter::Ui::Console::CommandDispatcher

check_hash, #client, #docs_dir, #filter_commands, #initialize, #log_error, #msf_loaded?, #session, set_hash, #unknown_command

Methods included from Msf::Ui::Console::CommandDispatcher::Session

#cmd_background, #cmd_background_help, #cmd_exit, #cmd_irb, #cmd_irb_help, #cmd_irb_tabs, #cmd_pry, #cmd_pry_help, #cmd_resource, #cmd_resource_help, #cmd_resource_tabs, #cmd_sessions, #cmd_sessions_help

Methods included from Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt

Instance Method Details

#cmd_dhcp_load_options(*args) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 176

def cmd_dhcp_load_options(*args)
  @@dhcp_set_option_opts.parse(args) { |opt, idx, val|
    case opt
    when '-h'
      print_dhcp_set_option_usage
      return true
    end
  }

  if args.length < 1
    print_dhcp_load_options_usage
    return true
  end

  datastore = args.shift

  unless datastore.is_a?(Hash) || datastore.is_a?(Msf::DataStoreWithFallbacks)
    print_dhcp_load_options_usage
    return true
  end

  client.lanattacks.dhcp.load_options(datastore)
end

#cmd_dhcp_log(*args) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 209

def cmd_dhcp_log(*args)
  @@dhcp_log_opts.parse(args) { |opt, idx, val|
    case opt
    when '-h'
      print_dhcp_log_usage
      return true
    end
  }

  log = client.lanattacks.dhcp.log

  table = Rex::Text::Table.new(
    'Header'    => 'DHCP Server Log',
    'Indent'    => 0,
    'SortIndex' => 0,
    'Columns'   => [ 'MAC Address', 'IP Address' ]
  )

  log.each { |l|
    table << [ l[:mac], l[:ip] ]
  }

  print_line
  print_line( table.to_s )
  print_line( "Total log entries: #{log.length}" )
  print_line
end

#cmd_dhcp_reset(*args) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 107

def cmd_dhcp_reset(*args)
  @@dhcp_reset_opts.parse(args) { |opt, idx, val|
    case opt
    when '-h'
      print_dhcp_reset_usage
      return true
    end
  }

  print_status( "Resetting DHCP server ...")
  client.lanattacks.dhcp.reset
  print_good( "DHCP server reset.")
end

#cmd_dhcp_set_option(*args) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 138

def cmd_dhcp_set_option(*args)
  @@dhcp_set_option_opts.parse(args) { |opt, idx, val|
    case opt
    when '-h'
      print_dhcp_set_option_usage
      return true
    end
  }

  if args.length < 2
    print_dhcp_set_option_usage
    return true
  end


  name = args.shift.upcase
  value = args.shift

  if not @@dhcp_set_option_valid_options.include? name
    print_error( "Invalid option name '#{name}'." )
    return true
  end

  client.lanattacks.dhcp.set_option(name, value)
end

#cmd_dhcp_start(*args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 61

def cmd_dhcp_start(*args)
  @@dhcp_start_opts.parse(args) { |opt, idx, val|
    case opt
    when '-h'
      print_dhcp_start_usage
      return true
    end
  }

  print_status( "Starting DHCP server ...")
  client.lanattacks.dhcp.start
  print_good( "DHCP server started.")
end

#cmd_dhcp_stop(*args) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 84

def cmd_dhcp_stop(*args)
  @@dhcp_stop_opts.parse(args) { |opt, idx, val|
    case opt
    when '-h'
      print_dhcp_stop_usage
      return true
    end
  }

  print_status( "Stopping DHCP server ...")
  client.lanattacks.dhcp.stop
  print_good( "DHCP server stopped.")
end

#commandsObject

List of supported commands.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 25

def commands
  all = {
    'dhcp_start'        => 'Start the DHCP server',
    'dhcp_stop'         => 'Stop the DHCP server',
    'dhcp_reset'        => 'Reset the DHCP server',
    'dhcp_set_option'   => 'Set a DHCP server option',
    'dhcp_load_options' => 'Load DHCP optionis from a datastore',
    'dhcp_log'          => 'Log DHCP server activity'
  }
  reqs = {
    'dhcp_start'        => [COMMAND_ID_LANATTACKS_START_DHCP],
    'dhcp_stop'         => [COMMAND_ID_LANATTACKS_STOP_DHCP],
    'dhcp_reset'        => [COMMAND_ID_LANATTACKS_RESET_DHCP],
    'dhcp_set_option'   => [COMMAND_ID_LANATTACKS_SET_DHCP_OPTION],
    'dhcp_load_options' => [COMMAND_ID_LANATTACKS_SET_DHCP_OPTION],
    'dhcp_log'          => [COMMAND_ID_LANATTACKS_DHCP_LOG]
  }
  filter_commands(all, reqs)
end

#nameObject

Name for this dispatcher.



48
49
50
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 48

def name
  "Lanattacks: DHCP"
end


167
168
169
170
171
172
173
174
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 167

def print_dhcp_load_options_usage
  print("dhcp_load_options <datastore> [-h]\n\n" +
        "Load settings from a datastore to the active DHCP server.\n\n" +
        "The datastore must be a hash of name/value pairs.\n" +
        "Valid names are:\n" +
        @@dhcp_set_option_valid_options.map {|o| "  - #{o}\n" }.join('') +
        @@dhcp_set_option_opts.usage + "\n")
end


203
204
205
206
207
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 203

def print_dhcp_log_usage
  print("dhcp_log [-h]\n\n" +
        "Logs the DHCP operations captured by the DHCP server.\n" +
        @@dhcp_log_opts.usage + "\n")
end


101
102
103
104
105
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 101

def print_dhcp_reset_usage
  print("dhcp_reset [-h]\n\n" +
        "Resets the currently running DHCP server.\n" +
        @@dhcp_reset_opts.usage + "\n")
end


130
131
132
133
134
135
136
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 130

def print_dhcp_set_option_usage
  print("dhcp_set_option <name> <value> [-h]\n\n" +
        "Set a DHCP server option.\n\n" +
        "Valid names are:\n" +
        @@dhcp_set_option_valid_options.map {|o| "  - #{o}\n" }.join('') +
        @@dhcp_set_option_opts.usage + "\n")
end


55
56
57
58
59
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 55

def print_dhcp_start_usage
  print("dhcp_start [-h]\n\n" +
        "Starts a DHCP server in the current Meterpreter session.\n" +
        @@dhcp_start_opts.usage + "\n")
end


78
79
80
81
82
# File 'lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb', line 78

def print_dhcp_stop_usage
  print("dhcp_stop [-h]\n\n" +
        "Stops the currently running DHCP server.\n" +
        @@dhcp_stop_opts.usage + "\n")
end