lib/http.rb in arachni-0.2.2.1 vs lib/http.rb in arachni-0.2.2.2

- old
+ new

@@ -14,10 +14,11 @@ require Options.instance.dir['lib'] + 'typhoeus/request' require Options.instance.dir['lib'] + 'typhoeus/response' require Options.instance.dir['lib'] + 'module/utilities' require Options.instance.dir['lib'] + 'module/trainer' +require Options.instance.dir['lib'] + 'mixins/observable' # # Arachni::Module::HTTP class # # Provides a simple, high-performance and thread-safe HTTP interface to modules. @@ -31,17 +32,18 @@ # Point is, you don't need to worry about it. # # @author: Tasos "Zapotek" Laskos # <tasos.laskos@gmail.com> # <zapotek@segfault.gr> -# @version: 0.2.3 +# @version: 0.2.5 # class HTTP include Arachni::UI::Output include Singleton include Arachni::Module::Utilities + include Arachni::Mixins::Observable # # @return [URI] # attr_reader :last_url @@ -84,11 +86,10 @@ req_limit = opts.http_req_limit hydra_opts = { :max_concurrency => req_limit, - :disable_ssl_peer_verification => true, :username => opts.url.user, :password => opts.url.password, :method => :auto, } @@ -123,10 +124,11 @@ } if opts.proxy_addr @opts = { :user_agent => opts.user_agent, :follow_location => false, + :disable_ssl_peer_verification => true, # :timeout => 8000 }.merge( proxy_opts ) @request_count = 0 @response_count = 0 @@ -135,15 +137,11 @@ @rand_seed = seed( ) @curr_res_time = 0 @curr_res_cnt = 0 - @on_complete = [] - @on_queue = [] - @after_run = [] - @after_run_persistent = [] end # # Runs Hydra (all the asynchronous queued HTTP requests) # @@ -156,17 +154,13 @@ @after_run.each { |block| block.call } - @after_run.clear - @after_run_persistent.each { - |block| - block.call - } + call_after_run_persistent( ) @curr_res_time = 0 @curr_res_cnt = 0 } end @@ -205,14 +199,11 @@ # def queue( req, async = true ) req.id = @request_count - @on_queue.each { - |block| - exception_jail{ block.call( req, async ) } - } + call_on_queue( req, async ) if( !async ) @hydra_sync.queue( req ) else @hydra.queue( req ) @@ -235,14 +226,11 @@ @response_count += 1 @curr_res_cnt += 1 @curr_res_time += res.start_transfer_time - @on_complete.each { - |block| - exception_jail{ block.call( res ) } - } + call_on_complete( res ) parse_and_set_cookies( res ) print_debug( '------------' ) print_debug( 'Got response.' ) @@ -278,31 +266,11 @@ # def after_run( &block ) @after_run << block end - def after_run_persistent( &block ) - @after_run_persistent << block - end - # - # Gets called each time a request completes and passes the response - # to the block - # - def on_complete( &block ) - @on_complete << block - end - - # - # Gets called each time a request is queued and passes the request - # to the block - # - def on_queue( &block ) - @on_queue << block - end - - # # Makes a generic request # # @param [URI] url # @param [Hash] opts # @@ -653,9 +621,11 @@ return if cookie_hash.empty? # update framework cookies Arachni::Options.instance.cookies = cookie_hash + + call_on_new_cookies( cookie_hash, res ) current = parse_cookie_str( @init_headers['cookie'] ) set_cookies( current.merge( cookie_hash ) ) end