Codebase list ruby-cms-scanner / 11106f0
Update upstream source from tag 'upstream/0.10.0' Update to upstream version '0.10.0' with Debian dir 82ebdb492460ebdff7d0674241ae858aa04bb99b Sophie Brun 4 years ago
5 changed file(s) with 62 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
88 module ClassMethods
99 # @return [ Array<Symbol> ]
1010 def references_keys
11 @references_keys ||= %i[cve exploitdb url metasploit packetstorm securityfocus]
11 @references_keys ||= %i[cve exploitdb url metasploit packetstorm securityfocus youtube]
1212 end
1313 end
1414
1717 @references = {}
1818
1919 self.class.references_keys.each do |key|
20 @references[key] = [*refs[key]].map(&:to_s) if refs.key?(key)
20 next unless refs.key?(key)
21
22 @references[key] = if key == :youtube
23 [*refs[:youtube]].map { |id| youtube_url(id) }
24 else
25 [*refs[key]].map(&:to_s)
26 end
2127 end
2228 end
2329
2935 # @return [ Array<String> ] All the references URLs
3036 def references_urls
3137 cve_urls + exploitdb_urls + urls + msf_urls +
32 packetstorm_urls + securityfocus_urls
38 packetstorm_urls + securityfocus_urls + youtube_urls
3339 end
3440
3541 # @return [ Array<String> ] The CVEs
111117 def securityfocus_url(id)
112118 "https://www.securityfocus.com/bid/#{id}/"
113119 end
120
121 # @return [ Array<String> ]
122 def youtube_urls
123 references[:youtube] || []
124 end
125
126 # @return [ String ]
127 def youtube_url(id)
128 "https://www.youtube.com/watch?v=#{id}"
129 end
114130 end
115131 end
11
22 # Version
33 module CMSScanner
4 VERSION = '0.9.0'
4 VERSION = '0.10.0'
55 end
44 class Vulnerability
55 include References
66
7 attr_reader :title, :type, :fixed_in
7 attr_reader :title, :type, :fixed_in, :cvss
88
99 # @param [ String ] title
1010 # @param [ Hash ] references
11 # @option references [ Array<String>, String ] cve
12 # @option references [ Array<String>, String ] secunia
13 # @option references [ Array<String>, String ] osvdb
14 # @option references [ Array<String>, String ] exploitdb
15 # @option references [ Array<String> ] url URL(s) to related advisories etc
16 # @option references [ Array<String>, String ] metasploit The related metasploit module(s)
11 # @option references [ Array<String>, String ] :cve
12 # @option references [ Array<String>, String ] :secunia
13 # @option references [ Array<String>, String ] :osvdb
14 # @option references [ Array<String>, String ] :exploitdb
15 # @option references [ Array<String> ] :url URL(s) to related advisories etc
16 # @option references [ Array<String>, String ] :metasploit The related metasploit module(s)
17 # @option references [ Array<String> ] :youtube
1718 # @param [ String ] type
1819 # @param [ String ] fixed_in
19 def initialize(title, references = {}, type = nil, fixed_in = nil)
20 # @param [ HashSymbol ] cvss
21 # @option cvss [ String ] :score
22 # @option cvss [ String ] :vector
23 def initialize(title, references: {}, type: nil, fixed_in: nil, cvss: nil)
2024 @title = title
2125 @type = type
2226 @fixed_in = fixed_in
27 @cvss = { score: cvss[:score], vector: cvss[:vector] } if cvss
2328
2429 self.references = references
2530 end
3136 title == other.title &&
3237 type == other.type &&
3338 references == other.references &&
34 fixed_in == other.fixed_in
39 fixed_in == other.fixed_in &&
40 cvss == other.cvss
3541 end
3642 end
3743 end
00 # frozen_string_literal: true
11
22 describe CMSScanner::Vulnerability do
3 subject(:vuln) { described_class.new(title, references) }
3 subject(:vuln) { described_class.new(title, references: references, cvss: cvss) }
44 let(:title) { 'Test Vuln' }
55 let(:references) { {} }
6 let(:cvss) { nil }
67
78 it_behaves_like CMSScanner::References
89
1112 its(:references) { should eql({}) }
1213 its(:type) { should eql nil }
1314 its(:fixed_in) { should eql nil }
15 its(:cvss) { should eql nil }
16
17 context 'when CVSS' do
18 let(:cvss) { { score: '5.4', vector: 'spec', y: 'key should not be added' } }
19
20 its(:cvss) { should eql({ score: '5.4', vector: 'spec' }) }
21 end
1422 end
1523
1624 describe '#==' do
17 context 'when te same vuln' do
25 context 'when the same vuln' do
26 let(:cvss) { { score: '5.4', vector: 'spec' } }
27
1828 it 'returns true' do
1929 expect(vuln).to eq vuln.dup
2030 end
33 describe '#references_keys' do
44 it 'returns the expected array of symbols' do
55 expect(subject.class.references_keys)
6 .to eql %i[cve exploitdb url metasploit packetstorm securityfocus]
6 .to eql %i[cve exploitdb url metasploit packetstorm securityfocus youtube]
77 end
88 end
99
1010 describe 'references' do
1111 context 'when no references' do
12 %i[cves exploitdb_ids urls msf_modules packetstorm_ids securityfocus_ids].each do |attribute|
12 %i[cves exploitdb_ids urls msf_modules packetstorm_ids securityfocus_ids youtube_urls].each do |attribute|
1313 its(attribute) { should eql([]) }
1414 end
1515
16 %i[cve_urls exploitdb_urls msf_urls packetstorm_urls securityfocus_urls].each do |attribute|
16 %i[cve_urls exploitdb_urls msf_urls packetstorm_urls securityfocus_urls youtube_urls].each do |attribute|
1717 its(attribute) { should eql([]) }
1818 end
1919
3636 url: 'single-url',
3737 metasploit: '/exploit/yolo',
3838 packetstorm: 15,
39 securityfocus: 16
39 securityfocus: 16,
40 youtube: 'xAAAA'
4041 }
4142 end
4243
5758 its(:securityfocus_ids) { should eq %w[16] }
5859 its(:securityfocus_urls) { should eql %w[https://www.securityfocus.com/bid/16/] }
5960
61 its(:youtube_urls) { should eql %w[https://www.youtube.com/watch?v=xAAAA] }
62
6063 its(:references_urls) do
6164 should eql [
6265 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-11',
6467 'single-url',
6568 'https://www.rapid7.com/db/modules/exploit/yolo',
6669 'https://packetstormsecurity.com/files/15/',
67 'https://www.securityfocus.com/bid/16/'
70 'https://www.securityfocus.com/bid/16/',
71 'https://www.youtube.com/watch?v=xAAAA'
6872 ]
6973 end
7074 end
7983 url: %w[single-url another-url],
8084 metasploit: %w[/exploit/yolo exploit/aa],
8185 packetstorm: [50, 51],
82 securityfocus: [60, 61]
86 securityfocus: [60, 61],
87 youtube: %w[xBBBB]
8388 }
8489 end
8590
115120 https://www.securityfocus.com/bid/61/]
116121 end
117122
123 its(:youtube_urls) { should eql %w[https://www.youtube.com/watch?v=xBBBB] }
124
118125 its(:references_urls) do
119126 should eql [
120127 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-10',
128135 'https://packetstormsecurity.com/files/50/',
129136 'https://packetstormsecurity.com/files/51/',
130137 'https://www.securityfocus.com/bid/60/',
131 'https://www.securityfocus.com/bid/61/'
138 'https://www.securityfocus.com/bid/61/',
139 'https://www.youtube.com/watch?v=xBBBB'
132140 ]
133141 end
134142 end