Class: Wmap::WpTracker
Overview
Main class to automatically track the site inventory
Constant Summary
Constants included from Utils::UrlMagic
Utils::UrlMagic::Max_http_timeout
Constants included from Utils::DomainRoot
Utils::DomainRoot::File_ccsld, Utils::DomainRoot::File_cctld, Utils::DomainRoot::File_gtld, Utils::DomainRoot::File_tld
Instance Attribute Summary collapse
-
#data_dir ⇒ Object
include Singleton.
-
#http_timeout ⇒ Object
include Singleton.
-
#known_wp_sites ⇒ Object
readonly
Returns the value of attribute known_wp_sites.
-
#max_parallel ⇒ Object
include Singleton.
-
#sites_wp ⇒ Object
include Singleton.
-
#verbose ⇒ Object
include Singleton.
Instance Method Summary collapse
-
#add(url, use_cache = true) ⇒ Object
‘setter’ to add wordpress entry to the cache one at a time.
-
#initialize(params = {}) ⇒ WpTracker
constructor
WordPress checker instance default variables.
-
#is_wp?(url) ⇒ Boolean
logic to determin if it’s a wordpress site.
-
#load_from_file(file = @file_stores, lc = true) ⇒ Object
‘setter’ to load the known wordpress sites into an instance variable.
-
#refresh(target, use_cache = false) ⇒ Object
Refresh one site entry then update the instance variable (cache).
-
#refreshs(num = @max_parallel, use_cache = false) ⇒ Object
Refresh wordpress site entries within the sitetracker list.
-
#save_to_file!(file_wps = @file_wps, wps = @known_wp_sites) ⇒ Object
(also: #save!)
Save the current hash table into a file.
-
#wp_css?(url) ⇒ Boolean
Wordpress detection checkpoint - install.css.
-
#wp_login?(url) ⇒ Boolean
Wordpress detection checkpoint - wp-login.
-
#wp_meta?(url) ⇒ Boolean
Wordpress detection checkpoint - meta generator.
-
#wp_readme?(url) ⇒ Boolean
Wordpress detection checkpoint - readme.html.
-
#wp_rpc?(url) ⇒ Boolean
Wordpress detection checkpoint - xml-rpc.
-
#wp_ver(url) ⇒ Object
Extract the WordPress version.
-
#wp_ver_login(url, pattern) ⇒ Object
Identify wordpress version through the login page.
-
#wp_ver_meta(url) ⇒ Object
Identify wordpress version through the meta link.
-
#wp_ver_readme(url) ⇒ Object
Wordpress version detection via - readme.html.
Methods included from Utils
#cidr_2_ips, #file_2_hash, #file_2_list, #get_nameserver, #get_nameservers, #host_2_ip, #host_2_ips, #is_cidr?, #is_fqdn?, #is_ip?, #list_2_file, #reverse_dns_lookup, #sort_ips, #valid_dns_record?, #zone_transferable?
Methods included from Utils::Logger
Methods included from Utils::UrlMagic
#create_absolute_url_from_base, #create_absolute_url_from_context, #host_2_url, #is_site?, #is_ssl?, #is_url?, #landing_location, #make_absolute, #normalize_url, #open_page, #redirect_location, #response_code, #url_2_host, #url_2_path, #url_2_port, #url_2_site, #urls_on_same_domain?
Methods included from Utils::DomainRoot
#get_domain_root, #get_domain_root_by_ccsld, #get_domain_root_by_cctld, #get_domain_root_by_tlds, #get_sub_domain, #is_domain_root?, #print_ccsld, #print_cctld, #print_gtld
Constructor Details
#initialize(params = {}) ⇒ WpTracker
WordPress checker instance default variables
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wmap/wp_tracker.rb', line 25 def initialize (params = {}) @verbose=params.fetch(:verbose, false) @data_dir=params.fetch(:data_dir, File.dirname(__FILE__)+'/../../data/') Dir.mkdir(@data_dir) unless Dir.exist?(@data_dir) wp_sites=@data_dir+'wp_sites' @file_wps=params.fetch(:sites_wp, wp_sites) @http_timeout=params.fetch(:http_timeout, 5000) @max_parallel=params.fetch(:max_parallel, 40) Dir.mkdir(@data_dir) unless Dir.exist?(@data_dir) @log_file=@data_dir + "wp_checker.log" @known_wp_sites=load_from_file(@file_wps) end |
Instance Attribute Details
#data_dir ⇒ Object
include Singleton
21 22 23 |
# File 'lib/wmap/wp_tracker.rb', line 21 def data_dir @data_dir end |
#http_timeout ⇒ Object
include Singleton
21 22 23 |
# File 'lib/wmap/wp_tracker.rb', line 21 def http_timeout @http_timeout end |
#known_wp_sites ⇒ Object (readonly)
Returns the value of attribute known_wp_sites.
22 23 24 |
# File 'lib/wmap/wp_tracker.rb', line 22 def known_wp_sites @known_wp_sites end |
#max_parallel ⇒ Object
include Singleton
21 22 23 |
# File 'lib/wmap/wp_tracker.rb', line 21 def max_parallel @max_parallel end |
#sites_wp ⇒ Object
include Singleton
21 22 23 |
# File 'lib/wmap/wp_tracker.rb', line 21 def sites_wp @sites_wp end |
#verbose ⇒ Object
include Singleton
21 22 23 |
# File 'lib/wmap/wp_tracker.rb', line 21 def verbose @verbose end |
Instance Method Details
#add(url, use_cache = true) ⇒ Object
‘setter’ to add wordpress entry to the cache one at a time
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/wmap/wp_tracker.rb', line 88 def add(url, use_cache=true) puts "Add entry to the local cache table: #{url}" if @verbose site=url_2_site(url) if use_cache && @known_wp_sites.key?(site) puts "Site is already exist. Skipping: #{site}" else record=Hash.new redirection = landing_location(site) if is_wp?(redirection) version = wp_ver(site) record['site'] = site record['version'] = version record['redirection'] = redirection @known_wp_sites[site]=record puts "Entry loaded: #{record}" end end return record rescue => ee puts "Exception on method #{__method__}: #{ee}: #{url}" if @verbose end |
#is_wp?(url) ⇒ Boolean
logic to determin if it’s a wordpress site
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/wmap/wp_tracker.rb', line 111 def is_wp?(url) site=url_2_site(url) if wp_readme?(site) found=true elsif wp_css?(site) found=true elsif (site) found=true elsif wp_login?(site) found=true elsif wp_rpc?(site) found=true else found=false end return found rescue => ee puts "Exception on method #{__method__}: #{ee}: #{url}" if @verbose end |
#load_from_file(file = @file_stores, lc = true) ⇒ Object
‘setter’ to load the known wordpress sites into an instance variable
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/wp_tracker.rb', line 40 def load_from_file (file=@file_stores, lc=true) puts "Loading trusted file: #{file}" if @verbose known_wp_sites=Hash.new f_wp_sites=File.open(file, 'r') f_wp_sites.each_line do |line| puts "Processing line: #{line}" if @verbose line=line.chomp.strip next if line.nil? next if line.empty? next if line =~ /^\s*#/ line=line.downcase if lc==true entry=line.split(',') site = entry[0].strip() if known_wp_sites.key?(site) next else known_wp_sites[site] = Hash.new known_wp_sites[site]['site'] = site known_wp_sites[site]['version'] = entry[1].strip() known_wp_sites[site]['redirection'] = entry[2].strip() end end f_wp_sites.close return known_wp_sites rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose return Hash.new end |
#refresh(target, use_cache = false) ⇒ Object
Refresh one site entry then update the instance variable (cache)
132 133 134 |
# File 'lib/wmap/wp_tracker.rb', line 132 def refresh (target,use_cache=false) return add(target,use_cache) end |
#refreshs(num = @max_parallel, use_cache = false) ⇒ Object
Refresh wordpress site entries within the sitetracker list
137 138 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 |
# File 'lib/wmap/wp_tracker.rb', line 137 def refreshs (num=@max_parallel,use_cache=false) puts "Add entries to the local cache table from site tracker: " if @verbose results=Hash.new wps=Wmap::SiteTracker.instance.known_sites.keys if wps.size > 0 Parallel.map(wps, :in_processes => num) { |target| refresh(target,use_cache) }.each do |process| if process.nil? next elsif process.empty? #do nothing else site = process['site'] results[site] = process end end @known_wp_sites.merge!(results) puts "Done loading entries." return results else puts "Error: no entry is loaded. Please check your list and try again." end wps=nil return results rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose return Hash.new end |
#save_to_file!(file_wps = @file_wps, wps = @known_wp_sites) ⇒ Object Also known as: save!
Save the current hash table into a file
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/wmap/wp_tracker.rb', line 71 def save_to_file!(file_wps=@file_wps, wps=@known_wp_sites) puts "Saving the current wordpress site table from memory to file: #{file_wps} ..." if @verbose =Time.now f=File.open(file_wps, 'w') f.write "# Local wps file created by class #{self.class} method #{__method__} at: #{}\n" f.write "# WP Site URL, WP Version, Redirection \n" wps.keys.sort.map do |key| f.write "#{key}, #{wps[key]['version']}, #{wps[key]['redirection']}\n" end f.close puts "WordPress site cache table is successfully saved: #{file_wps}" rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose end |
#wp_css?(url) ⇒ Boolean
Wordpress detection checkpoint - install.css
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/wmap/wp_tracker.rb', line 191 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_login?(url) ⇒ Boolean
Wordpress detection checkpoint - wp-login
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/wmap/wp_tracker.rb', line 236 def wp_login?(url) site=url_2_site(url) login_url=site + "wp-login.php" k=Wmap::UrlChecker.new if k.response_code(login_url) == 200 k=nil doc=open_page(login_url) 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 - meta generator
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/wmap/wp_tracker.rb', line 216 def (url) site=url_2_site(url) k=Wmap::UrlChecker.new if k.response_code(site) == 200 k=nil doc=open_page(site) =doc.css('meta') if .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
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/wmap/wp_tracker.rb', line 168 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
257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/wmap/wp_tracker.rb', line 257 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
Extract the WordPress version
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/wmap/wp_tracker.rb', line 273 def wp_ver(url) if !wp_ver_readme(url).nil? return wp_ver_readme(url) elsif !(url).nil? return (url) elsif !wp_ver_login(url,"login.min.css").nil? return wp_ver_login(url,"login.min.css") elsif !wp_ver_login(url,"buttons.min.css").nil? return wp_ver_login(url,"buttons.min.css") elsif !wp_ver_login(url,"wp-admin.min.css").nil? return wp_ver_login(url,"wp-admin.min.css") else return nil end 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
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/wmap/wp_tracker.rb', line 293 def wp_ver_login(url,pattern) puts "Check for #{pattern}" if @verbose site=url_2_site(url) login_url=site + "wp-login.php" k=Wmap::UrlChecker.new #puts "Res code: #{k.response_code(login_url)}" if @verbose if k.response_code(login_url) == 200 doc=open_page(login_url) #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 return tag.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_meta(url) ⇒ Object
Identify wordpress version through the meta link
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/wmap/wp_tracker.rb', line 320 def (url) site=url_2_site(url) k=Wmap::UrlChecker.new if k.response_code(site) == 200 doc=open_page(site) #puts doc.inspect =doc.css('meta') #puts meta.inspect .each do |tag| if tag.to_s =~ /wordpress/i #puts tag.to_s k=nil return tag.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
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/wmap/wp_tracker.rb', line 344 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 logo=doc.css('h1#logo')[0] puts logo.inspect if @verbose return logo.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 |