|
| 1 | +require 'spec_helper' |
1 | 2 | require 'metasploit/framework/login_scanner/cisco_firepower'
|
2 | 3 |
|
3 | 4 | RSpec.describe Metasploit::Framework::LoginScanner::CiscoFirepower do
|
4 | 5 |
|
5 | 6 | it_behaves_like 'Metasploit::Framework::LoginScanner::Base', has_realm_key: true, has_default_realm: false
|
6 | 7 | it_behaves_like 'Metasploit::Framework::LoginScanner::RexSocket'
|
7 | 8 |
|
| 9 | + subject do |
| 10 | + described_class.new |
| 11 | + end |
| 12 | + |
| 13 | + let(:successful_auth_response) do |
| 14 | + res = Rex::Proto::Http::Response.new(302, 'Found') |
| 15 | + res.headers['Location'] = '/' |
| 16 | + res.headers['Set-Cookie'] = 'CGISESSID=NEWSESSIONID;' |
| 17 | + res |
| 18 | + end |
| 19 | + |
| 20 | + let(:fail_auth_response) do |
| 21 | + Rex::Proto::Http::Response.new(200, 'OK') |
| 22 | + end |
| 23 | + |
| 24 | + describe '#attempt_login' do |
| 25 | + |
| 26 | + context 'when the credential is valid' do |
| 27 | + let(:username) { 'user' } |
| 28 | + let(:password) { 'goddpass' } |
| 29 | + |
| 30 | + before do |
| 31 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:request_cgi).with(any_args) |
| 32 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:send_recv).with(any_args).and_return(successful_auth_response) |
| 33 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:set_config).with(any_args) |
| 34 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:close) |
| 35 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:connect) |
| 36 | + end |
| 37 | + |
| 38 | + it 'returns a Result object indicating a successful login' do |
| 39 | + cred = Metasploit::Framework::Credential.new(public: username, private: password) |
| 40 | + result = subject.attempt_login(cred) |
| 41 | + expect(result).to be_kind_of(Metasploit::Framework::LoginScanner::Result) |
| 42 | + expect(result.status).to eq(Metasploit::Model::Login::Status::SUCCESSFUL) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'when the credential is invalid' do |
| 47 | + let(:username) { 'admin' } |
| 48 | + let(:password) { 'badpass' } |
| 49 | + |
| 50 | + before(:example) do |
| 51 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:request_cgi).with(any_args) |
| 52 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:send_recv).with(any_args).and_return(fail_auth_response) |
| 53 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:set_config).with(any_args) |
| 54 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:close) |
| 55 | + allow_any_instance_of(Rex::Proto::Http::Client).to receive(:connect) |
| 56 | + end |
| 57 | + |
| 58 | + it 'returns a Result object indicating a failed login' do |
| 59 | + cred = Metasploit::Framework::Credential.new(public: username, private: password) |
| 60 | + result = subject.attempt_login(cred) |
| 61 | + expect(result).to be_kind_of(Metasploit::Framework::LoginScanner::Result) |
| 62 | + expect(result.status).to eq(Metasploit::Model::Login::Status::INCORRECT) |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + |
8 | 68 | end
|
0 commit comments