Class: Arachni::Element::Server

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

Overview

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

Author:

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, #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?, #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.



19
20
21
22
# File 'lib/arachni/element/server.rb', line 19

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

Instance Method Details

#httpObject



90
91
92
# File 'lib/arachni/element/server.rb', line 90

def http
    auditor.http
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)
    • ‘nil` if no URL was provided.

    • ‘false` if the request couldn’t be fired.

    • ‘true` if everything went fine.

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/arachni/element/server.rb', line 43

def log_remote_file_if_exists( url, silent = false, &block )
    return nil if !url

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

        block.call( res ) if block_given?
        auditor.log_remote_file( res )

        # If the file exists let the trainer parse it since it may contain
        # brand new data to audit.
        auditor.framework.trainer.push( res )
    end
    true
end

#remote_file_exist?(url, &block) ⇒ Boolean 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:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/arachni/element/server.rb', line 71

def remote_file_exist?( url, &block )
    if http.needs_custom_404_check?( url )
        http.get( url, performer: self ) do |r|
            if r.code == 200
                http.custom_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

    nil
end