From 227418bd1157aa253726e876a9a2311bb21b57df Mon Sep 17 00:00:00 2001 From: James Lee Date: Mon, 8 Oct 2012 23:07:04 -0500 Subject: [PATCH 1/3] Make AR a soft dependency again Ensures that the absence of activerecord does not prevent msfconsole from loading. This returns us to the previous state of affairs where it is possible to use the framework entirely without a database. To test: 1. rm -rf lib/gemcache/ruby/1.9.1/gems/activerecord* 2. remove any locally installed versions of activerecord 3. msfconsole msfconsole should load up with a warning like so: [-] *** [-] * WARNING: No database support: LoadError cannot load such file -- active_record [-] *** ... and should still be functional. --- lib/msf/core/db_manager.rb | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/msf/core/db_manager.rb b/lib/msf/core/db_manager.rb index 63783a8005..f7d4fb0362 100644 --- a/lib/msf/core/db_manager.rb +++ b/lib/msf/core/db_manager.rb @@ -1,5 +1,4 @@ # -*- coding: binary -*- -require "active_record" require 'msf/core' require 'msf/core/db' @@ -7,14 +6,6 @@ require 'msf/core/task_manager' require 'fileutils' require 'shellwords' -# Provide access to ActiveRecord models shared w/ commercial versions -require "metasploit_data_models" - -# Patches issues with ActiveRecord -require "msf/core/patches/active_record" - - - module Msf ### @@ -36,16 +27,6 @@ class DBManager end end - # Only include Mdm if we're not using Metasploit commercial versions - # If Mdm::Host is defined, the dynamically created classes - # are already in the object space - begin - include MetasploitDataModels unless defined? Mdm::Host - rescue NameError => e - warn_about_rubies - raise e - end - # Provides :framework and other accessors include Framework::Offspring @@ -117,6 +98,14 @@ class DBManager # Database drivers can reset our KCODE, do not let them $KCODE = 'NONE' if RUBY_VERSION =~ /^1\.8\./ + require "active_record" + + # Provide access to ActiveRecord models shared w/ commercial versions + require "metasploit_data_models" + + # Patches issues with ActiveRecord + require "msf/core/patches/active_record" + @usable = true rescue ::Exception => e @@ -125,6 +114,16 @@ class DBManager return false end + # Only include Mdm if we're not using Metasploit commercial versions + # If Mdm::Host is defined, the dynamically created classes + # are already in the object space + begin + include MetasploitDataModels unless defined? Mdm::Host + rescue NameError => e + warn_about_rubies + raise e + end + # # Determine what drivers are available # From b3e27b16d5294dcd710a449e0054cfc3bf10dfdd Mon Sep 17 00:00:00 2001 From: James Lee Date: Tue, 9 Oct 2012 01:52:19 -0500 Subject: [PATCH 2/3] Derp, include is a class method --- lib/msf/core/db_manager.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/msf/core/db_manager.rb b/lib/msf/core/db_manager.rb index f7d4fb0362..e20c5f6576 100644 --- a/lib/msf/core/db_manager.rb +++ b/lib/msf/core/db_manager.rb @@ -19,7 +19,7 @@ class DBManager # Mainly, it's Ruby 1.9.1 that cause a lot of problems now, along with Ruby 1.8.6. # Ruby 1.8.7 actually seems okay, but why tempt fate? Let's say 1.9.3 and beyond. - def self.warn_about_rubies + def warn_about_rubies if ::RUBY_VERSION =~ /^1\.9\.[012]($|[^\d])/ $stderr.puts "**************************************************************************************" $stderr.puts "Metasploit requires at least Ruby 1.9.3. For an easy upgrade path, see https://rvm.io/" @@ -118,7 +118,9 @@ class DBManager # If Mdm::Host is defined, the dynamically created classes # are already in the object space begin - include MetasploitDataModels unless defined? Mdm::Host + unless defined? Mdm::Host + self.class.send :include, MetasploitDataModels + end rescue NameError => e warn_about_rubies raise e From 592851e15537203d59a520a6047a450166ff2a5a Mon Sep 17 00:00:00 2001 From: James Lee Date: Tue, 9 Oct 2012 02:05:08 -0500 Subject: [PATCH 3/3] Add requires for active_support deps in use Hash for #assert_valid_keys, Module for #parent. --- lib/msf/core/module_manager/module_paths.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/msf/core/module_manager/module_paths.rb b/lib/msf/core/module_manager/module_paths.rb index 3c50599fd8..83a9e87d92 100644 --- a/lib/msf/core/module_manager/module_paths.rb +++ b/lib/msf/core/module_manager/module_paths.rb @@ -2,6 +2,8 @@ # Gems # require 'active_support/concern' +require 'active_support/core_ext/hash' +require 'active_support/core_ext/module' # Deals with module paths in the {Msf::ModuleManager} module Msf::ModuleManager::ModulePaths