Class: Arachni::Page

Inherits:
Object show all
Defined in:
lib/arachni/page.rb

Overview

It holds page data like elements, cookies, headers, etc…

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Page

Returns a new instance of Page.

Parameters:

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

    Hash from which to set instance attributes.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/arachni/page.rb', line 103

def initialize( opts = {} )
    opts.each { |k, v| instance_variable_set( "@#{k}".to_sym, try_dup( v ) ) }

    @forms ||= []
    @links ||= []
    @cookies ||= []
    @headers ||= []

    @cookiejar ||= {}
    @paths ||= []

    @response_headers ||= {}
    @request_headers  ||= {}
    @query_vars       ||= {}

    @url    = Utilities.normalize_url( @url )
    @body ||= ''
end

Instance Attribute Details

#bodyString (readonly)

Returns HTTP response body.

Returns:

  • (String)

    HTTP response body.



36
37
38
# File 'lib/arachni/page.rb', line 36

def body
  @body
end

#codeFixnum (readonly)

Returns HTTP response code.

Returns:

  • (Fixnum)

    HTTP response code.



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

def code
  @code
end

#cookiejarArray<Element::Cookie>

Returns Cookies extracted from the supplied cookie-jar.

Returns:



64
65
66
# File 'lib/arachni/page.rb', line 64

def cookiejar
  @cookiejar
end

#cookiesArray<Element::Cookie>



60
61
62
# File 'lib/arachni/page.rb', line 60

def cookies
  @cookies
end

#formsArray<Element::Form>

Returns:

See Also:



56
57
58
# File 'lib/arachni/page.rb', line 56

def forms
  @forms
end

#headersArray<Element::Header> (readonly)

Returns HTTP request headers.

Returns:



39
40
41
# File 'lib/arachni/page.rb', line 39

def headers
  @headers
end

Returns:

See Also:



52
53
54
# File 'lib/arachni/page.rb', line 52

def links
  @links
end

#pathsArray<String> (readonly)

Returns Paths contained in this page.

Returns:



48
49
50
# File 'lib/arachni/page.rb', line 48

def paths
  @paths
end

#query_varsHash (readonly)

Returns URL query parameters.

Returns:

  • (Hash)

    URL query parameters.



33
34
35
# File 'lib/arachni/page.rb', line 33

def query_vars
  @query_vars
end

#request_headersHash (readonly)

Returns HTTP request headers.

Returns:

  • (Hash)

    HTTP request headers.



42
43
44
# File 'lib/arachni/page.rb', line 42

def request_headers
  @request_headers
end

#response_headersHash (readonly)

Returns HTTP response headers.

Returns:

  • (Hash)

    HTTP response headers.



45
46
47
# File 'lib/arachni/page.rb', line 45

def response_headers
  @response_headers
end

#urlString (readonly)

Returns URL of the page.

Returns:

  • (String)

    URL of the page



27
28
29
# File 'lib/arachni/page.rb', line 27

def url
  @url
end

Class Method Details

.from_response(res, opts = Options) ⇒ Page Also known as: from_http_response

Parameters:

Returns:



97
98
99
# File 'lib/arachni/page.rb', line 97

def self.from_response( res, opts = Options )
    Parser.new( res, opts ).page
end

.from_url(url, opts = {}, &block) ⇒ Page

Parameters:

  • url (String)

    URL to fetch.

  • opts (Hash) (defaults to: {})
  • block (Block)

    Block to which to pass the page object. If given, the request will be performed asynchronously. If no block is given, the page will be fetched synchronously and be returned by this method.

Options Hash (opts):

  • :precision (Integer) — default: 1

    How many times to request the page and examine changes between requests. Used tp identify nonce tokens etc.

  • :http (Hash)

    HTTP request options.

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/arachni/page.rb', line 77

def self.from_url( url, opts = {}, &block )
    responses = []

    opts[:precision] ||= 1
    opts[:precision].times {
        HTTP.get( url, opts[:http] || {} ) do |res|
            responses << res
            next if responses.size != opts[:precision]
            block.call( from_response( responses ) ) if block_given?
        end
    }

    if !block_given?
        HTTP.run
        from_response( responses )
    end
end

Instance Method Details

#==(other) ⇒ Object



187
188
189
# File 'lib/arachni/page.rb', line 187

def ==( other )
    hash == other.hash
end

#documentNokogiri::HTML

Returns Parsed HTML document.

Returns:

  • (Nokogiri::HTML)

    Parsed HTML document.



144
145
146
# File 'lib/arachni/page.rb', line 144

def document
    @document ||= Nokogiri::HTML( @body )
end

#dupObject



195
196
197
# File 'lib/arachni/page.rb', line 195

def dup
    self.deep_clone
end

#elementsArray

Returns All page elements.

Returns:

  • (Array)

    All page elements.



128
129
130
# File 'lib/arachni/page.rb', line 128

def elements
    @links | @forms | @cookies | @headers
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/arachni/page.rb', line 191

def eql?( other )
    self == other
end

#hashObject



181
182
183
184
185
# File 'lib/arachni/page.rb', line 181

def hash
    ((links.map { |e| e.hash } + forms.map { |e| e.hash } +
        cookies.map { |e| e.hash } + headers.map { |e| e.hash }).sort.join +
        body.to_s).hash
end

#htmlObject

See Also:



139
140
141
# File 'lib/arachni/page.rb', line 139

def html
    @body
end

#marshal_dumpObject



148
149
150
151
152
153
154
# File 'lib/arachni/page.rb', line 148

def marshal_dump
    instance_variables.inject( {} ) do |h, iv|
        next h if iv == :@document
        h[iv] = instance_variable_get( iv )
        h
    end
end

#marshal_load(h) ⇒ Object



156
157
158
# File 'lib/arachni/page.rb', line 156

def marshal_load( h )
    h.each { |k, v| instance_variable_set( k, v ) }
end

#method(*args) ⇒ String

Returns the request method that returned the page.

Returns:

  • (String)

    the request method that returned the page



133
134
135
136
# File 'lib/arachni/page.rb', line 133

def method( *args )
    return super( *args ) if args.any?
    @method
end

#platformsPlatform

Returns Applicable platforms for the page.

Returns:

  • (Platform)

    Applicable platforms for the page.



123
124
125
# File 'lib/arachni/page.rb', line 123

def platforms
    Platform::Manager[@url]
end

#text?Boolean

Returns ‘true` if the body of the page is text-base, `false` otherwise.

Returns:

  • (Boolean)

    ‘true` if the body of the page is text-base, `false` otherwise.



162
163
164
# File 'lib/arachni/page.rb', line 162

def text?
    !!@text
end

#titleString

Returns Title of the page.

Returns:

  • (String)

    Title of the page.



167
168
169
# File 'lib/arachni/page.rb', line 167

def title
    document.css( 'title' ).first.text rescue nil
end

#to_hHash Also known as: to_hash

Returns Converts the page data to a hash.

Returns:

  • (Hash)

    Converts the page data to a hash.



172
173
174
175
176
177
178
# File 'lib/arachni/page.rb', line 172

def to_h
    instance_variables.reduce({}) do |h, iv|
        next h if iv == :@document
        h[iv.to_s.gsub( '@', '').to_sym] = try_dup( instance_variable_get( iv ) )
        h
    end
end