Class: Arachni::Plugin::Base Abstract

Inherits:
Component::Base show all
Includes:
Component, MonitorMixin
Defined in:
lib/arachni/plugin/base.rb

Overview

This class is abstract.

An abstract class which all plugins must extend.

Author:

  • Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>

Constant Summary

Constants included from Arachni

BANNER, Cookie, Form, Header, JSON, Link, LinkTemplate, NestedCookie, Severity, UIForm, UIInput, VERSION, WEBSITE, WIKI, XML

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component::Base

author, description, fullname, #shortname, shortname, shortname=, version

Methods included from Component::Output

#depersonalize_output, #depersonalize_output?, #intercept_print_message

Methods included from UI::Output

#debug?, #debug_level_1?, #debug_level_2?, #debug_level_3?, #debug_level_4?, #debug_off, #debug_on, #disable_only_positives, #included, #mute, #muted?, #only_positives, #only_positives?, #print_bad, #print_debug, #print_debug_backtrace, #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, #unmute, #verbose?, #verbose_on

Methods included from 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 Arachni

URI, collect_young_objects, #get_long_win32_filename, jruby?, null_device, profile?, windows?

Constructor Details

#initialize(framework, options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • framework (Framework)
  • options (Hash)

    Options to pass to the plugin.



32
33
34
35
# File 'lib/arachni/plugin/base.rb', line 32

def initialize( framework, options )
    @framework = framework
    @options   = options
end

Instance Attribute Details

#frameworkFramework (readonly)

Returns:



27
28
29
# File 'lib/arachni/plugin/base.rb', line 27

def framework
  @framework
end

#optionsHash (readonly)

Returns Plugin options.

Returns:

  • (Hash)

    Plugin options.



24
25
26
# File 'lib/arachni/plugin/base.rb', line 24

def options
  @options
end

Class Method Details

.distributableObject

Should the plug-in be distributed across all instances or only run by the master prior to any distributed operations?



127
128
129
# File 'lib/arachni/plugin/base.rb', line 127

def self.distributable
    @distributable = true
end

.distributable?Boolean

Note:

*OPTIONAL*

Only used when in Grid mode.

Should the plug-in be distributed across all instances or only run by the master prior to any distributed operations?

For example, if a plug-in dynamically modifies the framework options in any way and wants these changes to be identical across instances this method should return `false`.

Returns:

  • (Boolean)


121
122
123
# File 'lib/arachni/plugin/base.rb', line 121

def self.distributable?
    @distributable ||= false
end

.gemsArray

Should return an array of plugin related gem dependencies.

Returns:



148
149
150
# File 'lib/arachni/plugin/base.rb', line 148

def self.gems
    []
end

.infoHash

This method is abstract.

REQUIRED

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/arachni/plugin/base.rb', line 156

def self.info
    {
        name:        'Abstract plugin class',
        description: %q{Abstract plugin class.},
        author:      'Tasos "Zapotek" Laskos <tasos.laskos@arachni-scanner.com>',
        version:     '0.1',
        options:     [
            #                       option name        required?       description                        default
            # Options::Bool.new( 'print_framework', [ false, 'Do you want to print the framework?', false ] ),
            # Options::String.new( 'my_name_is',    [ false, 'What\'s you name?', 'Tasos' ] ),
        ],
        # specify an execution priority group
        # plug-ins will be separated in groups based on this number
        # and lowest will be first
        #
        # if this option is omitted the plug-in will be run last
        #
        priority:    0
    }
end

.is_distributableObject

Should the plug-in be distributed across all instances or only run by the master prior to any distributed operations?



133
134
135
# File 'lib/arachni/plugin/base.rb', line 133

def self.is_distributable
    distributable
end

.merge(results) ⇒ Object

Note:

*REQUIRED* if distributable? returns `true` and the plugin registers results.

Merges an array of results as gathered by the plug-in when ran by multiple instances.



142
143
# File 'lib/arachni/plugin/base.rb', line 142

def self.merge( results )
end

Instance Method Details

#browser_clusterObject



188
189
190
# File 'lib/arachni/plugin/base.rb', line 188

def browser_cluster
    framework.browser_cluster
end

#clean_upObject

This method is abstract.
Note:

*OPTIONAL*

Gets called right after #run and is used for generic clean-up.



78
79
# File 'lib/arachni/plugin/base.rb', line 78

def clean_up
end

#framework_abortObject

Aborts the #framework.



99
100
101
102
103
# File 'lib/arachni/plugin/base.rb', line 99

def framework_abort
    Thread.new do
        framework.abort
    end
end

#framework_pauseObject

Pauses the #framework.



94
95
96
# File 'lib/arachni/plugin/base.rb', line 94

def framework_pause
    @pause_id ||= framework.pause( false )
end

#framework_resumeObject

Resumes the #framework.



106
107
108
109
# File 'lib/arachni/plugin/base.rb', line 106

def framework_resume
    return if !@pause_id
    framework.resume @pause_id
end

#httpObject



184
185
186
# File 'lib/arachni/plugin/base.rb', line 184

def http
    framework.http
end

#infoObject



176
177
178
# File 'lib/arachni/plugin/base.rb', line 176

def info
    self.class.info
end

#prepareObject

This method is abstract.
Note:

*OPTIONAL*

Gets called right after the plugin is initialized and is used to prepare its data or setup hooks.

This method should not block as the system will wait for it to return prior to progressing.



46
47
# File 'lib/arachni/plugin/base.rb', line 46

def prepare
end

#register_results(results) ⇒ Object

Registers the plugin's results to Data::Plugins.

Parameters:



199
200
201
# File 'lib/arachni/plugin/base.rb', line 199

def register_results( results )
    Data.plugins.store( self, results )
end

#restore(state = nil) ⇒ Object

This method is abstract.
Note:

*OPTIONAL*

Gets called instead of #prepare when restoring a suspended plugin. If no #restore method has been defined, #prepare will be called instead.

Parameters:

  • state (Object) (defaults to: nil)

    State to restore.

See Also:



58
59
# File 'lib/arachni/plugin/base.rb', line 58

def restore( state = nil )
end

#runObject

This method is abstract.
Note:

*REQUIRED*

Gets called right after #prepare and delivers the plugin payload.

This method will be ran in its own thread, in parallel to any other system operation. However, once its job is done, the system will wait for this method to return prior to exiting.



70
71
# File 'lib/arachni/plugin/base.rb', line 70

def run
end

#sessionObject



180
181
182
# File 'lib/arachni/plugin/base.rb', line 180

def session
    framework.session
end

#suspendObject

This method is abstract.
Note:

*OPTIONAL*

Gets called right before killing the plugin and should return state data to be stored and passed to #restore.

Returns:

  • (Object)

    State to store.

See Also:



90
91
# File 'lib/arachni/plugin/base.rb', line 90

def suspend
end

#wait_while_framework_runningObject

Will block until the scan finishes.



204
205
206
# File 'lib/arachni/plugin/base.rb', line 204

def wait_while_framework_running
    sleep 0.1 while framework.running?
end

#with_browser(&block) ⇒ Object



192
193
194
# File 'lib/arachni/plugin/base.rb', line 192

def with_browser( &block )
    browser_cluster.with_browser( &block )
end