Class: Arachni::Element::LinkTemplate
- Defined in:
- lib/arachni/element/link_template.rb,
lib/arachni/element/link_template/dom.rb
Overview
Represents an auditable link element whose inputs have been extracted based on an externally provided template.
Defined Under Namespace
Classes: DOM
Constant Summary collapse
- INVALID_INPUT_DATA =
[ # Protocol URLs require a // which we can't preserve. '://' ]
Constants included from Capabilities::Analyzable::Differential
Capabilities::Analyzable::Differential::DIFFERENTIAL_OPTIONS
Constants included from Capabilities::Analyzable::Taint
Capabilities::Analyzable::Taint::TAINT_OPTIONS
Constants included from Capabilities::Auditable
Capabilities::Auditable::OPTIONS
Constants included from Capabilities::Mutable
Capabilities::Mutable::MUTATION_OPTIONS
Instance Attribute Summary collapse
-
#template ⇒ Regexp
readonly
Regular expressions with named captures, serving as templates used to identify and manipulate inputs in Capabilities::Submittable#action.
Attributes included from Capabilities::Auditable
Attributes included from Capabilities::WithAuditor
Attributes included from Capabilities::Mutable
#affected_input_name, #format, #seed
Attributes included from Capabilities::Inputtable
Attributes included from Capabilities::WithNode
Attributes inherited from Base
#initialization_options, #page
Class Method Summary collapse
- .decode(*args) ⇒ Object
- .encode(string) ⇒ Object
-
.extract_inputs(url, templates = Arachni::Options.audit.link_templates) ⇒ Array[Regexp, Hash]
Extracts inputs from a URL based on the given templates.
-
.from_document(url, document, templates = Arachni::Options.audit.link_templates) ⇒ Array<LinkTemplate>
Extracts link with inputs based on the provided templates from a document.
-
.from_response(response, templates = Arachni::Options.audit.link_templates) ⇒ Array<Link>
Extracts links from an HTTP response.
- .from_rpc_data(data) ⇒ Object
- .type ⇒ Object
Instance Method Summary collapse
- #coverage_id ⇒ Object
- #decode(*args) ⇒ Object
- #dom ⇒ DOM
- #encode(string) ⇒ Object
- #id ⇒ Object
-
#initialize(options) ⇒ LinkTemplate
constructor
A new instance of LinkTemplate.
-
#simple ⇒ Hash
Simple representation of self in the form of ‘{ Capabilities::Submittable#action => Capabilities::Inputtable#inputs }`.
- #to_rpc_data ⇒ Object
-
#to_s ⇒ String
URL updated with the configured Capabilities::Inputtable#inputs.
-
#valid_input_data?(data) ⇒ Bool
‘true` if the `data` don’t contain strings specified in #INVALID_INPUT_DATA, ‘false` otherwise.
-
#valid_input_name?(name) ⇒ Bool
‘true` if the `name` can be found as a named capture in #template, `false` otherwise.
Methods included from Capabilities::Analyzable
has_timeout_candidates?, reset, timeout_audit_run
Methods included from Capabilities::Analyzable::Differential
Methods included from Capabilities::Analyzable::Timeout
add_phase_2_candidate, candidates_include?, deduplicate, deduplicate?, do_not_deduplicate, #ensure_responsiveness, has_candidates?, payload_delay_from_options, reset, run, #timeout_analysis, timeout_from_options, #timeout_id, #timing_attack_probe, #timing_attack_verify
Methods included from Capabilities::Analyzable::Taint
Methods included from Capabilities::Auditable
#audit, #audit_id, #audit_status_message, #audit_status_message_action, #audit_verbose_message, #coverage_hash, #dup, #matches_skip_like_blocks?, #reset, reset, #skip?, skip_like
Methods included from Capabilities::WithAuditor
#dup, #marshal_dump, #orphan?, #prepare_for_report, #remove_auditor
Methods included from Capabilities::Mutable
#affected_input_value, #affected_input_value=, #dup, #each_mutation, #immutables, #mutation?, #mutations, #reset, #switch_method, #to_h
Methods included from Capabilities::Submittable
#action, #action=, #dup, #http, #method, #method=, #platforms, #submit, #to_h
Methods included from Capabilities::Inputtable
#[], #[]=, #changes, #dup, #has_inputs?, #inputtable_id, #reset, #to_h, #try_input, #update, #valid_input_name_data?, #valid_input_value?, #valid_input_value_data?
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::WithDOM
Methods included from Capabilities::WithNode
Methods inherited from Base
#==, #action, #dup, #hash, #marshal_dump, #marshal_load, #persistent_hash, #prepare_for_report, #reset, #to_h, #to_hash, #type, #url, #url=
Methods included from Capabilities::WithScope
Constructor Details
#initialize(options) ⇒ LinkTemplate
Returns a new instance of LinkTemplate.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/arachni/element/link_template.rb', line 43 def initialize( ) super( ) @template = [:template] if [:inputs] self.inputs = [:inputs] else if @template _, inputs = self.class.extract_inputs( self.action, [@template] ) self.inputs = inputs if inputs else @template, inputs = self.class.extract_inputs( self.action ) if @template self.inputs = inputs end end end self.inputs ||= {} @default_inputs = self.inputs.dup.freeze end |
Instance Attribute Details
#template ⇒ Regexp (readonly)
Returns Regular expressions with named captures, serving as templates used to identify and manipulate inputs in Capabilities::Submittable#action.
33 34 35 |
# File 'lib/arachni/element/link_template.rb', line 33 def template @template end |
Class Method Details
.decode(*args) ⇒ Object
238 239 240 |
# File 'lib/arachni/element/link_template.rb', line 238 def decode( *args ) URI.decode( *args ) end |
.encode(string) ⇒ Object
234 235 236 |
# File 'lib/arachni/element/link_template.rb', line 234 def encode( string ) URI.encode( URI.encode( URI.encode( string, ';' ) ), '/' ) end |
.extract_inputs(url, templates = Arachni::Options.audit.link_templates) ⇒ Array[Regexp, Hash]
Extracts inputs from a URL based on the given templates.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/arachni/element/link_template.rb', line 219 def extract_inputs( url, templates = Arachni::Options.audit.link_templates ) return [] if !url || templates.empty? templates.each do |template| if (match = url.scan_in_groups( template )).any? return [ template, match.inject({}){ |h, (k, v)| h[k] = decode(v); h } ] end end [] end |
.from_document(url, document, templates = Arachni::Options.audit.link_templates) ⇒ Array<LinkTemplate>
Extracts link with inputs based on the provided templates from a document.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/arachni/element/link_template.rb', line 182 def from_document( url, document, templates = Arachni::Options.audit.link_templates ) return [] if templates.empty? document = Nokogiri::HTML( document.to_s ) if !document.is_a?( Nokogiri::HTML::Document ) base_url = begin document.search( '//base[@href]' )[0]['href'] rescue url end document.search( '//a' ).map do |link| next if !(href = to_absolute( link['href'], base_url )) template, inputs = extract_inputs( href, templates ) next if !template && !DOM.data_from_node( link ) if (parsed_url = Arachni::URI( href )) next if parsed_url.scope.out? end new( url: url.freeze, action: href.freeze, inputs: inputs || {}, template: template, html: link.to_html.freeze ) end.compact end |
.from_response(response, templates = Arachni::Options.audit.link_templates) ⇒ Array<Link>
Extracts links from an HTTP response.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/arachni/element/link_template.rb', line 154 def from_response( response, templates = Arachni::Options.audit.link_templates ) url = response.url links = from_document( url, response.body, templates ) template, inputs = extract_inputs( url, templates ) if template links << new( url: url.freeze, action: url.freeze, inputs: inputs, template: template ) end links end |
.from_rpc_data(data) ⇒ Object
143 144 145 146 |
# File 'lib/arachni/element/link_template.rb', line 143 def from_rpc_data( data ) data['template'] = Regexp.new( data['template'] ) if data['template'] super data end |
.type ⇒ Object
242 243 244 |
# File 'lib/arachni/element/link_template.rb', line 242 def type :link_template end |
Instance Method Details
#coverage_id ⇒ Object
123 124 125 |
# File 'lib/arachni/element/link_template.rb', line 123 def coverage_id dom_data ? "#{super}:#{dom_data[:inputs].keys.sort}" : super end |
#decode(*args) ⇒ Object
119 120 121 |
# File 'lib/arachni/element/link_template.rb', line 119 def decode( *args ) self.class.decode( *args ) end |
#dom ⇒ DOM
68 69 70 71 72 73 |
# File 'lib/arachni/element/link_template.rb', line 68 def dom return @dom if @dom return if !dom_data super end |
#encode(string) ⇒ Object
115 116 117 |
# File 'lib/arachni/element/link_template.rb', line 115 def encode( string ) self.class.encode( string ) end |
#id ⇒ Object
127 128 129 |
# File 'lib/arachni/element/link_template.rb', line 127 def id dom_data ? "#{super}:#{dom_data[:inputs].sort_by { |k,_| k }}" : super end |
#simple ⇒ Hash
Returns Simple representation of self in the form of ‘{ Capabilities::Submittable#action => Capabilities::Inputtable#inputs }`.
100 101 102 |
# File 'lib/arachni/element/link_template.rb', line 100 def simple { self.action => self.inputs } end |
#to_rpc_data ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/arachni/element/link_template.rb', line 131 def to_rpc_data data = super return data if !@template data.merge!( 'template' => @template.source ) data['initialization_options'][:template] = data['template'] data.delete 'dom_data' data end |
#to_s ⇒ String
Returns URL updated with the configured Capabilities::Inputtable#inputs.
106 107 108 109 110 111 112 113 |
# File 'lib/arachni/element/link_template.rb', line 106 def to_s return self.action if self.inputs.empty? self.action.sub_in_groups( @template, inputs.inject({}) { |h, (k, v)| h[k] = encode(v); h } ) end |
#valid_input_data?(data) ⇒ Bool
Returns ‘true` if the `data` don’t contain strings specified in #INVALID_INPUT_DATA, ‘false` otherwise.
94 95 96 |
# File 'lib/arachni/element/link_template.rb', line 94 def valid_input_data?( data ) !INVALID_INPUT_DATA.find { |c| data.include? c } end |
#valid_input_name?(name) ⇒ Bool
Returns ‘true` if the `name` can be found as a named capture in #template, `false` otherwise.
81 82 83 84 |
# File 'lib/arachni/element/link_template.rb', line 81 def valid_input_name?( name ) return if !@template @template.names.include? name end |