Class: Arachni::Platform::Manager

Inherits:
Object
  • Object
show all
Extended by:
UI::Output, Utilities
Includes:
UI::Output, Utilities, Enumerable
Defined in:
lib/arachni/platform/manager.rb

Overview

Represents a collection of platform lists.

It also holds a DB of all fingerprints per URI as a class variable and provides helper method for accessing and manipulating it.

Author:

Constant Summary collapse

TYPES =
{
    os:         'Operating systems',
    db:         'Databases',
    servers:    'Web servers',
    languages:  'Programming languages',
    frameworks: 'Frameworks'
}
OS =
{
    # Generic *nix, flavor couldn't be identified.
    unix:    {
        linux:   {},

        # Generic BSD, flavor couldn't be identified.
        bsd:     {},
        solaris: {}
    },
    windows: {}
}
DB =
[
    :mysql,
    :pgsql,
    :mssql,
    :oracle,
    :sqlite,
    :emc,
    :db2,
    :coldfusion,
    :interbase,
    :informix,
    :firebird,
    :maxdb,
    :sybase,
    :frontbase,
    :ingres,
    :hsqldb,
    :access
]
SERVERS =
[
    :apache,
    :nginx,
    :tomcat,
    :iis,
    :jetty
]
LANGUAGES =
[
    :php,
    :jsp,
    :python,
    :ruby,
    :asp,
    :aspx,
    :perl
]
FRAMEWORKS =

WebApp frameworks.

[
    :rack
]
PLATFORM_NAMES =
{
    # Operating systems
    unix:       'Generic Unix family',
    linux:      'Linux',
    bsd:        'Generic BSD family',
    solaris:    'Solaris',
    windows:    'MS Windows',

    # Databases
    mysql:      'MySQL',
    pgsql:      'Postgresql',
    mssql:      'MSSQL',
    oracle:     'Oracle',
    sqlite:     'SQLite',
    emc:        'EMC',
    db2:        'DB2',
    coldfusion: 'ColdFusion',
    interbase:  'InterBase',
    informix:   'Informix',
    firebird:   'Firebird',
    maxdb:      'SaP Max DB',
    sybase:     'Sybase',
    frontbase:  'Frontbase',
    ingres:     'IngresDB',
    hsqldb:     'HSQLDB',
    access:     'MS Access',

    # Web servers
    apache:     'Apache',
    nginx:      'Nginx',
    tomcat:     'TomCat',
    iis:        'IIS',
    jetty:      'Jetty',

    # Programming languages
    php:    'PHP',
    jsp:    'JSP',
    python: 'Python',
    ruby:   'Ruby',
    asp:    'ASP',
    aspx:   'ASP.NET',
    perl:   'Perl',

    # Web frameworks
    rack:   'Rack'
}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

available_port, cookie_encode, cookies_from_document, cookies_from_file, cookies_from_response, exception_jail, exclude_path?, extract_domain, follow_protocol?, form_decode, form_encode, form_parse_request_body, forms_from_document, forms_from_response, generate_token, get_path, html_decode, html_encode, include_path?, links_from_document, links_from_response, normalize_url, page_from_response, page_from_url, parse_query, parse_set_cookie, parse_url_vars, path_in_domain?, path_too_deep?, port_available?, rand_port, redundant_path?, remove_constants, seed, skip_page?, skip_path?, skip_resource?, to_absolute, uri_decode, uri_encode, uri_parse, uri_parser, url_sanitize

Methods included from UI::Output

debug?, debug_off, debug_on, disable_only_positives, error_logfile, flush_buffer, log_error, mute, muted?, old_reset_output_options, only_positives, only_positives?, print_bad, print_debug, print_debug_backtrace, print_debug_pp, print_error, print_error_backtrace, print_info, print_line, print_ok, print_status, print_verbose, reroute_to_file, reroute_to_file?, reset_output_options, set_buffer_cap, set_error_logfile, uncap_buffer, unmute, verbose, verbose?

Methods included from Enumerable

#realsize

Constructor Details

#initialize(platforms = []) ⇒ Manager

Returns a new instance of Manager.

Parameters:

  • platforms (Array<String, Symbol>) (defaults to: [])

    Platforms with which to initialize the lists.



297
298
299
300
301
302
303
304
305
# File 'lib/arachni/platform/manager.rb', line 297

def initialize( platforms = [] )
    @platforms = {}
    TYPES.keys.each do |type|
        @platforms[type] =
            List.new( self.class.const_get( type.to_s.upcase.to_sym ) )
    end

    update [platforms | Options.platforms].flatten.compact
end

Class Method Details

.[](uri) ⇒ Manager

Returns Platform for the given ‘uri`.

Parameters:

Returns:

  • (Manager)

    Platform for the given ‘uri`



255
256
257
258
# File 'lib/arachni/platform/manager.rb', line 255

def self.[]( uri )
    return new if !(key = make_key( uri ))
    @platforms[key] ||= new
end

.[]=(uri, platforms) ⇒ Manager

Sets platform manager for the given ‘uri`.

Parameters:

Returns:

Raises:



235
236
237
238
239
# File 'lib/arachni/platform/manager.rb', line 235

def self.[]=( uri, platforms )
    return new( platforms ) if !(key = make_key( uri ))
    @platforms[key] =
        platforms.is_a?( self ) ? platforms : new( platforms )
end

.allHash<Integer, Platform>

Returns Platform per hashed URL.

Returns:



274
275
276
# File 'lib/arachni/platform/manager.rb', line 274

def self.all
    @platforms
end

.any?Boolean

Returns ‘true` if there are platforms fingerprints, `false` otherwise.

Returns:

  • (Boolean)

    ‘true` if there are platforms fingerprints, `false` otherwise.



268
269
270
# File 'lib/arachni/platform/manager.rb', line 268

def self.any?
    !empty?
end

.clearObject

Clears global platforms DB.



194
195
196
# File 'lib/arachni/platform/manager.rb', line 194

def self.clear
    @platforms.clear
end

.empty?Boolean

Returns ‘true` if there are no platforms fingerprints, `false` otherwise.

Returns:

  • (Boolean)

    ‘true` if there are no platforms fingerprints, `false` otherwise.



262
263
264
# File 'lib/arachni/platform/manager.rb', line 262

def self.empty?
    @platforms.empty?
end

.find_type(platform) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/arachni/platform/manager.rb', line 165

def self.find_type( platform )
    @find_type ||= {}

    if @find_type.empty?
        TYPES.keys.each do |type|

            platforms = const_get( type.to_s.upcase.to_sym )
            platforms = platforms.find_symbol_keys_recursively if platforms.is_a?( Hash )

            platforms.each do |p|
                @find_type[p] = type
            end
        end
    end

    @find_type[platform]
end

.fingerprint(page) ⇒ Manager

Runs all fingerprinters against the given ‘page`.

Parameters:

  • page (Page)

    Page to fingerprint.

Returns:



218
219
220
221
222
223
224
225
# File 'lib/arachni/platform/manager.rb', line 218

def self.fingerprint( page )
    fingerprinters.available.each do |name|
        exception_jail( false ) do
            fingerprinters[name].new( page ).run
        end
    end
    page
end

.fingerprintersObject



207
208
209
210
211
# File 'lib/arachni/platform/manager.rb', line 207

def self.fingerprinters
    @manager ||=
        Component::Manager.new( Options.dir['fingerprinters'],
                                Platform::Fingerprinters )
end

.lightHash{Integer=>Array<Symbol>}

Returns Light representation of the fingerprint DB with URL hashes as keys and arrays of symbols for platforms as values.

Returns:

  • (Hash{Integer=>Array<Symbol>})

    Light representation of the fingerprint DB with URL hashes as keys and arrays of symbols for platforms as values.



281
282
283
# File 'lib/arachni/platform/manager.rb', line 281

def self.light
    all.inject({}) { |h, (k, v)| h[k] = v.to_a; h }
end

.resetObject

Empties the global platform fingerprints.



199
200
201
202
203
204
# File 'lib/arachni/platform/manager.rb', line 199

def self.reset
    set Hash.new
    @manager.clear if @manager
    @manager = nil
    self
end

.set(platforms) ⇒ Object

Sets global platforms fingerprints



189
190
191
# File 'lib/arachni/platform/manager.rb', line 189

def self.set( platforms )
    @platforms = platforms
end

.update(uri, platforms) ⇒ Manager

Updates the ‘platforms` for the given `uri`.

Parameters:

Returns:

Raises:



249
250
251
# File 'lib/arachni/platform/manager.rb', line 249

def self.update( uri, platforms )
    self[uri].update platforms
end

.update_light(light_platforms) ⇒ Manager

Parameters:

  • light_platforms (Hash{Integer=>Array<Symbol>})

    Return value of light.

Returns:



288
289
290
291
292
293
# File 'lib/arachni/platform/manager.rb', line 288

def self.update_light( light_platforms )
    light_platforms.each do |url, platforms|
        @platforms[url] ||= new( platforms )
    end
    self
end

.validObject



183
184
185
# File 'lib/arachni/platform/manager.rb', line 183

def self.valid
    @valid ||= Set.new( PLATFORM_NAMES.keys )
end

Instance Method Details

#<<(platform) ⇒ Manager

Returns ‘self`.

Parameters:

  • platform (Symbol, String)

    Platform to add to the appropriate list.

Returns:

Raises:



439
440
441
442
# File 'lib/arachni/platform/manager.rb', line 439

def <<( platform )
    find_list( platform ) << platform
    self
end

#any?Boolean

Returns ‘true` if there are applicable platforms, `false` otherwise.

Returns:

  • (Boolean)

    ‘true` if there are applicable platforms, `false` otherwise.



423
424
425
# File 'lib/arachni/platform/manager.rb', line 423

def any?
    !empty?
end

#dbList

Returns Platform list for databases.

Returns:

  • (List)

    Platform list for databases.

See Also:



# File 'lib/arachni/platform/manager.rb', line 311

#each(&block) ⇒ Enumerator, Manager

Returns ‘Enumerator` if no `block` is given, `self` otherwise.

Parameters:

  • block (Block)

    Block to be passed each platform.

Returns:

  • (Enumerator, Manager)

    ‘Enumerator` if no `block` is given, `self` otherwise.



401
402
403
404
405
# File 'lib/arachni/platform/manager.rb', line 401

def each( &block )
    return enum_for( __method__ ) if !block_given?
    @platforms.map { |_, p| p.to_a }.flatten.each( &block )
    self
end

#empty?Boolean

Returns ‘true` if there are no applicable platforms, `false` otherwise.

Returns:

  • (Boolean)

    ‘true` if there are no applicable platforms, `false` otherwise.



417
418
419
# File 'lib/arachni/platform/manager.rb', line 417

def empty?
    !@platforms.map { |_, p| p.empty? }.include?( false )
end

#find_list(platform) ⇒ List

Returns Platform list.

Parameters:

  • platform (String, Symbol)

    Platform whose list to find.

Returns:

  • (List)

    Platform list.



453
454
455
# File 'lib/arachni/platform/manager.rb', line 453

def find_list( platform )
    @platforms[find_type( normalize( platform ) )]
end

#find_type(platform) ⇒ Symbol

Returns Platform type.

Parameters:

  • platform (String, Symbol)

    Platform whose type to find

Returns:

  • (Symbol)

    Platform type.



447
448
449
# File 'lib/arachni/platform/manager.rb', line 447

def find_type( platform )
    self.class.find_type( platform )
end

#frameworksList

Returns Platform list for frameworks.

Returns:

  • (List)

    Platform list for frameworks.

See Also:



327
328
329
330
331
# File 'lib/arachni/platform/manager.rb', line 327

[:os, :db, :servers, :languages, :frameworks].each do |type|
    define_method type do
        @platforms[type]
    end
end

#fullname(platform) ⇒ String

Converts a platform shortname to a full name.

Parameters:

  • platform (String, Symbol)

    Platform shortname.

Returns:

Raises:



340
341
342
# File 'lib/arachni/platform/manager.rb', line 340

def fullname( platform )
    PLATFORM_NAMES[normalize( platform )]
end

#include?(platform) ⇒ Boolean

Returns ‘true` if one of the lists contains the `platform`, `false` otherwise.

Parameters:

  • platform (Symbol, String)

    Platform to check.

Returns:

  • (Boolean)

    ‘true` if one of the lists contains the `platform`, `false` otherwise.

Raises:



411
412
413
# File 'lib/arachni/platform/manager.rb', line 411

def include?( platform )
    find_list( platform ).include?( platform )
end

#invalid?(platform) ⇒ Boolean

Returns ‘true` if platform is invalid (i.e. not in #valid), `false` otherwise.

Parameters:

  • platform (Symbol, String)

    Platform to check.

Returns:

  • (Boolean)

    ‘true` if platform is invalid (i.e. not in #valid), `false` otherwise.

See Also:



394
395
396
# File 'lib/arachni/platform/manager.rb', line 394

def invalid?( platform )
    !valid?( platform )
end

#languagesList

Returns Platform list for languages.

Returns:

  • (List)

    Platform list for languages.

See Also:



# File 'lib/arachni/platform/manager.rb', line 319

#osList

Returns Platform list for operating systems.

Returns:

  • (List)

    Platform list for operating systems.

See Also:



# File 'lib/arachni/platform/manager.rb', line 307

#pick(data_per_platform) ⇒ Hash

Selects appropriate data, depending on the applicable platforms, from ‘data_per_platform`.

Parameters:

  • data_per_platform (Hash{<Symbol, String> => Object})

    Hash with platform names as keys and arbitrary data as values.

Returns:

  • (Hash)

    ‘data_per_platform` with non-applicable entries (for non-empty platform lists) removed. Data for platforms whose list is empty will not be removed.

Raises:



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/arachni/platform/manager.rb', line 354

def pick( data_per_platform )
    data_per_list = {}
    data_per_platform.each do |platform, value|
        list = find_list( platform )
        data_per_list[list]           ||= {}
        data_per_list[list][platform]   = value
    end

    picked = {}
    data_per_list.each do |list, data|
        # If a platform list is empty pass the given data without picking...
        if list.empty?
            picked.merge! data
            next
        end

        # ...otherwise enforce its platform restrictions.
        picked.merge! list.pick( data )
    end

    picked
end

#serversList

Returns Platform list for web servers.

Returns:

  • (List)

    Platform list for web servers.

See Also:



# File 'lib/arachni/platform/manager.rb', line 315

#update(enum) ⇒ Manager

Returns Updated ‘self`.

Parameters:

  • enum (Enumerable)

    Enumerable object containing platforms.

Returns:

Raises:



430
431
432
433
# File 'lib/arachni/platform/manager.rb', line 430

def update( enum )
    enum.each { |p| self << p }
    self
end

#validSet<Symbol>

Returns List of valid platforms.

Returns:

  • (Set<Symbol>)

    List of valid platforms.



378
379
380
# File 'lib/arachni/platform/manager.rb', line 378

def valid
    self.class.valid
end

#valid?(platform) ⇒ Boolean

Returns ‘true` if platform is valid (i.e. in #valid), `false` otherwise.

Parameters:

  • platform (Symbol, String)

    Platform to check.

Returns:

  • (Boolean)

    ‘true` if platform is valid (i.e. in #valid), `false` otherwise.

See Also:



386
387
388
# File 'lib/arachni/platform/manager.rb', line 386

def valid?( platform )
    valid.include? platform
end