From 871c30c0b3c013c4ad1c3556d979541596819223 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 6 Jun 2017 14:05:07 +0800 Subject: [PATCH] refactor stdapi and lanattacks to use filter_commands --- .../console/command_dispatcher/lanattacks/dhcp.rb | 15 +-------------- .../console/command_dispatcher/lanattacks/tftp.rb | 15 +-------------- .../ui/console/command_dispatcher/stdapi/fs.rb | 13 +------------ .../ui/console/command_dispatcher/stdapi/net.rb | 13 +------------ .../ui/console/command_dispatcher/stdapi/sys.rb | 14 +------------- .../ui/console/command_dispatcher/stdapi/ui.rb | 14 +------------- .../console/command_dispatcher/stdapi/webcam.rb | 13 +------------ 7 files changed, 7 insertions(+), 90 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb index 1940a92e9d..bc6369800e 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb @@ -29,7 +29,6 @@ class Console::CommandDispatcher::Lanattacks::Dhcp "dhcp_load_options" => "Load DHCP optionis from a datastore", "dhcp_log" => "Log DHCP server activity" } - reqs = { "dhcp_start" => [ "lanattacks_start_dhcp" ], "dhcp_stop" => [ "lanattacks_stop_dhcp" ], @@ -38,19 +37,7 @@ class Console::CommandDispatcher::Lanattacks::Dhcp "dhcp_load_options" => [ "lanattacks_set_dhcp_option" ], "dhcp_log" => [ "lanattacks_dhcp_log" ] } - - all.delete_if do |cmd, desc| - del = false - reqs[cmd].each do |req| - next if client.commands.include? req - del = true - break - end - - del - end - - all + filter_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/tftp.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/tftp.rb index 29235f141c..beb69a1d02 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/tftp.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/tftp.rb @@ -27,26 +27,13 @@ class Console::CommandDispatcher::Lanattacks::Tftp "tftp_reset" => "Reset the TFTP server", "tftp_add_file" => "Add a file to the TFTP server" } - reqs = { "tftp_start" => [ "lanattacks_start_tftp" ], "tftp_stop" => [ "lanattacks_stop_tftp" ], "tftp_reset" => [ "lanattacks_reset_tftp" ], "tftp_add_file" => [ "lanattacks_add_tftp_file" ], } - - all.delete_if do |cmd, desc| - del = false - reqs[cmd].each do |req| - next if client.commands.include? req - del = true - break - end - - del - end - - all + filter_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb index 508d4820ea..40a2a97d67 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb @@ -102,18 +102,7 @@ class Console::CommandDispatcher::Stdapi::Fs 'show_mount' => ['stdapi_fs_mount_show'], } - all.delete_if do |cmd, desc| - del = false - reqs[cmd].each do |req| - next if client.commands.include? req - del = true - break - end - - del - end - - all + filter_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb index 5fd824d90e..e46eae9db2 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb @@ -108,18 +108,7 @@ class Console::CommandDispatcher::Stdapi::Net 'resolve' => ['stdapi_net_resolve_host'], } - all.delete_if do |cmd, desc| - del = false - reqs[cmd].each do |req| - next if client.commands.include? req - del = true - break - end - - del - end - - all + filter_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb index acfe737328..b62d5a965a 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb @@ -143,19 +143,7 @@ class Console::CommandDispatcher::Stdapi::Sys "sysinfo" => [ "stdapi_sys_config_sysinfo" ], "localtime" => [ "stdapi_sys_config_localtime" ], } - - all.delete_if do |cmd, desc| - del = false - reqs[cmd].each do |req| - next if client.commands.include? req - del = true - break - end - - del - end - - all + filter_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb index 844129db33..dd7a2de892 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb @@ -49,19 +49,7 @@ class Console::CommandDispatcher::Stdapi::Ui "stdapi_ui_enable_keyboard" ] } - - all.delete_if do |cmd, desc| - del = false - reqs[cmd].each do |req| - next if client.commands.include? req - del = true - break - end - - del - end - - all + filter_commands(all, reqs) end # diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb index 447097cd2b..bc8b270630 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb @@ -34,18 +34,7 @@ class Console::CommandDispatcher::Stdapi::Webcam "webcam_stream" => [ "webcam_start", "webcam_get_frame", "webcam_stop" ], "record_mic" => [ "webcam_audio_record" ] } - - all.delete_if do |cmd, _desc| - del = false - reqs[cmd].each do |req| - next if client.commands.include? req - del = true - break - end - del - end - - all + filter_commands(all, reqs) end #