Module: Wmap::Utils::WpDetect

Extended by:
WpDetect
Included in:
SiteTracker::WpTracker, WpDetect
Defined in:
lib/wmap/utils/wp_detect.rb

Instance Method Summary collapse

Instance Method Details

#is_wp?(url) ⇒ Boolean

Main method to detect if it’s a wordpress site

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/wmap/utils/wp_detect.rb', line 16

def is_wp?(url)
	site=url_2_site(url)
	if wp_readme?(site)
		return true
	elsif wp_css?(site)
		return true
	elsif wp_meta?(site)
		return true
	elsif wp_login?(site)
		return true
	elsif wp_rpc?(site)
		return true
	elsif wp_gen?(site)
		return true
   elsif wp_load_styles?(site)
		return true
	else
		return false
	end
rescue => ee
	puts "Exception on method #{__method__}: #{ee}: #{url}" if @verbose
end

#wp_css?(url) ⇒ Boolean

Wordpress detection checkpoint - install.css

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/wmap/utils/wp_detect.rb', line 94

def wp_css?(url)
site = url_2_site(url)
  css_url = site + "wp-admin/css/install.css"
  k=Wmap::UrlChecker.new
  if k.response_code(css_url) == 200
    k=nil
    parser = CssParser::Parser.new
    parser.load_uri!(css_url)
    rule = parser.find_by_selector('#logo a')
    if rule.length >0
      if rule[0] =~ /wordpress/i
        return true
      end
    end
  else
    k=nil
    return false
  end
  return false
  	rescue => ee
puts "Exception on method #{__method__} for site #{url}: #{ee}" if @verbose
return false
end

#wp_gen?(url) ⇒ Boolean

Wordpress detection checkpoint - WP generator tag

Returns:

  • (Boolean)


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/wmap/utils/wp_detect.rb', line 139

def wp_gen?(url)
puts "#{__method__} check for #{url}" if @verbose
site = url_2_site(url)
gen_url_1 = site + "feed/"
gen_url_2 = site + "comments/feed"
  k=Wmap::UrlChecker.new
  if k.response_code(gen_url_1) == 200
    doc=open_page(gen_url_1)
elsif k.response_code(gen_url_2) == 200
	doc=open_page(gen_url_2)
else
	k=nil
	return false
end
#puts doc.inspect
  gens=doc.css('generator')
if gens.nil?
	k=nil
	return false
end
gens.each do |gen|
	if gen.text.to_s =~ /wordpress/i
		k=doc=nil
      return true
    end
end
k=doc=nil
return false
  	rescue => ee
puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
return false
end

#wp_load_styles?(url) ⇒ Boolean

Wordpress detection checkpoint - /wp-admin/load-styles.php

Returns:

  • (Boolean)


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/wmap/utils/wp_detect.rb', line 210

def wp_load_styles?(url)
site = url_2_site(url)
  load_styles_url=site + "wp-admin/load-styles.php"
  k=Wmap::UrlChecker.new
  if k.response_code(load_styles_url) == 200 && k.response_headers(load_styles_url).keys.include?("etag")
    k=nil
    return true
  else
    k=nil
    return false
  end
  	rescue => ee
puts "Exception on method #{__method__} for site #{url}: #{ee}" if @verbose
return false
end

#wp_login?(url) ⇒ Boolean

Wordpress detection checkpoint - wp-login

Returns:

  • (Boolean)


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/wmap/utils/wp_detect.rb', line 173

def wp_login?(url)
site=url_2_site(url)
=site + "wp-login.php"
  k=Wmap::UrlChecker.new
  if k.response_code() == 200
    k=nil
    doc=open_page()
    links=doc.css('link')
    if links.to_s =~ /login.min.css/i
      return true
    else
      return false
    end
  end
return false
  	rescue => ee
puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
return false
end

#wp_meta?(url) ⇒ Boolean

Wordpress detection checkpoint - WP meta tag

Returns:

  • (Boolean)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/wmap/utils/wp_detect.rb', line 119

def wp_meta?(url)
site=url_2_site(url)
  k=Wmap::UrlChecker.new
  if k.response_code(site) == 200
    k=nil
    doc=open_page(site)
    meta=doc.css('meta')
    if meta.to_s =~ /wordpress/i
      return true
    else
      return false
    end
  end
return false
  	rescue => ee
puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
return false
end

#wp_readme?(url) ⇒ Boolean

Wordpress detection checkpoint - readme.html

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/wmap/utils/wp_detect.rb', line 71

def wp_readme?(url)
site = url_2_site(url)
  readme_url=site + "readme.html"
  k=Wmap::UrlChecker.new
  if k.response_code(readme_url) == 200
    k=nil
    doc=open_page(readme_url)
    title=doc.css('title')
    if title.to_s =~ /wordpress/i
      return true
    else
      return false
    end
  else
    k=nil
    return false
  end
  	rescue => ee
puts "Exception on method #{__method__} for site #{url}: #{ee}" if @verbose
return false
end

#wp_rpc?(url) ⇒ Boolean

Wordpress detection checkpoint - xml-rpc

Returns:

  • (Boolean)


194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/wmap/utils/wp_detect.rb', line 194

def wp_rpc?(url)
site=url_2_site(url)
rpc_url=site + "xmlrpc.php"
  k=Wmap::UrlChecker.new
#puts "res code", k.response_code(rpc_url)
  if k.response_code(rpc_url) == 405 # method not allowed
    k=nil
    return true
  end
return false
  	rescue => ee
puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
return false
end

#wp_ver(url) ⇒ Object

Main method to extract the WordPress version



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/wmap/utils/wp_detect.rb', line 40

def wp_ver(url)
	if !wp_ver_readme(url).nil?
		puts "WordPress version found by wp_ver_readme method. " if @verbose
		return wp_ver_readme(url)
	elsif !(url,"login.min.css").nil?
		puts "WordPress version found by login.min.css file. " if @verbose
		return (url,"login.min.css")
	elsif !(url,"buttons.min.css").nil?
		puts "WordPress version found by buttons.min.css file. " if @verbose
		return (url,"buttons.min.css")
	elsif !(url,"wp-admin.min.css").nil?
		puts "WordPress version found by wp-admin.min.css file. " if @verbose
		return (url,"wp-admin.min.css")
	elsif !wp_ver_meta(url).nil?
		puts "WordPress version found by wp_ver_meta method. " if @verbose
		return wp_ver_meta(url)
	elsif !wp_ver_generator(url).nil?
		puts "WordPress version found by wp_ver_generator method. " if @verbose
		return wp_ver_generator(url)
   elsif !wp_ver_load_styles(url).nil?
		puts "WordPress version found by wp_ver_load_styles method. " if @verbose
		return wp_ver_load_styles(url)
   else
		return nil
	end
rescue => ee
	puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
	return nil
end

#wp_ver_generator(url) ⇒ Object

Identify wordpress version through the generator tag: <generator>wordpress.org/?v=4.9.8</generator>



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/wmap/utils/wp_detect.rb', line 282

def wp_ver_generator(url)
	puts "#{__method__} check for #{url}" if @verbose
	site = url_2_site(url)
	gen_url_1 = site + "feed/"
	gen_url_2 = site + "comments/feed"
   k=Wmap::UrlChecker.new
   if k.response_code(gen_url_1) == 200
     doc=open_page(gen_url_1)
	elsif k.response_code(gen_url_2) == 200
		doc=open_page(gen_url_2)
	else
		k=nil
		return nil
	end
	#puts doc.inspect
   gens=doc.css('generator')
	if gens.nil?
		k=nil
		return nil
	end
	gens.each do |gen|
		if gen.text.to_s =~ /wordpress/i
			k=nil
       return gen.text.to_s.scan(/[\d+\.]+\d+/).first
     end
	end
   k=doc=nil
   return nil
rescue => ee
	puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
	return nil
end

#wp_ver_load_styles(url) ⇒ Object

Wordpress version detection via - /wp-admin/load-styles.php



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/wmap/utils/wp_detect.rb', line 337

def wp_ver_load_styles(url)
	site=url_2_site(url)
   load_styles_url = site + "wp-admin/load-styles.php"
   k=Wmap::UrlChecker.new
   if k.response_code(load_styles_url) == 200
     headers = k.response_headers(load_styles_url)
     if headers.keys.include?("etag")
       k=nil
       return headers["etag"]
     end
   end
   k=nil
   return nil
rescue => ee
	puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
	return nil
end

#wp_ver_login(url, pattern) ⇒ Object

Identify wordpress version through the login page



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/wmap/utils/wp_detect.rb', line 227

def (url,pattern)
puts "Check for #{pattern}" if @verbose
site=url_2_site(url)
=site + "wp-login.php"
  k=Wmap::UrlChecker.new
#puts "Res code: #{k.response_code(login_url)}" if @verbose
  if k.response_code() == 200
    doc=open_page()
	#puts doc.inspect
    links=doc.css('link')
	#puts links.inspect if @verbose
	links.each do |tag|
     if tag.to_s.include?(pattern)
			puts tag.to_s if @verbose
			k=nil
        if tag.to_s.scan(/[\d+\.]+\d+/).first =~ /\d+\./
          return tag.to_s.scan(/[\d+\.]+\d+/).first
         else
           return nil
         end
     end
	end
  end
  k=nil
  return nil
  	rescue => ee
puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
return nil
end

#wp_ver_meta(url) ⇒ Object

Identify wordpress version through the meta link



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/wmap/utils/wp_detect.rb', line 258

def wp_ver_meta(url)
site=url_2_site(url)
  k=Wmap::UrlChecker.new
  if k.response_code(site) == 200
    doc=open_page(site)
	#puts doc.inspect
    meta=doc.css('meta')
	#puts meta.inspect
	meta.each do |tag|
     if tag['content'].to_s =~ /wordpress/i
			#puts tag.to_s
			k=nil
       return tag['content'].to_s.scan(/[\d+\.]+\d+/).first
     end
	end
  end
  k=nil
  return nil
  	rescue => ee
puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
return nil
end

#wp_ver_readme(url) ⇒ Object

Wordpress version detection via - readme.html



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/wmap/utils/wp_detect.rb', line 316

def wp_ver_readme(url)
	site=url_2_site(url)
   readme_url=site + "readme.html"
   k=Wmap::UrlChecker.new
	puts "Res code: #{k.response_code(readme_url)}" if @verbose
   if k.response_code(readme_url) == 200
     k=nil
     doc=open_page(readme_url)
		puts doc if @verbose
     =doc.css('h1#logo')[0]
     puts .inspect if @verbose
		return .to_s.scan(/[\d+\.]+\d+/).first
   end
   k=nil
   return nil
rescue => ee
	puts "Exception on method #{__method__} for url #{url}: #{ee}" if @verbose
	return nil
end