Class: WhatWeb::Plugin

Inherits:
Object show all
Defined in:
lib/whatweb/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Plugin

Returns a new instance of Plugin.



9
10
11
12
13
14
# File 'lib/whatweb/plugin.rb', line 9

def initialize(name, &block)
  @name = name
  @locked = false
  instance_eval(&block)
  startup
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



8
9
10
# File 'lib/whatweb/plugin.rb', line 8

def author
  @author
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/whatweb/plugin.rb', line 8

def description
  @description
end

#dorksObject (readonly)

Returns the value of attribute dorks.



8
9
10
# File 'lib/whatweb/plugin.rb', line 8

def dorks
  @dorks
end

#matchesObject (readonly)

Returns the value of attribute matches.



8
9
10
# File 'lib/whatweb/plugin.rb', line 8

def matches
  @matches
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/whatweb/plugin.rb', line 8

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/whatweb/plugin.rb', line 8

def version
  @version
end

#websiteObject (readonly)

Returns the value of attribute website.



8
9
10
# File 'lib/whatweb/plugin.rb', line 8

def website
  @website
end

Class Method Details

.define(name, &block) ⇒ Object



16
17
18
19
20
# File 'lib/whatweb/plugin.rb', line 16

def self.define(name, &block)
  plugin = new(name, &block)
  PluginManager.instance.add_plugin plugin
  plugin
end

Instance Method Details

#aggressive(_target) ⇒ Object



36
37
38
# File 'lib/whatweb/plugin.rb', line 36

def aggressive(_target)
  []
end

#execute(target, is_aggressive = false) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/whatweb/plugin.rb', line 91

def execute(target, is_aggressive = false)
  results = []
  results += matches.map { |match| matching(target, match) } if matches
  results += passive(target)
  results += aggressive(target) if is_aggressive
  results.flatten!
  results.compact!
  results.each { |result| result[:certainty] = 100 unless result.key?(:certainty) }
  results
end

#lockObject



40
41
42
# File 'lib/whatweb/plugin.rb', line 40

def lock
  @locked = true
end

#locked?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/whatweb/plugin.rb', line 48

def locked?
  @locked
end

#matchers(target, match) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/whatweb/plugin.rb', line 56

def matchers(target, match)
  {
    ghdb:         Matcher::GHDB.new(target, match),
    text:         Matcher::Text.new(target, match),
    md5:          Matcher::MD5.new(target, match),
    tag_pattern:  Matcher::TagPattern.new(target, match),
    regexp:       Matcher::Common.new(target, match),
    account:      Matcher::Common.new(target, match),
    version:      Matcher::Common.new(target, match),
    os:           Matcher::Common.new(target, match),
    module:       Matcher::Common.new(target, match),
    model:        Matcher::Common.new(target, match),
    string:       Matcher::Common.new(target, match),
    firmware:     Matcher::Common.new(target, match),
    filepath:     Matcher::Common.new(target, match),
  }
end

#matching(target, match) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/whatweb/plugin.rb', line 74

def matching(target, match)
  results = []
  matchers(target, match).each do |key, matcher|
    next unless match.key?(key) && matcher.match?
    results << match
    # if a matcher is the common matcher, replace the key's value to the regexp match result
    results.last[key] = matcher.match_results if common_matcher?(matcher)
  end
  # return results if there is any match so far
  return results if results
  # if url and status are present, they must both match
  # url and status cannot be alone. there must be something else that has already matched
  results << match if Matcher::Status.match?(target, match)
  results << match if Matcher::URL.match?(target, match)
  results
end

#passive(_target) ⇒ Object



32
33
34
# File 'lib/whatweb/plugin.rb', line 32

def passive(_target)
  []
end

#randstrObject



52
53
54
# File 'lib/whatweb/plugin.rb', line 52

def randstr
  rand(36**8).to_s(36)
end

#shutdownObject

individual plugins can override this



30
# File 'lib/whatweb/plugin.rb', line 30

def shutdown; end

#startupObject

individual plugins can override this



27
# File 'lib/whatweb/plugin.rb', line 27

def startup; end

#unlockObject



44
45
46
# File 'lib/whatweb/plugin.rb', line 44

def unlock
  @locked = false
end

#version_detection?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/whatweb/plugin.rb', line 22

def version_detection?
  matches.any? { |match| match.key? :version }
end