Sha256: 00f87ca4a3a36ce839b3188a0a49f0183929458675401f526ddd11df235d6ee6

Contents?: true

Size: 1.71 KB

Versions: 26

Compression:

Stored size: 1.71 KB

Contents

module CMSScanner
  module Finders
    class Finder
      # Module to provide an easy way to fingerprint things such as versions
      module Fingerprinter
        # @param [ Hash ] fingerprints The fingerprints
        # Format should be like the following:
        # {
        #   file_path_1: {
        #     md5_hash_1: version_1,
        #     md5_hash_2: [version_2]
        #   },
        #   file_path_2: {
        #     md5_hash_3: [version_1, version_2],
        #     md5_hash_4: version_3
        #   }
        # }
        # Note that the version can either be an array or a string
        #
        # @param [ Hash ] opts
        # @option opts [ Boolean ] :show_progression Wether or not to display the progress bar
        #
        # @yield [ Mixed, String, String ] version/s, url, hash The version associated to the
        #                                                       fingerprint of the url
        def fingerprint(fingerprints, opts = {})
          create_progress_bar(opts.merge(total: fingerprints.size))

          fingerprints.each do |path, f|
            url     = target.url(path.dup)
            request = browser.forge_request(url, request_params)

            request.on_complete do |res|
              progress_bar.increment

              md5sum = hexdigest(res.body)

              next unless f.key?(md5sum)

              yield f[md5sum], url, md5sum
            end

            hydra.queue(request)
          end

          hydra.run
        end

        # @return [ Hash ]
        def request_params
          {}
        end

        # @return [ String ] The hashed value for the given body
        def hexdigest(body)
          Digest::MD5.hexdigest(body)
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
cms_scanner-0.0.41.10 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.9 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.8 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.7 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.6 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.5 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.4 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.3 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.2 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.1 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.41.0 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.40.3 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.40.2 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.40.1 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.40 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.39.4 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.39.3 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.39.2 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.39.1 lib/cms_scanner/finders/finder/fingerprinter.rb
cms_scanner-0.0.39.0 lib/cms_scanner/finders/finder/fingerprinter.rb