Class: Risu::Parsers::Nessus::PostProcess::RiskScore

Inherits:
Base::PostProcessBase show all
Defined in:
lib/risu/parsers/nessus/postprocess/risk_score.rb

Instance Attribute Summary

Attributes inherited from Base::PostProcessBase

#info

Instance Method Summary collapse

Methods inherited from Base::PostProcessBase

#<=>, #==, #calculate_severity, #create_item, #create_plugin, #has_findings, #has_host_findings, inherited

Constructor Details

#initializeRiskScore

Returns a new instance of RiskScore.



29
30
31
32
33
34
35
# File 'lib/risu/parsers/nessus/postprocess/risk_score.rb', line 29

def initialize
  @info =
  {
    :description => "RiskScore Calculator",
    :plugin_id => 0
  }            
end

Instance Method Details

#calculate_host_risk_scoreObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/risu/parsers/nessus/postprocess/risk_score.rb', line 76

def calculate_host_risk_score
  Host.all.each do |host|
    risk_score = 0.0

    host.items.to_a.each do |item|
      risk_score = risk_score + item.risk_score
    end

    #@TODO weighting goes here

    host.risk_score = risk_score
    host.save
  end
end

#calculate_item_risk_scoreObject

Calculates the RiskScore for a Item which is == to the Plugin’s RiskScore



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/risu/parsers/nessus/postprocess/risk_score.rb', line 40

def calculate_item_risk_score
  Item.all.each do |item|
    plugin = Plugin.where(:id => item.plugin_id).first

    risk_score = 0.0
    cvss_base_score = plugin.cvss_base_score.to_f || 1.0
    vuln_publication_date = plugin.vuln_publication_date

    vuln_pub_days = 1
    vuln_pub_days = (DateTime.now.to_date - vuln_publication_date.to_date).to_i if vuln_publication_date != nil

    exploitable = plugin.exploit_available
    exploitable_factor = 1

    if exploitable == "true"
      exploitable_factor = 0.6
    end

    risk_score = (cvss_base_score * vuln_pub_days * 0.8) * exploitable_factor

    item.risk_score = risk_score
    item.save
  end
end

#calculate_plugin_risk_scoreObject



66
67
68
69
70
71
72
73
# File 'lib/risu/parsers/nessus/postprocess/risk_score.rb', line 66

def calculate_plugin_risk_score
  Plugin.all.each do |plugin|
    items = Item.where(:plugin_id => plugin.id).to_a

    plugin.risk_score = items.first.risk_score * items.count
    plugin.save
  end
end

#runObject



92
93
94
95
96
# File 'lib/risu/parsers/nessus/postprocess/risk_score.rb', line 92

def run
  calculate_item_risk_score()
  calculate_plugin_risk_score()
  calculate_host_risk_score()
end