Class: Anemone::Core

Inherits:
Object
  • Object
show all
Includes:
Arachni::UI::Output
Defined in:
lib/anemone/core.rb

Overview

Overides Anemone’s Core class method skip_link?( link ) to support regexp matching to the whole url and enforce redundancy checks.
Messages were also added to inform the user in case of redundant URLs.

@author: Anastasios “Zapotek” Laskos

                                     <tasos.laskos@gmail.com>
                                     <zapotek@segfault.gr>

@version: 0.1-pre

Instance Method Summary (collapse)

Methods included from Arachni::UI::Output

#debug!, #debug?, #only_positives!, #only_positives?, #print_debug, #print_debug_backtrace, #print_debug_pp, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #verbose!, #verbose?

Instance Method Details

- (Object) do_page_blocks(page)

Execute the on_every_page blocks for page

Modified it to fix a bug in Anemone when given more than one
regular expression for “@on_pages_like_blocks”.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/anemone/core.rb', line 72

def do_page_blocks(page)
    @on_every_page_blocks.each do |block|
        block.call(page)
    end

    @on_pages_like_blocks.each do |patterns, blocks|
        if matches_pattern?( page.url.to_s, patterns )
            blocks.each { |block| block.call(page) }
        end
    end
end

- (Bool) matches_pattern?(url, patterns)

Decides whether or not a url matches any of the regular expressions in “patterns”.

Parameters:

  • (String) url
  • (Array) patterns

    array of regular expressions

Returns:

  • (Bool)


93
94
95
96
97
98
99
100
101
# File 'lib/anemone/core.rb', line 93

def matches_pattern?( url, patterns )
    
    patterns.each {
        |pattern|
        return true if url =~ pattern
    }
    
    return false
end

- (Boolean) skip_link?(link)

Returns true if link should not be visited because its URL matches a skip_link pattern or the reundancy countdown has reached zero.

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/anemone/core.rb', line 37

def skip_link?( link )

    url = link.to_s
    skip = false
    @opts['redundant'].each_with_index {
        |redundant, i|

        if( url =~ redundant['regexp'] )

            if( @opts['redundant'][i]['count'] == 0 )
                print_verbose( 'Discarding redundant page: \'' + url + '\'' )
                return true
            end

            print_info( 'Matched redundancy rule: ' +
            redundant['regexp'].to_s + ' for page \'' +
            url + '\'' )

            print_info( 'Count-down: ' +
            @opts['redundant'][i]['count'].to_s )

            @opts['redundant'][i]['count'] -= 1
        end
    }

    @skip_link_patterns.any? { |pattern| url =~ pattern }

end