class Arachni::Element::Link
Represents an auditable link element
@author Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>
Constants
- DECODE_CACHE
Private Class Methods
decode( *args )
click to toggle source
# File lib/arachni/element/link.rb, line 134 def decode( *args ) DECODE_CACHE.fetch( args ) do ::URI.decode( *args ) end end
encode( string )
click to toggle source
# File lib/arachni/element/link.rb, line 130 def encode( string ) Arachni::HTTP::Request.encode string end
from_parser( parser )
click to toggle source
@param [Parser] parser
@return [Array<Link>]
# File lib/arachni/element/link.rb, line 106 def from_parser( parser ) return [] if parser.body && !in_html?( parser.body ) parser.document.nodes_by_name( :a ).map do |link| next if too_big?( link['href'] ) href = to_absolute( link['href'], parser.base ) next if !href next if !(parsed_url = Arachni::URI( href )) || parsed_url.scope.out? new( url: parser.url, action: href.freeze, source: link.to_html.freeze ) end.compact end
from_response( response )
click to toggle source
Extracts links from an HTTP
response.
@param [Arachni::HTTP::Response] response
@return [Array<Link>]
# File lib/arachni/element/link.rb, line 98 def from_response( response ) url = response.url [new( url: url )] | from_parser( Arachni::Parser.new( response ) ) end
in_html?( html )
click to toggle source
# File lib/arachni/element/link.rb, line 126 def in_html?( html ) html.has_html_tag? 'a', /\?.*=/ end
new( options )
click to toggle source
@param [Hash] options @option options [String] :url
URL of the page which includes the link.
@option options [String] :action
Link URL -- defaults to `:url`.
@option options [Hash] :inputs
Query parameters as `name => value` pairs. If none have been provided they will automatically be extracted from {#action}.
Calls superclass method
Arachni::Element::Capabilities::Inputtable::new
# File lib/arachni/element/link.rb, line 48 def initialize( options ) super( options ) self.inputs = (self.inputs || {}).merge( options[:inputs] || {} ) @default_inputs = self.inputs.dup.freeze end
Private Instance Methods
decode( *args )
click to toggle source
@see .decode
# File lib/arachni/element/link.rb, line 77 def decode( *args ) self.class.decode( *args ) end
encode( *args )
click to toggle source
@see .encode
# File lib/arachni/element/link.rb, line 72 def encode( *args ) self.class.encode( *args ) end
http_request( opts, &block )
click to toggle source
# File lib/arachni/element/link.rb, line 144 def http_request( opts, &block ) self.method != :get ? http.post( self.action, opts, &block ) : http.get( self.action, opts, &block ) end
id()
click to toggle source
Calls superclass method
Arachni::Element::Base#id
# File lib/arachni/element/link.rb, line 81 def id dom_data ? "#{super}:#{dom_data[:inputs].sort_by { |k,_| k }}" : super end
simple()
click to toggle source
@return [Hash]
Simple representation of self in the form of `{ {#action} => {#inputs} }`.
# File lib/arachni/element/link.rb, line 57 def simple { self.action => self.inputs } end
to_rpc_data()
click to toggle source
Calls superclass method
Arachni::Element::Capabilities::Mutable#to_rpc_data
# File lib/arachni/element/link.rb, line 85 def to_rpc_data data = super data.delete 'dom_data' data end
to_s()
click to toggle source
@return [String]
Absolute URL with a merged version of {#action} and {#inputs} as a query.
# File lib/arachni/element/link.rb, line 63 def to_s uri = uri_parse( self.action ).dup uri.query = self.inputs. map { |k, v| "#{encode(k)}=#{encode(v)}" }. join( '&' ) uri.to_s end