Class: StatsPlugin

Inherits:
Plugin show all
Defined in:
lib/wpstools/plugins/stats/stats_plugin.rb

Instance Attribute Summary

Attributes inherited from Plugin

#author, #registered_options

Instance Method Summary collapse

Methods inherited from Plugin

#register_options

Constructor Details

#initializeStatsPlugin

Returns a new instance of StatsPlugin


5
6
7
8
9
10
11
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 5

def initialize
  super(author: 'WPScanTeam - Christian Mehlmauer')

  register_options(
      ['--stats', '-s', 'Show WpScan Database statistics.']
  )
end

Instance Method Details

#asset_fixed_in_count(json) ⇒ Object


102
103
104
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 102

def asset_fixed_in_count(json)
  json.map { |asset| asset[asset.keys.inject]['vulnerabilities'].map {|a| a['fixed_in'].nil? ? 0 : 1 }.inject(:+) }.inject(:+)
end

#asset_vulns_count(json) ⇒ Object


98
99
100
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 98

def asset_vulns_count(json)
  json.map { |asset| asset[asset.keys.inject]['vulnerabilities'].size }.inject(:+)
end

#fix_plugin_count(file = PLUGINS_VULNS_FILE) ⇒ Object


74
75
76
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 74

def fix_plugin_count(file=PLUGINS_VULNS_FILE)
  asset_fixed_in_count(json(file))
end

#fix_theme_count(file = THEMES_VULNS_FILE) ⇒ Object


82
83
84
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 82

def fix_theme_count(file=THEMES_VULNS_FILE)
  asset_fixed_in_count(json(file))
end

#fix_version_count(file = WP_VULNS_FILE) ⇒ Object


66
67
68
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 66

def fix_version_count(file=WP_VULNS_FILE)
  asset_fixed_in_count(json(file))
end

#lines_in_file(file) ⇒ Object


94
95
96
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 94

def lines_in_file(file)
  IO.readlines(file).size
end

#plugin_vulns_count(file = PLUGINS_VULNS_FILE) ⇒ Object


70
71
72
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 70

def plugin_vulns_count(file=PLUGINS_VULNS_FILE)
  asset_vulns_count(json(file))
end

#run(options = {}) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 13

def run(options = {})
  if options[:stats]
    date_wp = File.mtime(WP_VULNS_FILE)
    date_plugins = File.mtime(PLUGINS_VULNS_FILE)
    date_themes = File.mtime(THEMES_VULNS_FILE)
    date_plugins_full = File.mtime(PLUGINS_FULL_FILE)
    date_themes_full = File.mtime(THEMES_FULL_FILE)

    puts "WPScan Database Statistics:"
    puts "---------------------------"
    puts
    puts "[#] Total vulnerable versions: #{vuln_core_count}"
    puts "[#] Total vulnerable plugins:  #{vuln_plugin_count}"
    puts "[#] Total vulnerable themes:   #{vuln_theme_count}"
    puts
    puts "[#] Total version vulnerabilities: #{version_vulns_count}"
    puts "[#] Total fixed vulnerabilities:   #{fix_version_count}"
    puts
    puts "[#] Total plugin vulnerabilities:  #{plugin_vulns_count}"
    puts "[#] Total fixed vulnerabilities:   #{fix_plugin_count}"
    puts
    puts "[#] Total theme vulnerabilities:   #{theme_vulns_count}"
    puts "[#] Total fixed vulnerabilities:   #{fix_theme_count}"
    puts
    puts "[#] Total plugins to enumerate:  #{total_plugins}"
    puts "[#] Total themes to enumerate:   #{total_themes}"
    puts
    puts "[+] WordPress DB modified: #{date_wp.strftime('%Y-%m-%d %H:%M:%S')}"
    puts "[+] Plugins DB modified:   #{date_plugins.strftime('%Y-%m-%d %H:%M:%S')}"
    puts "[+] Themes DB modified:    #{date_themes.strftime('%Y-%m-%d %H:%M:%S')}"
    puts "[+] Enumeration plugins:   #{date_plugins_full.strftime('%Y-%m-%d %H:%M:%S')}"
    puts "[+] Enumeration themes:    #{date_themes_full.strftime('%Y-%m-%d %H:%M:%S')}"
    puts
    puts "[+] Report generated:      #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
  end
end

#theme_vulns_count(file = THEMES_VULNS_FILE) ⇒ Object


78
79
80
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 78

def theme_vulns_count(file=THEMES_VULNS_FILE)
  asset_vulns_count(json(file))
end

#total_plugins(file = PLUGINS_FULL_FILE) ⇒ Object


86
87
88
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 86

def total_plugins(file=PLUGINS_FULL_FILE)
  lines_in_file(file)
end

#total_themes(file = THEMES_FULL_FILE) ⇒ Object


90
91
92
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 90

def total_themes(file=THEMES_FULL_FILE)
  lines_in_file(file)
end

#version_vulns_count(file = WP_VULNS_FILE) ⇒ Object


62
63
64
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 62

def version_vulns_count(file=WP_VULNS_FILE)
  asset_vulns_count(json(file))
end

#vuln_core_count(file = WP_VULNS_FILE) ⇒ Object


50
51
52
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 50

def vuln_core_count(file=WP_VULNS_FILE)
  json(file).size
end

#vuln_plugin_count(file = PLUGINS_VULNS_FILE) ⇒ Object


54
55
56
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 54

def vuln_plugin_count(file=PLUGINS_VULNS_FILE)
  json(file).size
end

#vuln_theme_count(file = THEMES_VULNS_FILE) ⇒ Object


58
59
60
# File 'lib/wpstools/plugins/stats/stats_plugin.rb', line 58

def vuln_theme_count(file=THEMES_VULNS_FILE)
  json(file).size
end