Skip to content

Commit 253e39e

Browse files
committed
Land rapid7#7680, Fix rapid7#7679, LoginScanner should abort if there is no creds to try
2 parents f4db90e + d9ead44 commit 253e39e

File tree

10 files changed

+148
-2
lines changed

10 files changed

+148
-2
lines changed

lib/metasploit/framework/login_scanner/base.rb

+8
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ def validate_cred_details
304304
unless cred_details.respond_to? :each
305305
errors.add(:cred_details, "must respond to :each")
306306
end
307+
308+
if cred_details.prepended_creds.empty? &&
309+
cred_details.additional_publics.empty? &&
310+
cred_details.additional_privates.empty? &&
311+
!cred_details.username.present? &&
312+
!cred_details.password.present?
313+
errors.add(:cred_details, "can't be blank")
314+
end
307315
end
308316

309317
end

spec/lib/metasploit/framework/login_scanner/base_spec.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,26 @@ def self.model_name
1212
end
1313
}
1414

15+
let(:cred_collection) {
16+
creds = double('Metasploit::Framework::CredentialCollection')
17+
allow(creds).to receive(:pass_file)
18+
allow(creds).to receive(:username).and_return('user')
19+
allow(creds).to receive(:password).and_return('pass')
20+
allow(creds).to receive(:user_file)
21+
allow(creds).to receive(:userpass_file)
22+
allow(creds).to receive(:prepended_creds).and_return([])
23+
allow(creds).to receive(:additional_privates).and_return(['pass'])
24+
allow(creds).to receive(:additional_publics).and_return(['user'])
25+
allow(creds).to receive(:each).and_return(['user', 'pass'])
26+
allow(creds).to receive(:additional_publics).and_return([])
27+
creds
28+
}
29+
1530
let(:options) {
1631

1732
{
1833
connection_timeout: 1,
19-
cred_details: ["user", "pass"],
34+
cred_details: cred_collection,
2035
host: '1.2.3.4',
2136
port: 4444,
2237
stop_on_success: true,

spec/lib/metasploit/framework/login_scanner/ftp_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@
4949
it_behaves_like 'Metasploit::Framework::LoginScanner::RexSocket'
5050
it_behaves_like 'Metasploit::Framework::Tcp::Client'
5151

52+
before(:each) do
53+
creds = double('Metasploit::Framework::CredentialCollection')
54+
allow(creds).to receive(:pass_file)
55+
allow(creds).to receive(:username)
56+
allow(creds).to receive(:user_file)
57+
allow(creds).to receive(:password)
58+
allow(creds).to receive(:userpass_file)
59+
allow(creds).to receive(:prepended_creds).and_return([])
60+
allow(creds).to receive(:additional_privates).and_return([])
61+
allow(creds).to receive(:additional_publics).and_return([])
62+
ftp_scanner.cred_details = creds
63+
end
5264

5365

5466
context 'validations' do

spec/lib/metasploit/framework/login_scanner/mssql_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@
3939

4040
it { is_expected.to respond_to :windows_authentication }
4141

42+
before(:each) do
43+
creds = double('Metasploit::Framework::CredentialCollection')
44+
allow(creds).to receive(:pass_file)
45+
allow(creds).to receive(:username)
46+
allow(creds).to receive(:password)
47+
allow(creds).to receive(:user_file)
48+
allow(creds).to receive(:userpass_file)
49+
allow(creds).to receive(:prepended_creds).and_return([])
50+
allow(creds).to receive(:additional_privates).and_return([])
51+
allow(creds).to receive(:additional_publics).and_return([])
52+
login_scanner.cred_details = creds
53+
end
54+
4255
context 'validations' do
4356
context '#windows_authentication' do
4457
it 'is not valid for the string true' do

spec/lib/metasploit/framework/login_scanner/smb_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
it { is_expected.to respond_to :smb_pipe_evasion }
4848

4949
context 'validations' do
50+
before(:each) do
51+
creds = double('Metasploit::Framework::CredentialCollection')
52+
allow(creds).to receive(:pass_file)
53+
allow(creds).to receive(:username)
54+
allow(creds).to receive(:password)
55+
allow(creds).to receive(:user_file)
56+
allow(creds).to receive(:userpass_file)
57+
allow(creds).to receive(:prepended_creds).and_return([])
58+
allow(creds).to receive(:additional_privates).and_return([])
59+
allow(creds).to receive(:additional_publics).and_return([])
60+
login_scanner.cred_details = creds
61+
end
62+
5063
context '#smb_verify_signature' do
5164
it 'is not valid for the string true' do
5265
login_scanner.smb_verify_signature = 'true'

spec/lib/metasploit/framework/login_scanner/ssh_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@
6060

6161
it { is_expected.to respond_to :verbosity }
6262

63+
before(:each) do
64+
creds = double('Metasploit::Framework::CredentialCollection')
65+
allow(creds).to receive(:pass_file)
66+
allow(creds).to receive(:username)
67+
allow(creds).to receive(:password)
68+
allow(creds).to receive(:user_file)
69+
allow(creds).to receive(:userpass_file)
70+
allow(creds).to receive(:prepended_creds).and_return([])
71+
allow(creds).to receive(:additional_privates).and_return([])
72+
allow(creds).to receive(:additional_publics).and_return([])
73+
ssh_scanner.cred_details = creds
74+
end
75+
6376
context 'validations' do
6477

6578
context 'verbosity' do

spec/lib/metasploit/framework/login_scanner/telnet_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
it { is_expected.to respond_to :banner_timeout }
1313
it { is_expected.to respond_to :telnet_timeout }
1414

15+
before(:each) do
16+
creds = double('Metasploit::Framework::CredentialCollection')
17+
allow(creds).to receive(:pass_file)
18+
allow(creds).to receive(:username)
19+
allow(creds).to receive(:password)
20+
allow(creds).to receive(:user_file)
21+
allow(creds).to receive(:userpass_file)
22+
allow(creds).to receive(:prepended_creds).and_return([])
23+
allow(creds).to receive(:additional_privates).and_return([])
24+
allow(creds).to receive(:additional_publics).and_return([])
25+
login_scanner.cred_details = creds
26+
end
27+
1528
context 'validations' do
1629
context 'banner_timeout' do
1730
it 'is not valid for a non-number' do

spec/support/shared/examples/metasploit/framework/login_scanner/login_scanner_base.rb

+34-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@
6565
it { is_expected.to respond_to :proxies }
6666
it { is_expected.to respond_to :stop_on_success }
6767

68+
before do
69+
creds = double('Metasploit::Framework::CredentialCollection')
70+
allow(creds).to receive(:pass_file)
71+
allow(creds).to receive(:username)
72+
allow(creds).to receive(:password)
73+
allow(creds).to receive(:user_file)
74+
allow(creds).to receive(:userpass_file)
75+
allow(creds).to receive(:prepended_creds).and_return([])
76+
allow(creds).to receive(:additional_privates).and_return([])
77+
allow(creds).to receive(:additional_publics).and_return(['user'])
78+
login_scanner.cred_details = creds
79+
end
80+
6881
context 'validations' do
6982
context 'port' do
7083

@@ -160,12 +173,32 @@
160173

161174
context 'cred_details' do
162175
it 'is not valid for not set' do
176+
creds = double('Metasploit::Framework::CredentialCollection')
177+
allow(creds).to receive(:pass_file)
178+
allow(creds).to receive(:username)
179+
allow(creds).to receive(:password)
180+
allow(creds).to receive(:user_file)
181+
allow(creds).to receive(:userpass_file)
182+
allow(creds).to receive(:prepended_creds).and_return([])
183+
allow(creds).to receive(:additional_privates).and_return([])
184+
allow(creds).to receive(:additional_publics).and_return([])
185+
login_scanner.cred_details = creds
163186
expect(login_scanner).to_not be_valid
164187
expect(login_scanner.errors[:cred_details]).to include "can't be blank"
165188
end
166189

167190
it 'is not valid for a non-array input' do
168-
login_scanner.cred_details = rand(10)
191+
creds = double('Metasploit::Framework::CredentialCollection')
192+
allow(creds).to receive(:pass_file)
193+
allow(creds).to receive(:pass_file)
194+
allow(creds).to receive(:username)
195+
allow(creds).to receive(:password)
196+
allow(creds).to receive(:user_file)
197+
allow(creds).to receive(:userpass_file)
198+
allow(creds).to receive(:prepended_creds).and_return([])
199+
allow(creds).to receive(:additional_privates).and_return([])
200+
allow(creds).to receive(:additional_publics).and_return(['user'])
201+
login_scanner.cred_details = creds
169202
expect(login_scanner).to_not be_valid
170203
expect(login_scanner.errors[:cred_details]).to include "must respond to :each"
171204
end

spec/support/shared/examples/metasploit/framework/login_scanner/ntlm.rb

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111

1212
context 'validations' do
1313

14+
before(:each) do
15+
creds = double('Metasploit::Framework::CredentialCollection')
16+
allow(creds).to receive(:pass_file)
17+
allow(creds).to receive(:username)
18+
allow(creds).to receive(:password)
19+
allow(creds).to receive(:user_file)
20+
allow(creds).to receive(:userpass_file)
21+
allow(creds).to receive(:prepended_creds).and_return([])
22+
allow(creds).to receive(:additional_privates).and_return([])
23+
allow(creds).to receive(:additional_publics).and_return([])
24+
login_scanner.cred_details = creds
25+
end
26+
1427
context '#send_lm' do
1528
it 'is not valid for the string true' do
1629
login_scanner.send_lm = 'true'

spec/support/shared/examples/metasploit/framework/tcp/client.rb

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
it { is_expected.to respond_to :send_delay }
66
it { is_expected.to respond_to :max_send_size }
77

8+
before(:example) do
9+
creds = double('Metasploit::Framework::CredentialCollection')
10+
allow(creds).to receive(:pass_file)
11+
allow(creds).to receive(:username)
12+
allow(creds).to receive(:password)
13+
allow(creds).to receive(:user_file)
14+
allow(creds).to receive(:userpass_file)
15+
allow(creds).to receive(:prepended_creds).and_return([])
16+
allow(creds).to receive(:additional_privates).and_return([])
17+
allow(creds).to receive(:additional_publics).and_return(['user'])
18+
login_scanner.cred_details = creds
19+
end
20+
821
context 'send_delay' do
922
it 'is not valid for a non-number' do
1023
login_scanner.send_delay = "a"

0 commit comments

Comments
 (0)