From afcce8a511f74ae9e027b15fcbe95cdc9ee4c44d Mon Sep 17 00:00:00 2001 From: sinn3r Date: Tue, 22 Oct 2013 01:11:11 -0500 Subject: [PATCH] Merge osdetect and addonsdetect --- lib/msf/core/exploit/http/server.rb | 2 +- lib/rex/exploitation/js.rb | 5 +- lib/rex/exploitation/js/addonsdetect.rb | 30 ---------- lib/rex/exploitation/js/detect.rb | 56 +++++++++++++++++++ lib/rex/exploitation/js/osdetect.rb | 44 --------------- modules/auxiliary/server/browser_autopwn.rb | 5 +- .../rex/exploitation/js/addonsdetect_spec.rb | 16 ------ spec/lib/rex/exploitation/js/detect_spec.rb | 23 ++++++++ spec/lib/rex/exploitation/js/osdetect_spec.rb | 16 ------ 9 files changed, 85 insertions(+), 112 deletions(-) delete mode 100644 lib/rex/exploitation/js/addonsdetect.rb create mode 100644 lib/rex/exploitation/js/detect.rb delete mode 100644 lib/rex/exploitation/js/osdetect.rb delete mode 100644 spec/lib/rex/exploitation/js/addonsdetect_spec.rb create mode 100644 spec/lib/rex/exploitation/js/detect_spec.rb delete mode 100644 spec/lib/rex/exploitation/js/osdetect_spec.rb diff --git a/lib/msf/core/exploit/http/server.rb b/lib/msf/core/exploit/http/server.rb index 2267a01746..f185497061 100644 --- a/lib/msf/core/exploit/http/server.rb +++ b/lib/msf/core/exploit/http/server.rb @@ -810,7 +810,7 @@ protected end def js_os_detect - @cache_os_detect ||= ::Rex::Exploitation::Js::OSDetect.new + @cache_os_detect ||= ::Rex::Exploitation::Js::Detect.os end # Transmits a html response to the supplied client diff --git a/lib/rex/exploitation/js.rb b/lib/rex/exploitation/js.rb index 5847eeb290..721ecb824c 100644 --- a/lib/rex/exploitation/js.rb +++ b/lib/rex/exploitation/js.rb @@ -1,7 +1,6 @@ # -*- coding: binary -*- -require 'rex/exploitation/js/addonsdetect' require 'rex/exploitation/js/memory' require 'rex/exploitation/js/network' -require 'rex/exploitation/js/osdetect' -require 'rex/exploitation/js/utils' \ No newline at end of file +require 'rex/exploitation/js/utils' +require 'rex/exploitation/js/detect' \ No newline at end of file diff --git a/lib/rex/exploitation/js/addonsdetect.rb b/lib/rex/exploitation/js/addonsdetect.rb deleted file mode 100644 index af0aeed1dd..0000000000 --- a/lib/rex/exploitation/js/addonsdetect.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: binary -*- - -require 'msf/core' -require 'rex/text' -require 'rex/exploitation/jsobfu' - -module Rex -module Exploitation -module Js - -# -# Provides javascript functions to determine addon information. -# -# getMsOfficeVersion(): Returns the version for Microsoft Office -# -class AddonsDetect < JSObfu - - def initialize(custom_js = '', opts = {}) - @js = custom_js - @js += ::File.read(::File.join(Msf::Config.data_directory, "js", "detect", "addons.js")) - - super @js - - return @js - end - -end -end -end -end diff --git a/lib/rex/exploitation/js/detect.rb b/lib/rex/exploitation/js/detect.rb new file mode 100644 index 0000000000..c7f659f357 --- /dev/null +++ b/lib/rex/exploitation/js/detect.rb @@ -0,0 +1,56 @@ +# -*- coding: binary -*- + +require 'msf/core' +require 'rex/text' +require 'rex/exploitation/jsobfu' + +module Rex +module Exploitation +module Js + + +class Detect + + # + # Provides several javascript functions for determining the OS and browser versions of a client. + # + # getVersion(): returns an object with the following properties + # os_name - OS name, one of the Msf::OperatingSystems constants + # os_flavor - OS flavor as a string (e.g.: "XP", "2000") + # os_sp - OS service pack (e.g.: "SP2", will be empty on non-Windows) + # os_lang - OS language (e.g.: "en-us") + # ua_name - Client name, one of the Msf::HttpClients constants + # ua_version - Client version as a string (e.g.: "3.5.1", "6.0;SP2") + # arch - Architecture, one of the ARCH_* constants + # + # The following functions work on the version returned in obj.ua_version + # + # ua_ver_cmp(a, b): returns -1, 0, or 1 based on whether a < b, a == b, or a > b respectively + # ua_ver_lt(a, b): returns true if a < b + # ua_ver_gt(a, b): returns true if a > b + # ua_ver_eq(a, b): returns true if a == b + # + def self.os(custom_js = '') + js = custom_js + js << ::File.read(::File.join(Msf::Config.data_directory, "js", "detect", "os.js")) + + Rex::Exploitation::JSObfu.new(js) + end + + + # + # Provides javascript functions to determine addon information. + # + # getMsOfficeVersion(): Returns the version for Microsoft Office + # + def self.addons(custom_js = '') + js = custom_js + js << ::File.read(::File.join(Msf::Config.data_directory, "js", "detect", "addons.js")) + + Rex::Exploitation::JSObfu.new(js) + end + +end +end +end +end diff --git a/lib/rex/exploitation/js/osdetect.rb b/lib/rex/exploitation/js/osdetect.rb deleted file mode 100644 index 4ec67e5de1..0000000000 --- a/lib/rex/exploitation/js/osdetect.rb +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: binary -*- - -require 'msf/core' -require 'rex/text' -require 'rex/exploitation/jsobfu' - -module Rex -module Exploitation -module Js - -# -# Provides several javascript functions for determining the OS and browser versions of a client. -# -# getVersion(): returns an object with the following properties -# os_name - OS name, one of the Msf::OperatingSystems constants -# os_flavor - OS flavor as a string (e.g.: "XP", "2000") -# os_sp - OS service pack (e.g.: "SP2", will be empty on non-Windows) -# os_lang - OS language (e.g.: "en-us") -# ua_name - Client name, one of the Msf::HttpClients constants -# ua_version - Client version as a string (e.g.: "3.5.1", "6.0;SP2") -# arch - Architecture, one of the ARCH_* constants -# -# The following functions work on the version returned in obj.ua_version -# -# ua_ver_cmp(a, b): returns -1, 0, or 1 based on whether a < b, a == b, or a > b respectively -# ua_ver_lt(a, b): returns true if a < b -# ua_ver_gt(a, b): returns true if a > b -# ua_ver_eq(a, b): returns true if a == b -# -class OSDetect < JSObfu - - def initialize(custom_js = '', opts = {}) - @js = custom_js - @js += ::File.read(::File.join(Msf::Config.data_directory, "js", "detect", "os.js")) - - super @js - - return @js - end - -end -end -end -end diff --git a/modules/auxiliary/server/browser_autopwn.rb b/modules/auxiliary/server/browser_autopwn.rb index 8c0fc65116..a0fc5ea56e 100644 --- a/modules/auxiliary/server/browser_autopwn.rb +++ b/modules/auxiliary/server/browser_autopwn.rb @@ -9,7 +9,7 @@ # - caching is busted when different browsers come from the same IP require 'msf/core' -require 'rex/exploitation/js/osdetect' +require 'rex/exploitation/js/detect' require 'rex/exploitation/jsobfu' class Metasploit3 < Msf::Auxiliary @@ -171,7 +171,7 @@ class Metasploit3 < Msf::Auxiliary def setup print_status("Setup") - @init_js = ::Rex::Exploitation::Js::OSDetect.new <<-ENDJS + @init_js = ::Rex::Exploitation::Js::Detect.os(<<-ENDJS #{js_base64} @@ -223,6 +223,7 @@ class Metasploit3 < Msf::Auxiliary report_and_get_exploits(detected_version); } // function bodyOnLoad ENDJS + ) if (datastore['DEBUG']) print_debug("NOTE: Debug Mode; javascript will not be obfuscated") diff --git a/spec/lib/rex/exploitation/js/addonsdetect_spec.rb b/spec/lib/rex/exploitation/js/addonsdetect_spec.rb deleted file mode 100644 index 8b54379a99..0000000000 --- a/spec/lib/rex/exploitation/js/addonsdetect_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'rex/exploitation/js' - -describe Rex::Exploitation::Js::AddonsDetect do - - context "Class methods" do - - context ".initialize" do - it "should load the Addons Detect javascript" do - js = Rex::Exploitation::Js::AddonsDetect.new.to_s - js.should =~ /window\.addons_detect/ - end - end - - end - -end \ No newline at end of file diff --git a/spec/lib/rex/exploitation/js/detect_spec.rb b/spec/lib/rex/exploitation/js/detect_spec.rb new file mode 100644 index 0000000000..d029f0a5e1 --- /dev/null +++ b/spec/lib/rex/exploitation/js/detect_spec.rb @@ -0,0 +1,23 @@ +require 'rex/exploitation/js' + +describe Rex::Exploitation::Js::Detect do + + context "Class methods" do + + context ".os" do + it "should load the OS Detect javascript" do + js = Rex::Exploitation::Js::Detect.os.to_s + js.should =~ /window\.os_detect/ + end + end + + context ".addons" do + it "should load the Addons Detect javascript" do + js = Rex::Exploitation::Js::Detect.addons.to_s + js.should =~ /window\.addons_detect/ + end + end + + end + +end \ No newline at end of file diff --git a/spec/lib/rex/exploitation/js/osdetect_spec.rb b/spec/lib/rex/exploitation/js/osdetect_spec.rb deleted file mode 100644 index fa22cf9cf7..0000000000 --- a/spec/lib/rex/exploitation/js/osdetect_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'rex/exploitation/js' - -describe Rex::Exploitation::Js::OSDetect do - - context "Class methods" do - - context ".initialize" do - it "should load the OSDetect javascript" do - js = Rex::Exploitation::Js::OSDetect.new.to_s - js.should =~ /window\.os_detect/ - end - end - - end - -end \ No newline at end of file