Class: Arachni::Element::Base Abstract
- Extended by:
- Utilities
- Includes:
- Capabilities::WithScope, Utilities
- Defined in:
- lib/arachni/element/base.rb
Overview
Base class for all element types.
Direct Known Subclasses
Body, Cookie, Cookie::DOM, Form, Form::DOM, GenericDOM, Header, JSON, Link, Link::DOM, LinkTemplate, LinkTemplate::DOM, Path, Server, XML
Constant Summary collapse
- MAX_SIZE =
Maximum element size in bytes. Anything larger than this should be exempt from parse and storage or have its value ignored.
During the audit, thousands of copies will be generated and the same amount of HTP requests will be stored in the HTTP::Client queue. Thus, elements with inputs of excessive size will lead to excessive RAM consumption.
This will almost never be necessary, but there have been cases of buggy ‘_VIEWSTATE` inputs that grow infinitely.
10_000
Instance Attribute Summary collapse
-
#initialization_options ⇒ Object
readonly
Options used to initialize an identical element.
-
#page ⇒ Page
Page this element belongs to.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #action ⇒ Object
- #dup ⇒ Object
- #hash ⇒ Object
-
#id ⇒ String
String uniquely identifying self.
-
#initialize(options) ⇒ Base
constructor
A new instance of Base.
- #marshal_dump ⇒ Object
- #marshal_load(h) ⇒ Object
- #persistent_hash ⇒ Object
- #prepare_for_report ⇒ Object abstract
-
#reset ⇒ Element::Base
abstract
Reset the element to its original state.
-
#to_h ⇒ Hash
Simple representation of self.
- #to_hash ⇒ Object
-
#to_rpc_data ⇒ Hash
Data representing this instance that are suitable the RPC transmission.
-
#type ⇒ Symbol
Element type.
-
#url ⇒ String
URL of the page that owns the element.
- #url=(url) ⇒ Object
Methods included from Utilities
available_port, bytes_to_kilobytes, bytes_to_megabytes, 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
Constructor Details
#initialize(options) ⇒ Base
Returns a new instance of Base.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/arachni/element/base.rb', line 62 def initialize( ) = .my_symbolize_keys( false ) if !([:url] || [:action]) fail 'Needs :url or :action option.' end @initialization_options = .dup self.url = [:url] || [:action] end |
Instance Attribute Details
#initialization_options ⇒ Object (readonly)
Returns Options used to initialize an identical element.
60 61 62 |
# File 'lib/arachni/element/base.rb', line 60 def @initialization_options end |
#page ⇒ Page
Returns Page this element belongs to.
56 57 58 |
# File 'lib/arachni/element/base.rb', line 56 def page @page end |
Class Method Details
.from_rpc_data(data) ⇒ Base
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/arachni/element/base.rb', line 179 def self.from_rpc_data( data ) instance = allocate data.each do |name, value| value = case name when 'dom' next if !value 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 |
.too_big?(element) ⇒ Boolean
205 206 207 |
# File 'lib/arachni/element/base.rb', line 205 def self.too_big?( element ) (element.is_a?( Numeric ) ? element : element.to_s.size) >= MAX_SIZE end |
.type ⇒ Symbol
Returns Element type.
139 140 141 |
# File 'lib/arachni/element/base.rb', line 139 def self.type @type ||= name.split( ':' ).last.downcase.to_sym end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
111 112 113 |
# File 'lib/arachni/element/base.rb', line 111 def ==( other ) hash == other.hash end |
#action ⇒ Object
122 123 124 |
# File 'lib/arachni/element/base.rb', line 122 def action url end |
#dup ⇒ Object
143 144 145 146 147 |
# File 'lib/arachni/element/base.rb', line 143 def dup dupped = self.class.new( self. ) dupped.page = page dupped end |
#hash ⇒ Object
103 104 105 |
# File 'lib/arachni/element/base.rb', line 103 def hash id.hash end |
#id ⇒ String
Returns String uniquely identifying self.
86 87 88 |
# File 'lib/arachni/element/base.rb', line 86 def id defined? super ? super : "#{action}:#{type}" end |
#marshal_dump ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/arachni/element/base.rb', line 149 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
157 158 159 |
# File 'lib/arachni/element/base.rb', line 157 def marshal_load( h ) h.each { |k, v| instance_variable_set( k, v ) } end |
#persistent_hash ⇒ Object
107 108 109 |
# File 'lib/arachni/element/base.rb', line 107 def persistent_hash id.persistent_hash end |
#prepare_for_report ⇒ Object
81 82 |
# File 'lib/arachni/element/base.rb', line 81 def prepare_for_report end |
#reset ⇒ Element::Base
Returns Reset the element to its original state.
76 77 78 |
# File 'lib/arachni/element/base.rb', line 76 def reset self end |
#to_h ⇒ Hash
Returns Simple representation of self.
92 93 94 95 96 97 98 |
# File 'lib/arachni/element/base.rb', line 92 def to_h { class: self.class.to_s, type: type, url: url } end |
#to_hash ⇒ Object
99 100 101 |
# File 'lib/arachni/element/base.rb', line 99 def to_hash to_h end |
#to_rpc_data ⇒ Hash
Returns Data representing this instance that are suitable the RPC transmission.
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/arachni/element/base.rb', line 163 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 if data['initialization_options'].is_a? Hash data['initialization_options'] = data['initialization_options'].my_stringify_keys(false) end data end |
#type ⇒ Symbol
Returns Element type.
133 134 135 |
# File 'lib/arachni/element/base.rb', line 133 def type self.class.type end |
#url ⇒ String
Returns URL of the page that owns the element.
118 119 120 |
# File 'lib/arachni/element/base.rb', line 118 def url @url end |
#url=(url) ⇒ Object
127 128 129 |
# File 'lib/arachni/element/base.rb', line 127 def url=( url ) @url = normalize_url( url ).freeze end |