Class: Arachni::Check::Manager

Inherits:
Arachni::Component::Manager show all
Defined in:
lib/arachni/check/manager.rb

Overview

Manages and runs Arachni::Checks against Pages.

Author:

Defined Under Namespace

Classes: Error

Constant Summary collapse

NAMESPACE =

Namespace under which all checks reside.

::Arachni::Checks

Constants inherited from Arachni::Component::Manager

Arachni::Component::Manager::EXCLUDE, Arachni::Component::Manager::WILDCARD

Instance Attribute Summary

Attributes inherited from Arachni::Component::Manager

#lib, #namespace

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Arachni::Component::Manager

#available, #clear, #delete, #include?, #load, #load_all, #load_by_tags, #loaded, #matches_glob?, #matches_globs?, #name_to_path, #parse, #path_to_name, #paths, #prepare_options

Methods included from Arachni::Component::Utilities

#read_file

Methods included from Utilities

#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_file, #cookies_from_parser, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_parser, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_parser, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite

Methods included from UI::Output

#caller_location, #debug?, #debug_level, #debug_level_1?, #debug_level_2?, #debug_level_3?, #debug_level_4?, #debug_off, #debug_on, #disable_only_positives, #error_buffer, #error_log_fd, #error_logfile, #has_error_log?, #included, #log_error, #mute, #muted?, #only_positives, #only_positives?, #print_bad, #print_debug, #print_debug_backtrace, #print_debug_exception, #print_debug_level_1, #print_debug_level_2, #print_debug_level_3, #print_debug_level_4, #print_error, #print_error_backtrace, #print_exception, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?, reset_output_options, #set_error_logfile, #unmute, #verbose?, #verbose_off, #verbose_on

Methods inherited from Hash

#apply_recursively, #downcase, #find_symbol_keys_recursively, #my_stringify, #my_stringify_keys, #my_symbolize_keys, #recode, #recode!, #stringify_recursively_and_freeze

Constructor Details

#initialize(framework) ⇒ Manager

Returns a new instance of Manager.

Parameters:


39
40
41
42
43
44
# File 'lib/arachni/check/manager.rb', line 39

def initialize( framework )
    self.class.reset

    @framework = framework
    super( @framework.options.paths.checks, NAMESPACE )
end

Class Method Details

.resetObject


134
135
136
# File 'lib/arachni/check/manager.rb', line 134

def self.reset
    remove_constants( NAMESPACE )
end

Instance Method Details

#[](name) ⇒ Check::Base

Parameters:

  • name (Symbol, String)

    Name of the check to retrieve.

Returns:

Raises:


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/arachni/check/manager.rb', line 59

def []( name )
    check = super( name )

    if !Platform::Manager.valid?( check.platforms )
        unload name
        fail Error::InvalidPlatforms,
             "Check #{name} contains invalid platforms: #{check.platforms.join(', ')}"
    end

    check
end

#resetObject


137
138
139
# File 'lib/arachni/check/manager.rb', line 137

def reset
    self.class.reset
end

#run(page) ⇒ Object

Parameters:


48
49
50
# File 'lib/arachni/check/manager.rb', line 48

def run( page )
    schedule.each { |mod| exception_jail( false ){ run_one( mod, page ) } }
end

#run_one(check, page) ⇒ Bool

Runs a single check against page.

Parameters:

  • check (Check::Base)

    Check to run as a class.

  • page (Page)

    Page to audit.

Returns:

  • (Bool)

    true if the check was ran (based on Check::Auditor.check?), false otherwise.


123
124
125
126
127
128
129
130
131
132
# File 'lib/arachni/check/manager.rb', line 123

def run_one( check, page )
    return false if !check.check?( page )

    check_new = check.new( page, @framework )
    check_new.prepare
    check_new.run
    check_new.clean_up

    true
end

#scheduleArray

Returns Checks in proper running order, taking account their declared preferences.

Returns:

  • (Array)

    Checks in proper running order, taking account their declared preferences.


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
# File 'lib/arachni/check/manager.rb', line 74

def schedule
    schedule       = Set.new
    preferred_over = Hash.new([])

    preferred = self.reject do |name, klass|
        preferred_over[name] = klass.preferred if klass.preferred.any?
    end

    return self.values if preferred_over.empty? || preferred.empty?

    preferred_over.size.times do
        update = {}
        preferred.each do |name, klass|
            schedule << klass
            preferred_over.select { |_, v| v.include?( name.to_sym ) }.each do |k, v|
                schedule << (update[k] = self[k])
            end
        end

        preferred.merge!( update )
    end

    schedule |= preferred_over.keys.map { |n| self[n] }

    schedule.to_a
end

#with_platformsHash

Returns Checks targeting specific platforms.

Returns:

  • (Hash)

    Checks targeting specific platforms.


103
104
105
# File 'lib/arachni/check/manager.rb', line 103

def with_platforms
    select { |k, v| v.has_platforms? }
end

#without_platformsHash

Returns Platform-agnostic checks.

Returns:

  • (Hash)

    Platform-agnostic checks.


109
110
111
# File 'lib/arachni/check/manager.rb', line 109

def without_platforms
    select { |k, v| !v.has_platforms? }
end