diff --git a/lib/constants.rb b/lib/constants.rb index 3f147fd01..4288cc78a 100644 --- a/lib/constants.rb +++ b/lib/constants.rb @@ -23,13 +23,14 @@ module Constants module Browsers - FF = 'FF' # Firefox - M = 'M' # Mozila - IE = 'IE' # Internet Explorer - S = 'S' # Safari - K = 'K' # Konqueror - C = 'C' # Chrome - ALL = 'ALL' # ALL + FF = 'FF' # Firefox + M = 'M' # Mozila + IE = 'IE' # Internet Explorer + S = 'S' # Safari + K = 'K' # Konqueror + C = 'C' # Chrome + ALL = 'ALL' # ALL + UNKNOWN = 'UNKNOWN' # Unknown FRIENDLY_FF_NAME = 'Firefox' FRIENDLY_M_NAME = 'Mozila' @@ -51,7 +52,6 @@ module Constants end - end # The User Agent strings for browser detection @@ -83,8 +83,8 @@ module Constants OS_LINUX_IMG = 'linux.png' OS_MAC_UA_STR = 'Mac' OS_MAC_IMG = 'mac.png' - OS_IPHONE_UA_STR = 'iPhone' - OS_IPHONE_IMG = 'iphone.png' + OS_IPHONE_UA_STR = 'iPhone' + OS_IPHONE_IMG = 'iphone.png' end diff --git a/lib/modules/command.rb b/lib/modules/command.rb index 6924398c3..b87b07463 100644 --- a/lib/modules/command.rb +++ b/lib/modules/command.rb @@ -39,11 +39,12 @@ module BeEF BD = BeEF::Models::BrowserDetails - ALL = BeEF::Constants::Browsers::ALL - IE = BeEF::Constants::Browsers::IE - S = BeEF::Constants::Browsers::S - FF = BeEF::Constants::Browsers::FF - C = BeEF::Constants::Browsers::C + UNKNOWN = BeEF::Constants::Browsers::UNKNOWN + ALL = BeEF::Constants::Browsers::ALL + IE = BeEF::Constants::Browsers::IE + S = BeEF::Constants::Browsers::S + FF = BeEF::Constants::Browsers::FF + C = BeEF::Constants::Browsers::C VERIFIED_WORKING = BeEF::Constants::CommandModule::MODULE_TARGET_VERIFIED_WORKING VERIFIED_NOT_WORKING = BeEF::Constants::CommandModule::MODULE_TARGET_VERIFIED_NOT_WORKING @@ -136,6 +137,7 @@ module BeEF return VERIFIED_UNKNOWN if not @target # no target specified in the module + # loop through each definition and check it @target.each {|definition| return definition['verified_status'] if test_target(definition) } @@ -146,37 +148,59 @@ module BeEF # test if the target definition matches the hooked browser # this function is used when determining the code of the node icon - def test_target(target_definition) - # if the target is not set in the module return unknown - return false if target_definition.nil? - # return false if not target_definition[0]['browser_name'] - return false if target_definition['browser_name'].nil? + def test_target_attribute(hb_attr_name, hb_attr_ver, target_attr_name, target_attr_max_ver, target_attr_min_ver) - # retrieve the target browser name - browser_name = get_browser_detail('BrowserName') - return false if browser_name.eql? 'UNKNOWN' or browser_name.nil? + # check if wild cards are set + return true if not target_attr_name + return true if target_attr_name.nil? + return true if target_attr_name.eql? ALL + + # can't answer based on hb_attr_name + return false if not hb_attr_name + return false if hb_attr_name.nil? + return false if hb_attr_name.eql? UNKNOWN - # check if the browser is targeted - all_browsers_targeted = target_definition['browser_name'].eql? BeEF::Constants::Browsers::ALL - target_browser_matches = browser_name.eql? target_definition['browser_name'] - return false if not (target_browser_matches || all_browsers_targeted) + # check if the attribute is targeted + return false if not target_attr_name.eql? hb_attr_name - # assume that the browser_maxver and browser_minver were excluded - return true if target_definition['browser_maxver'].nil? && target_definition['browser_minver'].nil? + # assume that the max version and min version were purposefully excluded + return true if target_attr_max_ver.nil? && target_attr_min_ver.nil? - # check if the browser version is targeted - browser_version = get_browser_detail('BrowserVersion') - browser_version = 'UNKNOWN' if browser_version.nil? - return false if browser_version.eql? 'UNKNOWN' + # check if the framework can detect hb version + return false if hb_attr_ver.eql? 'UNKNOWN' - # check the browser version number is within range - return false if browser_version.to_f > target_definition['browser_maxver'].to_f - return false if browser_version.to_f < target_definition['browser_minver'].to_f + # check the version number is within range + return false if hb_attr_ver.to_f > target_attr_max_ver.to_f + return false if hb_attr_ver.to_f < target_attr_min_ver.to_f - # all the checks passed and this module targets the user agent + # all the checks passed true end + # test if the target definition matches the hooked browser + # this function is used when determining the code of the node icon + def test_target(target_definition) + + # if the definition is nill we don't know + return false if target_definition.nil? + + # check if the browser is a target + hb_browser_name = get_browser_detail('BrowserName') + hb_browser_version = get_browser_detail('BrowserVersion') + target_browser_name = target_definition['browser_name'] + target_browser_max_ver = target_definition['browser_maxver'] + target_browser_min_ver = target_definition['browser_minver'] + browser_match = test_target_attribute(hb_browser_name, hb_browser_version, target_browser_name, target_browser_max_ver, target_browser_min_ver) + + # check if the operating system is a target + hb_os_name = get_browser_detail('OSName') + target_os_name = target_definition['os_name'] + os_match = test_target_attribute(hb_os_name, nil, target_os_name, nil, nil) + + return browser_match && os_match + + end + # Store the browser detail in the database. def set_browser_detail(key, value) raise WEBrick::HTTPStatus::BadRequest, "@session_id is invalid" if not BeEF::Filter.is_valid_hook_session_id?(@session_id) diff --git a/modules/commands/browser/site_redirect/site_redirect.rb b/modules/commands/browser/site_redirect/site_redirect.rb index 86a90d9dd..97dd435ef 100644 --- a/modules/commands/browser/site_redirect/site_redirect.rb +++ b/modules/commands/browser/site_redirect/site_redirect.rb @@ -17,9 +17,9 @@ class Site_redirect < BeEF::Command }) set_target({ - 'verified_status' => VERIFIED_WORKING, - 'browser_name' => ALL - }) + 'verified_status' => VERIFIED_USER_NOTIFY, + 'browser_name' => ALL + }) use_template! end diff --git a/modules/commands/browser/site_redirect_iframe/site_redirect_iframe.rb b/modules/commands/browser/site_redirect_iframe/site_redirect_iframe.rb index 9a0679318..33730effb 100644 --- a/modules/commands/browser/site_redirect_iframe/site_redirect_iframe.rb +++ b/modules/commands/browser/site_redirect_iframe/site_redirect_iframe.rb @@ -23,7 +23,7 @@ class Site_redirect_iframe < BeEF::Command }) set_target({ - 'verified_status' => VERIFIED_WORKING, + 'verified_status' => VERIFIED_USER_NOTIFY, 'browser_name' => ALL }) diff --git a/modules/commands/misc/alert_dialog/alert_dialog.rb b/modules/commands/misc/alert_dialog/alert_dialog.rb index 0fe40ec54..b9d42bbfb 100644 --- a/modules/commands/misc/alert_dialog/alert_dialog.rb +++ b/modules/commands/misc/alert_dialog/alert_dialog.rb @@ -19,8 +19,8 @@ class Alert_dialog < BeEF::Command }) set_target({ - 'verified_status' => VERIFIED_WORKING, - 'browser_name' => ALL + 'verified_status' => VERIFIED_USER_NOTIFY, + 'browser_name' => ALL }) # This tells the framework to use the file 'alert.js' as the command module instructions. diff --git a/modules/commands/misc/deface_web_page/deface_web_page.rb b/modules/commands/misc/deface_web_page/deface_web_page.rb index 7ca6a8c10..e03233cea 100644 --- a/modules/commands/misc/deface_web_page/deface_web_page.rb +++ b/modules/commands/misc/deface_web_page/deface_web_page.rb @@ -28,7 +28,7 @@ class Deface_web_page < BeEF::Command }) set_target({ - 'verified_status' => VERIFIED_WORKING, + 'verified_status' => VERIFIED_USER_NOTIFY, 'browser_name' => ALL }) diff --git a/modules/commands/misc/prompt_dialog/prompt_dialog.rb b/modules/commands/misc/prompt_dialog/prompt_dialog.rb index 487c5be75..733d9e28d 100644 --- a/modules/commands/misc/prompt_dialog/prompt_dialog.rb +++ b/modules/commands/misc/prompt_dialog/prompt_dialog.rb @@ -15,8 +15,8 @@ class Prompt_dialog < BeEF::Command }) set_target({ - 'verified_status' => VERIFIED_WORKING, - 'browser_name' => ALL + 'verified_status' => VERIFIED_USER_NOTIFY, + 'browser_name' => ALL }) use_template! diff --git a/modules/commands/persistence/popunder_window/popunder_window.rb b/modules/commands/persistence/popunder_window/popunder_window.rb index 2c4274a25..6b651b845 100644 --- a/modules/commands/persistence/popunder_window/popunder_window.rb +++ b/modules/commands/persistence/popunder_window/popunder_window.rb @@ -18,7 +18,7 @@ class Popunder_window < BeEF::Command }) set_target({ - 'verified_status' => VERIFIED_WORKING, + 'verified_status' => VERIFIED_USER_NOTIFY, 'browser_name' => ALL })