Browse Source

add -n (disable database) option for msfconsole, gives 33% startup time reduction

git-svn-id: file:///home/svn/framework3/trunk@9959 4d416f70-5f16-0410-b530-b9f4589650
Joshua Drake 9 years ago
parent
commit
53e2a010cd
4 changed files with 26 additions and 5 deletions
  1. 18
    2
      lib/msf/core/db_manager.rb
  2. 1
    1
      lib/msf/core/framework.rb
  3. 2
    2
      lib/msf/ui/console/driver.rb
  4. 5
    0
      msfconsole

+ 18
- 2
lib/msf/core/db_manager.rb View File

@@ -18,6 +18,7 @@ class DBManager
18 18
 
19 19
 	# Returns true if we are ready to load/store data
20 20
 	def active
21
+		return false if not @usable
21 22
 		(ActiveRecord::Base.connected? && ActiveRecord::Base.connection.active?)
22 23
 	end
23 24
 
@@ -36,11 +37,24 @@ class DBManager
36 37
 	# Stores a TaskManager for serializing database events
37 38
 	attr_accessor :sink
38 39
 
39
-	def initialize(framework)
40
+	def initialize(framework, opts = {})
40 41
 
41 42
 		self.framework = framework
42 43
 		@usable = false
43 44
 
45
+		# Don't load the database is the user said they didn't need it.
46
+		if (opts['DisableDatabase'])
47
+			self.error = "User Disabled Database Support"
48
+			return
49
+		end
50
+
51
+		initialize_database_support
52
+	end
53
+
54
+	#
55
+	# Do what is necessary to load our database support
56
+	#
57
+	def initialize_database_support
44 58
 		#
45 59
 		# Prefer our local copy of active_record and active_support
46 60
 		#
@@ -70,7 +84,7 @@ class DBManager
70 84
 		rescue ::Exception => e
71 85
 			self.error = e
72 86
 			elog("DB is not enabled due to load error: #{e}")
73
-			return
87
+			return false
74 88
 		end
75 89
 
76 90
 		#
@@ -82,6 +96,8 @@ class DBManager
82 96
 		# Instantiate the database sink
83 97
 		#
84 98
 		initialize_sink
99
+
100
+		true
85 101
 	end
86 102
 
87 103
 	#

+ 1
- 1
lib/msf/core/framework.rb View File

@@ -77,7 +77,7 @@ class Framework
77 77
 		self.datastore = DataStore.new
78 78
 		self.jobs      = Rex::JobContainer.new
79 79
 		self.plugins   = PluginManager.new(self)
80
-		self.db        = DBManager.new(self)
80
+		self.db        = DBManager.new(self, opts)
81 81
 
82 82
 		subscriber = FrameworkEventSubscriber.new(self)
83 83
 		events.add_exploit_subscriber(subscriber)

+ 2
- 2
lib/msf/ui/console/driver.rb View File

@@ -82,7 +82,7 @@ class Driver < Msf::Ui::Driver
82 82
 		load_preconfig
83 83
 
84 84
 		# Initialize attributes
85
-		self.framework = opts['Framework'] || Msf::Simple::Framework.create
85
+		self.framework = opts['Framework'] || Msf::Simple::Framework.create(opts)
86 86
 
87 87
 		# Initialize the user interface to use a different input and output
88 88
 		# handle if one is supplied
@@ -106,7 +106,7 @@ class Driver < Msf::Ui::Driver
106 106
 		end
107 107
 
108 108
 		# Add the database dispatcher if it is usable
109
-		if(framework.db.usable)
109
+		if (framework.db.usable)
110 110
 			require 'msf/ui/console/command_dispatcher/db'
111 111
 			enstack_dispatcher(CommandDispatcher::Db)
112 112
 		else

+ 5
- 0
msfconsole View File

@@ -66,6 +66,11 @@ class OptsConsole
66 66
 				options['RealReadline'] = true
67 67
 			end
68 68
 
69
+			# Boolean switch.
70
+			opts.on("-n", "--no-database", "Disable database support") do |v|
71
+				options['DisableDatabase'] = true
72
+			end
73
+
69 74
 			opts.separator ""
70 75
 			opts.separator "Common options:"
71 76
 

Loading…
Cancel
Save