class Arachni::RPC::Server::Framework

Wraps the framework of the local instance and the frameworks of all its slaves (when it is a Master in multi-Instance mode) into a neat, easy to handle package.

@note Ignore:

* Inherited methods and attributes -- only public methods of this class are
    accessible over RPC.
* `block` parameters, they are an RPC implementation detail for methods which
    perform asynchronous operations.

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

Public Class Methods

new( * ) click to toggle source
Calls superclass method Arachni::Framework::new
# File lib/arachni/rpc/server/framework.rb, line 69
def initialize( * )
    super

    # Override standard framework components with their RPC-server counterparts.
    @checks  = Check::Manager.new( self )
    @plugins = Plugin::Manager.new( self )
end

Public Instance Methods

busy?( &block ) click to toggle source

@return [Bool]

`true` If the system is scanning, `false` if {#run} hasn't been called
yet or if the scan has finished.
# File lib/arachni/rpc/server/framework.rb, line 116
def busy?( &block )
    # If we have a block it means that it was called via RPC, so use the
    # status variable to determine if the scan is done.
    if block_given?
        block.call @prepared && status != :done
        return
    end

    !!@extended_running
end
clean_up( &block ) click to toggle source

If the scan needs to be aborted abruptly this method takes care of any unfinished business (like signaling running plug-ins to finish).

Should be called before grabbing the {#report}, especially when running in multi-Instance mode, as it will take care of merging the plug-in results of all instances.

You don’t need to call this if you’ve let the scan complete.

# File lib/arachni/rpc/server/framework.rb, line 171
def clean_up( &block )
    if @rpc_cleaned_up
        # Don't shutdown the BrowserCluster here, its termination will be
        # handled by Instance#shutdown.
        block.call false if block_given?
        return false
    end

    @rpc_cleaned_up   = true
    @extended_running = false

    r = super( false )

    if !block_given?
        state.status = :done
        return r
    end

    if !has_slaves?
        state.status = :done
        block.call r
        return
    end

    foreach = proc do |instance, iter|
        instance.framework.clean_up do
            instance.plugins.results do |res|
                iter.return( !res.rpc_exception? ? res : nil )
            end
        end
    end
    after = proc do |results|
        @plugins.merge_results( results.compact )
        state.status = :done
        block.call true
    end
    map_slaves( foreach, after )
end
error_test( str, &block ) click to toggle source

@private

# File lib/arachni/rpc/server/framework.rb, line 245
def error_test( str, &block )
    print_error str.to_s
    return block.call if !has_slaves?

    each = proc { |instance, iter| instance.framework.error_test( str ) { iter.next } }
    each_slave( each, &block )
end
issues() click to toggle source

@return [Array<Hash>]

Issues as {Arachni::Issue#to_rpc_data RPC data}.

@private

# File lib/arachni/rpc/server/framework.rb, line 214
def issues
    Data.issues.sort.map(&:to_rpc_data)
end
issues_as_hash() click to toggle source

@return [Array<Hash>]

{#issues} as an array of Hashes.

@see issues

# File lib/arachni/rpc/server/framework.rb, line 222
def issues_as_hash
    Data.issues.sort.map(&:to_h)
end
list_checks() click to toggle source

@return (see Arachni::Framework#list_checks)

# File lib/arachni/rpc/server/framework.rb, line 106
def list_checks
    super.map do |check|
        check[:issue][:severity] = check[:issue][:severity].to_s
        check
    end
end
list_plugins() click to toggle source

@return (see Arachni::Framework#list_plugins)

# File lib/arachni/rpc/server/framework.rb, line 90
def list_plugins
    super.map do |plugin|
        plugin[:options] = plugin[:options].map(&:to_h)
        plugin
    end
end
list_reporters() click to toggle source

@return (see Arachni::Framework#list_reporters)

# File lib/arachni/rpc/server/framework.rb, line 98
def list_reporters
    super.map do |reporter|
        reporter[:options] = reporter[:options].map(&:to_h)
        reporter
    end
end
report( &block ) click to toggle source

@return [Report]

{Report#to_rpc_data}
# File lib/arachni/rpc/server/framework.rb, line 79
def report( &block )
    # If a block is given it means the call was form an RPC client.
    if block_given?
        block.call super.to_rpc_data
        return
    end

    super
end
run() click to toggle source

Starts the scan.

@return [Bool]

`false` if already running, `true` otherwise.
Calls superclass method Arachni::Framework#run
# File lib/arachni/rpc/server/framework.rb, line 141
def run
    # Return if we're already running.
    return false if busy?

    @extended_running = true

    # Prepare the local instance (runs plugins and starts the timer).
    prepare

    # Start the scan  -- we can't block the RPC server so we're using a Thread.
    # Thread.abort_on_exception = true
    Thread.new do
        if !solo?
            multi_run
        else
            super
        end
    end

    true
end
self_url() click to toggle source

@return [String]

URL of this instance.

@private

# File lib/arachni/rpc/server/framework.rb, line 230
def self_url
    options.dispatcher.external_address ||= options.rpc.server_address

    @self_url ||= options.dispatcher.external_address ?
        "#{options.dispatcher.external_address }:#{options.rpc.server_port}" :
        options.rpc.server_socket
end
sitemap_entries( from_index = 0 ) click to toggle source

@param [Integer] from_index

Get sitemap entries after this index.

@return [Hash<String=>Integer>]

# File lib/arachni/rpc/server/framework.rb, line 131
def sitemap_entries( from_index = 0 )
    return {} if sitemap.size <= from_index + 1

    Hash[sitemap.to_a[from_index..-1] || {}]
end
token() click to toggle source

@return [String]

This instance's RPC token.
# File lib/arachni/rpc/server/framework.rb, line 240
def token
    options.datastore.token
end

Private Instance Methods

prepare() click to toggle source
# File lib/arachni/rpc/server/framework.rb, line 255
def prepare
    return if @prepared
    super
    @prepared = true
end