Class: Anemone::HTTP

Inherits:
Object
  • Object
show all
Includes:
Arachni::UI::Output
Defined in:
lib/anemone/http.rb

Overview

Overides Anemone’s HTTP class methods:

 o refresh_connection( ): added proxy support
 o get_response( ): upped the retry counter to 7 and generalized exception handling

@author: Anastasios “Zapotek” Laskos

                                     <tasos.laskos@gmail.com>
                                     <zapotek@segfault.gr>

@version: 0.1-pre

Instance Method Summary (collapse)

Methods included from Arachni::UI::Output

#debug!, #debug?, #only_positives!, #only_positives?, #print_debug, #print_debug_backtrace, #print_debug_pp, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #verbose!, #verbose?

Instance Method Details

- (Object) get_response(url, referer = nil)

Get an HTTPResponse for url, sending the appropriate User-Agent string



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/anemone/http.rb', line 46

def get_response(url, referer = nil)
    full_path = url.query.nil? ? url.path : "#{url.path}?#{url.query}"

    opts = {}
    opts['User-Agent'] = user_agent if user_agent
    opts['Referer'] = referer.to_s if referer
    opts['Cookie'] = @cookie_store.to_s unless @cookie_store.empty? || (!accept_cookies? && @opts[:cookies].nil?)

    retries = 0
    begin
        start = Time.now()
        response = connection(url).get(full_path, opts)
        finish = Time.now()
        response_time = ((finish - start) * 1000).round
        @cookie_store.merge!(response['Set-Cookie']) if accept_cookies?
        return response, response_time
    rescue Exception => e
        retries += 1
        
        print_error( e.to_s )
        print_info( ( 7 - retries ).to_s +
            ' retries remaining for url: ' + url.to_s )
            
        print_debug_backtrace( e )
        refresh_connection(url)
        retry unless retries > 7
    end
end

- (Object) refresh_connection(url)



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/anemone/http.rb', line 29

def refresh_connection( url )

    http = Net::HTTP.new( url.host, url.port,
    @opts['proxy_addr'], @opts['proxy_port'],
    @opts['proxy_user'], @opts['proxy_pass'] )

    if url.scheme == 'https'
        http.use_ssl = true
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end

    @connections[url.host][url.port] = http.start
end