Class: Arachni::Module::Registry
- Inherits:
-
Object
- Object
- Arachni::Module::Registry
- Includes:
- Arachni::UI::Output
- Defined in:
- lib/module/registry.rb
Overview
Arachni::Module::Registry class
Holds and manages the registry of the modules, their results and their shared datastore.
It also provides methods for getting modules’ info, listing available modules etc.
@author: Anastasios “Zapotek” Laskos
<tasos.laskos@gmail.com> <zapotek@segfault.gr>
@version: 0.1-pre
Class Attribute Summary (collapse)
-
+ (Array<Module>) module_registry
readonly
Class variable.
-
+ (Array<Vulnerability>) module_results
readonly
Class variable.
-
+ (Array<Hash>) module_storage
readonly
Class variable.
Instance Attribute Summary (collapse)
-
- (String) mod_lib
readonly
Path to the module directory.
Class Method Summary (collapse)
-
+ (Object) add_storage(obj)
Stores an object regulated by Registrar#add_storage in @@module_storage.
-
+ (Object) clean
Un-registers all modules.
-
+ (Array<Arachni::Module>) clean_up
Class method.
-
+ (Array<Arachni::Module>) get_registry
Class method.
-
+ (Object) get_results
Class method.
-
+ (Object) get_storage(key)
Gets data from storage by key, regulated by Registrar#get_storage.
-
+ (Array<Hash>) get_store
Gets the entire storage array.
-
+ (Object) register(mod)
Registers a module with the framework.
-
+ (Object) register_results(results)
Class method.
Instance Method Summary (collapse)
-
- (Arachni::Module) get_module_by_name(name)
Gets a module by its filename, without the extension.
-
- (String) get_path_from_name(name)
Gets the path of the specified module.
-
- (Array<Arachni::Module>) get_registry
Lists the loaded modules.
-
- (Registry) initialize(mod_lib)
constructor
Initializes Arachni::Module::Registry with the module library.
- - (Object) ls(type)
- - (Object) ls_audit
-
- (Hash<Hash<String, String>>) ls_available
Lists all available modules and puts them in a Hash.
-
- (Array<Arachni::Module>) ls_loaded
Lists the loaded modules.
- - (Object) ls_recon
-
- (Hash) mod_info(reg_id)
Grabs the information of a module based on its ID in the @@module_registry.
-
- (Arachni::Module) mod_load(mod_name)
Loads and registers a module by it’s filename, without the extension It also takes care of its dependencies.
Methods included from Arachni::UI::Output
#debug!, #debug?, #only_positives!, #only_positives?, #print_debug, #print_debug_backtrace, #print_debug_pp, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #verbose!, #verbose?
Constructor Details
- (Registry) initialize(mod_lib)
Initializes Arachni::Module::Registry with the module library
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/module/registry.rb', line 76 def initialize( mod_lib ) @mod_lib = mod_lib @@module_registry = [] @@module_results = [] @@module_storage = Hash.new @available_mods = Hash.new end |
Class Attribute Details
+ (Array<Module>) module_registry (readonly)
Class variable
Array of module objects
49 50 51 |
# File 'lib/module/registry.rb', line 49 def module_registry @module_registry end |
+ (Array<Vulnerability>) module_results (readonly)
Class variable
Array of Arachni::Vulnerability instances discovered by modules
58 59 60 |
# File 'lib/module/registry.rb', line 58 def module_results @module_results end |
+ (Array<Hash>) module_storage (readonly)
Class variable
Array of module data
67 68 69 |
# File 'lib/module/registry.rb', line 67 def module_storage @module_storage end |
Instance Attribute Details
- (String) mod_lib (readonly)
Path to the module directory
38 39 40 |
# File 'lib/module/registry.rb', line 38 def mod_lib @mod_lib end |
Class Method Details
+ (Object) add_storage(obj)
Stores an object regulated by Arachni::Module::Registrar#add_storage in @@module_storage
TODO: this isn’t smart, classify it by module name instead
288 289 290 |
# File 'lib/module/registry.rb', line 288 def Registry.add_storage( obj ) @@module_storage.merge( obj ) end |
+ (Object) clean
Un-registers all modules
232 233 234 |
# File 'lib/module/registry.rb', line 232 def Registry.clean( ) @@module_registry = [] end |
+ (Array<Arachni::Module>) clean_up
Class method
Cleans the registry from boolean values passed with the Arachni::Module::Base objects and updates it
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/module/registry.rb', line 326 def Registry.clean_up( ) clean_reg = [] @@module_registry.each { |mod| begin if mod < Arachni::Module::Base clean_reg << mod end rescue Exception => e end } @@module_registry = clean_reg end |
+ (Array<Arachni::Module>) get_registry
Class method
Lists the loaded modules
243 244 245 |
# File 'lib/module/registry.rb', line 243 def Registry.get_registry( ) @@module_registry.uniq end |
+ (Object) get_results
Class method
Gets module results
265 266 267 |
# File 'lib/module/registry.rb', line 265 def Registry.get_results( ) @@module_results end |
+ (Object) get_storage(key)
Gets data from storage by key, regulated by Registrar#get_storage
302 303 304 305 306 307 |
# File 'lib/module/registry.rb', line 302 def Registry.get_storage( key ) @@module_storage.each { |item| if( item.keys[0] == key ) then return item[key] end } end |
+ (Array<Hash>) get_store
Gets the entire storage array
314 315 316 |
# File 'lib/module/registry.rb', line 314 def Registry.get_store( ) @@module_storage end |
+ (Object) register(mod)
Registers a module with the framework
Used by the Registrar only
224 225 226 227 |
# File 'lib/module/registry.rb', line 224 def Registry.register( mod ) @@module_registry << mod Registry.clean_up( ) end |
+ (Object) register_results(results)
Class method
Registers module results with…well..us.
254 255 256 |
# File 'lib/module/registry.rb', line 254 def Registry.register_results( results ) @@module_results += results end |
Instance Method Details
- (Arachni::Module) get_module_by_name(name)
Gets a module by its filename, without the extension
195 196 197 198 199 200 201 |
# File 'lib/module/registry.rb', line 195 def get_module_by_name( name ) begin load( get_path_from_name( name ) ) rescue Exception => e raise e end end |
- (String) get_path_from_name(name)
Gets the path of the specified module
210 211 212 213 214 215 216 217 |
# File 'lib/module/registry.rb', line 210 def get_path_from_name( name ) begin ls_available( )[name]['path'].to_s rescue Exception => e raise( Arachni::Exceptions::ModNotFound, "Module '#{mod_name}' not found." ) end end |
- (Array<Arachni::Module>) get_registry
Lists the loaded modules
274 275 276 |
# File 'lib/module/registry.rb', line 274 def get_registry( ) Registry.get_registry( ) end |
- (Object) ls(type)
116 117 118 |
# File 'lib/module/registry.rb', line 116 def ls( type ) Dir.glob( @mod_lib + "#{type}/" + '*.rb' ) end |
- (Object) ls_audit
112 113 114 |
# File 'lib/module/registry.rb', line 112 def ls_audit ls( "audit" ) end |
- (Hash<Hash<String, String>>) ls_available
Lists all available modules and puts them in a Hash
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/module/registry.rb', line 92 def ls_available( ) (ls_recon | ls_audit).each { |class_path| filename = class_path.gsub( Regexp.escape( @mod_lib ) , '' ) filename = filename.gsub( /(recon|audit)\// , '' ) filename.gsub!( Regexp.new( '.rb' ) , '' ) @available_mods[filename] = Hash.new @available_mods[filename]['path'] = class_path } @available_mods end |
- (Array<Arachni::Module>) ls_loaded
Lists the loaded modules
149 150 151 |
# File 'lib/module/registry.rb', line 149 def ls_loaded( ) get_registry end |
- (Object) ls_recon
108 109 110 |
# File 'lib/module/registry.rb', line 108 def ls_recon ls( "recon" ) end |
- (Hash) mod_info(reg_id)
Grabs the information of a module based on its ID in the @@module_registry
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/module/registry.rb', line 128 def mod_info( reg_id ) @@module_registry.each_with_index { |mod, i| if i == reg_id info = mod.info if( mod.methods.index( :deps ) ) info = info.merge( { 'Dependencies' => mod.deps } ) end return info end } end |
- (Arachni::Module) mod_load(mod_name)
Loads and registers a module by it’s filename, without the extension It also takes care of its dependencies.
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 186 |
# File 'lib/module/registry.rb', line 161 def mod_load( mod_name ) Registry.register( get_module_by_name( mod_name ) ) # grab the module we just registered mod = @@module_registry[-1] # if it doesn't have any dependencies we're done if( !mod.methods.index( :deps ) ) then return end # go through its dependencies and load them recursively mod.deps.each { |dep_mod| if ( !dep_mod ) then next end begin mod_load( dep_mod ) rescue Exception => e raise( Arachni::Exceptions::DepModNotFound, "In '#{mod_name}' dependencies: " + e.to_s ) end } end |