Class: Msf::Plugin::OpenVAS::OpenVASCommandDispatcher
Instance Attribute Summary
#driver
#shell, #tab_complete_items
Instance Method Summary
collapse
#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #initialize, #load_config, #log_error, #remove_lines
#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
#args?(args, min = 1, max = nil) ⇒ Boolean
Verify correct number of arguments and verify -h was not given. Return true if correct number of arguments and help was not requested.
119
120
121
122
123
124
125
126
|
# File 'plugins/openvas.rb', line 119
def args?(args, min=1, max=nil)
if not max then max = min end
if (args.length < min or args.length > max or args[0] == "-h")
return false
end
return true
end
|
#cmd_openvas_config_list(*args) ⇒ Object
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
# File 'plugins/openvas.rb', line 412
def cmd_openvas_config_list(*args)
return unless openvas?
begin
tbl = Rex::Text::Table.new(
'Columns' => [ "ID", "Name" ])
@ov.config_get_all.each do |config|
tbl << [ config["id"], config["name"] ]
end
print_good("OpenVAS list of configs")
print_line
print_line tbl.to_s
print_line
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
end
|
#cmd_openvas_connect(*args) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'plugins/openvas.rb', line 162
def cmd_openvas_connect(*args)
if not database?
print_error("No database has been configured.")
return
end
if @ov then
print_error("Session already open, please use openvas_disconnect first.")
return
end
if args?(args, 4, 5)
user, pass, host, port, sslv = args
if(host != "localhost" and host != "127.0.0.1" and sslv != "ok")
print_error("Warning: SSL connections are not verified in this release, it is possible for an attacker")
print_error(" with the ability to man-in-the-middle the OpenVAS traffic to capture the OpenVAS")
print_error(" credentials. If you are running this on a trusted network, please pass in 'ok'")
print_error(" as an additional parameter to this command.")
return
end
begin
print_status("Connecting to OpenVAS instance at #{host}:#{port} with username #{user}...")
ov = OpenVASOMP::OpenVASOMP.new('user' => user, 'password' => pass, 'host' => host, 'port' => port)
rescue OpenVASOMP::OMPAuthError => e
print_error("Authentication failed: #{e.reason}")
return
rescue OpenVASOMP::OMPConnectionError => e
print_error("Connection failed: #{e.reason}")
return
end
print_good("OpenVAS connection successful")
@ov = ov
else
print_status("Usage:")
print_status("openvas_connect username password host port <ssl-confirm>")
end
end
|
#cmd_openvas_debug(*args) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'plugins/openvas.rb', line 131
def cmd_openvas_debug(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.debug(args[0].to_i)
print_good(resp)
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage:")
print_status("openvas_debug integer")
end
end
|
#cmd_openvas_disconnect ⇒ Object
Disconnect from an OpenVAS manager
209
210
211
212
213
|
# File 'plugins/openvas.rb', line 209
def cmd_openvas_disconnect()
return unless openvas?
@ov.logout
@ov = nil
end
|
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
# File 'plugins/openvas.rb', line 434
def cmd_openvas_format_list(*args)
return unless openvas?
begin
tbl = Rex::Text::Table.new(
'Columns' => ["ID", "Name", "Extension", "Summary"])
format_get_all.each do |format|
tbl << [ format["id"], format["name"], format["extension"], format["summary"] ]
end
print_good("OpenVAS list of report formats")
print_line
print_line tbl.to_s
print_line
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
end
|
#cmd_openvas_help ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'plugins/openvas.rb', line 55
def cmd_openvas_help()
print_status("openvas_help Display this help")
print_status("openvas_debug Enable/Disable debugging")
print_status("openvas_version Display the version of the OpenVAS server")
print_status
print_status("CONNECTION")
print_status("==========")
print_status("openvas_connect Connects to OpenVAS")
print_status("openvas_disconnect Disconnects from OpenVAS")
print_status
print_status("TARGETS")
print_status("=======")
print_status("openvas_target_create Create target")
print_status("openvas_target_delete Deletes target specified by ID")
print_status("openvas_target_list Lists targets")
print_status
print_status("TASKS")
print_status("=====")
print_status("openvas_task_create Create task")
print_status("openvas_task_delete Delete a task and all associated reports")
print_status("openvas_task_list Lists tasks")
print_status("openvas_task_start Starts task specified by ID")
print_status("openvas_task_stop Stops task specified by ID")
print_status("openvas_task_pause Pauses task specified by ID")
print_status("openvas_task_resume Resumes task specified by ID")
print_status("openvas_task_resume_or_start Resumes or starts task specified by ID")
print_status
print_status("CONFIGS")
print_status("=======")
print_status("openvas_config_list Lists scan configurations")
print_status
print_status("FORMATS")
print_status("=======")
print_status("openvas_format_list Lists available report formats")
print_status
print_status("REPORTS")
print_status("=======")
print_status("openvas_report_list Lists available reports")
print_status("openvas_report_delete Delete a report specified by ID")
print_status("openvas_report_import Imports an OpenVAS report specified by ID")
print_status("openvas_report_download Downloads an OpenVAS report specified by ID")
end
|
#cmd_openvas_report_delete(*args) ⇒ Object
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
|
# File 'plugins/openvas.rb', line 481
def cmd_openvas_report_delete(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.report_delete(args[0])
print_status(resp)
cmd_openvas_report_list
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_report_delete <id>")
end
end
|
#cmd_openvas_report_download(*args) ⇒ Object
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
# File 'plugins/openvas.rb', line 497
def cmd_openvas_report_download(*args)
return unless openvas?
if args?(args, 4)
begin
report = @ov.report_get_raw("report_id"=>args[0],"format"=>args[1])
::FileUtils.mkdir_p(args[2])
name = ::File.join(args[2], args[3])
print_status("Saving report to #{name}")
output = ::File.new(name, "w")
data = nil
report.elements.each("//get_reports_response"){|r| data = r.to_s}
output.puts(data)
output.close
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_report_download <report_id> <format_id> <path> <report_name>")
end
end
|
#cmd_openvas_report_import(*args) ⇒ Object
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
# File 'plugins/openvas.rb', line 519
def cmd_openvas_report_import(*args)
return unless openvas?
if args?(args, 2)
begin
report = @ov.report_get_raw("report_id"=>args[0],"format"=>args[1])
data = nil
report.elements.each("//get_reports_response"){|r| data = r.to_s}
print_status("Importing report to database.")
framework.db.import({:data => data})
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_report_import <report_id> <format_id>")
print_status("Only the NBE and XML formats are supported for importing.")
end
end
|
#cmd_openvas_report_list(*args) ⇒ Object
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
# File 'plugins/openvas.rb', line 455
def cmd_openvas_report_list(*args)
return unless openvas?
begin
tbl = Rex::Text::Table.new(
'Columns' => ["ID", "Task Name", "Start Time", "Stop Time"])
resp = @ov.report_get_raw
resp.elements.each("//get_reports_response/report") do |report|
report_id = report.elements["report"].attributes["id"]
report_task = report.elements["task/name"].get_text
report_start_time = report.elements["creation_time"].get_text
report_stop_time = report.elements["modification_time"].get_text
tbl << [ report_id, report_task, report_start_time, report_stop_time ]
end
print_good("OpenVAS list of reports")
print_line
print_line tbl.to_s
print_line
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
end
|
#cmd_openvas_target_create(*args) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'plugins/openvas.rb', line 219
def cmd_openvas_target_create(*args)
return unless openvas?
if args?(args, 3)
begin
resp = @ov.target_create('name' => args[0], 'hosts' => args[1], 'comment' => args[2])
print_status(resp)
cmd_openvas_target_list
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_target_create <name> <hosts> <comment>")
end
end
|
#cmd_openvas_target_delete(*args) ⇒ Object
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# File 'plugins/openvas.rb', line 236
def cmd_openvas_target_delete(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.target_delete(args[0])
print_status(resp)
cmd_openvas_target_list
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_target_delete <target_id>")
end
end
|
#cmd_openvas_target_list(*args) ⇒ Object
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'plugins/openvas.rb', line 252
def cmd_openvas_target_list(*args)
return unless openvas?
begin
tbl = Rex::Text::Table.new(
'Columns' => ["ID", "Name", "Hosts", "Max Hosts", "In Use", "Comment"])
@ov.target_get_all().each do |target|
tbl << [ target["id"], target["name"], target["hosts"], target["max_hosts"],
target["in_use"], target["comment"] ]
end
print_good("OpenVAS list of targets")
print_line
print_line tbl.to_s
print_line
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
end
|
#cmd_openvas_task_create(*args) ⇒ Object
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'plugins/openvas.rb', line 274
def cmd_openvas_task_create(*args)
return unless openvas?
if args?(args, 4)
begin
resp = @ov.task_create('name' => args[0], 'comment' => args[1], 'config' => args[2], 'target'=> args[3])
print_status(resp)
cmd_openvas_task_list
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_task_create <name> <comment> <config_id> <target_id>")
end
end
|
#cmd_openvas_task_delete(*args) ⇒ Object
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'plugins/openvas.rb', line 291
def cmd_openvas_task_delete(*args)
return unless openvas?
if args?(args, 2)
if(args[1] != "ok")
print_error("Warning: Deleting a task will also delete all reports associated with the ")
print_error("task, please pass in 'ok' as an additional parameter to this command.")
return
end
begin
resp = @ov.task_delete(args[0])
print_status(resp)
cmd_openvas_task_list
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_task_delete <id> ok")
print_error("This will delete the task and all associated reports.")
end
end
|
#cmd_openvas_task_list(*args) ⇒ Object
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
# File 'plugins/openvas.rb', line 316
def cmd_openvas_task_list(*args)
return unless openvas?
begin
tbl = Rex::Text::Table.new(
'Columns' => ["ID", "Name", "Comment", "Status", "Progress"])
@ov.task_get_all().each do |task|
tbl << [ task["id"], task["name"], task["comment"], task["status"], task["progress"] ]
end
print_good("OpenVAS list of tasks")
print_line
print_line tbl.to_s
print_line
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
end
|
#cmd_openvas_task_pause(*args) ⇒ Object
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
# File 'plugins/openvas.rb', line 364
def cmd_openvas_task_pause(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.task_pause(args[0])
print_status(resp)
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_task_pause <id>")
end
end
|
#cmd_openvas_task_resume(*args) ⇒ Object
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
# File 'plugins/openvas.rb', line 379
def cmd_openvas_task_resume(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.task_resume_paused(args[0])
print_status(resp)
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_task_resume <id>")
end
end
|
#cmd_openvas_task_resume_or_start(*args) ⇒ Object
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# File 'plugins/openvas.rb', line 394
def cmd_openvas_task_resume_or_start(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.task_resume_or_start(args[0])
print_status(resp)
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_task_resume_or_start <id>")
end
end
|
#cmd_openvas_task_start(*args) ⇒ Object
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
# File 'plugins/openvas.rb', line 334
def cmd_openvas_task_start(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.task_start(args[0])
print_status(resp)
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_task_start <id>")
end
end
|
#cmd_openvas_task_stop(*args) ⇒ Object
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
# File 'plugins/openvas.rb', line 349
def cmd_openvas_task_stop(*args)
return unless openvas?
if args?(args)
begin
resp = @ov.task_stop(args[0])
print_status(resp)
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
else
print_status("Usage: openvas_task_stop <id>")
end
end
|
#cmd_openvas_version ⇒ Object
147
148
149
150
151
152
153
154
155
156
|
# File 'plugins/openvas.rb', line 147
def cmd_openvas_version()
return unless openvas?
begin
ver = @ov.version_get
print_good("Using OMP version #{ver}")
rescue OpenVASOMP::OMPError => e
print_error(e.to_s)
end
end
|
#commands ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'plugins/openvas.rb', line 23
def commands
{
'openvas_help' => "Displays help",
'openvas_version' => "Display the version of the OpenVAS server",
'openvas_debug' => "Enable/Disable debugging",
'openvas_connect' => "Connect to an OpenVAS manager using OMP",
'openvas_disconnect' => "Disconnect from OpenVAS manager",
'openvas_task_create' => "Create a task (name, comment, target, config)",
'openvas_task_delete' => "Delete task by ID",
'openvas_task_list' => "Display list of tasks",
'openvas_task_start' => "Start task by ID",
'openvas_task_stop' => "Stop task by ID",
'openvas_task_pause' => "Pause task by ID",
'openvas_task_resume' => "Resume task by ID",
'openvas_task_resume_or_start' => "Resume task or start task by ID",
'openvas_target_create' => "Create target (name, hosts, comment)",
'openvas_target_delete' => "Delete target by ID",
'openvas_target_list' => "Display list of targets",
'openvas_config_list' => "Quickly display list of configs",
'openvas_format_list' => "Display list of available report formats",
'openvas_report_list' => "Display a list of available report formats",
'openvas_report_delete' => "Delete a report specified by ID",
'openvas_report_download' => "Save a report to disk",
'openvas_report_import' => "Import report specified by ID into framework",
}
end
|
#database? ⇒ Boolean
Verify the database is connected and usable
99
100
101
102
103
104
105
|
# File 'plugins/openvas.rb', line 99
def database?
if !(framework.db and framework.db.usable)
return false
else
return true
end
end
|
Format Functions
Get a list of report formats
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
# File 'plugins/openvas.rb', line 544
def format_get_all
begin
resp = @ov.omp_request_xml("<get_report_formats/>")
if @debug then print resp end
list = Array.new
resp.elements.each('//get_report_formats_response/report_format') do |report|
td = Hash.new
td["id"] = report.attributes["id"]
td["name"] = report.elements["name"].text
td["extension"] = report.elements["extension"].text
td["summary"] = report.elements["summary"].text
list.push td
end
@formats = list
return list
rescue
raise OMPResponseError
end
end
|
#name ⇒ Object
19
20
21
|
# File 'plugins/openvas.rb', line 19
def name
"OpenVAS"
end
|
#openvas? ⇒ Boolean
Verify there is an active OpenVAS connection
108
109
110
111
112
113
114
115
|
# File 'plugins/openvas.rb', line 108
def openvas?
if @ov
return true
else
print_error("No OpenVAS connection available. Please use openvas_connect.")
return false
end
end
|