Class: Arachni::Element::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
Utilities
Includes:
Capabilities::WithScope, Utilities
Defined in:
lib/arachni/element/base.rb

Overview

This class is abstract.

Base class for all element types.

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options) ⇒ Base

Returns a new instance of Base.



50
51
52
53
54
55
56
57
58
59
# File 'lib/arachni/element/base.rb', line 50

def initialize( options )
    options = options.my_symbolize_keys( false )

    if !(options[:url] || options[:action])
        fail 'Needs :url or :action option.'
    end

    @initialization_options = options.dup
    self.url = options[:url] || options[:action]
end

Instance Attribute Details

#initialization_optionsObject (readonly)

Returns Options used to initialize an identical element.

Returns:

  • (Object)

    Options used to initialize an identical element.



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

def initialization_options
  @initialization_options
end

#pagePage

Returns Page this element belongs to.

Returns:

  • (Page)

    Page this element belongs to.



44
45
46
# File 'lib/arachni/element/base.rb', line 44

def page
  @page
end

Class Method Details

.from_rpc_data(data) ⇒ Base

Parameters:

Returns:



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/arachni/element/base.rb', line 161

def self.from_rpc_data( data )
    instance = allocate
    data.each do |name, value|
        value = case name
                    when 'dom'
                        self::DOM.from_rpc_data( value )

                    when 'initialization_options'
                        value.is_a?( Hash ) ?
                            value.my_symbolize_keys( false ) : value

                    when 'method'
                        value.to_sym

                    else
                        value
                end

        instance.instance_variable_set( "@#{name}", value )
    end

    instance.instance_variable_set( :@audit_options, {} )
    instance
end

.typeSymbol

Returns Element type.

Returns:

  • (Symbol)

    Element type.



127
128
129
# File 'lib/arachni/element/base.rb', line 127

def self.type
    name.split( ':' ).last.downcase.to_sym
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



99
100
101
# File 'lib/arachni/element/base.rb', line 99

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

#actionObject



110
111
112
# File 'lib/arachni/element/base.rb', line 110

def action
    url
end

#dupObject



131
132
133
134
135
# File 'lib/arachni/element/base.rb', line 131

def dup
    dupped = self.class.new( self.initialization_options )
    dupped.page = page
    dupped
end

#hashObject



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

def hash
    id.hash
end

#idString

Returns String uniquely identifying self.

Returns:

  • (String)

    String uniquely identifying self.



74
75
76
# File 'lib/arachni/element/base.rb', line 74

def id
    defined? super ? super : "#{action}:#{type}"
end

#marshal_dumpObject



137
138
139
140
141
142
143
# File 'lib/arachni/element/base.rb', line 137

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

#marshal_load(h) ⇒ Object



145
146
147
# File 'lib/arachni/element/base.rb', line 145

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

#persistent_hashObject



95
96
97
# File 'lib/arachni/element/base.rb', line 95

def persistent_hash
    id.persistent_hash
end

#prepare_for_reportObject

This method is abstract.


69
70
# File 'lib/arachni/element/base.rb', line 69

def prepare_for_report
end

#resetElement::Base

This method is abstract.

Returns Reset the element to its original state.

Returns:



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

def reset
    self
end

#to_hHash

Returns Simple representation of self.

Returns:

  • (Hash)

    Simple representation of self.



80
81
82
83
84
85
86
# File 'lib/arachni/element/base.rb', line 80

def to_h
    {
        class: self.class.to_s,
        type:  type,
        url:   url
    }
end

#to_hashObject



87
88
89
# File 'lib/arachni/element/base.rb', line 87

def to_hash
    to_h
end

#to_rpc_dataHash

Returns Data representing this instance that are suitable the RPC transmission.

Returns:

  • (Hash)

    Data representing this instance that are suitable the RPC transmission.



151
152
153
154
155
156
157
# File 'lib/arachni/element/base.rb', line 151

def to_rpc_data
    data = marshal_dump.inject({}) { |h, (k, v)| h[k.to_s.gsub('@', '')] = v.to_rpc_data_or_self; h }
    data.delete 'audit_options'
    data.delete 'scope'
    data['class'] = self.class.to_s
    data
end

#typeSymbol

Returns Element type.

Returns:

  • (Symbol)

    Element type.



121
122
123
# File 'lib/arachni/element/base.rb', line 121

def type
    self.class.type
end

#urlString

Returns URL of the page that owns the element.

Returns:

  • (String)

    URL of the page that owns the element.



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

def url
    @url
end

#url=(url) ⇒ Object

See Also:



115
116
117
# File 'lib/arachni/element/base.rb', line 115

def url=( url )
    @url = normalize_url( url ).freeze
end