-
Notifications
You must be signed in to change notification settings - Fork 0
/
detail.rb
86 lines (77 loc) · 2.74 KB
/
detail.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
# coding: utf-8
require 'net/https'
require 'rexml/document'
require_relative 'cvssinfo'
def init(proxy_addr = nil, proxy_port = nil)
@proxy_addr = proxy_addr
@proxy_port = proxy_port
end
def printval(item, elem_name)
item.elements.each(elem_name) do |elem|
print elem_name + ": " + elem.text + "\n"
end
end
def getinfo(id)
http = Net::HTTP::Proxy(@proxy_addr, @proxy_port).new('jvndb.jvn.jp', 443)
http.use_ssl = true
http.ca_file = './DigiCertGlobalRootG2.crt.pem'
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.start do | session |
puts "=== Info of " + id + " ==="
response = session.get("/myjvn?method=getVulnDetailInfo&feed=hnd&vulnId=#{id}&lang=ja")
if response.code != '200'
STDERR.puts "#{response.code} - #{response.message}"
return
end
# puts response.body
xml = REXML::Document.new(response.body)
if xml.root.elements['/VULDEF-Document/status:Status'].nil?
STDERR.puts "Fatal error"
return
end
if xml.root.elements['/VULDEF-Document/status:Status'].attributes['totalResRet'] == '0'
STDERR.puts "No results"
return
end
vulinfo = xml.root.elements['/VULDEF-Document/Vulinfo']
puts "VulinfoID: " + vulinfo.elements['VulinfoID'].text
data = vulinfo.elements['VulinfoData']
puts "Title: " + data.elements['Title'].text
puts "Overview: " + data.elements['VulinfoDescription/Overview'].text
data.elements.each('Impact/Cvss') do |cvss|
version = cvss.attributes['version']
severity = cvss.elements['Severity'].text
score = cvss.elements['Base'].text # score
vector = cvss.elements['Vector'].text
puts "version: " + version
puts "\tscore: " + score
puts "\tseverity: " + severity
if not vector.nil? and vector.length > 0
result = CvssInfo.new(vector, version)
puts "\tcalc score: " + result.score.to_s
puts "\tcalc severity: " + result.severity
end
end
data.elements.each('Impact/ImpactItem') do |item|
puts "ImpactItemDesc: " + item.elements['Description'].text
end
data.elements.each('Solution/SolutionItem') do |item|
puts "SolutionItemDesc: " + item.elements['Description'].text
end
data.elements.each('Related/RelatedItem') do |item|
puts "-- RelatedItem --"
printval(item, 'Name')
printval(item, 'VulinfoID')
printval(item, 'Title')
printval(item, 'URL')
end
puts "DateFirstPublished: " + data.elements['DateFirstPublished'].text
puts "DateLastUpdated: " + data.elements['DateLastUpdated'].text
puts "DatePublic: " + data.elements['DatePublic'].text
end
end
init() # proxy なし
getinfo("JVNDB-2017-001234")
getinfo("JVNDB-2016-001234")
getinfo("JVNDB-2017-000432")
getinfo("JVNDB-2037-000432")