Class: WPScan::Finders::DynamicFinder::Version::ConfigParser

Inherits:
Finder
  • Object
show all
Defined in:
lib/wpscan/finders/dynamic_finder/version/config_parser.rb

Overview

Version finder using by parsing config files, such as composer.json and so on

Direct Known Subclasses

WpItemVersion::ConfigParser

Constant Summary collapse

ALLOWED_PARSERS =
[JSON, YAML].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Finder

#aggressive, child_class_constant, create_child_class

Class Method Details

.child_class_constantsObject



12
13
14
15
16
# File 'lib/wpscan/finders/dynamic_finder/version/config_parser.rb', line 12

def self.child_class_constants
  @child_class_constants ||= super.merge(
    PARSER: nil, KEY: nil, PATTERN: /(?<v>\d+\.[\.\d]+)/, CONFIDENCE: 70
  )
end

Instance Method Details

#find(response, _opts = {}) ⇒ Version

Parameters:

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wpscan/finders/dynamic_finder/version/config_parser.rb', line 42

def find(response, _opts = {})
  parsed_body = parse(response.body)
  # Create indexes for the #dig, digits are converted to integers
  indexes     = self.class::KEY.split(':').map { |e| e == e.to_i.to_s ? e.to_i : e }

  return unless (data = parsed_body&.dig(*indexes)) && data =~ self.class::PATTERN

  create_version(
    Regexp.last_match[:v],
    interesting_entries: ["#{response.effective_url}, Match: '#{Regexp.last_match}'"]
  )
end

#parse(body) ⇒ Hash?

Returns The parsed body, with an available parser, if possible.

Parameters:

  • body (String)

Returns:

  • (Hash, nil)

    The parsed body, with an available parser, if possible



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wpscan/finders/dynamic_finder/version/config_parser.rb', line 20

def parse(body)
  parsers = ALLOWED_PARSERS.include?(self.class::PARSER) ? [self.class::PARSER] : ALLOWED_PARSERS

  parsers.each do |parser|
    begin
      parsed = parser.respond_to?(:safe_load) ? parser.safe_load(body) : parser.load(body)

      return parsed if parsed.is_a?(Hash) || parsed.is_a?(Array)
    rescue StandardError
      next
    end
  end

  nil # Make sure nil is returned in case none of the parsers managed to parse the body correctly
end

#passive(opts = {}) ⇒ Object

No Passive way



37
# File 'lib/wpscan/finders/dynamic_finder/version/config_parser.rb', line 37

def passive(opts = {}); end