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.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/arachni/page.rb', line 123

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 the HTML response.

Returns:

  • (String)

    the HTML response



50
51
52
# File 'lib/arachni/page.rb', line 50

def body
  @body
end

#codeFixnum (readonly)

Returns the HTTP response code.

Returns:

  • (Fixnum)

    the HTTP response code



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

def code
  @code
end

#cookiejarArray<Element::Cookie>

Cookies extracted from the supplied cookiejar

Returns:



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

def cookiejar
  @cookiejar
end

#cookiesArray<Element::Cookie>



91
92
93
# File 'lib/arachni/page.rb', line 91

def cookies
  @cookies
end

#formsArray<Element::Form>

Returns:

See Also:



84
85
86
# File 'lib/arachni/page.rb', line 84

def forms
  @forms
end

#headersArray<Element::Header> (readonly)

Request headers

Returns:



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

def headers
  @headers
end

Returns:

See Also:



77
78
79
# File 'lib/arachni/page.rb', line 77

def links
  @links
end

#methodString (readonly)

Returns the request method that returned the page.

Returns:

  • (String)

    the request method that returned the page



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

def method
  @method
end

#pathsArray<String> (readonly)

Returns:



70
71
72
# File 'lib/arachni/page.rb', line 70

def paths
  @paths
end

#query_varsHash (readonly)

Returns url variables.

Returns:

  • (Hash)

    url variables



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

def query_vars
  @query_vars
end

#request_headersHash (readonly)

Returns:

  • (Hash)


62
63
64
# File 'lib/arachni/page.rb', line 62

def request_headers
  @request_headers
end

#response_headersHash (readonly)

Returns:

  • (Hash)


67
68
69
# File 'lib/arachni/page.rb', line 67

def response_headers
  @response_headers
end

#urlString (readonly)

Returns url of the page.

Returns:

  • (String)

    url of the page



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

def url
  @url
end

Class Method Details

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



118
119
120
# File 'lib/arachni/page.rb', line 118

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

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/arachni/page.rb', line 100

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



173
174
175
# File 'lib/arachni/page.rb', line 173

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

#documentObject



146
147
148
# File 'lib/arachni/page.rb', line 146

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

#dupObject



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

def dup
    self.deep_clone
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/arachni/page.rb', line 177

def eql?( other )
    self == other
end

#hashObject



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

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



142
143
144
# File 'lib/arachni/page.rb', line 142

def html
    @body
end

#text?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/arachni/page.rb', line 150

def text?
    !!@text
end

#titleObject



154
155
156
# File 'lib/arachni/page.rb', line 154

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

#to_hashObject



158
159
160
161
162
163
164
165
# File 'lib/arachni/page.rb', line 158

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