From af7becdfc3f905745338eda0b9f516cf8e4bac7c Mon Sep 17 00:00:00 2001 From: Christian Frichot Date: Sun, 27 Nov 2011 18:46:26 +0800 Subject: [PATCH] Tidying up some of the in-built console shell interface --- .../console/lib/command_dispatcher/core.rb | 32 ++++++++++++++++--- extensions/console/lib/shellinterface.rb | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/extensions/console/lib/command_dispatcher/core.rb b/extensions/console/lib/command_dispatcher/core.rb index 5614631de..541035ad0 100644 --- a/extensions/console/lib/command_dispatcher/core.rb +++ b/extensions/console/lib/command_dispatcher/core.rb @@ -67,7 +67,7 @@ class Core print_status("Move back one step") end - def cmd_exit + def cmd_exit(* args) driver.stop end @@ -92,10 +92,12 @@ class Core print_error("no such job") else #This is a special job, that has to be terminated different prior to cleanup - driver.http_hook_server.stop if driver.jobs[val].name == "http_hook_server" - - print_line("Stopping job: #{val}...") - driver.jobs.stop_job(val) + if driver.jobs[val].name == "http_hook_server" + print_line("Nah uh uh - can't stop this job ya BeEF head!") + else + print_line("Stopping job: #{val}...") + driver.jobs.stop_job(val) + end end when "-l" cmd_jobs_list @@ -206,6 +208,16 @@ class Core return end + onlinezombies = [] + BeEF::Core::Models::HookedBrowser.all(:lastseen.gt => (Time.new.to_i - 30)).each do |zombie| + onlinezombies << zombie.id + end + + if not onlinezombies.include?(args[0].to_i) + print_status("Browser does not appear to be online..") + return false + end + if not driver.interface.settarget(args[0]).nil? if (driver.dispatcher_stack.size > 1 and @@ -239,6 +251,16 @@ class Core return end + offlinezombies = [] + BeEF::Core::Models::HookedBrowser.all(:lastseen.lt => (Time.new.to_i - 30)).each do |zombie| + offlinezombies << zombie.id + end + + if not offlinezombies.include?(args[0].to_i) + print_status("Browser does not appear to be offline..") + return false + end + if not driver.interface.setofflinetarget(args[0]).nil? if (driver.dispatcher_stack.size > 1 and driver.current_dispatcher.name != 'Core') diff --git a/extensions/console/lib/shellinterface.rb b/extensions/console/lib/shellinterface.rb index c49b585dd..07b489fe1 100644 --- a/extensions/console/lib/shellinterface.rb +++ b/extensions/console/lib/shellinterface.rb @@ -403,7 +403,7 @@ class ShellInterface end # set and add the System Platform - system_platform = BD.get(zombie_session, 'SystemPlatform') + system_platform = BD.get(self.targetsession, 'SystemPlatform') if not system_platform.nil? encoded_system_platform = CGI.escapeHTML(system_platform) encoded_system_platform_hash = { 'System Platform' => encoded_system_platform }