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:

Constant Summary

Constants included from Arachni

BANNER, Cookie, Form, Header, Link, LinkTemplate, Severity, VERSION, WEBSITE, WIKI

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::Utilities

#read_file

Methods included from Utilities

#available_port, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_document, #forms_from_response, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_document, #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?, #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 Component::Output

#depersonalize_output, #depersonalize_output?, #intercept_print_message

Methods included from UI::Output

#debug?, #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_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 Arachni

URI, 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?



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

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)


114
115
116
# File 'lib/arachni/plugin/base.rb', line 114

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

.gemsArray

Should return an array of plugin related gem dependencies.

Returns:



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

def self.gems
    []
end

.infoHash

This method is abstract.

REQUIRED

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/arachni/plugin/base.rb', line 149

def self.info
    {
        name:        'Abstract plugin class',
        description: %q{Abstract plugin class.},
        author:      'Tasos "Zapotek" Laskos <[email protected]>',
        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?



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

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.



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

def self.merge( results )
end

Instance Method Details

#clean_upObject

This method is abstract.
Note:

OPTIONAL

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



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

def clean_up
end

#framework_abortObject

Aborts the #framework.



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

def framework_abort
    Thread.new do
        framework.abort
    end
end

#framework_pauseObject

Pauses the #framework.



87
88
89
# File 'lib/arachni/plugin/base.rb', line 87

def framework_pause
    @pause_id ||= framework.pause
end

#framework_resumeObject

Resumes the #framework.



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

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

#httpObject



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

def http
    framework.http
end

#infoObject



169
170
171
# File 'lib/arachni/plugin/base.rb', line 169

def info
    self.class.info
end

#prepareObject

This method is abstract.
Note:

OPTIONAL

Gets called right after the plugin is initialized and it used to prepare its data.



43
44
# File 'lib/arachni/plugin/base.rb', line 43

def prepare
end

#register_results(results) ⇒ Object

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

Parameters:



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

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:



55
56
# File 'lib/arachni/plugin/base.rb', line 55

def restore( state = nil )
end

#runObject

This method is abstract.
Note:

REQUIRED

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



63
64
# File 'lib/arachni/plugin/base.rb', line 63

def run
end

#sessionObject



173
174
175
# File 'lib/arachni/plugin/base.rb', line 173

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:



83
84
# File 'lib/arachni/plugin/base.rb', line 83

def suspend
end

#wait_while_framework_runningObject

Will block until the scan finishes.



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

def wait_while_framework_running
    sleep 1 while framework.running?
end