Class: Prenus::Output::Htmlout

Inherits:
Baseout
  • Object
show all
Defined in:
lib/output/htmlout.rb

Instance Method Summary collapse

Constructor Details

#initialize(events, hosts, options) ⇒ Object

Initialises the Htmlout class into an object

Examples:

object = Prenus::Output::Htmlout(events,hosts,options)


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
# File 'lib/output/htmlout.rb', line 20

def initialize(events, hosts, options)
  super

  #prepare folder - copy js files
  FileUtils.cp(File.expand_path($root_dir + '/lib/js/jquery.min.js'), options[:output] + '/jquery.min.js')
  FileUtils.cp(File.expand_path($root_dir + '/lib/js/highcharts.js'), options[:output] + '/highcharts.js')
  FileUtils.cp(File.expand_path($root_dir + '/lib/js/jquery.dataTables.js'), options[:output] + '/jquery.dataTables.js')

  #prepare folder - copy css files
  FileUtils.cp(File.expand_path($root_dir + '/lib/css/table.css'), options[:output] + '/table.css')

  #prepare folder - copy image files
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/back_disabled.png'), options[:output] + '/back_disabled.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/back_enabled.png'), options[:output] + '/back_enabled.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/back_enabled_hover.png'), options[:output] + '/back_enabled_hover.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/forward_disabled.png'), options[:output] + '/forward_disabled.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/forward_enabled.png'), options[:output] + '/forward_enabled.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/forward_enabled_hover.png'), options[:output] + '/forward_enabled_hover.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/sort_asc.png'), options[:output] + '/sort_asc.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/sort_asc_disabled.png'), options[:output] + '/sort_asc_disabled.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/sort_both.png'), options[:output] + '/sort_both.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/sort_desc.png'), options[:output] + '/sort_desc.png')
  FileUtils.cp(File.expand_path($root_dir + '/lib/images/sort_desc_disabled.png'), options[:output] + '/sort_desc_disabled.png')

end

Instance Method Details

#bar_js(fp, renderto, title, data) ⇒ Object

Prints the Highcharts javascript for a bar graph into the nominated output file

Examples:

File.open(@options[:output] + "/file.html",'w') do |f|
   bar_js(f,"bargraph1","Some title",{0 => {:hostname => 'hostname',:ip => 'ip'}})

   body_text(f,"<div id='bargraph1'>")
end

Returns:

  • Returns nothing



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/output/htmlout.rb', line 544

def bar_js(fp,renderto,title,data)
  fp.puts "  $(function () {\n      var chart;\n      $(document).ready(function() {\n          chart = new Highcharts.Chart({\n              chart: {\n                  renderTo: '\#{renderto}',\n                  type: 'bar'\n              },\n              title: {\n                  text: '\#{title}'\n              },\n              xAxis: {\n      categories: [\n  eos\n\n  data.each_with_index do |entry,index|\n    tmpline = \"'\"\n    if entry[1][:hostname] == \"\"\n      tmpline += entry[1][:ip]\n    else\n      tmpline += entry[1][:hostname] + \" (\" + entry[1][:ip] + \")\"\n    end\n    tmpline += \"'\"\n    tmpline += \",\" unless index == data.length - 1\n    fp.puts tmpline\n  end\n  fp.puts <<-eos\n  ]\n           },\n           yAxis: {\n               min: 0,\n               title: {\n                   text: 'Findings'\n               }\n           },\n           legend: {\n               backgroundColor: '#FFFFFF',\n               reversed: true\n           },\n           tooltip: {\n               formatter: function() {\n                   return ''+\n                       this.series.name +': '+ this.y +'';\n               }\n           },\n           plotOptions: {\n               series: {\n                   stacking: 'normal',\n                   dataLabels: {\n                    enabled: true,\n                    color: '#000000',\n                    x: 0,\n                    align: 'center'\n                   },\n                   events: {\n                    click: function(event) {\n                      //alert(target_lookup[event.point.category])\n                      document.location.href = 'host_' + target_lookup[event.point.category] + '.html#' + event.currentTarget.name;\n                      //console.log(event)\n                    }\n                   }\n               }\n           },\n               series: [\n  eos\n\n  if @options[:severity] <= 4\n    fp.puts \"{name: 'Critical',\"\n    fp.puts \"color: 'purple',\"\n    tmpline = \"data: [\"\n\n    data.each_with_index do |entry,index|\n      tmpline += entry[1][:crit].to_s\n      tmpline += \",\" unless index == data.length - 1\n    end\n    tmpline += \"]\"\n    fp.puts tmpline\n    fp.puts \"}\"\n  end\n\n  if @options[:severity] <= 3\n    fp.puts \",{name: 'High',\"\n    fp.puts \"color: 'red',\"\n    tmpline = \"data: [\"\n\n    data.each_with_index do |entry,index|\n      tmpline += entry[1][:high].to_s\n      tmpline += \",\" unless index == data.length - 1\n    end\n    tmpline += \"]\"\n    fp.puts tmpline\n    fp.puts \"}\"\n  end\n\n  if @options[:severity] <= 2\n    fp.puts \",{name: 'Medium',\"\n    fp.puts \"color: 'orange',\"\n    tmpline = \"data: [\"\n\n    data.each_with_index do |entry,index|\n      tmpline += entry[1][:med].to_s\n      tmpline += \",\" unless index == data.length - 1\n    end\n    tmpline += \"]\"\n    fp.puts tmpline\n    fp.puts \"}\"\n  end\n\n  if @options[:severity] <= 1\n\n    fp.puts \",{name: 'Low',\"\n    fp.puts \"color: 'green',\"\n    tmpline = \"data: [\"\n\n    data.each_with_index do |entry,index|\n      tmpline += entry[1][:low].to_s\n      tmpline += \",\" unless index == data.length - 1\n    end\n    tmpline += \"]\"\n    fp.puts tmpline\n    fp.puts \"}\"\n  end\n\n  fp.puts <<-eos\n          \n              ]\n          });\n      });\n      \n  });\n  eos\nend\n"

#body_text(fp, text) ⇒ Object

Prints out miscellanrous HTML text into the nominated output file

Examples:

File.open(@options[:output] + "/file.html",'w') do |f|
    tmpline = "Sometext<br />"
     tmpline += "Some more text here<br />"
     body_text(f,tmpline)
end

Returns:

  • Returns nothing



502
503
504
# File 'lib/output/htmlout.rb', line 502

def body_text(fp,text)
  fp.puts text
end

#close_all(fp) ⇒ Object

Closes out the HTML of the page in the nominated output file

Examples:

@see html_header's @example

Returns:

  • Returns nothing



518
519
520
521
522
523
# File 'lib/output/htmlout.rb', line 518

def close_all(fp)
  fp.puts "      </body>\n    </html>\n  eos\nend\n"

#close_html_header(fp) ⇒ Object

Prints out the closing statements for the universal HTML header into the nominated output file

Examples:

@see html_header's @example

Returns:

  • Returns nothing

See Also:

  • html_header(fp,title)


476
477
478
479
480
481
482
483
# File 'lib/output/htmlout.rb', line 476

def close_html_header(fp)
  fp.puts "  </script>\n    </head>\n    <body>\n  <script src=\"highcharts.js\"></script>\n  eos\nend\n"

#html_header(fp, title) ⇒ Object

Prints the universal HTML header into the nominated output file

html_header(f,“Title”)

end

Examples:

File.open(@options[:output] + "/file.html", 'w') do |f|

Returns:

  • Returns nothing



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/output/htmlout.rb', line 407

def html_header(fp,title)
  fp.puts "\n  <!DOCTYPE HTML>\n  <html>\n    <head>\n      <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n      <title>\#{title}</title>\n\n      <script type=\"text/javascript\" src=\"jquery.min.js\"></script>\n      <script type=\"text/javascript\" src=\"jquery.dataTables.js\"></script>\n      <style type=\"text/css\" title=\"currentStyle\">\n        @import \"table.css\";\n      </style>\n      <script type=\"text/javascript\">\n      jQuery.fn.dataTableExt.aTypes.unshift(\n          function ( sData )\n          {\n              if (/^.*\\\\d{1,3}[\\\\.]\\\\d{1,3}[\\\\.]\\\\d{1,3}[\\\\.]\\\\d{1,3}.*$/.test(sData)) {\n                  return 'ip-address';\n              }\n              return null;\n          }\n      );\n\n      jQuery.extend( jQuery.fn.dataTableExt.oSort, {\n          \"ip-address-pre\": function ( a ) {\n           var b = a.replace(/<.*?>/g,\"\");\n              var m = b.split(\".\"), x = \"\";\n       \n              for(var i = 0; i < m.length; i++) {\n                  var item = m[i];\n                  if(item.length == 1) {\n                      x += \"00\" + item;\n                  } else if(item.length == 2) {\n                      x += \"0\" + item;\n                  } else {\n                      x += item;\n                  }\n              }\n       \n              return x;\n          },\n       \n          \"ip-address-asc\": function ( a, b ) {\n              return ((a < b) ? -1 : ((a > b) ? 1 : 0));\n          },\n       \n          \"ip-address-desc\": function ( a, b ) {\n              return ((a < b) ? 1 : ((a > b) ? -1 : 0));\n          }\n      } );\n  eos\nend\n"

#pie_js(fp, renderto, title, seriesname, series, clickfunction = nil) ⇒ Object

Prints the Highcharts javascript for a pie graph into the nominated output file

Examples:

File.open(@options[:output] + "/file.html",'w') do |f|
   pie_js(f,"pie_graph","Vuln Breakdown","Vuln Breakdown",[['Low',2],['Medium',5],['High',3]],"document.location.href = 'vuln_overview.html#' + event.point.name;")

   body_text(f,"<div id='pie_graph'>")
end

Returns:

  • Returns nothing



700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# File 'lib/output/htmlout.rb', line 700

def pie_js(fp,renderto,title,seriesname,series,clickfunction = nil)
  fp.puts "  $(function () {\n      var chart;\n      $(document).ready(function() {\n          chart = new Highcharts.Chart({\n              chart: {\n                  renderTo: '\#{renderto}',\n                  plotBackgroundColor: null,\n                  plotBorderWidth: null,\n                  plotShadow: false\n              },\n              title: {\n                  text: '\#{title}'\n              },\n              tooltip: {\n                  formatter: function() {\n                      return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';\n                  }\n              },\n              plotOptions: {\n                  pie: {\n                      allowPointSelect: true,\n                      cursor: 'pointer',\n                      dataLabels: {\n                          enabled: true,\n                          color: '#000000',\n                          connectorColor: '#000000',\n                          formatter: function() {\n                              return '<b>'+ this.point.name +'</b>: '+ this.y;\n                          }\n                      }\n  eos\n\n  if not clickfunction.nil?\n    fp.puts ',events: { click: function(event) { ' + clickfunction + '} }'\n  end \n\n  fp.puts <<-eos\n               }\n           },\n           series: [{\n               type: 'pie',\n               name: '\#{seriesname}',\n               data: [\n  eos\n  series.each_with_index do |val,index|\n    tmpline =  \"\\t\\t\\t['\" + val[0] + \"',\" + val[1].to_s + \"]\"\n    tmpline += \",\" unless index == series.length - 1\n    fp.puts tmpline\n  end\n\n  fp.puts <<-eos\n                  ]\n              }]\n          });\n      });\n      \n  });\n  eos\n  \nend\n"

Generates the various host_*.html files, outputting them to the nominated output directory

@see @options[:output]

Examples:

print_hosts

Returns:

  • Returns nothing



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/output/htmlout.rb', line 260

def print_hosts
  @hosts.each do |id,values|
    File.open(@options[:output] + "/host_" + id.to_s + ".html", 'w') do |f|

      html_header(f,values[:ip])

      if values[:total_excl_info] == 0
        pie_js(f,"pie_graph","Criticality Breakdown","Criticality Breakdown",[['Informational ONLY',values[:info].to_i]])         
      else
        pie_data = []
        pie_data << ['Low',values[:low].to_i] if @options[:severity] <= 1
        pie_data << ['Medium',values[:med].to_i] if @options[:severity] <= 2
        pie_data << ['High',values[:high].to_i] if @options[:severity] <= 3
        pie_data << ['Critical',values[:crit].to_i] if @options[:severity] <= 4
        pie_js(f,"pie_graph","Criticality Breakdown","Criticality Breakdown",pie_data,"document.location.href = '#' + event.point.name;")
      end

      close_html_header(f)

      body = '<a href="index.html">Home</a><br /><div id="host"><div id="overview">Hostname: ' + values[:hostname] + '<br />IP: ' + values[:ip] + '<br />OS: ' + values[:os] + '<br /></div>'
      body += '<div id="graphs"><h2>Overview</h2>'
      body += '<div id="pie_graph" style="min-width: 400px; height: 400px; margin: 0 auto"></div>'
      body += '</div>'

      body += '<div id="vulns"><h2>Vulns</h2>'


      if @options[:severity] <= 4
        body += '<div id="critical"><a name="Critical"></a><h3>Critical</h3>'

        body += '<table id="critical_table" class="display"><thead><tr><th>Nessus ID</th><th>Name</th><th>Synopsis</th><th>Result</th><th>Family</th><th>Port</th></tr></thead><tbody>'
        @events.sort_by{|k,v| v[:port].to_s}.each do |vuln_id,vuln_data|
          vuln_data[:ports].each {|k,v|

            v[:hosts].each do |h,v2|
              if h == id and vuln_data[:severity] == 4
                body += '<tr><td><a href="vuln_' + vuln_id.to_s + '.html">' + vuln_id.to_s + '</a></td><td>' + vuln_data[:plugin_name] + '</td><td>' + vuln_data[:synopsis] + '</td><td>' + v2.to_s.gsub(/<\/?[^>]*>/, "").gsub("\n","<br />") + '</td><td>' + vuln_data[:family] + '</td><td>' + k.to_s + '</td></tr>'
              end
            end
          }
        end
        body += '</tbody></table></div>'
      end

      if @options[:severity] <= 3

        body += '<div id="high"><a name="High"></a><h3>High</h3>'

        body += '<table id="high_table" class="display"><thead><tr><th>Nessus ID</th><th>Name</th><th>Synopsis</th><th>Result</th><th>Family</th><th>Port</th></tr></thead><tbody>'
        @events.sort_by{|k,v| v[:port].to_s}.each do |vuln_id,vuln_data|
          vuln_data[:ports].each {|k,v|
            v[:hosts].each do |h,v2|
              if h == id and vuln_data[:severity] == 3
                body += '<tr><td><a href="vuln_' + vuln_id.to_s + '.html">' + vuln_id.to_s + '</a></td><td>' + vuln_data[:plugin_name] + '</td><td>' + vuln_data[:synopsis] + '</td><td>' + v2.to_s.gsub(/<\/?[^>]*>/, "").gsub("\n","<br />") + '</td><td>' + vuln_data[:family] + '</td><td>' + k.to_s + '</td></tr>'
              end
            end
          }
        end
        body += '</tbody></table></div>'
      end

      if @options[:severity] <= 2

        body += '<div id="medium"><a name="Medium"></a><h3>Medium</h3>'

        body += '<table id="medium_table" class="display"><thead><tr><th>Nessus ID</th><th>Name</th><th>Synopsis</th><th>Result</th><th>Family</th><th>Port</th></tr></thead><tbody>'
        @events.sort_by{|k,v| v[:port].to_s}.each do |vuln_id,vuln_data|
          vuln_data[:ports].each {|k,v|
            v[:hosts].each do |h,v2|
              if h == id and vuln_data[:severity] == 2
                body += '<tr><td><a href="vuln_' + vuln_id.to_s + '.html">' + vuln_id.to_s + '</a></td><td>' + vuln_data[:plugin_name] + '</td><td>' + vuln_data[:synopsis] + '</td><td>' + v2.to_s.gsub(/<\/?[^>]*>/, "").gsub("\n","<br />") + '</td><td>' + vuln_data[:family] + '</td><td>' + k.to_s + '</td></tr>'
              end
            end
          }
        end
        body += '</tbody></table></div>'

      end

      if @options[:severity] <= 1

        body += '<div id="low"><a name="Low"></a><h3>Low</h3>'

        body += '<table id="low_table" class="display"><thead><tr><th>Nessus ID</th><th>Name</th><th>Synopsis</th><th>Result</th><th>Family</th><th>Port</th></tr></thead><tbody>'
        @events.sort_by{|k,v| v[:port].to_s}.each do |vuln_id,vuln_data|
          vuln_data[:ports].each {|k,v|
            v[:hosts].each do |h,v2|
              if h == id and vuln_data[:severity] == 1
                body += '<tr><td><a href="vuln_' + vuln_id.to_s + '.html">' + vuln_id.to_s + '</a></td><td>' + vuln_data[:plugin_name] + '</td><td>' + vuln_data[:synopsis] + '</td><td>' + v2.to_s.gsub(/<\/?[^>]*>/, "").gsub("\n","<br />") + '</td><td>' + vuln_data[:family] + '</td><td>' + k.to_s + '</td></tr>'
              end
            end
          }
        end
        body += '</tbody></table></div>'
      end

      if @options[:severity] <= 0

        body += '<div id="informational"><a name="Informational"></a><h3>Informational</h3>'

        body += '<table id="informational_table" class="display"><thead><tr><th>Nessus ID</th><th>Name</th><th>Synopsis</th><th>Result</th><th>Family</th><th>Port</th></tr></thead><tbody>'
        @events.sort_by{|k,v| v[:port].to_s}.each do |vuln_id,vuln_data|
          vuln_data[:ports].each {|k,v|
            v[:hosts].each do |h,v2|
              if h == id and vuln_data[:severity] == 0
                body += '<tr><td><a href="vuln_' + vuln_id.to_s + '.html">' + vuln_id.to_s + '</a></td><td>' + vuln_data[:plugin_name] + '</td><td>' + vuln_data[:synopsis] + '</td><td>' + v2.to_s.gsub(/<\/?[^>]*>/, "").gsub("\n","<br />") + '</td><td>' + vuln_data[:family] + '</td><td>' + k.to_s + '</td></tr>'
              end
            end
          }
        end
        body += '</tbody></table></div>'
      end


      body += "<script>$(document).ready(function() {\n ";
      body += "$('#critical_table').dataTable({\"bPaginate\": false});\n" if @options[:severity] > 4
      body += "$('#high_table').dataTable({\"bPaginate\": false});\n" if @options[:severity] > 3
      body += "$('#medium_table').dataTable({\"bPaginate\": false});\n" if @options[:severity] > 2
      body += "$('#low_table').dataTable({\"bPaginate\": false});\n" if @options[:severity] > 1
      body += "$('#informational_table').dataTable({\"bPaginate\": false});\n" if @options[:severity] > 0
      body += "});</script>"

      body += '</div></div>'

      body_text(f,body)

      close_all(f)
    end
  end

end

Generate the index.html file, outputting it to the nominated output directory + /index.html

@see @options[:output]

Examples:

print_index

Returns:

  • Returns nothing



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/output/htmlout.rb', line 72

def print_index
  File.open(@options[:output] + "/index.html",'w') do |f|
    html_header(f,"Home")

    bar_js(f,"bar_graph","Top 20 Hosts",@hosts.sort_by{|k,v| v[:total_excl_info]}.reverse.take(20))

    crit_total = 0
    high_total = 0
    med_total = 0
    low_total = 0

    @events.each do |k,v|
      crit_total += 1 if v[:severity] == 4
      high_total += 1 if v[:severity] == 3
      med_total += 1 if v[:severity] == 2
      low_total += 1 if v[:severity] == 1
    end

    pie_data = []
    pie_data << ['Low',low_total.to_i] if @options[:severity] <= 1
    pie_data << ['Medium',med_total.to_i] if @options[:severity] <= 2
    pie_data << ['High',high_total.to_i] if @options[:severity] <= 3
    pie_data << ['Critical',crit_total.to_i] if @options[:severity] <= 4

    pie_js(f,"pie_graph","Vuln Breakdown","Vuln Breakdown",pie_data,"document.location.href = 'vuln_overview.html';")

    target_lookup = "var target_lookup = {"
    @hosts.each_with_index do |host,index|
      if host[1][:hostname] == ""
        target_lookup += "'" + host[1][:ip] + "'"
      else
        target_lookup += "'" + host[1][:hostname] + " (" + host[1][:ip] + ")" + "'"
      end
      target_lookup += ": " + host[0].to_s
      target_lookup += "," unless index == @hosts.length - 1
    end
    target_lookup += "}"

    f.puts target_lookup

    close_html_header(f)

    body = '<div id="pie_graph" style="min-width: 400px; height: 400px; margin: 0 auto"></div>'
    body += '<div id="bar_graph" style="min-width: 400px; height: 900px; margin: 0 auto"></div>'

    body += '<div id="allhosts"><h3>All Hosts</h3>'

    ips = []
    @hosts.each do |host|
      ips << host[1][:ip]
    end

    body += '<table id="hosts_table" class="display"><thead><tr><th>IP</th><th>Hostname</th><th>OS</th><th>Number of vulns (Low to Critical)</th></tr></thead><tbody>'
    ips.sort_by{|ip| ip.split('.').map{|octet| octet.to_i}}.each do |ip|
      @hosts.select{|k,v| v[:ip] == ip}.each do |k,v|
        body += '<tr><td><a href="host_' + k.to_s + '.html">' + ip + '</a></td><td>' + v[:hostname] + '</td><td>' + v[:os] + '</td><td>' + v[:total_excl_info].to_s + '</td></tr>'
      end
    end
    body += '</tbody></table>'

    body += '<script>$(document).ready(function() { $(\'#hosts_table\').dataTable({"bPaginate": false}); });</script>'

    body_text(f,body)

    close_all(f)

  end

end

Generate the vuln_overview.html file, outputting it to the nominated output directory + /vuln_overview.html

@see @options[:output]

Examples:

print_vuln_overvire

Returns:

  • Returns nothing



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/output/htmlout.rb', line 152

def print_vuln_overview
  File.open(@options[:output] + "/vuln_overview.html", 'w') do |f|
    html_header(f,"Vulns Overview")

    close_html_header(f)

    body = '<a href="index.html">Home</a><br /><div id="vulns"><h2>Vulns</h2>'

    body += '<table id="vulns_table" class="display"><thead><tr><th>Nessus ID</th><th>Severity</th><th>Name</th><th>Family</th><th>Ports</th><th>Number of impacted hosts</th></tr></thead><tbody>'
    @events.each do |k,v| 
      next if v[:severity].to_i < @options[:severity].to_i
      body += '<tr><td><a href="vuln_' + k.to_s + '.html">' + k.to_s
      body += '</a></td><td>' + v[:severity].to_s + '<td>' + v[:plugin_name] + '</td>'
      body += '<td>' + v[:family].to_s + '</td><td>'
      impacted_hosts = []
      v[:ports].each_with_index do |(k2,v2),index|
        body += k2.to_s 
        body += ", " unless index == v[:ports].length - 1
        v2[:hosts].each do |h,w|
          impacted_hosts << h
        end
      end
      impacted_hosts.uniq!
      body += '</td><td>' + impacted_hosts.count.to_s + '</td></tr>'
    end
    body += '</tbody></table>'

    body += '<script>$(document).ready(function() { $(\'#vulns_table\').dataTable({"bPaginate": false,"aaSorting": [[1,"desc"],[5,"desc"]]}); });</script>'
    body_text(f,body)

    close_all(f)
  end
end

Generates the various vuln_*.html files, outputting them to the nominated output directory

@see @options[:output]

Examples:

print_vulns

Returns:

  • Returns nothing



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/output/htmlout.rb', line 196

def print_vulns
  @events.each do |id,values|
    next if values[:severity].to_i < @options[:severity].to_i
    File.open(@options[:output] + "/vuln_" + id.to_s + ".html", 'w') do |f|
      html_header(f,id.to_s)

      close_html_header(f)

      body = '<a href="index.html">Home</a><br /><div id="vuln"><div id="overview">Nessus ID: ' + id.to_s + '<br />Name: ' + values[:plugin_name] + '<br />Severity: ' + values[:severity].to_s + '<br />Family: ' + values[:family] + '<br />Ports: '
      impacted_hosts = []
      values[:ports].each_with_index {|(k,v),index|
        body += k.to_s
        v[:hosts].each do |h,w|
          impacted_hosts << h
        end
        body += ", " unless index == values[:ports].length - 1
      }
        body += '<br /><br />Synopsis:<br />' + values[:synopsis] + '<br /><br />Description:<br />' + values[:description] + '<br /><br />Solution:<br />' + values[:solution] + '<br /><br />See Also:<br />'
      values[:see_also].each do |val|
        val.split("\n").each do |val2|
          body += '<a href="' + val2 + '">' + val2 + '</a><br />'
        end
      end
      body +='<br /><br />CVE: ' + values[:cve].to_s + '<br />CVSS Base Score: ' + values[:cvss_base_score].to_s + '<br />CVSS Vector: ' + values[:cvss_vector].to_s + '</div>'
      body += '</div>'

      body += '<div id="hosts"><h2>Hosts</h2>'

      body += '<table id="hosts_table" class="display"><thead><tr><th>Host IP</th><th>Hostname</th><th>OS</th><th>Port</th><th>Result</th></tr></thead><tbody>'

      impacted_hosts.uniq.each do |host|
        
        values[:ports].each{|k,v|
          v[:hosts].each do |h,w|
            if h == host
              body += '<tr><td><a href="host_' + host.to_s + '.html">' + @hosts[host][:ip] + '</a></td><td>' + @hosts[host][:hostname] + '</td><td>' + @hosts[host][:os] + '</td>'
              body += '<td>' + k.to_s + '</td><td>' + w.to_s.gsub(/<\/?[^>]*>/, "").gsub("\n","<br />\n") + "</td></tr>\n"
            end
          end
        }
      end

      body += '</tbody></table>'

      body += '<script>$(document).ready(function() { $(\'#hosts_table\').dataTable({"bPaginate": false,"aaSorting": [[0,"asc"]]}); });</script>'

      body_text(f,body)

      close_all(f)
    end
  end
end

#runObject

Run the Htmlout class - this will generate all the necessary HTML files and copy other dependencies (JS/CSS/PNGs) to the target folder

Examples:

object.run

Returns:

  • Returns nothing



55
56
57
58
59
60
# File 'lib/output/htmlout.rb', line 55

def run
  self.print_hosts # generate all the host_*.html files
  self.print_index # generate the index.html file
  self.print_vulns # generate all the vuln_*.html files
  self.print_vuln_overview # generate the vuln_overview.html file
end