Land #7680, Fix #7679, LoginScanner should abort if there is no creds to try

bug/bundler_fix
bwatters 2017-01-23 14:08:32 -06:00
commit 253e39e18c
No known key found for this signature in database
GPG Key ID: ECC0F0A52E65F268
10 changed files with 148 additions and 2 deletions

View File

@ -304,6 +304,14 @@ module Metasploit
unless cred_details.respond_to? :each
errors.add(:cred_details, "must respond to :each")
end
if cred_details.prepended_creds.empty? &&
cred_details.additional_publics.empty? &&
cred_details.additional_privates.empty? &&
!cred_details.username.present? &&
!cred_details.password.present?
errors.add(:cred_details, "can't be blank")
end
end
end

View File

@ -12,11 +12,26 @@ RSpec.describe Metasploit::Framework::LoginScanner::Base do
end
}
let(:cred_collection) {
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username).and_return('user')
allow(creds).to receive(:password).and_return('pass')
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return(['pass'])
allow(creds).to receive(:additional_publics).and_return(['user'])
allow(creds).to receive(:each).and_return(['user', 'pass'])
allow(creds).to receive(:additional_publics).and_return([])
creds
}
let(:options) {
{
connection_timeout: 1,
cred_details: ["user", "pass"],
cred_details: cred_collection,
host: '1.2.3.4',
port: 4444,
stop_on_success: true,

View File

@ -49,6 +49,18 @@ RSpec.describe Metasploit::Framework::LoginScanner::FTP do
it_behaves_like 'Metasploit::Framework::LoginScanner::RexSocket'
it_behaves_like 'Metasploit::Framework::Tcp::Client'
before(:each) do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:user_file)
allow(creds).to receive(:password)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return([])
ftp_scanner.cred_details = creds
end
context 'validations' do

View File

@ -39,6 +39,19 @@ RSpec.describe Metasploit::Framework::LoginScanner::MSSQL do
it { is_expected.to respond_to :windows_authentication }
before(:each) do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return([])
login_scanner.cred_details = creds
end
context 'validations' do
context '#windows_authentication' do
it 'is not valid for the string true' do

View File

@ -47,6 +47,19 @@ RSpec.describe Metasploit::Framework::LoginScanner::SMB do
it { is_expected.to respond_to :smb_pipe_evasion }
context 'validations' do
before(:each) do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return([])
login_scanner.cred_details = creds
end
context '#smb_verify_signature' do
it 'is not valid for the string true' do
login_scanner.smb_verify_signature = 'true'

View File

@ -60,6 +60,19 @@ RSpec.describe Metasploit::Framework::LoginScanner::SSH do
it { is_expected.to respond_to :verbosity }
before(:each) do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return([])
ssh_scanner.cred_details = creds
end
context 'validations' do
context 'verbosity' do

View File

@ -12,6 +12,19 @@ RSpec.describe Metasploit::Framework::LoginScanner::Telnet do
it { is_expected.to respond_to :banner_timeout }
it { is_expected.to respond_to :telnet_timeout }
before(:each) do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return([])
login_scanner.cred_details = creds
end
context 'validations' do
context 'banner_timeout' do
it 'is not valid for a non-number' do

View File

@ -65,6 +65,19 @@ RSpec.shared_examples_for 'Metasploit::Framework::LoginScanner::Base' do | opts
it { is_expected.to respond_to :proxies }
it { is_expected.to respond_to :stop_on_success }
before do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return(['user'])
login_scanner.cred_details = creds
end
context 'validations' do
context 'port' do
@ -160,12 +173,32 @@ RSpec.shared_examples_for 'Metasploit::Framework::LoginScanner::Base' do | opts
context 'cred_details' do
it 'is not valid for not set' do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return([])
login_scanner.cred_details = creds
expect(login_scanner).to_not be_valid
expect(login_scanner.errors[:cred_details]).to include "can't be blank"
end
it 'is not valid for a non-array input' do
login_scanner.cred_details = rand(10)
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return(['user'])
login_scanner.cred_details = creds
expect(login_scanner).to_not be_valid
expect(login_scanner.errors[:cred_details]).to include "must respond to :each"
end

View File

@ -11,6 +11,19 @@ RSpec.shared_examples_for 'Metasploit::Framework::LoginScanner::NTLM' do
context 'validations' do
before(:each) do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return([])
login_scanner.cred_details = creds
end
context '#send_lm' do
it 'is not valid for the string true' do
login_scanner.send_lm = 'true'

View File

@ -5,6 +5,19 @@ RSpec.shared_examples_for 'Metasploit::Framework::Tcp::Client' do
it { is_expected.to respond_to :send_delay }
it { is_expected.to respond_to :max_send_size }
before(:example) do
creds = double('Metasploit::Framework::CredentialCollection')
allow(creds).to receive(:pass_file)
allow(creds).to receive(:username)
allow(creds).to receive(:password)
allow(creds).to receive(:user_file)
allow(creds).to receive(:userpass_file)
allow(creds).to receive(:prepended_creds).and_return([])
allow(creds).to receive(:additional_privates).and_return([])
allow(creds).to receive(:additional_publics).and_return(['user'])
login_scanner.cred_details = creds
end
context 'send_delay' do
it 'is not valid for a non-number' do
login_scanner.send_delay = "a"