Class: Arachni::Element::Server

Inherits:
Base show all
Includes:
Capabilities::WithAuditor
Defined in:
lib/arachni/element/server.rb

Overview

Represents a remote server, mainly for checking for and logging remote resources.

Author:

Constant Summary collapse

SIMILARITY_TOLERANCE =

Used to determine how different a resource should be in order to be sent to the Trainer#push.

Ideally, all identified resources should be analyzed by the Trainer but there can be cases where unreliable custom-4o4 signatures lead to FPs and feeding FPs to the system can create an infinite loop.

0.25

Instance Attribute Summary

Attributes included from Capabilities::WithAuditor

#auditor

Attributes inherited from Base

#initialization_options, #page

Instance Method Summary collapse

Methods included from Capabilities::WithAuditor

#dup, #marshal_dump, #orphan?, #prepare_for_report, #remove_auditor

Methods inherited from Base

#==, #action, #dup, from_rpc_data, #hash, #id, #marshal_dump, #marshal_load, #persistent_hash, #prepare_for_report, #reset, #to_h, #to_hash, #to_rpc_data, type, #type, #url, #url=

Methods included from Utilities

#available_port, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_document, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite

Methods included from Capabilities::WithScope

#scope

Constructor Details

#initialize(url) ⇒ Server

Returns a new instance of Server.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/arachni/element/server.rb', line 27

def initialize( url )
    super url: url
    @initialization_options = url

    # Holds possible issue responses, they'll be logged after #analyze
    # goes over them.
    @candidates = []

    # Process responses that may point to issues.
    http.after_run( &method(:analyze) )
end

Instance Method Details

#httpObject



106
107
108
# File 'lib/arachni/element/server.rb', line 106

def http
    Arachni::HTTP::Client
end

#inspectObject



110
111
112
113
114
115
116
117
118
119
# File 'lib/arachni/element/server.rb', line 110

def inspect
    s = "#<#{self.class} "

    if !orphan?
        s << "auditor=#{auditor.class} "
    end

    s << "url=#{url.inspect}"
    s << '>'
end

#log_remote_file_if_exists(url, silent = false, &block) ⇒ Object Also known as: log_remote_directory_if_exists

Note:

Ignores custom 404 responses.

Logs a remote file or directory if it exists.

Parameters:

  • url (String)

    Resource to check.

  • silent (Bool) (defaults to: false)

    If ‘false`, a message will be printed to stdout containing the status of the operation.

  • block (Proc)

    Called if the file exists, just before logging the issue, and is passed the HTTP response.

Returns:

  • (Object)
    • ‘false` if an invalid URL was provided.

    • ‘true` if everything went fine.

See Also:



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/arachni/element/server.rb', line 57

def log_remote_file_if_exists( url, silent = false, &block )
    # Make sure the URL is valid.
    return false if !full_and_absolute_url?( url )

    auditor.print_status( "Checking for #{url}" ) if !silent
    remote_file_exist?( url ) do |bool, response|
        auditor.print_status( "Analyzing response for: #{url}" ) if !silent
        next if !bool

        @candidates << [response, block]
    end
end

#remote_file_exist?(url, &block) ⇒ Object Also known as: remote_file_exists?

Note:

Ignores custom 404 responses.

Checks whether or not a remote resource exists.

Parameters:

  • url (String)

    Resource to check.

  • block (Block)

    Block to be passed ‘true` if the resource exists or `false` otherwise and the response for the resource check.

Returns:

  • (Object)
    • ‘false` if an invalid URL was provided.

    • ‘true` if everything went fine.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/arachni/element/server.rb', line 84

def remote_file_exist?( url, &block )
    # Make sure the URL is valid.
    return false if !full_and_absolute_url?( url )

    if http.dynamic_404_handler.needs_check?( url )
        http.get( url, performer: self ) do |r|
            if r.code == 200
                http.dynamic_404_handler._404?( r ) { |bool| block.call( !bool, r ) }
            else
                block.call( false, r )
            end
        end
    else
        http.request( url, method: :head, performer: self ) do |response|
            block.call( response.code == 200, response )
        end
    end

    true
end