Module: Arachni::ElementFilter

Includes:
Utilities
Included in:
Trainer
Defined in:
lib/arachni/element_filter.rb

Overview

Filter for Page elements used to keep track of what elements have already been seen and separate them from new ones.

Mostly used by the Trainer.

Author:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#available_port, #cookie_encode, #cookies_from_document, #cookies_from_file, #cookies_from_response, #exception_jail, #exclude_path?, #extract_domain, #follow_protocol?, #form_decode, #form_encode, #form_parse_request_body, #forms_from_document, #forms_from_response, #generate_token, #get_path, #html_decode, #html_encode, #include_path?, #links_from_document, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_query, #parse_set_cookie, #parse_url_vars, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #redundant_path?, #remove_constants, #seed, #skip_page?, #skip_path?, #skip_resource?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parser, #url_sanitize

Class Method Details

.resetObject



34
35
36
37
38
# File 'lib/arachni/element_filter.rb', line 34

def self.reset
    @@forms.clear
    @@links.clear
    @@cookies.clear
end

Instance Method Details

Returns:

  • (Boolean)


139
140
141
142
# File 'lib/arachni/element_filter.rb', line 139

def cookie_in_jar?( cookie )
    @@cookies.each { |c| return true if c.raw['name'] == cookie.raw['name'] }
    false
end

#init_cookies(cookies) ⇒ Object

Initializes @@cookies with the cookies found during the crawl/analysis



63
64
65
# File 'lib/arachni/element_filter.rb', line 63

def init_cookies( cookies )
    @@cookies = cookies
end

#init_db_from_page(page) ⇒ Object



40
41
42
43
44
# File 'lib/arachni/element_filter.rb', line 40

def init_db_from_page( page )
    init_links page.links
    init_forms page.forms
    init_cookies page.cookies
end

#init_forms(forms) ⇒ Object

Initializes @@forms with the cookies found during the crawl/analysis



49
50
51
# File 'lib/arachni/element_filter.rb', line 49

def init_forms( forms )
    forms.each { |form| @@forms << form.id }
end

Initializes @@links with the links found during the crawl/analysis



56
57
58
# File 'lib/arachni/element_filter.rb', line 56

def init_links( links )
    links.each { |link| @@links << link.id }
end

#update_cookies(cookies) ⇒ Object

Updates @@cookies wth new cookies that may have dynamically appeared<br/> after analyzing the HTTP responses during the audit.

Parameters:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/arachni/element_filter.rb', line 116

def update_cookies( cookies )
    return [], 0 if cookies.size == 0

    cookie_cnt = 0
    @new_cookies ||= []

    cookies.reverse.each do |cookie|
        @@cookies.each_with_index do |page_cookie, i|
            if page_cookie.raw['name'] == cookie.raw['name']
                @@cookies[i] = cookie
            elsif !cookie_in_jar?( cookie )
                @new_cookies << cookie
                cookie_cnt += 1
            end
        end
    end

    @@cookies.flatten!
    @@cookies |= @new_cookies

    [@@cookies, cookie_cnt]
end

#update_forms(forms) ⇒ Object

Updates @@forms wth new forms that may have dynamically appeared<br/> after analyzing the HTTP responses during the audit.

Parameters:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/arachni/element_filter.rb', line 73

def update_forms( forms )
    return [], 0 if forms.size == 0

    form_cnt = 0
    new_forms ||= []

    forms.each do |form|
        next if @@forms.include?( form.id )
        @@forms   << form.id
        new_forms << form
        form_cnt += 1
    end

    [new_forms, form_cnt]
end

Updates @@links wth new links that may have dynamically appeared<br/> after analyzing the HTTP responses during the audit.

Parameters:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/arachni/element_filter.rb', line 95

def update_links( links )
  return [], 0 if links.size == 0

  link_cnt = 0
  new_links ||= []
  links.each do |link|
      next if @@links.include?( link.id )
      @@links   << link.id
      new_links << link
      link_cnt += 1
  end

  [new_links, link_cnt]
end