-
Notifications
You must be signed in to change notification settings - Fork 14k
/
framework.rb
186 lines (150 loc) · 4.26 KB
/
framework.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# -*- coding: binary -*-
require 'msf/base/simple'
require 'msf/base/simple/framework/module_paths'
module Msf
module Simple
###
#
# This class wraps the framework-core supplied Framework class and adds some
# helper methods for analyzing statistics as well as other potentially useful
# information that is directly necessary to drive the framework-core.
#
###
module Framework
include Msf::Simple::Framework::ModulePaths
###
#
# Extends the framework.plugins class instance to automatically check in
# the framework plugin's directory.
#
###
module PluginManager
#
# Loads the supplied plugin by checking to see if it exists in the
# framework default plugin path as necessary.
#
def load(path, opts = {})
def_path = Msf::Config.plugin_directory + File::SEPARATOR + path
if (File.exists?(def_path) or File.exists?(def_path + ".rb"))
super(def_path, opts)
else
super
end
end
end
#
# We extend modules when we're created, and we do it by registering a
# general event subscriber.
#
include GeneralEventSubscriber
#
# Simplifies module instances when they're created.
#
def on_module_created(instance)
Msf::Simple::Framework.simplify_module(instance)
end
ModuleSimplifiers =
{
MODULE_ENCODER => Msf::Simple::Encoder,
MODULE_EXPLOIT => Msf::Simple::Exploit,
MODULE_NOP => Msf::Simple::Nop,
MODULE_PAYLOAD => Msf::Simple::Payload,
MODULE_AUX => Msf::Simple::Auxiliary,
MODULE_POST => Msf::Simple::Post,
}
#
# Create a simplified instance of the framework. This routine takes a hash
# of parameters as an argument. This hash can contain:
#
# OnCreateProc => A callback procedure that is called once the framework
# instance is created.
#
def self.create(opts = {})
framework = Msf::Framework.new(opts)
return simplify(framework, opts)
end
#
# Extends a framework object that may already exist.
#
def self.simplify(framework, opts)
# If the framework instance has not already been extended, do it now.
if (framework.kind_of?(Msf::Simple::Framework) == false)
framework.extend(Msf::Simple::Framework)
framework.plugins.extend(Msf::Simple::Framework::PluginManager)
end
# Initialize the simplified framework
framework.init_simplified()
# Call the creation procedure if one was supplied
if (opts['OnCreateProc'])
opts['OnCreateProc'].call(framework)
end
# Change to a different configuration path if requested
if opts['ConfigDirectory']
Msf::Config::Defaults['ConfigDirectory'] = opts['ConfigDirectory']
end
# Initialize configuration and logging
Msf::Config.init
Msf::Logging.init
# Load the configuration
framework.load_config
# Register the framework as its own general event subscriber in this
# instance
framework.events.add_general_subscriber(framework)
unless opts['DeferModuleLoads']
framework.init_module_paths
end
return framework
end
#
# Simplifies a module instance if the type is supported by extending it
# with the simplified module interface.
#
def self.simplify_module(instance, load_saved_config = true)
if ((ModuleSimplifiers[instance.type]) and
(instance.class.include?(ModuleSimplifiers[instance.type]) == false))
instance.extend(ModuleSimplifiers[instance.type])
instance.init_simplified(load_saved_config)
end
end
##
#
# Simplified interface
#
##
#
# Initializes the simplified interface.
#
def init_simplified
self.stats = Statistics.new(self)
end
#
# Loads configuration, populates the root datastore, etc.
#
def load_config
self.datastore.from_file(Msf::Config.config_file, 'framework/core')
end
#
# Saves the module's datastore to the file
#
def save_config
self.datastore.to_file(Msf::Config.config_file, 'framework/core')
end
#
# Statistics.
#
attr_reader :stats
#
# Boolean indicating whether the cache is initialized yet
#
attr_reader :cache_initialized
#
# Thread of the running rebuild operation
#
attr_reader :cache_thread
attr_writer :cache_initialized # :nodoc:
attr_writer :cache_thread # :nodoc:
protected
attr_writer :stats # :nodoc:
end
end
end