Skip to content

Commit e603880

Browse files
committed
Address PR feedback
1 parent dbb631f commit e603880

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

lib/metasploit/framework/login_scanner/postgres.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
require 'metasploit/framework/login_scanner/base'
2-
require 'metasploit/framework/login_scanner/rex_socket'
3-
require 'metasploit/framework/tcp/client'
42
require 'postgres_msf'
53

64
module Metasploit
@@ -12,8 +10,25 @@ module LoginScanner
1210
# and attempting them. It then saves the results.
1311
class Postgres
1412
include Metasploit::Framework::LoginScanner::Base
15-
include Metasploit::Framework::LoginScanner::RexSocket
16-
include Metasploit::Framework::Tcp::Client
13+
14+
# @!attribute ssl
15+
# @return [Boolean] Whether the connection should use SSL
16+
attr_accessor :ssl
17+
# @!attribute ssl_version
18+
# @return [String] The version of SSL to implement
19+
attr_accessor :ssl_version
20+
# @!attribute ssl_verify_mode
21+
# @return [String] the SSL certification verification mechanism
22+
attr_accessor :ssl_verify_mode
23+
# @!attribute ssl_cipher
24+
# @return [String] The SSL cipher to use for the context
25+
attr_accessor :ssl_cipher
26+
# @!attribute max_send_size
27+
# @return [Integer] The max size of the data to encapsulate in a single packet
28+
attr_accessor :max_send_size
29+
# @!attribute send_delay
30+
# @return [Integer] The delay between sending packets
31+
attr_accessor :send_delay
1732

1833
# @returns [Boolean] If a login is successful and this attribute is true - a Msf::Db::PostgresPR::Connection instance is used as proof,
1934
# and the socket is not immediately closed

lib/metasploit/framework/tcp/client.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ def connect(global = true, opts={})
8080
dossl = ssl
8181
end
8282

83-
# For Postgres, always connect with SSL disabled; SSL is enabled after the initial connection is made
84-
if defined?(self) && self.class.name =~ /Postgres/
85-
dossl = false
86-
end
87-
8883
nsock = Rex::Socket::Tcp.create(
8984
'PeerHost' => opts['RHOST'] || rhost,
9085
'PeerHostname' => opts['SSLServerNameIndication'] || opts['RHOSTNAME'],
@@ -211,3 +206,4 @@ def proxies
211206
end
212207
end
213208
end
209+

lib/postgres/postgres-pr/connection.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,14 @@ def establish_connection(uri, proxies, ssl = nil)
358358
'Proxies' => proxies
359359
)
360360
if ssl
361-
# Send SSLRequest packet
362-
ssl_request = [8, 80877103].pack('N2')
363-
@conn.write(ssl_request)
361+
ssl_request_message = SSLRequest.new(80877103)
362+
@conn.write(ssl_request_message.dump)
364363
response = @conn.read(1)
365364
if response == 'S'
366365
ssl_context = OpenSSL::SSL::SSLContext.new
367366
ssl_socket = OpenSSL::SSL::SSLSocket.new(@conn, ssl_context)
367+
# Ensure the underlying TCP socket is closed when the SSL socket is closed
368+
# This prevents resource leaks and ensures proper cleanup of the connection
368369
ssl_socket.sync_close = true
369370
ssl_socket.connect
370371
@conn = ssl_socket

0 commit comments

Comments
 (0)