Skip to content

Commit 147c6d8

Browse files
committed
Merge branch 'feature/MSP-10660/realm_adjustments' into staging/electro-release
2 parents e104f73 + 8833429 commit 147c6d8

36 files changed

+245
-92
lines changed

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ group :db do
77
# Needed for Msf::DbManager
88
gem 'activerecord', '>= 3.0.0', '< 4.0.0'
99
# Metasploit::Credential database models
10-
gem 'metasploit-credential', git: 'github-metasploit-credential:rapid7/metasploit-credential.git', tag: 'v0.5.6.pre.electro.pre.release'
10+
gem 'metasploit-credential', git: 'github-metasploit-credential:rapid7/metasploit-credential.git', tag: 'v0.6.0-electro-release'
1111
# Database models shared between framework and Pro.
1212
gem 'metasploit_data_models', '>= 0.18.0', '< 0.19'
1313
# Needed for module caching in Mdm::ModuleDetails
@@ -35,10 +35,10 @@ group :development, :test do
3535
# running documentation generation tasks and rspec tasks
3636
gem 'rake', '>= 10.0.0'
3737
# testing framework
38-
gem 'rspec', '>= 2.12'
38+
gem 'rspec', '>= 2.12', '< 3.0.0'
3939
# Define `rake spec`. Must be in development AND test so that its available by default as a rake test when the
4040
# environment is development
41-
gem 'rspec-rails'
41+
gem 'rspec-rails' , '>= 2.12', '< 3.0.0'
4242
end
4343

4444
group :pcap do

Gemfile.lock

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
GIT
22
remote: github-metasploit-credential:rapid7/metasploit-credential.git
3-
revision: 8a8b4f74535d728b1852e4d4d55abb9d828b8a8a
4-
tag: v0.5.6.pre.electro.pre.release
3+
revision: 1a472b5f7f6df6fa6a01233e0831ec4383c8f5a2
4+
tag: v0.6.0-electro-release
55
specs:
6-
metasploit-credential (0.5.6.pre.electro.pre.release)
6+
metasploit-credential (0.6.0)
77
metasploit-concern (~> 0.1.0)
8-
metasploit-model (>= 0.25.1, < 0.26)
8+
metasploit-model (>= 0.25.3, < 0.26)
99
metasploit_data_models (>= 0.18.0, < 0.19)
1010
rubyntlm
1111
rubyzip (~> 1.1)
@@ -30,25 +30,25 @@ PATH
3030
GEM
3131
remote: https://rubygems.org/
3232
specs:
33-
actionpack (3.2.17)
34-
activemodel (= 3.2.17)
35-
activesupport (= 3.2.17)
33+
actionpack (3.2.19)
34+
activemodel (= 3.2.19)
35+
activesupport (= 3.2.19)
3636
builder (~> 3.0.0)
3737
erubis (~> 2.7.0)
3838
journey (~> 1.0.4)
3939
rack (~> 1.4.5)
4040
rack-cache (~> 1.2)
4141
rack-test (~> 0.6.1)
4242
sprockets (~> 2.2.1)
43-
activemodel (3.2.17)
44-
activesupport (= 3.2.17)
43+
activemodel (3.2.19)
44+
activesupport (= 3.2.19)
4545
builder (~> 3.0.0)
46-
activerecord (3.2.17)
47-
activemodel (= 3.2.17)
48-
activesupport (= 3.2.17)
46+
activerecord (3.2.19)
47+
activemodel (= 3.2.19)
48+
activesupport (= 3.2.19)
4949
arel (~> 3.0.2)
5050
tzinfo (~> 0.3.29)
51-
activesupport (3.2.17)
51+
activesupport (3.2.19)
5252
i18n (~> 0.6, >= 0.6.4)
5353
multi_json (~> 1.0)
5454
arel (3.0.3)
@@ -69,7 +69,7 @@ GEM
6969
json (1.8.1)
7070
metasploit-concern (0.1.1)
7171
activesupport (~> 3.0, >= 3.0.0)
72-
metasploit-model (0.25.2)
72+
metasploit-model (0.25.3)
7373
activesupport
7474
metasploit_data_models (0.18.0)
7575
activerecord (>= 3.2.13, < 4.0.0)
@@ -87,9 +87,9 @@ GEM
8787
packetfu (1.1.9)
8888
pcaprub (0.11.3)
8989
pg (0.17.1)
90-
pry (0.9.12.6)
91-
coderay (~> 1.0)
92-
method_source (~> 0.8)
90+
pry (0.10.0)
91+
coderay (~> 1.1.0)
92+
method_source (~> 0.8.1)
9393
slop (~> 3.4)
9494
rack (1.4.5)
9595
rack-cache (1.2)
@@ -98,38 +98,41 @@ GEM
9898
rack
9999
rack-test (0.6.2)
100100
rack (>= 1.0)
101-
railties (3.2.17)
102-
actionpack (= 3.2.17)
103-
activesupport (= 3.2.17)
101+
railties (3.2.19)
102+
actionpack (= 3.2.19)
103+
activesupport (= 3.2.19)
104104
rack-ssl (~> 1.3.2)
105105
rake (>= 0.8.7)
106106
rdoc (~> 3.4)
107107
thor (>= 0.14.6, < 2.0)
108-
rake (10.3.1)
108+
rake (10.3.2)
109109
rdoc (3.12.2)
110110
json (~> 1.4)
111-
redcarpet (3.1.1)
111+
redcarpet (3.1.2)
112112
rkelly-remix (0.0.6)
113113
robots (0.10.1)
114-
rspec (2.14.1)
115-
rspec-core (~> 2.14.0)
116-
rspec-expectations (~> 2.14.0)
117-
rspec-mocks (~> 2.14.0)
118-
rspec-core (2.14.8)
119-
rspec-expectations (2.14.5)
114+
rspec (2.99.0)
115+
rspec-core (~> 2.99.0)
116+
rspec-expectations (~> 2.99.0)
117+
rspec-mocks (~> 2.99.0)
118+
rspec-collection_matchers (1.0.0)
119+
rspec-expectations (>= 2.99.0.beta1)
120+
rspec-core (2.99.1)
121+
rspec-expectations (2.99.1)
120122
diff-lcs (>= 1.1.3, < 2.0)
121-
rspec-mocks (2.14.6)
122-
rspec-rails (2.14.2)
123+
rspec-mocks (2.99.1)
124+
rspec-rails (2.99.0)
123125
actionpack (>= 3.0)
124126
activemodel (>= 3.0)
125127
activesupport (>= 3.0)
126128
railties (>= 3.0)
127-
rspec-core (~> 2.14.0)
128-
rspec-expectations (~> 2.14.0)
129-
rspec-mocks (~> 2.14.0)
129+
rspec-collection_matchers
130+
rspec-core (~> 2.99.0)
131+
rspec-expectations (~> 2.99.0)
132+
rspec-mocks (~> 2.99.0)
130133
rubyntlm (0.4.0)
131-
rubyzip (1.1.4)
132-
shoulda-matchers (2.6.0)
134+
rubyzip (1.1.6)
135+
shoulda-matchers (2.6.1)
133136
activesupport (>= 3.0.0)
134137
simplecov (0.5.4)
135138
multi_json (~> 1.0.3)
@@ -165,8 +168,8 @@ DEPENDENCIES
165168
pry
166169
rake (>= 10.0.0)
167170
redcarpet
168-
rspec (>= 2.12)
169-
rspec-rails
171+
rspec (>= 2.12, < 3.0.0)
172+
rspec-rails (>= 2.12, < 3.0.0)
170173
shoulda-matchers
171174
simplecov (= 0.5.4)
172175
timecop

lib/metasploit/framework/login_scanner/afp.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AFP
1919
LIKELY_PORTS = [ DEFAULT_PORT ]
2020
LIKELY_SERVICE_NAMES = [ "afp" ]
2121
PRIVATE_TYPES = [ :password ]
22+
REALM_KEY = nil
2223

2324
# @!attribute login_timeout
2425
# @return [Integer] Number of seconds to wait before giving up
@@ -38,9 +39,10 @@ def attempt_login(credential)
3839
end
3940

4041
def set_sane_defaults
41-
self.port = DEFAULT_PORT if self.port.nil?
42-
self.max_send_size = 0 if self.max_send_size.nil?
43-
self.send_delay = 0 if self.send_delay.nil?
42+
self.connection_timeout ||= 30
43+
self.port ||= DEFAULT_PORT
44+
self.max_send_size ||= 0
45+
self.send_delay ||= 0
4446
end
4547
end
4648
end

lib/metasploit/framework/login_scanner/axis2.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module LoginScanner
99
class Axis2 < HTTP
1010

1111
DEFAULT_PORT = 8080
12-
# Inherit LIKELY_PORTS and LIKELY_SERVICE_NAMES from HTTP
12+
# Inherit LIKELY_PORTS,LIKELY_SERVICE_NAMES, and REALM_KEY from HTTP
1313

1414
CAN_GET_SESSION = true
1515
PRIVATE_TYPES = [ :password ]
@@ -20,6 +20,9 @@ def attempt_login(credential)
2020
host, port, {}, ssl, ssl_version
2121
)
2222

23+
result_opts = {
24+
credential: credential
25+
}
2326
begin
2427
http_client.connect
2528
body = "userName=#{Rex::Text.uri_encode(credential.public)}&password=#{Rex::Text.uri_encode(credential.private)}&submit=+Login+"
@@ -29,13 +32,18 @@ def attempt_login(credential)
2932
'data' => body,
3033
)
3134
response = http_client.send_recv(request)
32-
end
3335

34-
if response && response.code == 200 && response.body.include?("upload")
35-
Result.new(status: :success, credential: credential, proof: response)
36-
else
37-
Result.new(status: :failed, credential: credential, proof: response)
36+
if response && response.code == 200 && response.body.include?("upload")
37+
result_opts.merge!(status: :success, proof: response)
38+
else
39+
result_opts.merge!(status: :failed, proof: response)
40+
end
41+
rescue ::EOFError, Rex::ConnectionError, ::Timeout::Error
42+
result_opts.merge!(status: :connection_error)
3843
end
44+
45+
Result.new(result_opts)
46+
3947
end
4048

4149
# (see Base#set_sane_defaults)

lib/metasploit/framework/login_scanner/base.rb

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,38 @@ def attempt_login(credential)
7777
raise NotImplementedError
7878
end
7979

80+
81+
def each_credential
82+
cred_details.each do |raw_cred|
83+
# This could be a Credential object, or a Credential Core, or an Attempt object
84+
# so make sure that whatever it is, we end up with a Credential.
85+
credential = raw_cred.to_credential
86+
87+
if credential.realm.present? && self.class::REALM_KEY.present?
88+
credential.realm_key = self.class::REALM_KEY
89+
yield credential
90+
elsif credential.realm.blank? && self.class::REALM_KEY.present? && self.class::DEFAULT_REALM.present?
91+
credential.realm_key = self.class::REALM_KEY
92+
credential.realm = self.class::DEFAULT_REALM
93+
yield credential
94+
elsif credential.realm.present? && self.class::REALM_KEY.blank?
95+
second_cred = credential.dup
96+
# Strip the realm off here, as we don't want it
97+
credential.realm = nil
98+
credential.realm_key = nil
99+
yield credential
100+
# Some services can take a domain in the username like this even though
101+
# they do not explicitly take a domain as part of the protocol.
102+
second_cred.public = "#{second_cred.realm}\\#{second_cred.public}"
103+
second_cred.realm = nil
104+
second_cred.realm_key = nil
105+
yield second_cred
106+
else
107+
yield credential
108+
end
109+
end
110+
end
111+
80112
# Attempt to login with every {Credential credential} in
81113
# {#cred_details}, by calling {#attempt_login} once for each.
82114
#
@@ -91,8 +123,7 @@ def scan!
91123
consecutive_error_count = 0
92124
total_error_count = 0
93125

94-
cred_details.each do |raw_credential|
95-
credential = raw_credential.to_credential
126+
each_credential do |credential|
96127
result = attempt_login(credential)
97128
result.freeze
98129

lib/metasploit/framework/login_scanner/db2.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ class DB2
1414
include Metasploit::Framework::Tcp::Client
1515

1616
DEFAULT_PORT = 50000
17+
DEFAULT_REALM = 'toolsdb'
1718
LIKELY_PORTS = [ DEFAULT_PORT ]
1819
# @todo XXX
1920
LIKELY_SERVICE_NAMES = [ ]
2021
PRIVATE_TYPES = [ :password ]
22+
REALM_KEY = Metasploit::Model::Realm::Key::DB2_DATABASE
2123

2224
# @see Base#attempt_login
2325
def attempt_login(credential)
@@ -94,10 +96,12 @@ def send_probe(database_name)
9496
# This method sets the sane defaults for things
9597
# like timeouts and TCP evasion options
9698
def set_sane_defaults
97-
self.port ||= DEFAULT_PORT
98-
self.max_send_size ||= 0
99-
self.send_delay ||= 0
100-
self.ssl ||= false
99+
self.connection_timeout ||= 30
100+
self.port ||= DEFAULT_PORT
101+
self.max_send_size ||= 0
102+
self.send_delay ||= 0
103+
104+
self.ssl = false if self.ssl.nil?
101105
end
102106

103107
# This method takes a response packet and checks to see

lib/metasploit/framework/login_scanner/ftp.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class FTP
1818
LIKELY_PORTS = [ DEFAULT_PORT, 2121 ]
1919
LIKELY_SERVICE_NAMES = [ 'ftp' ]
2020
PRIVATE_TYPES = [ :password ]
21+
REALM_KEY = nil
2122

2223
# @!attribute ftp_timeout
2324
# @return [Fixnum] The timeout in seconds to wait for a response to an FTP command
@@ -61,10 +62,11 @@ def attempt_login(credential)
6162
# This method sets the sane defaults for things
6263
# like timeouts and TCP evasion options
6364
def set_sane_defaults
64-
self.port = DEFAULT_PORT if self.port.nil?
65-
self.max_send_size = 0 if self.max_send_size.nil?
66-
self.send_delay = 0 if self.send_delay.nil?
67-
self.ftp_timeout = 16 if self.ftp_timeout.nil?
65+
self.connection_timeout ||= 30
66+
self.port ||= DEFAULT_PORT
67+
self.max_send_size ||= 0
68+
self.send_delay ||= 0
69+
self.ftp_timeout ||= 16
6870
end
6971

7072
end

lib/metasploit/framework/login_scanner/http.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class HTTP
1212
include Metasploit::Framework::LoginScanner::Base
1313
include Metasploit::Framework::LoginScanner::RexSocket
1414

15+
DEFAULT_REALM = nil
1516
DEFAULT_PORT = 80
1617
DEFAULT_SSL_PORT = 443
1718
LIKELY_PORTS = [ 80, 443, 8000, 8080 ]
1819
LIKELY_SERVICE_NAMES = [ 'http', 'https' ]
1920
PRIVATE_TYPES = [ :password ]
21+
REALM_KEY = Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN
2022

2123
# @!attribute uri
2224
# @return [String] The path and query string on the server to
@@ -91,6 +93,7 @@ def attempt_login(credential)
9193
# This method sets the sane defaults for things
9294
# like timeouts and TCP evasion options
9395
def set_sane_defaults
96+
self.connection_timeout ||= 20
9497
self.max_send_size = 0 if self.max_send_size.nil?
9598
self.send_delay = 0 if self.send_delay.nil?
9699

lib/metasploit/framework/login_scanner/mssql.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ class MSSQL
1717
include Metasploit::Framework::MSSQL::Client
1818

1919
DEFAULT_PORT = 1433
20+
DEFAULT_REALM = 'WORKSTATION'
2021
# Lifted from lib/msf/core/exploit/mssql.rb
2122
LIKELY_PORTS = [ 1433, 1434, 1435, 14330, 2533, 9152, 2638 ]
2223
# Lifted from lib/msf/core/exploit/mssql.rb
2324
LIKELY_SERVICE_NAMES = [ 'ms-sql-s', 'ms-sql2000', 'sybase' ]
2425
PRIVATE_TYPES = [ :password, :ntlm_hash ]
26+
REALM_KEY = Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN
2527

2628
# @!attribute windows_authentication
2729
# @return [Boolean] Whether to use Windows Authentication instead of SQL Server Auth.
@@ -51,9 +53,12 @@ def attempt_login(credential)
5153
private
5254

5355
def set_sane_defaults
54-
self.port = DEFAULT_PORT if self.port.nil?
55-
self.max_send_size = 0 if self.max_send_size.nil?
56-
self.send_delay = 0 if self.send_delay.nil?
56+
self.connection_timeout ||= 30
57+
self.port ||= DEFAULT_PORT
58+
self.max_send_size ||= 0
59+
self.send_delay ||= 0
60+
61+
# Don't use ||= with booleans
5762
self.send_lm = true if self.send_lm.nil?
5863
self.send_ntlm = true if self.send_ntlm.nil?
5964
self.send_spn = true if self.send_spn.nil?

0 commit comments

Comments
 (0)