Class: Arachni::Module::Registry

Inherits:
Object
  • Object
show all
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)

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

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

Parameters:

  • (String) mod_lib

    path the the module directory



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

Returns:



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

Returns:



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

Returns:

  • (Array<Hash>)


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

Returns:

  • (String)


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

Parameters:

  • (Object) obj

See Also:



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

Returns:



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

Returns:



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

Parameters:

  • (Array)


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

Parameters:

  • (Object) key

Returns:

  • (Object)

    the data under key

See Also:



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

Returns:

  • (Array<Hash>)


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.

Parameters:

  • (Array)


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

Parameters:

  • (String) name

    the name of the module

Returns:



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

Parameters:

  • (String) name

    the name of the module

Returns:

  • (String)

    the path of the 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

Returns:



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

Returns:

  • (Hash<Hash<String, String>>)


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

Returns:



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

Parameters:

  • (Integer) reg_id

Returns:

  • (Hash)

    the info of the module



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.

Parameters:

  • (String) mod_name

    the module to load

Returns:



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