Class: Arachni::Processes::Dispatchers

Inherits:
Object
  • Object
show all
Includes:
Utilities, Singleton
Defined in:
lib/arachni/processes/dispatchers.rb

Overview

Helper for managing RPC::Server::Dispatcher processes.

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#available_port, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #follow_protocol?, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #generate_token, #get_path, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_query, #parse_set_cookie, #parse_url_vars, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #redundant_path?, #remove_constants, #seed, #skip_page?, #skip_path?, #skip_resource?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize

Constructor Details

#initializeDispatchers

Returns a new instance of Dispatchers.



32
33
34
35
# File 'lib/arachni/processes/dispatchers.rb', line 32

def initialize
    @list = []
    @dispatcher_connections = {}
end

Instance Attribute Details

#listArray<String> (readonly)

Returns URLs of all running Dispatchers.

Returns:



30
31
32
# File 'lib/arachni/processes/dispatchers.rb', line 30

def list
  @list
end

Class Method Details

.method_missing(sym, *args, &block) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/arachni/processes/dispatchers.rb', line 134

def self.method_missing( sym, *args, &block )
    if instance.respond_to?( sym )
        instance.send( sym, *args, &block )
    elsif
    super( sym, *args, &block )
    end
end

.respond_to?(m) ⇒ Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/arachni/processes/dispatchers.rb', line 142

def self.respond_to?( m )
    super( m ) || instance.respond_to?( m )
end

Instance Method Details

#connect(url, options = { }) ⇒ RPC::Client::Dispatcher

Connects to a Dispatcher by URL.

Parameters:

  • url (String)

    URL of the Dispatcher.

  • options (Hash) (defaults to: { })

    Options for the RPC client.

Returns:



45
46
47
48
# File 'lib/arachni/processes/dispatchers.rb', line 45

def connect( url, options = { } )
    opts = OpenStruct.new( options )
    @dispatcher_connections[url] ||= RPC::Client::Dispatcher.new( opts, url )
end

#each(&block) ⇒ Object

Parameters:

  • block (Block)

    Block to pass an RPC client for each Dispatcher.



51
52
53
54
55
# File 'lib/arachni/processes/dispatchers.rb', line 51

def each( &block )
    @list.each do |url|
        block.call connect( url )
    end
end

#kill(url) ⇒ Object

Note:

Will also kill all Instances started by the Dispatcher.

Parameters:

  • url (String)

    URL of the Dispatcher to kill.



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/arachni/processes/dispatchers.rb', line 114

def kill( url )
    dispatcher = connect( url )
    Manager.kill_many dispatcher.stats['consumed_pids']
    Manager.kill dispatcher.proc_info['pid'].to_i
rescue => e
    #ap e
    #ap e.backtrace
    nil
ensure
    @list.delete( url )
    @dispatcher_connections.delete( url )
end

#killallObject

Kills all #list.



128
129
130
131
132
# File 'lib/arachni/processes/dispatchers.rb', line 128

def killall
    @list.dup.each do |url|
        kill url
    end
end

#light_spawn(options = {}, &block) ⇒ Object

Same as #spawn but sets the pool size to ‘1`.



107
108
109
# File 'lib/arachni/processes/dispatchers.rb', line 107

def light_spawn( options = {}, &block )
    spawn( options.merge( pool_size: 1 ), &block )
end

#spawn(options = {}, &block) ⇒ RPC::Client::Dispatcher

Spawns a RPC::Server::Dispatcher process.

Parameters:

  • options (Hash) (defaults to: {})

    To be passed to Options#set. Allows ‘address` instead of `rpc_address` and `port` instead of `rpc_port`.

  • block (Block)

    Passed Options to configure the Dispatcher options.

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/arachni/processes/dispatchers.rb', line 69

def spawn( options = {}, &block )
    options = Options.to_hash.symbolize_keys( false ).merge( options )

    options[:rpc_port]    = options.delete( :port ) if options.include?( :port )
    options[:rpc_address] = options.delete( :address ) if options.include?( :address )

    options[:rpc_port]    ||= available_port

    url = "#{options[:rpc_address]}:#{options[:rpc_port]}"

    Manager.fork_em do
        Options.set( options )
        block.call( Options.instance ) if block_given?

        require "#{Arachni::Options.dir['lib']}/rpc/server/dispatcher"

        RPC::Server::Dispatcher.new
    end

    begin
        Timeout.timeout( 10 ) do
            while sleep( 0.1 )
                begin
                    connect( url, max_retries: 1 ).alive?
                    break
                rescue Exception
                end
            end
        end
    rescue Timeout::Error
        abort "Dispatcher '#{url}' never started!"
    end

    @list << url
    connect( url )
end