lib/arachni/element/body.rb in arachni-0.4.7 vs lib/arachni/element/body.rb in arachni-1.0

- old
+ new

@@ -1,19 +1,49 @@ =begin - Copyright 2010-2014 Tasos Laskos <tasos.laskos@gmail.com> + Copyright 2010-2014 Tasos Laskos <tasos.laskos@arachni-scanner.com> - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + This file is part of the Arachni Framework project and is subject to + redistribution and commercial restrictions. Please see the Arachni Framework + web site for more information on licensing and terms of use. =end +require Arachni::Options.paths.lib + 'element/base' + module Arachni::Element - BODY = 'body' + +# @author Tasos "Zapotek" Laskos <tasos.laskos@arachni-scanner.com> +class Body < Base + include Capabilities::WithAuditor + + def initialize( url ) + super url: url + @initialization_options = url + end + + # Matches an array of regular expressions against a string and logs the + # result as an issue. + # + # @param [Array<Regexp>] patterns + # Array of regular expressions to be tested. + # @param [Block] block + # Block to verify matches before logging, must return `true`/`false`. + def match_and_log( patterns, &block ) + elements = auditor.class.info[:elements] + elements = auditor.class::OPTIONS[:elements] if !elements || elements.empty? + + return if !elements.include?( Body ) + + [patterns].flatten.each do |pattern| + auditor.page.body.scan( pattern ).flatten.uniq.compact.each do |proof| + next if block_given? && !block.call( proof ) + + auditor.log( + signature: pattern, + proof: proof, + vector: self + ) + end + end + end + +end end