Module: PWN::Reports::SARIF

Defined in:
lib/pwn/reports/sarif.rb

Overview

SARIF 2.1.0 writer for finding export.

Class Method Summary collapse

Class Method Details

.authorsObject



39
40
41
# File 'lib/pwn/reports/sarif.rb', line 39

public_class_method def self.authors
  "AUTHOR(S):\n  0day Inc. <[email protected]>\n"
end

.generate(opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pwn/reports/sarif.rb', line 9

public_class_method def self.generate(opts = {})
  payload = PWN::Reports.report_payload(opts)
  doc = {
    version: '2.1.0',
    '$schema' => 'https://json.schemastore.org/sarif-2.1.0.json',
    runs: [
      {
        tool: { driver: { name: 'pwn', version: (defined?(PWN::VERSION) ? PWN::VERSION : '0') } },
        results: Array(payload[:findings]).map { |row| result_row(row: row) }
      }
    ]
  }
  path = PWN::Reports.resolve_path(opts.merge(ext: 'sarif.json'))
  File.write(path, ::JSON.pretty_generate(doc))
  path
end

.helpObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pwn/reports/sarif.rb', line 43

public_class_method def self.help
  puts "USAGE:
    # Write a SARIF 2.1 document from a findings hash.
    #{self}.generate(
      results_hash: 'required - Hash with :findings Array',
      dir_path: 'optional - output directory',
      report_name: 'optional - basename without extension',
      path: 'optional - exact output path'
    )

    # Print the AUTHOR(S) string for this module.
    #{self}.authors
  "
  constants.sort
end