|
238 | 238 | end
|
239 | 239 | end
|
240 | 240 |
|
| 241 | + describe '#check_version_from_custom_file' do |
| 242 | + before :each do |
| 243 | + allow(subject).to receive(:send_request_cgi) do |opts| |
| 244 | + res = Rex::Proto::Http::Response.new |
| 245 | + res.code = wp_code |
| 246 | + res.body = wp_body |
| 247 | + res |
| 248 | + end |
| 249 | + end |
| 250 | + |
| 251 | + let(:wp_code) { 200 } |
| 252 | + let(:wp_body) { nil } |
| 253 | + let(:wp_path) { '/test/' } |
| 254 | + let(:wp_fixed_version) { nil } |
| 255 | + let(:wp_regex) { /(?:Version):\s*([0-9a-z.-]+)/i } |
| 256 | + |
| 257 | + context 'when no file is found' do |
| 258 | + let(:wp_code) { 404 } |
| 259 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Unknown) } |
| 260 | + end |
| 261 | + |
| 262 | + context 'when no version can be extracted from style' do |
| 263 | + let(:wp_code) { 200 } |
| 264 | + let(:wp_body) { 'invalid content' } |
| 265 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Detected) } |
| 266 | + end |
| 267 | + |
| 268 | + context 'when version from style has arbitrary leading whitespace' do |
| 269 | + let(:wp_code) { 200 } |
| 270 | + let(:wp_fixed_version) { '1.0.1' } |
| 271 | + let(:wp_body) { 'Version: 1.0.0' } |
| 272 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) } |
| 273 | + let(:wp_body) { 'Version:1.0.0' } |
| 274 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) } |
| 275 | + end |
| 276 | + |
| 277 | + context 'when installed version is vulnerable' do |
| 278 | + let(:wp_code) { 200 } |
| 279 | + let(:wp_fixed_version) { '1.0.1' } |
| 280 | + let(:wp_body) { 'Version: 1.0.0' } |
| 281 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) } |
| 282 | + end |
| 283 | + |
| 284 | + context 'when installed version is not vulnerable' do |
| 285 | + let(:wp_code) { 200 } |
| 286 | + let(:wp_fixed_version) { '1.0.1' } |
| 287 | + let(:wp_body) { 'Version: 1.0.2' } |
| 288 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Safe) } |
| 289 | + end |
| 290 | + |
| 291 | + context 'when installed version is vulnerable (version range)' do |
| 292 | + let(:wp_code) { 200 } |
| 293 | + let(:wp_fixed_version) { '1.0.2' } |
| 294 | + let(:wp_introd_version) { '1.0.0' } |
| 295 | + let(:wp_body) { 'Version: 1.0.1' } |
| 296 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Appears) } |
| 297 | + end |
| 298 | + |
| 299 | + context 'when installed version is older (version range)' do |
| 300 | + let(:wp_code) { 200 } |
| 301 | + let(:wp_fixed_version) { '1.0.1' } |
| 302 | + let(:wp_introd_version) { '1.0.0' } |
| 303 | + let(:wp_body) { 'Version: 0.0.9' } |
| 304 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Safe) } |
| 305 | + end |
| 306 | + |
| 307 | + context 'when installed version is newer (version range)' do |
| 308 | + let(:wp_code) { 200 } |
| 309 | + let(:wp_fixed_version) { '1.0.1' } |
| 310 | + let(:wp_introd_version) { '1.0.0' } |
| 311 | + let(:wp_body) { 'Version: 1.0.2' } |
| 312 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Safe) } |
| 313 | + end |
| 314 | + |
| 315 | + context 'when installed version is newer (text in version number)' do |
| 316 | + let(:wp_code) { 200 } |
| 317 | + let(:wp_fixed_version) { '1.5.3' } |
| 318 | + let(:wp_body) { 'Version: 2.0.0-beta1' } |
| 319 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Safe) } |
| 320 | + end |
| 321 | + |
| 322 | + context 'when all versions are vulnerable' do |
| 323 | + let(:wp_code) { 200 } |
| 324 | + let(:wp_body) { 'Version: 1.0.0' } |
| 325 | + it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex)).to be(Msf::Exploit::CheckCode::Appears) } |
| 326 | + end |
| 327 | + end |
| 328 | + |
241 | 329 | end
|
0 commit comments