From 77c986948c400093e46f673d99c142a0f05106dc Mon Sep 17 00:00:00 2001 From: HD Moore Date: Tue, 31 Jan 2012 02:08:02 -0600 Subject: [PATCH] Proper fix for IPv6 postgresql connections --- lib/msf/core/exploit/postgres.rb | 6 ++++++ lib/postgres/postgres-pr/connection.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/msf/core/exploit/postgres.rb b/lib/msf/core/exploit/postgres.rb index 8cd6db67f7..3d9f8daea1 100644 --- a/lib/msf/core/exploit/postgres.rb +++ b/lib/msf/core/exploit/postgres.rb @@ -160,7 +160,13 @@ module Exploit::Remote::Postgres password = args[:password] || datastore['PASSWORD'] rhost = args[:server] || datastore['RHOST'] rport = args[:port] || datastore['RPORT'] + uri = "tcp://#{rhost}:#{rport}" + if Rex::Socket.is_ipv6?(rhost) + uri = "tcp://[#{rhost}]:#{rport}" + end + + verbose = args[:verbose] || datastore['VERBOSE'] begin self.postgres_conn = Connection.new(db,username,password,uri) diff --git a/lib/postgres/postgres-pr/connection.rb b/lib/postgres/postgres-pr/connection.rb index be06f1ec2d..68210bd30c 100644 --- a/lib/postgres/postgres-pr/connection.rb +++ b/lib/postgres/postgres-pr/connection.rb @@ -171,7 +171,7 @@ class Connection case u.scheme when 'tcp' @conn = Rex::Socket.create( - 'PeerHost' => (u.host || DEFAULT_HOST), + 'PeerHost' => (u.host || DEFAULT_HOST).gsub(/[\[\]]/, ''), # Strip any brackets off (IPv6) 'PeerPort' => (u.port || DEFAULT_PORT), 'proto' => 'tcp' )