diff --git a/extensions/console/lib/command_dispatcher/target.rb b/extensions/console/lib/command_dispatcher/target.rb index 1c1c4a2ef..a22c6e2f8 100644 --- a/extensions/console/lib/command_dispatcher/target.rb +++ b/extensions/console/lib/command_dispatcher/target.rb @@ -30,7 +30,9 @@ class Target { "commands" => "List available commands against this particular target", "info" => "Info about the target", - "select" => "Prepare the command module for execution against this target" + "select" => "Prepare the command module for execution against this target", + "hosts" => "List identified network hosts", + "services" => "List identified network services" } end @@ -145,7 +147,84 @@ class Target def cmd_info_help(*args) print_status("Display initialisation information about the hooked browser.") end - + + def cmd_hosts(*args) + + @@bare_opts.parse(args) {|opt, idx, val| + case opt + when "-h" + cmd_hosts_help + return false + end + } + + configuration = BeEF::Core::Configuration.instance + if !configuration.get("beef.extension.network.enable") + print_error("Network extension is disabled") + return + end + + tbl = Rex::Ui::Text::Table.new( + 'Columns' => + [ + 'IP', + 'Hostname', + 'Type', + 'Operating System', + 'MAC Address' + ]) + + driver.interface.select_network_hosts['results'].each do |x| + tbl << [x['ip'],x['hostname'],x['type'],x['os'],x['mac']] + end + + puts "\nNetwork Hosts:\n\n" + puts tbl.to_s + "\n" + + end + + def cmd_hosts_help(*args) + print_status("Display information about network hosts on the hooked browser's network.") + end + + def cmd_services(*args) + + @@bare_opts.parse(args) {|opt, idx, val| + case opt + when "-h" + cmd_services_help + return false + end + } + + configuration = BeEF::Core::Configuration.instance + if !configuration.get("beef.extension.network.enable") + print_error("Network extension is disabled") + return + end + + tbl = Rex::Ui::Text::Table.new( + 'Columns' => + [ + 'IP', + 'Port', + 'Protocol', + 'Type' + ]) + + driver.interface.select_network_services['results'].each do |x| + tbl << [x['ip'],x['port'],x['proto'],x['type']] + end + + puts "\nNetwork Services:\n\n" + puts tbl.to_s + "\n" + + end + + def cmd_services_help(*args) + print_status("Display information about network services on the hooked browser's network.") + end + def cmd_select(*args) @@bare_opts.parse(args) {|opt, idx, val| case opt diff --git a/extensions/console/lib/shellinterface.rb b/extensions/console/lib/shellinterface.rb index 978769831..318c7de05 100644 --- a/extensions/console/lib/shellinterface.rb +++ b/extensions/console/lib/shellinterface.rb @@ -362,6 +362,79 @@ class ShellInterface summary_grid_hash end + def select_network_hosts + + return if self.targetsession.nil? + + configuration = BeEF::Core::Configuration.instance + if !configuration.get("beef.extension.network.enable") + print_error("Network extension is disabled") + return { + 'success' => 'false', + 'results' => [] + } + end + + # init the summary grid + summary_grid_hash = { + 'success' => 'true', + 'results' => [] + } + @nh = BeEF::Core::Models::NetworkHost + hosts = @nh.all(:hooked_browser_id => self.targetsession) + + # add property to summary hash + if not hosts.empty? + hosts.each do |x| + summary_grid_hash['results'].push({ + 'ip' => x['ip'].to_s, + 'hostname' => x['hostname'].to_s, + 'type' => x['type'].to_s, + 'os' => x['os'].to_s, + 'mac' => x['mac'].to_s + }) + end + end + + summary_grid_hash + end + + def select_network_services + + return if self.targetsession.nil? + + configuration = BeEF::Core::Configuration.instance + if !configuration.get("beef.extension.network.enable") + print_error("Network extension is disabled") + return { + 'success' => 'false', + 'results' => [] + } + end + + # init the summary grid + summary_grid_hash = { + 'success' => 'true', + 'results' => [] + } + @ns = BeEF::Core::Models::NetworkService + services = @ns.all(:hooked_browser_id => self.targetsession) + + # add property to summary hash + if not services.empty? + services.each do |x| + summary_grid_hash['results'].push({ + 'proto' => x['proto'].to_s, + 'ip' => x['ip'].to_s, + 'port' => x['port'].to_s, + 'type' => x['type'].to_s + }) + end + end + + summary_grid_hash + end + attr_reader :targetsession attr_reader :targetid attr_reader :targetip