Module: CMSScanner::Finders::Finder::Enumerator
- Included in:
- Fingerprinter
- Defined in:
- lib/cms_scanner/finders/finder/enumerator.rb
Overview
Module to provide an easy way to enumerate items such as plugins, themes etc
Instance Method Summary collapse
- #enumerate(urls, opts = {}) {|Typhoeus::Response, String| ... } ⇒ Object
- #full_request_params ⇒ Hash
- #head_or_get_request_params ⇒ Hash
- #maybe_get_full_response(head_res, opts) ⇒ Typhoeus::Response?
- #valid_response_codes ⇒ Array<Integer>
Instance Method Details
#enumerate(urls, opts = {}) {|Typhoeus::Response, String| ... } ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 28 def enumerate(urls, opts = {}) (opts.merge(total: urls.size)) urls.each do |url, id| request = browser.forge_request(url, head_or_get_request_params) request.on_complete do |head_res| .increment next unless valid_response_codes.include?(head_res.code) next if opts[:exclude_content] && head_res.response_headers&.match(opts[:exclude_content]) head_or_full_res = maybe_get_full_response(head_res, opts) yield head_or_full_res, id if head_or_full_res end hydra.queue(request) end hydra.run end |
#full_request_params ⇒ Hash
71 72 73 |
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 71 def full_request_params @full_request_params ||= {} end |
#head_or_get_request_params ⇒ Hash
9 10 11 12 13 14 |
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 9 def head_or_get_request_params # Disabling the cache, as it causes a 'stack level too deep' exception # with a large number of requests. # See https://github.com/typhoeus/typhoeus/issues/408 @head_or_get_request_params ||= target.head_or_get_params.merge(cache_ttl: 0) end |
#maybe_get_full_response(head_res, opts) ⇒ Typhoeus::Response?
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 56 def maybe_get_full_response(head_res, opts) return head_res unless opts[:check_full_response] == true || Array(opts[:check_full_response]).include?(head_res.code) full_res = NS::Browser.get(head_res.effective_url, full_request_params) return unless valid_response_codes.include?(full_res.code) return if target.homepage_or_404?(full_res) || (opts[:exclude_content] && full_res.body&.match(opts[:exclude_content])) full_res end |
#valid_response_codes ⇒ Array<Integer>
17 18 19 |
# File 'lib/cms_scanner/finders/finder/enumerator.rb', line 17 def valid_response_codes @valid_response_codes ||= [200] end |