-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpwndoc-ng2sysreptor_vulns.rb
executable file
·101 lines (92 loc) · 2.67 KB
/
pwndoc-ng2sysreptor_vulns.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
49
50
51
52
53
54
55
56
57
58
59
60
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
94
95
96
97
98
99
100
101
#!/usr/bin/env ruby
# frozen_string_literal: true
# Copyright (c) 2023 Alexandre ZANNI (noraj)
require 'yaml'
require 'json'
require 'kramdown'
begin
# Ruby 3.2
require 'random/formatter'
rescue LoadError
# Ruby 3.0
require 'securerandom'
end
require 'date'
raise ArgumentError, 'Invalid argument count (2 expected)' if ARGV.length != 2
pwndoc_file = ARGV[0]
sysreptor_folder = ARGV[1]
pwndoc_data = YAML.load_file(pwndoc_file)
def to_md(html)
html ||= ''
Kramdown::Document.new(html, html_to_native: true).to_kramdown
end
def uuidgen
# Ruby 3.2
Random.uuid
rescue LoadError
# Ruby 3.0
SecureRandom.uuid
end
# pwndoc locale -> sysreptor language position
LANG_MAP = {
'en' => 0,
'fr' => 1
}.freeze
pwndoc_data.each do |pv|
uuid_main = uuidgen
sysreptor_data = {
'format' => 'templates/v2',
'id' => uuid_main,
'created' => DateTime.now.rfc3339,
'updated' => DateTime.now.rfc3339,
'tags' => [
pv['category']
],
'translations' => [
{
'id' => uuidgen,
'created' => DateTime.now.rfc3339,
'updated' => DateTime.now.rfc3339,
'is_main' => true,
'language' => 'en-US',
'status' => 'in-progress',
'data' => {
'title' => 'TODO: set title',
'cvss' => pv['cvssv3'].sub('3.0', '3.1')
}
},
{
'id' => uuidgen,
'created' => DateTime.now.rfc3339,
'updated' => DateTime.now.rfc3339,
'is_main' => false,
'language' => 'fr-FR',
'status' => 'in-progress',
'data' => {
'title' => 'TODO: choisir un titre'
}
}
]
}
pv['details'].each do |details|
pos = LANG_MAP[details['locale']]
# wrapper for quick access
translation = sysreptor_data['translations'][pos]['data']
translation['title'] = details['title']
translation['references'] = details['references']
translation['refid'] = details.dig('customFields', 0, 'text')
translation['summary'] = to_md(details['description'])
translation['description'] = to_md(details['observation'])
translation['recommendation'] = to_md(details['remediation'])
# write back to object
sysreptor_data['translations'][pos]['data'] = translation
end
Dir.mkdir(sysreptor_folder) unless File.exist?(sysreptor_folder)
File.open("#{sysreptor_folder}/#{uuid_main}.json", 'w') do |file|
JSON.dump(sysreptor_data, file)
end
# Individual archive
`tar czf #{sysreptor_folder}/#{uuid_main}.tar.gz --directory #{sysreptor_folder} #{uuid_main}.json`
end
# Global archive
`tar -czf #{sysreptor_folder}/all-vulns.tar.gz -C #{sysreptor_folder} $(find #{sysreptor_folder} -maxdepth 1 -type f -name "*.json" -printf "%f\n")`