Module: Arachni::Framework::Parts::State

Included in:
Arachni::Framework
Defined in:
lib/arachni/framework/parts/state.rb

Overview

Provides access to State::Framework and helpers.

Author:

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#abort(wait = true) ⇒ Object

Aborts the framework #run on a best effort basis.

Parameters:

  • wait (Bool) (defaults to: true)

    Wait until the system has been aborted.


292
293
294
# File 'lib/arachni/framework/parts/state.rb', line 292

def abort( wait = true )
    state.abort wait
end

#abort?Bool

Returns true if the framework has been instructed to abort (i.e. is in the process of being aborted or has been aborted), false otherwise.

Returns:

  • (Bool)

    true if the framework has been instructed to abort (i.e. is in the process of being aborted or has been aborted), false otherwise.


278
279
280
# File 'lib/arachni/framework/parts/state.rb', line 278

def abort?
    state.abort?
end

#aborted?Bool

Returns true if the framework #run has been aborted, false otherwise.

Returns:

  • (Bool)

    true if the framework #run has been aborted, false otherwise.


271
272
273
# File 'lib/arachni/framework/parts/state.rb', line 271

def aborted?
    state.aborted?
end

#aborting?Bool

Returns true if the framework is in the process of aborting, false otherwise.

Returns:

  • (Bool)

    true if the framework is in the process of aborting, false otherwise.


284
285
286
# File 'lib/arachni/framework/parts/state.rb', line 284

def aborting?
    state.aborting?
end

#clean_up(shutdown_browsers = true) ⇒ Object

Cleans up the framework; should be called after running the audit or after canceling a running scan.

It stops the clock and waits for the plugins to finish up.


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/arachni/framework/parts/state.rb', line 103

def clean_up( shutdown_browsers = true )
    return if @cleaned_up
    @cleaned_up = true

    state.force_resume

    state.status = :cleanup

    if shutdown_browsers
        state.set_status_message :browser_cluster_shutdown
        shutdown_browser_cluster
    end

    state.set_status_message :clearing_queues
    page_queue.clear
    url_queue.clear

    @finish_datetime  = Time.now
    @start_datetime ||= Time.now

    # Make sure this is disabled or it'll break reporter output.
    disable_only_positives

    state.running = false

    state.set_status_message :waiting_for_plugins
    @plugins.block

    # Plugins may need the session right till the very end so save it for last.
    @session.clean_up
    @session = nil

    true
end

#done?Bool

Returns true if the system has completed successfully, false otherwise.

Returns:

  • (Bool)

    true if the system has completed successfully, false otherwise.


248
249
250
# File 'lib/arachni/framework/parts/state.rb', line 248

def done?
    state.done?
end

#initializeObject


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/arachni/framework/parts/state.rb', line 65

def initialize
    super

    Element::Capabilities::Auditable.skip_like do |element|
        if pause?
            print_debug "Blocking on element audit: #{element.audit_id}"
        end

        wait_if_paused
    end

    state.status = :ready
end

#pause(wait = true) ⇒ Integer

Note:

Each call from a unique caller is counted as a pause request and in order for the system to resume all pause callers need to #resume it.

Pauses the framework on a best effort basis.

Parameters:

  • wait (Bool) (defaults to: true)

    Wait until the system has been paused.

Returns:

  • (Integer)

    ID identifying this pause request.


263
264
265
266
267
# File 'lib/arachni/framework/parts/state.rb', line 263

def pause( wait = true )
    id = generate_token.hash
    state.pause id, wait
    id
end

#pause?Bool

Returns true if the framework has been instructed to pause (i.e. is in the process of being paused or has been paused), false otherwise.

Returns:

  • (Bool)

    true if the framework has been instructed to pause (i.e. is in the process of being paused or has been paused), false otherwise.


237
238
239
# File 'lib/arachni/framework/parts/state.rb', line 237

def pause?
    state.pause?
end

#paused?Bool

Returns true if the framework is paused, false otherwise.

Returns:

  • (Bool)

    true if the framework is paused, false otherwise.


230
231
232
# File 'lib/arachni/framework/parts/state.rb', line 230

def paused?
    state.paused?
end

#pausing?Bool

Returns true if the framework is in the process of pausing, false otherwise.

Returns:

  • (Bool)

    true if the framework is in the process of pausing, false otherwise.


243
244
245
# File 'lib/arachni/framework/parts/state.rb', line 243

def pausing?
    state.pausing?
end

#resetObject

Note:

Prefer this from #reset if you already have an instance.

Note:

You should first reset Options.

Resets everything and allows the framework to be re-used.


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/arachni/framework/parts/state.rb', line 147

def reset
    @cleaned_up  = false
    @browser_job = nil

    @failures.clear
    @retries.clear

    # This needs to happen before resetting the other components so they
    # will be able to put in their hooks.
    self.class.reset

    clear_observers
    reset_trainer
    reset_session

    @checks.clear
    @reporters.clear
    @plugins.clear
end

#restore(afs) ⇒ Framework

Returns Restored instance.

Parameters:

  • afs (String)

    Path to an .afs. (Arachni Framework Snapshot) file created by #suspend.

Returns:


177
178
179
180
181
182
183
184
185
186
# File 'lib/arachni/framework/parts/state.rb', line 177

def restore( afs )
    Snapshot.load afs

    browser_job_update_skip_states state.browser_skip_states

    checks.load  Options.checks
    plugins.load Options.plugins.keys

    nil
end

#resume(id) ⇒ Object

Note:

Each call from a unique caller is counted as a pause request and in order for the system to resume all pause callers need to #resume it.

Removes a #pause request for the current caller.

Parameters:

  • id (Integer)

    ID of the #pause request.


304
305
306
# File 'lib/arachni/framework/parts/state.rb', line 304

def resume( id )
    state.resume id
end

#running?Bool

Returns true if the framework is running, false otherwise. This is true even if the scan is #paused?.

Returns:

  • (Bool)

    true if the framework is running, false otherwise. This is true even if the scan is #paused?.


218
219
220
# File 'lib/arachni/framework/parts/state.rb', line 218

def running?
    state.running?
end

#scanning?Bool

Returns true if the system is scanning, false otherwise.

Returns:

  • (Bool)

    true if the system is scanning, false otherwise.


224
225
226
# File 'lib/arachni/framework/parts/state.rb', line 224

def scanning?
    state.scanning?
end

#snapshot_pathString

Returns Provisioned #suspend dump file for this instance.

Returns:


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/arachni/framework/parts/state.rb', line 81

def snapshot_path
    return @state_archive if @state_archive

    default_filename =
        "#{URI(options.url).host} #{Time.now.to_s.gsub( ':', '_' )} " <<
            "#{generate_token}.afs"

    location = options.snapshot.save_path

    if !location
        location = default_filename
    elsif File.directory? location
        location += "/#{default_filename}"
    end

    @state_archive ||= File.expand_path( location )
end

#stateState::Framework

Returns:


168
169
170
# File 'lib/arachni/framework/parts/state.rb', line 168

def state
    Arachni::State.framework
end

#statusSymbol

Returns Status of the instance, possible values are (in order):

  • :ready -- Initialised and waiting for instructions.
  • :preparing -- Getting ready to start (i.e. initializing plugins etc.).
  • :scanning -- The instance is currently auditing the webapp.
  • :pausing -- The instance is being paused (if applicable).
  • :paused -- The instance has been paused (if applicable).
  • :suspending -- The instance is being suspended (if applicable).
  • :suspended -- The instance has being suspended (if applicable).
  • :cleanup -- The scan has completed and the instance is cleaning up after itself (i.e. waiting for plugins to finish etc.).
  • :aborted -- The scan has been #abort, you can grab the report and shutdown.
  • :done -- The scan has completed, you can grab the report and shutdown.

Returns:

  • (Symbol)

    Status of the instance, possible values are (in order):

    • :ready -- Initialised and waiting for instructions.
    • :preparing -- Getting ready to start (i.e. initializing plugins etc.).
    • :scanning -- The instance is currently auditing the webapp.
    • :pausing -- The instance is being paused (if applicable).
    • :paused -- The instance has been paused (if applicable).
    • :suspending -- The instance is being suspended (if applicable).
    • :suspended -- The instance has being suspended (if applicable).
    • :cleanup -- The scan has completed and the instance is cleaning up after itself (i.e. waiting for plugins to finish etc.).
    • :aborted -- The scan has been #abort, you can grab the report and shutdown.
    • :done -- The scan has completed, you can grab the report and shutdown.

211
212
213
# File 'lib/arachni/framework/parts/state.rb', line 211

def status
    state.status
end

#status_messagesArray<String>

Returns Messages providing more information about the current #status of the framework.

Returns:

  • (Array<String>)

    Messages providing more information about the current #status of the framework.


191
192
193
# File 'lib/arachni/framework/parts/state.rb', line 191

def status_messages
    state.status_messages
end

#suspend(wait = true) ⇒ String?

Writes a Snapshot.dump to disk and aborts the scan.

Parameters:

  • wait (Bool) (defaults to: true)

    Wait for the system to write it state to disk.

Returns:

  • (String, nil)

    Path to the state file wait is true, nil otherwise.


315
316
317
318
319
# File 'lib/arachni/framework/parts/state.rb', line 315

def suspend( wait = true )
    state.suspend( wait )
    return snapshot_path if wait
    nil
end

#suspend?Bool

Returns true if the system is in the process of being suspended, false otherwise.

Returns:

  • (Bool)

    true if the system is in the process of being suspended, false otherwise.


324
325
326
# File 'lib/arachni/framework/parts/state.rb', line 324

def suspend?
    state.suspend?
end

#suspended?Bool

Returns true if the system has been suspended, false otherwise.

Returns:

  • (Bool)

    true if the system has been suspended, false otherwise.


330
331
332
# File 'lib/arachni/framework/parts/state.rb', line 330

def suspended?
    state.suspended?
end