Codebase list ruby-cms-scanner / upstream/0.6.0
New upstream version 0.6.0 Sophie Brun 4 years ago
10 changed file(s) with 53 addition(s) and 101 deletion(s). Raw diff Collapse all Expand all
5858 default: 60),
5959 OptPositiveInteger.new(['--connect-timeout SECONDS', 'The connection timeout in seconds'],
6060 default: 30),
61 OptBoolean.new(['--disable-tls-checks', 'Disables SSL/TLS certificate verification'])
61 OptBoolean.new(['--disable-tls-checks',
62 'Disables SSL/TLS certificate verification, and downgrade to TLS1.0+ ' \
63 '(requires cURL 7.66 for the latter)'])
6264 ] + cli_browser_proxy_options + cli_browser_cookies_options + cli_browser_cache_options
6365 end
6466
1818 s.test_files = []
1919 s.require_paths = ['lib']
2020
21 s.add_dependency 'nokogiri', '~> 1.10.0'
22 s.add_dependency 'opt_parse_validator', '~> 1.7.4'
21 s.add_dependency 'nokogiri', '~> 1.10.4'
22 s.add_dependency 'opt_parse_validator', '~> 1.8.0'
2323 s.add_dependency 'public_suffix', '>= 3.0', '< 4.1'
2424 s.add_dependency 'ruby-progressbar', '~> 1.10.0'
2525 s.add_dependency 'typhoeus', '~> 1.3.0'
3434 s.add_development_dependency 'rubocop', '~> 0.74.0'
3535 s.add_development_dependency 'rubocop-performance', '~> 1.4.0'
3636 s.add_development_dependency 'simplecov', '~> 0.16.1'
37 s.add_development_dependency 'webmock', '~> 3.6.0'
37 s.add_development_dependency 'webmock', '~> 3.7.0'
3838 end
5656 # See http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html
5757 params[:ssl_verifypeer] = false
5858 params[:ssl_verifyhost] = 0
59 # TLSv1.0 and plus, allows to use a protocol potentially lower than the OS default
60 params[:sslversion] = :tlsv1
5961 end
6062
6163 typhoeus_to_browser_opts.each do |typhoeus_opt, browser_opt|
88 def initialize(option_parser = OptParseValidator::OptParser.new(nil, 40))
99 @option_parser = option_parser
1010
11 register_options_files
11 register_config_files
12
13 option_parser.config_files.result_key = 'cli_options'
1214 end
1315
1416 # Adds the potential option file paths to the option_parser
15 def register_options_files
17 def register_config_files
1618 [Dir.home, Dir.pwd].each do |dir|
17 option_parser.options_files.class.supported_extensions.each do |ext|
18 @option_parser.options_files << Pathname.new(dir).join(".#{NS.app_name}", "cli_options.#{ext}").to_s
19 option_parser.config_files.class.supported_extensions.each do |ext|
20 option_parser.config_files << Pathname.new(dir).join(".#{NS.app_name}", "scan.#{ext}").to_s
1921 end
2022 end
2123 end
88 module ClassMethods
99 # @return [ Array<Symbol> ]
1010 def references_keys
11 @references_keys ||= %i[cve secunia osvdb exploitdb url metasploit packetstorm securityfocus]
11 @references_keys ||= %i[cve exploitdb url metasploit packetstorm securityfocus]
1212 end
1313 end
1414
2828
2929 # @return [ Array<String> ] All the references URLs
3030 def references_urls
31 cve_urls + secunia_urls + osvdb_urls + exploitdb_urls + urls + msf_urls +
31 cve_urls + exploitdb_urls + urls + msf_urls +
3232 packetstorm_urls + securityfocus_urls
3333 end
3434
4545 # @return [ String ] The URL to the CVE
4646 def cve_url(cve)
4747 "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-#{cve}"
48 end
49
50 # @return [ Array<String> ] The Secunia IDs
51 def secunia_ids
52 references[:secunia] || []
53 end
54
55 # @return [ Array<String> ]
56 def secunia_urls
57 secunia_ids.reduce([]) { |acc, elem| acc << secunia_url(elem) }
58 end
59
60 # @return [ String ] The URL to the Secunia advisory
61 def secunia_url(id)
62 "https://secuniaresearch.flexerasoftware.com/advisories/#{id}/"
63 end
64
65 # @return [ Array<String> ] The OSVDB IDs
66 def osvdb_ids
67 references[:osvdb] || []
68 end
69
70 # @return [ Array<String> ]
71 def osvdb_urls
72 osvdb_ids.reduce([]) { |acc, elem| acc << osvdb_url(elem) }
73 end
74
75 # @return [ String ] The URL to the ExploitDB advisory
76 def osvdb_url(id)
77 "http://osvdb.org/show/osvdb/#{id}"
7848 end
7949
8050 # @return [ Array<String> ] The ExploitDB ID
12494
12595 # @return [ String ]
12696 def packetstorm_url(id)
127 "http://packetstormsecurity.com/files/#{id}/"
97 "https://packetstormsecurity.com/files/#{id}/"
12898 end
12999
130100 # @return [ Array<String> ] The Security Focus IDs
139109
140110 # @return [ String ]
141111 def securityfocus_url(id)
142 "http://www.securityfocus.com/bid/#{id}/"
112 "https://www.securityfocus.com/bid/#{id}/"
143113 end
144114 end
145115 end
11
22 # Version
33 module CMSScanner
4 VERSION = '0.5.7'
4 VERSION = '0.6.0'
55 end
4141 cache_ttl: 200, connecttimeout: 10,
4242 userpwd: 'log:pwd', proxyuserpwd: 'u:pwd',
4343 cookiejar: options[:cookie_jar], cookiefile: options[:cookie_jar],
44 ssl_verifypeer: false, ssl_verifyhost: 0
44 ssl_verifypeer: false, ssl_verifyhost: 0, sslversion: :tlsv1
4545 ).merge(headers: default[:headers].merge('Host' => 'testing', 'Test' => 'aa', 'Referer' => 'http://wp.lo/'))
4646 end
4747
2020 describe CMSScanner::Controllers do
2121 subject(:controllers) { described_class.new }
2222 let(:controller_mod) { CMSScanner::Controller }
23
24 its(:'option_parser.config_files.result_key') { should eql 'cli_options' }
2325
2426 describe '#<<' do
2527 its(:size) { should be 0 }
137139 end
138140 end
139141
140 describe '#register_options_files' do
142 describe '#register_config_files' do
141143 it 'register the correct files' do
142144 expect(File).to receive(:exist?).exactly(4).times.and_return(true)
143145
145147 option_parser = controllers.option_parser
146148
147149 [Dir.home, Dir.pwd].each do |dir|
148 option_parser.options_files.class.supported_extensions.each do |ext|
149 expected << File.join(dir, '.cms_scanner', "cli_options.#{ext}")
150 option_parser.config_files.class.supported_extensions.each do |ext|
151 expected << File.join(dir, '.cms_scanner', "scan.#{ext}")
150152 end
151153 end
152154
153 expect(option_parser.options_files.map(&:path)).to eql expected
155 expect(option_parser.config_files.map(&:path)).to eql expected
154156 end
155157 end
156158 end
2626
2727 # Testing the override of the register_options_files
2828 class Controllers < CMSScanner::Controllers
29 def register_options_files
30 option_parser.options_files << File.join(".#{SubScanner.app_name}", 'rspec.yml')
29 def register_config_files
30 option_parser.config_files << File.join(".#{SubScanner.app_name}", 'rspec.yml')
3131 end
3232 end
3333
101101 end
102102 end
103103
104 describe '#register_options_files' do
105 let(:options_file_path) { '.subscanner/rspec.yml' }
104 describe '#register_config_files' do
105 let(:config_file_path) { '.subscanner/rspec.yml' }
106106
107107 it 'register the correct file' do
108108 allow(File).to receive(:exist?).and_call_original
109 allow(File).to receive(:exist?).with(options_file_path).and_return(true)
109 allow(File).to receive(:exist?).with(config_file_path).and_return(true)
110110
111111 option_parser = SubScanner::Scan.new.controllers.option_parser
112112
113 expect(option_parser.options_files.map(&:path)).to eql [options_file_path]
113 expect(option_parser.config_files.map(&:path)).to eql [config_file_path]
114114 end
115115 end
116116 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 secunia osvdb exploitdb url metasploit packetstorm securityfocus]
6 .to eql %i[cve exploitdb url metasploit packetstorm securityfocus]
77 end
88 end
99
1010 describe 'references' do
1111 context 'when no references' do
12 %i[cves secunia_ids osvdb_ids exploitdb_ids urls
13 msf_modules packetstorm_ids securityfocus_ids].each do |attribute|
12 %i[cves exploitdb_ids urls msf_modules packetstorm_ids securityfocus_ids].each do |attribute|
1413 its(attribute) { should eql([]) }
1514 end
1615
17 %i[cve_urls secunia_urls osvdb_urls exploitdb_urls msf_urls
18 packetstorm_urls secunia_urls].each do |attribute|
16 %i[cve_urls exploitdb_urls msf_urls packetstorm_urls securityfocus_urls].each do |attribute|
1917 its(attribute) { should eql([]) }
2018 end
2119
2826 its(:references) { should eql(cve: %w[1]) }
2927 end
3028
31 context 'when references provided as string' do
29 context 'when references provided as string/integer' do
3230 let(:references) do
3331 {
34 cve: 11,
35 secunia: 12,
36 osvdb: 13,
37 exploitdb: 14,
32 cve: '11',
33 secunia: '12', # Secunia and OSVDB have been left here to make sure they don't raise errors
34 osvdb: '13',
35 exploitdb: '14',
3836 url: 'single-url',
3937 metasploit: '/exploit/yolo',
4038 packetstorm: 15,
4543 its(:cves) { should eql %w[11] }
4644 its(:cve_urls) { should eql %w[https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-11] }
4745
48 its(:secunia_ids) { should eql %w[12] }
49 its(:secunia_urls) { should eql %w[https://secuniaresearch.flexerasoftware.com/advisories/12/] }
50
51 its(:osvdb_ids) { should eql %w[13] }
52 its(:osvdb_urls) { should eql %w[http://osvdb.org/show/osvdb/13] }
53
5446 its(:exploitdb_ids) { should eql %w[14] }
5547 its(:exploitdb_urls) { should eql %w[https://www.exploit-db.com/exploits/14/] }
5648
6052 its(:msf_urls) { should eql %w[https://www.rapid7.com/db/modules/exploit/yolo] }
6153
6254 its(:packetstorm_ids) { should eq %w[15] }
63 its(:packetstorm_urls) { should eql %w[http://packetstormsecurity.com/files/15/] }
55 its(:packetstorm_urls) { should eql %w[https://packetstormsecurity.com/files/15/] }
6456
6557 its(:securityfocus_ids) { should eq %w[16] }
66 its(:securityfocus_urls) { should eql %w[http://www.securityfocus.com/bid/16/] }
58 its(:securityfocus_urls) { should eql %w[https://www.securityfocus.com/bid/16/] }
6759
6860 its(:references_urls) do
6961 should eql [
7062 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-11',
71 'https://secuniaresearch.flexerasoftware.com/advisories/12/',
72 'http://osvdb.org/show/osvdb/13',
7363 'https://www.exploit-db.com/exploits/14/',
7464 'single-url',
7565 'https://www.rapid7.com/db/modules/exploit/yolo',
76 'http://packetstormsecurity.com/files/15/',
77 'http://www.securityfocus.com/bid/16/'
66 'https://packetstormsecurity.com/files/15/',
67 'https://www.securityfocus.com/bid/16/'
7868 ]
7969 end
8070 end
8373 let(:references) do
8474 {
8575 cve: [10, 11],
86 secunia: [20, 21],
76 secunia: [20, 21], # Secunia and OSVDB have been left here to make sure they don't raise errors
8777 osvdb: [30, 31],
8878 exploitdb: [40, 41],
8979 url: %w[single-url another-url],
9787 its(:cve_urls) do
9888 should eql %w[https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-10
9989 https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-11]
100 end
101
102 its(:secunia_ids) { should eql %w[20 21] }
103 its(:secunia_urls) do
104 should eql %w[https://secuniaresearch.flexerasoftware.com/advisories/20/
105 https://secuniaresearch.flexerasoftware.com/advisories/21/]
106 end
107
108 its(:osvdb_ids) { should eql %w[30 31] }
109 its(:osvdb_urls) do
110 should eql %w[http://osvdb.org/show/osvdb/30
111 http://osvdb.org/show/osvdb/31]
11290 end
11391
11492 its(:exploitdb_ids) { should eql %w[40 41] }
127105
128106 its(:packetstorm_ids) { should eq %w[50 51] }
129107 its(:packetstorm_urls) do
130 should eql %w[http://packetstormsecurity.com/files/50/
131 http://packetstormsecurity.com/files/51/]
108 should eql %w[https://packetstormsecurity.com/files/50/
109 https://packetstormsecurity.com/files/51/]
132110 end
133111
134112 its(:securityfocus_ids) { should eq %w[60 61] }
135113 its(:securityfocus_urls) do
136 should eql %w[http://www.securityfocus.com/bid/60/
137 http://www.securityfocus.com/bid/61/]
114 should eql %w[https://www.securityfocus.com/bid/60/
115 https://www.securityfocus.com/bid/61/]
138116 end
139117
140118 its(:references_urls) do
141119 should eql [
142120 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-10',
143121 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-11',
144 'https://secuniaresearch.flexerasoftware.com/advisories/20/',
145 'https://secuniaresearch.flexerasoftware.com/advisories/21/',
146 'http://osvdb.org/show/osvdb/30',
147 'http://osvdb.org/show/osvdb/31',
148122 'https://www.exploit-db.com/exploits/40/',
149123 'https://www.exploit-db.com/exploits/41/',
150124 'single-url',
151125 'another-url',
152126 'https://www.rapid7.com/db/modules/exploit/yolo',
153127 'https://www.rapid7.com/db/modules/exploit/aa',
154 'http://packetstormsecurity.com/files/50/',
155 'http://packetstormsecurity.com/files/51/',
156 'http://www.securityfocus.com/bid/60/',
157 'http://www.securityfocus.com/bid/61/'
128 'https://packetstormsecurity.com/files/50/',
129 'https://packetstormsecurity.com/files/51/',
130 'https://www.securityfocus.com/bid/60/',
131 'https://www.securityfocus.com/bid/61/'
158132 ]
159133 end
160134 end