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

Inherits:
Object
  • Object
show all
Defined in:
lib/risu/parsers/nessus/postprocess/post_process.rb

Overview

< Risu::Base::PostProcessBase

Instance Method Summary collapse

Constructor Details

#initializePostProcess

Returns a new instance of PostProcess.



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

def initialize
  @name = ""
  @plugin_id = -1
  @plugin_ids = []
  @plugin_name = ""
  @item_name = ""
end

Instance Method Details

#calculate_severity(current_severity, severity) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/risu/parsers/nessus/postprocess/post_process.rb', line 131

def calculate_severity current_severity, severity
  if severity > current_severity
    return severity
  else
    return current_severity
  end
end

#create_item(host_id, severity) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/risu/parsers/nessus/postprocess/post_process.rb', line 96

def create_item(host_id, severity)
  item = Item.new

    item.host_id = host_id
    item.plugin_id = @plugin_id
    item.plugin_output = nil
    item.port = 0
    item.severity = severity
    item.plugin_name = @item_name

  item.save
end

#create_pluginObject

Creates a rollup plugin



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/risu/parsers/nessus/postprocess/post_process.rb', line 61

def create_plugin
  plugin = Plugin.find_by_id(@plugin_id)

  newest_plugin = newest_plugin()

  if newest_plugin == nil
    return
  end

  if plugin == nil
    plugin = Plugin.new
  end

  plugin.id = @plugin_id
  plugin.plugin_name = @plugin_name
  plugin.family_name = "Risu Rollup Plugins"
  plugin.description = @description #newest_plugin.description || ""
  plugin.plugin_version = newest_plugin.plugin_version || ""
  plugin.plugin_publication_date = newest_plugin.plugin_publication_date
  plugin.plugin_modification_date = newest_plugin.plugin_modification_date
  plugin.vuln_publication_date = newest_plugin.vuln_publication_date
  plugin.cvss_vector = newest_plugin.cvss_vector || ""
  plugin.cvss_base_score = newest_plugin.cvss_base_score
  plugin.cvss_temporal_score = newest_plugin.cvss_temporal_score
  plugin.cvss_temporal_vector = newest_plugin.cvss_temporal_vector
  plugin.risk_factor = newest_plugin.risk_factor
  plugin.solution = newest_plugin.solution
  plugin.synopsis = newest_plugin.synopsis
  plugin.plugin_type = "Rollup"
  plugin.rollup = true

  plugin.save
end

#has_findingsObject



110
111
112
113
114
115
116
117
118
# File 'lib/risu/parsers/nessus/postprocess/post_process.rb', line 110

def has_findings
  @plugin_ids.each do |plugin_id|
    if Item.where(:plugin_id => plugin_id)
      return true
    end
  end

  return false
end

#has_host_findings?(host_id) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
123
124
125
126
127
128
# File 'lib/risu/parsers/nessus/postprocess/post_process.rb', line 120

def has_host_findings? host_id
  @plugin_ids.each do |plugin_id|
    if Item.where(:plugin_id => plugin_id).where(:host_id => host_id).count >= 1
      return true
    end
  end

  return false
end

#newest_pluginObject

NOTE: looks like its working



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/risu/parsers/nessus/postprocess/post_process.rb', line 39

def newest_plugin
  newest = DateTime.new(0001, 01, 01)
  newest_plugin = nil

  @plugin_ids.uniq.each do |id|
    plugin = Plugin.find_by_id(id)

    if plugin == nil || plugin.plugin_modification_date == nil
      next
    end

    if plugin.plugin_modification_date >= newest
      newest = plugin.plugin_modification_date if plugin.plugin_modification_date != nil
      newest_plugin = plugin
    end
  end

  return newest_plugin
end

#runObject



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
# File 'lib/risu/parsers/nessus/postprocess/post_process.rb', line 140

def run
  if !has_findings()
    return
  end

  #Create the dummy plugin
  create_plugin()

  Host.all.each do |host|
    if !has_host_findings?(host.id)
      next
    end

    finding_severity = 0

    @plugin_ids.each do |plugin_id|
      Item.where(:plugin_id => plugin_id).each do |item|
        severity = item.severity
        item.real_severity = severity
        item.severity = -1
        item.save

        finding_severity = calculate_severity(finding_severity, severity)
      end
    end

    create_item(host.id, finding_severity)
  end
end