Class: Arachni::State::Framework
- Defined in:
- lib/arachni/state/framework.rb,
lib/arachni/state/framework/rpc.rb
Overview
State information for Framework.
Defined Under Namespace
Instance Attribute Summary collapse
- #audited_page_count ⇒ Integer
- #browser_skip_states ⇒ Set readonly
- #page_queue_filter ⇒ Support::LookUp::HashSet readonly
- #pause_signals ⇒ Array readonly
- #rpc ⇒ RPC
- #running ⇒ Bool
- #status ⇒ Symbol
- #status_messages ⇒ Array<String> readonly
- #url_queue_filter ⇒ Support::LookUp::HashSet readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#abort(block = true) ⇒ Bool
‘true` if the abort request was successful, `false` if the system is already #suspended? or is #suspending?.
-
#abort? ⇒ Bool
‘true` if a #abort signal is in place , `false` otherwise.
-
#aborted ⇒ Object
Signals a completed abort operation.
-
#aborted? ⇒ Bool
‘true` if the system has been aborted, `false` otherwise.
-
#aborting? ⇒ Bool
‘true` if the system is being aborted, `false` otherwise.
-
#add_status_message(message, *sprintf) ⇒ Object
Pushes a message to #status_messages.
-
#available_status_messages ⇒ Hash{Symbol=>String}
All possible #status_messages by type.
- #clear ⇒ Object
-
#clear_status_messages ⇒ Object
Clears #status_messages.
- #dump(directory) ⇒ Object
-
#initialize ⇒ Framework
constructor
A new instance of Framework.
- #page_seen(page) ⇒ Object
-
#page_seen?(page) ⇒ Bool
‘true` if the `page` has already been seen (based on the #page_queue_filter), `false` otherwise.
-
#pause(caller, block = true) ⇒ TrueClass
Pauses the framework on a best effort basis, might take a while to take effect.
-
#pause? ⇒ Bool
‘true` if the framework should pause, `false` otherwise.
-
#paused ⇒ Object
Signals that the system has been paused..
-
#paused? ⇒ Bool
‘true` if the framework is paused.
-
#pausing? ⇒ Bool
‘true` if the system is being paused, `false` otherwise.
-
#resume(caller) ⇒ Bool
Resumes a paused system.
- #running? ⇒ Boolean
-
#scanning? ⇒ Bool
‘true` if the system is scanning, `false` otherwise.
-
#set_status_message(*args) ⇒ Object
Sets a message as #status_messages.
- #statistics ⇒ Object
-
#suspend(block = true) ⇒ Bool
‘true` if the suspend request was successful, `false` if the system is already #suspended? or is #suspending?.
-
#suspend? ⇒ Bool
‘true` if an #abort signal is in place , `false` otherwise.
-
#suspended ⇒ Object
Signals a completed suspension.
-
#suspended? ⇒ Bool
‘true` if the system has been suspended, `false` otherwise.
-
#suspending? ⇒ Bool
‘true` if the system is being suspended, `false` otherwise.
- #update_browser_skip_states(states) ⇒ Object
- #url_seen(url) ⇒ Object
-
#url_seen?(url) ⇒ Bool
‘true` if the `url` has already been seen (based on the #url_queue_filter), `false` otherwise.
Constructor Details
#initialize ⇒ Framework
Returns a new instance of Framework.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/arachni/state/framework.rb', line 65 def initialize @rpc = RPC.new @audited_page_count = 0 @browser_skip_states = Support::LookUp::HashSet.new( hasher: :persistent_hash ) @page_queue_filter = Support::LookUp::HashSet.new( hasher: :persistent_hash ) @url_queue_filter = Support::LookUp::HashSet.new( hasher: :persistent_hash ) @running = false @pre_pause_status = nil @pause_signals = Set.new @paused_signal = Queue.new @suspended_signal = Queue.new @aborted_signal = Queue.new @status_messages = [] end |
Instance Attribute Details
#audited_page_count ⇒ Integer
57 58 59 |
# File 'lib/arachni/state/framework.rb', line 57 def audited_page_count @audited_page_count end |
#browser_skip_states ⇒ Set (readonly)
48 49 50 |
# File 'lib/arachni/state/framework.rb', line 48 def browser_skip_states @browser_skip_states end |
#page_queue_filter ⇒ Support::LookUp::HashSet (readonly)
42 43 44 |
# File 'lib/arachni/state/framework.rb', line 42 def page_queue_filter @page_queue_filter end |
#pause_signals ⇒ Array (readonly)
60 61 62 |
# File 'lib/arachni/state/framework.rb', line 60 def pause_signals @pause_signals end |
#running ⇒ Bool
54 55 56 |
# File 'lib/arachni/state/framework.rb', line 54 def running @running end |
#status ⇒ Symbol
51 52 53 |
# File 'lib/arachni/state/framework.rb', line 51 def status @status end |
#status_messages ⇒ Array<String> (readonly)
63 64 65 |
# File 'lib/arachni/state/framework.rb', line 63 def @status_messages end |
#url_queue_filter ⇒ Support::LookUp::HashSet (readonly)
45 46 47 |
# File 'lib/arachni/state/framework.rb', line 45 def url_queue_filter @url_queue_filter end |
Class Method Details
.load(directory) ⇒ Object
387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/arachni/state/framework.rb', line 387 def self.load( directory ) framework = new framework.rpc = RPC.load( "#{directory}/rpc/" ) %w(page_queue_filter url_queue_filter browser_skip_states).each do |attribute| framework.send(attribute).merge Marshal.load( IO.binread( "#{directory}/#{attribute}" ) ) end framework.audited_page_count = Marshal.load( IO.binread( "#{directory}/audited_page_count" ) ) framework end |
Instance Method Details
#abort(block = true) ⇒ Bool
Returns ‘true` if the abort request was successful, `false` if the system is already #suspended? or is #suspending?.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/arachni/state/framework.rb', line 202 def abort( block = true ) return false if aborting? || aborted? if !running? fail Error::StateNotAbortable, 'Cannot suspend an idle state.' end :aborting @status = :aborting @abort = true @aborted_signal.pop if block true end |
#abort? ⇒ Bool
Returns ‘true` if a #abort signal is in place , `false` otherwise.
219 220 221 |
# File 'lib/arachni/state/framework.rb', line 219 def abort? !!@abort end |
#aborted ⇒ Object
Signals a completed abort operation.
224 225 226 227 228 229 |
# File 'lib/arachni/state/framework.rb', line 224 def aborted @abort = false @status = :aborted @aborted_signal << true nil end |
#aborted? ⇒ Bool
Returns ‘true` if the system has been aborted, `false` otherwise.
233 234 235 |
# File 'lib/arachni/state/framework.rb', line 233 def aborted? @status == :aborted end |
#aborting? ⇒ Bool
Returns ‘true` if the system is being aborted, `false` otherwise.
239 240 241 |
# File 'lib/arachni/state/framework.rb', line 239 def aborting? @status == :aborting end |
#add_status_message(message, *sprintf) ⇒ Object
Pushes a message to #status_messages.
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/arachni/state/framework.rb', line 127 def ( , *sprintf ) if .is_a? Symbol if !.include?( ) fail Error::InvalidStatusMessage, "Could not find status message for: '#{}'" end = [] % sprintf end @status_messages << .to_s end |
#available_status_messages ⇒ Hash{Symbol=>String}
Returns All possible #status_messages by type.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/arachni/state/framework.rb', line 95 def { pausing: 'Will pause as soon as the current page is audited.', suspending: 'Will suspend as soon as the current page is audited.', waiting_for_browser_cluster_jobs: 'Waiting for %i browser cluster jobs to finish.', suspending_plugins: 'Suspending plugins.', saving_snapshot: 'Saving snapshot at: %s', snapshot_location: 'Snapshot location: %s', browser_cluster_startup: 'Initialising the browser cluster.', browser_cluster_shutdown: 'Shutting down the browser cluster.', clearing_queues: 'Clearing the audit queues.', waiting_for_plugins: 'Waiting for the plugins to finish.', aborting: 'Aborting the scan.' } end |
#clear ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/arachni/state/framework.rb', line 400 def clear rpc.clear @page_queue_filter.clear @url_queue_filter.clear @pause_signals.clear @paused_signal.clear @suspended_signal.clear @running = false @pre_pause_status = nil @browser_skip_states.clear @audited_page_count = 0 end |
#clear_status_messages ⇒ Object
Clears #status_messages.
141 142 143 |
# File 'lib/arachni/state/framework.rb', line 141 def @status_messages.clear end |
#dump(directory) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/arachni/state/framework.rb', line 375 def dump( directory ) FileUtils.mkdir_p( directory ) rpc.dump( "#{directory}/rpc/" ) %w(page_queue_filter url_queue_filter browser_skip_states audited_page_count).each do |attribute| IO.binwrite( "#{directory}/#{attribute}", Marshal.dump( send(attribute) ) ) end end |
#page_seen(page) ⇒ Object
160 161 162 |
# File 'lib/arachni/state/framework.rb', line 160 def page_seen( page ) @page_queue_filter << page end |
#page_seen?(page) ⇒ Bool
Returns ‘true` if the `page` has already been seen (based on the #page_queue_filter), `false` otherwise.
152 153 154 |
# File 'lib/arachni/state/framework.rb', line 152 def page_seen?( page ) @page_queue_filter.include? page end |
#pause(caller, block = true) ⇒ TrueClass
Returns Pauses the framework on a best effort basis, might take a while to take effect.
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/arachni/state/framework.rb', line 313 def pause( caller, block = true ) @pre_pause_status ||= @status if !paused? && !pausing? if !paused? @status = :pausing :pausing end @pause_signals << caller paused if !running? @paused_signal.pop if block && !paused? true end |
#pause? ⇒ Bool
Returns ‘true` if the framework should pause, `false` otherwise.
350 351 352 |
# File 'lib/arachni/state/framework.rb', line 350 def pause? @pause_signals.any? end |
#paused ⇒ Object
Signals that the system has been paused..
330 331 332 333 334 |
# File 'lib/arachni/state/framework.rb', line 330 def paused @status = :paused @paused_signal << nil end |
#paused? ⇒ Bool
Returns ‘true` if the framework is paused.
338 339 340 |
# File 'lib/arachni/state/framework.rb', line 338 def paused? @status == :paused end |
#pausing? ⇒ Bool
Returns ‘true` if the system is being paused, `false` otherwise.
344 345 346 |
# File 'lib/arachni/state/framework.rb', line 344 def pausing? @status == :pausing end |
#resume(caller) ⇒ Bool
Resumes a paused system
363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/arachni/state/framework.rb', line 363 def resume( caller ) @pause_signals.delete( caller ) if @pause_signals.empty? @status = @pre_pause_status @pre_pause_status = nil return true end false end |
#running? ⇒ Boolean
188 189 190 |
# File 'lib/arachni/state/framework.rb', line 188 def running? !!@running end |
#scanning? ⇒ Bool
Returns ‘true` if the system is scanning, `false` otherwise.
300 301 302 |
# File 'lib/arachni/state/framework.rb', line 300 def scanning? @status == :scanning end |
#set_status_message(*args) ⇒ Object
Sets a message as #status_messages.
115 116 117 118 |
# File 'lib/arachni/state/framework.rb', line 115 def ( *args ) ( *args ) end |
#statistics ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/arachni/state/framework.rb', line 85 def statistics { rpc: @rpc.statistics, audited_page_count: @audited_page_count, browser_states: @browser_skip_states.size } end |
#suspend(block = true) ⇒ Bool
Returns ‘true` if the suspend request was successful, `false` if the system is already #suspended? or is #suspending?.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/arachni/state/framework.rb', line 253 def suspend( block = true ) return false if suspending? || suspended? if paused? || pausing? fail Error::StateNotSuspendable, 'Cannot suspend a paused state.' end if !running? fail Error::StateNotSuspendable, 'Cannot suspend an idle state.' end :suspending @status = :suspending @suspend = true @suspended_signal.pop if block true end |
#suspend? ⇒ Bool
Returns ‘true` if an #abort signal is in place , `false` otherwise.
274 275 276 |
# File 'lib/arachni/state/framework.rb', line 274 def suspend? !!@suspend end |
#suspended ⇒ Object
Signals a completed suspension.
279 280 281 282 283 284 |
# File 'lib/arachni/state/framework.rb', line 279 def suspended @suspend = false @status = :suspended @suspended_signal << true nil end |
#suspended? ⇒ Bool
Returns ‘true` if the system has been suspended, `false` otherwise.
288 289 290 |
# File 'lib/arachni/state/framework.rb', line 288 def suspended? @status == :suspended end |
#suspending? ⇒ Bool
Returns ‘true` if the system is being suspended, `false` otherwise.
294 295 296 |
# File 'lib/arachni/state/framework.rb', line 294 def suspending? @status == :suspending end |
#update_browser_skip_states(states) ⇒ Object
184 185 186 |
# File 'lib/arachni/state/framework.rb', line 184 def update_browser_skip_states( states ) @browser_skip_states.merge states end |
#url_seen(url) ⇒ Object
179 180 181 |
# File 'lib/arachni/state/framework.rb', line 179 def url_seen( url ) @url_queue_filter << url end |
#url_seen?(url) ⇒ Bool
Returns ‘true` if the `url` has already been seen (based on the #url_queue_filter), `false` otherwise.
171 172 173 |
# File 'lib/arachni/state/framework.rb', line 171 def url_seen?( url ) @url_queue_filter.include? url end |