Class: Arachni::ElementFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/arachni/element_filter.rb

Overview

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

Mostly used by the Trainer.

Author:

Constant Summary collapse

TYPES =
[:links, :forms, :cookies]

Class Method Summary collapse

Class Method Details

.cookiesSupport::LookUp::HashSet



# File 'lib/arachni/element_filter.rb', line 36

.cookies_include?(cookie) ⇒ Bool

Parameters:

Returns:

  • (Bool)


# File 'lib/arachni/element_filter.rb', line 52

.formsSupport::LookUp::HashSet



# File 'lib/arachni/element_filter.rb', line 32

.forms_include?(form) ⇒ Bool

Parameters:

Returns:

  • (Bool)


# File 'lib/arachni/element_filter.rb', line 40

.include?(element) ⇒ Bool

Parameters:

Returns:

  • (Bool)


109
110
111
112
113
114
115
# File 'lib/arachni/element_filter.rb', line 109

def include?( element )
    TYPES.each do |type|
        return true if send( "#{type}_include?", element )
    end

    false
end


# File 'lib/arachni/element_filter.rb', line 28

Parameters:

Returns:

  • (Bool)


# File 'lib/arachni/element_filter.rb', line 46

.resetObject



22
23
24
25
26
# File 'lib/arachni/element_filter.rb', line 22

def reset
    @mutex = Mutex.new
    State.element_filter.clear
    nil
end

Returns Amount of new cookies.

Parameters:

Returns:

  • (Integer)

    Amount of new cookies.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/arachni/element_filter.rb', line 79

TYPES.each do |type|
    define_method type do
        State.element_filter.send type
    end

    define_method "#{type}_include?" do |element|
        send(type).include? element.id
    end

    define_method "update_#{type}" do |elements|
        elements = [elements].flatten.compact
        return 0 if elements.size == 0

        synchronize do
            new_element_cnt = 0
            elements.each do |element|
                next if send( "#{type}_include?", element )

                send( "#{type}" ) << element.id
                new_element_cnt += 1
            end
            new_element_cnt
        end
    end

end

.update_forms(forms) ⇒ Integer

Returns Amount of new forms.

Parameters:

Returns:

  • (Integer)

    Amount of new forms.



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

.update_from_page(page) ⇒ Integer

Returns Amount of new elements.

Parameters:

Returns:

  • (Integer)

    Amount of new elements.



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

def update_from_page( page )
    TYPES.map { |type| send( "update_#{type}", page.send( type ) ) }.inject(&:+)
end

.update_from_page_cache(page) ⇒ Integer

Updates the elements from the Page#cache, useful in situations where resources need to be preserved (thus avoiding a full page parse) and the need for a full coverage update isn’t vital.

Parameters:

Returns:

  • (Integer)

    Amount of new elements.



133
134
135
# File 'lib/arachni/element_filter.rb', line 133

def update_from_page_cache( page )
    TYPES.map { |type| send( "update_#{type}", page.cache[type] ) }.inject(&:+)
end

Returns Amount of new links.

Parameters:

Returns:

  • (Integer)

    Amount of new links.



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