Skip to content

Commit d544488

Browse files
Adam Cammackacammack-r7
authored andcommitted
Land rapid7#6461, backport net-ssh ECDH kex algorithms
2 parents 8102fc2 + 765d7fa commit d544488

File tree

29 files changed

+827
-120
lines changed

29 files changed

+827
-120
lines changed

CODE_OF_CONDUCT.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ This Code of Conduct applies both within project spaces and in public spaces
3535
when an individual is representing the project or its community.
3636

3737
Instances of abusive, harassing, or otherwise unacceptable behavior may be
38-
reported by contacting a project maintainer at [email protected]. All
39-
complaints will be reviewed and investigated and will result in a response that
40-
is deemed necessary and appropriate to the circumstances. Maintainers are
41-
obligated to maintain confidentiality with regard to the reporter of an
42-
incident.
43-
38+
reported by contacting the project maintainers at [email protected]. If
39+
the incident involves a committer, you may report directly to
40+
41+
42+
All complaints will be reviewed and investigated and will result in a
43+
response that is deemed necessary and appropriate to the circumstances.
44+
Maintainers are obligated to maintain confidentiality with regard to the
45+
reporter of an incident.
4446

4547
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
4648
version 1.3.0, available at

Gemfile.lock

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
metasploit-framework (4.11.7)
4+
metasploit-framework (4.11.8)
55
actionpack (>= 4.0.9, < 4.1.0)
66
activerecord (>= 4.0.9, < 4.1.0)
77
activesupport (>= 4.0.9, < 4.1.0)
@@ -246,3 +246,6 @@ DEPENDENCIES
246246
simplecov
247247
timecop
248248
yard
249+
250+
BUNDLED WITH
251+
1.11.2

data/logos/zsploit-1.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
____________
2+
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| $a,|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
3+
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| $S`?a,|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
4+
 [%%%%%%%%%%%%%%%%%%%%__%%%%%%%%%%|`?a, |%%%%%%%%__%%%%%%%%%__%%__ %%%%]
5+
 [% .--------..-----.| |_ .---.-.|.,a$%|.-----.| |.-----.|__|| |_ %%]
6+
 [% ||| -__|| _|| _ || ,,aS$""` || _ || || _ || || _|%%]
7+
 [% |__|__|__||_____||____||___._||%$P"`|| __||__||_____||__||____|%%]
8+
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%| `"a,||__|%%%%%%%%%%%%%%%%%%%%%%%%%%]
9+
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|____`"a,$$__|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
10+
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%`"$ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]
11+
 [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]

data/logos/zsploit-2.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
..
4+
.
5+
6+
dBBBBBBb dBBBP dBBBBBBP dBBBBBb .o
7+
' dB'BBP
8+
dB'dB'dB' dBBPdBPdBP BB
9+
dB'dB'dB' dBPdBPdBP BB
10+
dB'dB'dB' dBBBBP dBPdBBBBBBB
11+
12+
dBBBBBP dBBBBBb dBP dBBBBP dBP dBBBBBBP
13+
..dB' dBP dB'.BP
14+
|dBP dBBBB' dBP dB'.BP dBP dBP
15+
--o-- dBP dBP dBP dB'.BP dBP dBP
16+
|dBBBBP dBP dBBBBP dBBBBP dBP dBP
17+
18+
.
19+
.
20+
oTo boldly shell were no
21+
shell has gone before

data/logos/zsploit-3.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
.,,..
3+
.\$$$$$L..,,==aaccaacc%#s$b.d8, d8P
4+
d8P#$$$$$$$$$$$$$$$$$$$$$$$$$$$b. `BP d888888p
5+
d888888P'7$$$$\""""''^^`` .7$$$|D*"'```?88'
6+
d8bd8b.d8p d8888b ?88' d888b8b_.os#$|8*"` d8P?8b 88P
7+
88P`?P'?P d8b_,dP 88P d8P' ?88.oaS###S*"`d8P d8888b ?88b 88b
8+
d88 d8 ?8 88b88b 88b ,88b .osS$$$$*" ?88,.d88b, d88 d8P' ?88 88P `?8b
9+
d88' d88b 8b`?8888P'`?8b`?88P'.aS$$$$Q*"` `?88' ?88 ?88 88b d88 d88
10+
.a#$$$$$$"`88b d8P 88b`?8888P'
11+
,s$$$$$$$"`888888P' 88n_.,,,ass;:
12+
.a$$$$$$$P`d88P' .,.ass%#S$$$$$$$$$$$$$$'
13+
.a$###$$$P`_.,,-aqsc#SS$$$$$$$$$$$$$$$$$$$$$$$$$$'
14+
,a$$###$$P` _.,-ass#S$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$####SSSS'
15+
.a$$$$$$$$$$SSS$$$$$$$$$$$$$$$$$$$$$$$$$$$$SS##==--""''^^/$$$$$$'
16+
_______________________________________________________________ ,&$$$$$$'_____,
17+
ll&&$$$$'
18+
.;;lll&&&&'
19+
...;;lllll&'
20+
......;;;llll;;;....
21+
` ......;;;;... . .
22+
` `` `

lib/metasploit/framework/common_engine.rb

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,44 +42,7 @@ module Metasploit::Framework::CommonEngine
4242
# `initializer`s
4343
#
4444

45-
initializer 'metasploit_framework.merge_meterpreter_extensions' do
46-
Rails.application.railties.engines.each do |engine|
47-
merge_meterpreter_extensions(engine)
48-
end
4945

50-
# The Rails.application itself could have paths['data/meterpreter'], but will not be part of
51-
# Rails.application.railties.engines because only direct subclasses of `Rails::Engine` are returned.
52-
merge_meterpreter_extensions(Rails.application)
53-
end
5446
end
5547

56-
#
57-
# Instance Methods
58-
#
59-
60-
private
61-
62-
# Merges the meterpreter extensions from `engine`'s `paths['data/meterpreter]`.
63-
#
64-
# @param engine [Rails::Engine] a Rails engine or application that has meterpreter extensions
65-
# @return [void]
66-
# @todo Make metasploit-framework look for meterpreter extension in paths['data/meterpreter'] from the engine instead of copying them.
67-
def merge_meterpreter_extensions(engine)
68-
data_meterpreter_paths = engine.paths['data/meterpreter']
69-
70-
# may be `nil` since 'data/meterpreter' is not part of the core Rails::Engine paths set.
71-
if data_meterpreter_paths
72-
source_paths = data_meterpreter_paths.existent
73-
destination_directory = root.join('data', 'meterpreter').to_path
74-
75-
source_paths.each do |source_path|
76-
basename = File.basename(source_path)
77-
destination_path = File.join(destination_directory, basename)
78-
79-
unless destination_path == source_path
80-
FileUtils.copy(source_path, destination_directory)
81-
end
82-
end
83-
end
84-
end
8548
end

lib/metasploit/framework/login_scanner/mssql.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class MSSQL
3232
validates :windows_authentication,
3333
inclusion: { in: [true, false] }
3434

35+
attr_accessor :tdsencryption
36+
37+
validates :tdsencryption,
38+
inclusion: { in: [true, false] }
39+
3540
def attempt_login(credential)
3641
result_options = {
3742
credential: credential,
@@ -70,6 +75,7 @@ def set_sane_defaults
7075
self.use_ntlm2_session = true if self.use_ntlm2_session.nil?
7176
self.use_ntlmv2 = true if self.use_ntlmv2.nil?
7277
self.windows_authentication = false if self.windows_authentication.nil?
78+
self.tdsencryption = false if self.tdsencryption.nil?
7379
end
7480
end
7581

lib/metasploit/framework/mssql/client.rb

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'metasploit/framework/tcp/client'
2+
require 'metasploit/framework/mssql/tdssslproxy'
23

34
module Metasploit
45
module Framework
@@ -48,11 +49,7 @@ def mssql_login(user='sa', pass='', db='', domain_name='')
4849

4950
disconnect if self.sock
5051
connect
51-
52-
# Send a prelogin packet and check that encryption is not enabled
53-
if mssql_prelogin() != ENCRYPT_NOT_SUP
54-
raise ::Rex::ConnectionError, "Encryption is not supported"
55-
end
52+
mssql_prelogin
5653

5754
if windows_authentication
5855
idx = 0
@@ -150,7 +147,14 @@ def mssql_login(user='sa', pass='', db='', domain_name='')
150147
# has a strange behavior that differs from the specifications
151148
# upon receiving the ntlm_negociate request it send an ntlm_challenge but the status flag of the tds packet header
152149
# is set to STATUS_NORMAL and not STATUS_END_OF_MESSAGE, then internally it waits for the ntlm_authentification
153-
resp = mssql_send_recv(pkt,15, false)
150+
151+
if tdsencryption == true
152+
proxy = TDSSSLProxy.new(sock)
153+
proxy.setup_ssl
154+
resp = proxy.send_recv(pkt)
155+
else
156+
resp = mssql_send_recv(pkt)
157+
end
154158

155159
# Get default data
156160
begin
@@ -199,8 +203,13 @@ def mssql_login(user='sa', pass='', db='', domain_name='')
199203

200204
pkt = pkt_hdr.pack("CCnnCC") + ntlmssp
201205

202-
resp = mssql_send_recv(pkt)
203-
206+
if self.tdsencryption == true
207+
resp = mssql_ssl_send_recv(pkt,proxy)
208+
proxy.cleanup
209+
proxy = nil
210+
else
211+
resp = mssql_send_recv(pkt)
212+
end
204213

205214
#SQL Server Authentification
206215
else
@@ -282,13 +291,23 @@ def mssql_login(user='sa', pass='', db='', domain_name='')
282291
# Packet header and total length including header
283292
pkt = "\x10\x01" + [pkt.length + 8].pack('n') + [0].pack('n') + [1].pack('C') + "\x00" + pkt
284293

285-
resp = mssql_send_recv(pkt)
294+
if self.tdsencryption == true
295+
proxy = TDSSSLProxy.new(sock)
296+
proxy.setup_ssl
297+
resp = mssql_ssl_send_recv(pkt,proxy)
298+
proxy.cleanup
299+
proxy = nil
300+
else
301+
resp = mssql_send_recv(pkt)
302+
end
286303

287304
end
288305

289306
info = {:errors => []}
290307
info = mssql_parse_reply(resp,info)
291308

309+
disconnect
310+
292311
return false if not info
293312
info[:login_ack] ? true : false
294313
end
@@ -586,7 +605,14 @@ def mssql_prelogin(enc_error=false)
586605
]
587606

588607
version = [0x55010008,0x0000].pack("Vv")
589-
encryption = ENCRYPT_NOT_SUP # off
608+
609+
# if manually set, we will honour
610+
if tdsencryption == true
611+
encryption = ENCRYPT_ON
612+
else
613+
encryption = ENCRYPT_NOT_SUP
614+
end
615+
590616
instoptdata = "MSSQLServer\0"
591617

592618
threadid = "\0\0" + Rex::Text.rand_text(2)
@@ -639,12 +665,57 @@ def mssql_prelogin(enc_error=false)
639665
if idx > 0
640666
encryption_mode = resp[idx,1].unpack("C")[0]
641667
else
642-
#force to ENCRYPT_NOT_SUP and hope for the best
668+
raise RunTimeError, "Unable to parse encryption req. "\
669+
"from server during prelogin"
643670
encryption_mode = ENCRYPT_NOT_SUP
644671
end
645672

646-
if encryption_mode != ENCRYPT_NOT_SUP and enc_error
647-
raise RuntimeError,"Encryption is not supported"
673+
##########################################################
674+
# Our initial prelogin pkt above said we didnt support
675+
# encryption (it's quicker and the default).
676+
#
677+
# Per the matrix on the following link, SQL Server will
678+
# terminate the connection if it does require TLS,
679+
# otherwise it will accept an unencrypted session. As
680+
# part of this initial response packet, it also returns
681+
# ENCRYPT_REQ.
682+
#
683+
# https://msdn.microsoft.com\
684+
# /en-us/library/ee320519(v=sql.105).aspx
685+
#
686+
##########################################################
687+
688+
if encryption_mode == ENCRYPT_REQ
689+
# restart prelogin process except that we tell SQL Server
690+
# than we are now able to encrypt
691+
disconnect if self.sock
692+
connect
693+
694+
# offset 35 is the flag - turn it on
695+
pkt[35] = [ENCRYPT_ON].pack('C')
696+
self.tdsencryption = true
697+
framework_module.print_status("TLS encryption has " \
698+
"been enabled based on server response.")
699+
700+
resp = mssql_send_recv(pkt)
701+
702+
idx = 0
703+
704+
while resp and resp[0,1] != "\xff" and resp.length > 5
705+
token = resp.slice!(0,5)
706+
token = token.unpack("Cnn")
707+
idx -= 5
708+
if token[0] == 0x01
709+
idx += token[1]
710+
break
711+
end
712+
end
713+
if idx > 0
714+
encryption_mode = resp[idx,1].unpack("C")[0]
715+
else
716+
raise RuntimeError, "Unable to parse encryption "\
717+
"req during pre-login"
718+
end
648719
end
649720
encryption_mode
650721
end
@@ -687,6 +758,10 @@ def mssql_send_recv(req, timeout=15, check_status = true)
687758
resp
688759
end
689760

761+
def mssql_ssl_send_recv(req,tdsproxy,timeout=15,check_status=true)
762+
tdsproxy.send_recv(req)
763+
end
764+
690765
#
691766
# Encrypt a password according to the TDS protocol (encode)
692767
#

0 commit comments

Comments
 (0)