Class: WhatWeb::Matcher::GHDB
- Inherits:
-
Base
show all
- Defined in:
- lib/whatweb/matcher/ghdb.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#match, #target
Instance Method Summary
collapse
Methods inherited from Base
#compiled_regexp, match?, #search_context
Constructor Details
#initialize(target, match) ⇒ GHDB
Returns a new instance of GHDB.
7
8
9
10
|
# File 'lib/whatweb/matcher/ghdb.rb', line 7
def initialize(target, match)
super(target, match)
@query = match[:ghdb].to_s
end
|
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
6
7
8
|
# File 'lib/whatweb/matcher/ghdb.rb', line 6
def query
@query
end
|
Instance Method Details
#match? ⇒ Boolean
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/whatweb/matcher/ghdb.rb', line 56
def match?
matches = []
matches << match_intitle? if /intitle:/i.match?(query)
matches << match_filetype? if /filetype:/i.match?(query)
matches << match_inurl? if /inurl:/i.match?(query)
matches << match_others?
matches.uniq == [true]
end
|
#match_filetype? ⇒ Boolean
19
20
21
22
23
24
|
# File 'lib/whatweb/matcher/ghdb.rb', line 19
def match_filetype?
filetype = (query.scan(/filetype:"([^"]*)"/i) + query.scan(/filetype:([^"]\w+)/i)).flatten.join("|")
return false if filetype.empty?
base_uri = target.uri.to_s.split("?").first
base_uri.match? /#{Regexp.escape(filetype)}$/i
end
|
#match_intitle? ⇒ Boolean
12
13
14
15
16
17
|
# File 'lib/whatweb/matcher/ghdb.rb', line 12
def match_intitle?
intitle = (query.scan(/intitle:"([^"]*)"/i) + query.scan(/intitle:([^"]\w+)/i)).flatten.join("|")
return false if intitle.empty?
target.body.match? /<title>[^<]*#{Regexp.escape(intitle)}[^<]*<\/title>/i
end
|
#match_inurl? ⇒ Boolean
26
27
28
29
30
31
|
# File 'lib/whatweb/matcher/ghdb.rb', line 26
def match_inurl?
inurl = (query.scan(/inurl:"([^"]*)"/i) + query.scan(/inurl:([^"]\w+)(\.*)(\w*)/i)).flatten
return false if inurl.empty?
inurl.all? { |x| target.uri.to_s.match? /#{Regexp.escape(x)}/i }
end
|
#match_others? ⇒ Boolean
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/whatweb/matcher/ghdb.rb', line 41
def match_others?
words = query_for_others.scan(/([^ "]+)|("[^"]+")/i).flatten.compact.each { |w| w.delete!('"') }.sort.uniq
return false if words.empty?
words.all? do |w|
if w[0] == '-'
!target.text.match? /#{Regexp.escape(w[1..-1])}/i
else
w = w[1..-1] if w[0] == '+' target.text.match? /#{Regexp.escape(w)}/i
end
end
end
|
#query_for_others ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/whatweb/matcher/ghdb.rb', line 33
def query_for_others
s = query
s = s.gsub(/intitle:"([^"]*)"/i, '').gsub(/intitle:([^"]\w+)/i, '')
s = s.gsub(/filetype:"([^"]*)"/i, '').gsub( /filetype:([^"]\w+)/i, '')
s = s.gsub(/inurl:"([^"]*)"/i, '').gsub(/inurl:([^"]\w+)(\.*)(\w*)/i, '')
s
end
|