-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsa.rb
More file actions
119 lines (103 loc) · 2.85 KB
/
dsa.rb
File metadata and controls
119 lines (103 loc) · 2.85 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
#
# dsa.rb
#
# Author: Ryosuke KUTSUNA <[email protected]>
#
require 'net/http'
require 'open-uri'
require 'nokogiri'
require 'tmpdir'
require 'tempfile'
class DSA
def initialize(num, year=nil, lang="en")
@dsabase = "http://www.debian.org/security"
@cvebase = "http://web.nvd.nist.gov/view/vuln/detail?vulnId="
@bugidbase = "bugs.debian.org/cgi-bin/bugreport.cgi?bug="
unless num then
puts "DSA num not exist."
exit 1
else
@dsa_num = num
end
if year == nil then
t = Time.new
@year = t.year
else
@year = year
end
@lang = lang
@tmpfile = Tempfile.new('dsa')
getDSAHtml()
parseDSA()
@tmpfile.close
@tmpfile.unlink
end
def getURL
return "#{@dsabase}/#{@year}/dsa-#{@dsa_num}.#{@lang}.html"
end
def getDate
return @dsa_date
end
def getAffected
return @dsa_affected
end
def getVulnerable
return @dsa_vulnerable
end
def getReferences
return @dsa_references
end
def getReferencesWithURL
text0 = @dsa_references.gsub!(/(CVE-[0-9]+-[0-9]+)/, "<a href=\"#{@cvebase}" + '\1' + "\">" + '\1' + "</a>")
text1 = text0.gsub(/Bug ([0-9]+)/, "Bug <a href=\"#{@bugidbase}" + '\1' + "\">" + '\1' + "</a>")
return text1
end
def getInformation
return @dsa_information
end
private
# get DSA Announce HTML
def getDSAHtml()
dldsa = "#{@dsabase}/#{@year}/dsa-#{@dsa_num}.#{@lang}.html"
begin
open(dldsa) do |s|
@tmpfile.print(s.read)
end
rescue => e
p e.message
print "Not found: #{dldsa}\n"
exit 1
end
end
# parse DSA Announce HTML
def parseDSA()
doc = Nokogiri::HTML(open(@tmpfile))
doc.xpath('//div[@id = "content"]/dl/dt').each do |c|
case c.text
when "Date Reported:", "報告日時:" then
@dsa_date = doc.xpath('//div[@id = "content"]/dl/dd')[0].text
when "DSA Affected Packages:", "影響を受けるパッケージ:" then
@dsa_affected = doc.xpath('//div[@id = "content"]/dl/dd')[1].text
when "Vulnerable:", "危険性:" then
@dsa_vulnerable = doc.xpath('//div[@id = "content"]/dl/dd')[2].text
when "Security database references:", "参考セキュリティデータベース:" then
@dsa_references = doc.xpath('//div[@id = "content"]/dl/dd')[3].text
when "More information:", "詳細:" then
@dsa_information = doc.xpath('//div[@id = "content"]/dl/dd')[4].text
end
end
end
end
### main ###
if __FILE__ == $0
dsa = DSA.new(2668, 2013, "en")
print "Date : #{dsa.getDate}\n"
print "Affected : #{dsa.getAffected}\n"
print "Vulnerable : #{dsa.getVulnerable}\n"
print "References : #{dsa.getReferences}\n"
print "Information: #{dsa.getInformation}\n"
print "References(a) : #{dsa.getReferencesWithURL}\n"
end
# EOF