2010-02-05 15:20:59 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2010-02-05 15:20:59 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::Postgres
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
2010-03-30 17:57:22 +00:00
|
|
|
|
2010-02-05 15:20:59 +00:00
|
|
|
# Creates an instance of this module.
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2010-03-30 17:57:22 +00:00
|
|
|
'Name' => 'PostgreSQL Version Probe',
|
2010-02-05 15:20:59 +00:00
|
|
|
'Description' => %q{
|
|
|
|
Enumerates the verion of PostgreSQL servers.
|
|
|
|
},
|
|
|
|
'Author' => [ 'todb' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
2011-07-24 19:36:37 +00:00
|
|
|
[ 'URL', 'http://www.postgresql.org' ]
|
2010-02-05 15:20:59 +00:00
|
|
|
],
|
|
|
|
'Version' => '$Revision$' # 2009-02-05
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options([ ], self.class) # None needed.
|
|
|
|
|
|
|
|
deregister_options('SQL', 'RETURN_ROWSET')
|
|
|
|
end
|
|
|
|
|
|
|
|
# Loops through each host in turn. Note the current IP address is both
|
|
|
|
# ip and datastore['RHOST']
|
|
|
|
def run_host(ip)
|
|
|
|
user = datastore['USERNAME']
|
|
|
|
pass = postgres_password
|
2012-03-06 19:01:20 +00:00
|
|
|
do_fingerprint(user,pass,datastore['DATABASE'])
|
2010-02-05 15:20:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Alias for RHOST
|
|
|
|
def rhost
|
|
|
|
datastore['RHOST']
|
|
|
|
end
|
|
|
|
|
2010-03-30 17:57:22 +00:00
|
|
|
# Alias for RPORT
|
2010-02-05 15:20:59 +00:00
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
|
|
|
|
2012-03-06 19:01:20 +00:00
|
|
|
def do_fingerprint(user=nil,pass=nil,database=nil)
|
2010-02-05 15:20:59 +00:00
|
|
|
begin
|
2010-02-16 18:09:51 +00:00
|
|
|
msg = "#{rhost}:#{rport} Postgres -"
|
|
|
|
password = pass || postgres_password
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_status("#{msg} Trying username:'#{user}' with password:'#{password}' against #{rhost}:#{rport} on database '#{database}'")
|
2010-02-16 18:09:51 +00:00
|
|
|
result = postgres_fingerprint(
|
|
|
|
:db => database,
|
|
|
|
:username => user,
|
|
|
|
:password => password
|
2010-02-05 15:20:59 +00:00
|
|
|
)
|
2010-02-16 18:09:51 +00:00
|
|
|
if result[:auth]
|
2012-03-06 19:01:20 +00:00
|
|
|
vprint_good "#{rhost}:#{rport} Postgres - Logged in to '#{database}' with '#{user}':'#{password}'"
|
2010-09-14 14:43:56 +00:00
|
|
|
print_status "#{rhost}:#{rport} Postgres - Version #{result[:auth]} (Post-Auth)"
|
2010-02-16 18:09:51 +00:00
|
|
|
elsif result[:preauth]
|
2010-09-14 14:43:56 +00:00
|
|
|
print_status "#{rhost}:#{rport} Postgres - Version #{result[:preauth]} (Pre-Auth)"
|
2010-02-16 18:09:51 +00:00
|
|
|
else # It's something we don't know yet
|
2012-01-30 19:08:35 +00:00
|
|
|
vprint_status "#{rhost}:#{rport} Postgres - Authentication Error Fingerprint: #{result[:unknown]}"
|
2010-09-14 14:43:56 +00:00
|
|
|
print_status "#{rhost}:#{rport} Postgres - Version Unknown (Pre-Auth)"
|
2010-02-16 18:09:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Reporting
|
|
|
|
|
|
|
|
report_service(
|
2010-02-05 15:20:59 +00:00
|
|
|
:host => rhost,
|
|
|
|
:port => rport,
|
2010-02-16 18:09:51 +00:00
|
|
|
:name => "postgres",
|
|
|
|
:info => result.values.first
|
2010-02-05 15:20:59 +00:00
|
|
|
)
|
|
|
|
|
2010-02-16 18:09:51 +00:00
|
|
|
if self.postgres_conn
|
|
|
|
report_auth_info(
|
|
|
|
:host => rhost,
|
2010-08-18 00:58:20 +00:00
|
|
|
:port => rport,
|
|
|
|
:sname => "postgres",
|
2010-02-16 18:09:51 +00:00
|
|
|
:user => user,
|
|
|
|
:pass => password,
|
2010-08-18 00:58:20 +00:00
|
|
|
:active => true
|
2010-02-16 18:09:51 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if result[:unknown]
|
|
|
|
report_note(
|
|
|
|
:host => rhost,
|
2011-02-04 01:54:32 +00:00
|
|
|
:proto => 'tcp',
|
2011-02-22 20:49:44 +00:00
|
|
|
:sname => 'postgres',
|
2010-02-16 18:09:51 +00:00
|
|
|
:port => rport,
|
2011-06-03 00:49:45 +00:00
|
|
|
:ntype => 'postgresql.fingerprint',
|
2010-02-16 18:09:51 +00:00
|
|
|
:data => "Unknown Pre-Auth fingerprint: #{result[:unknown]}"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Logout
|
|
|
|
|
|
|
|
postgres_logout
|
2010-02-05 15:20:59 +00:00
|
|
|
|
2010-02-16 18:05:51 +00:00
|
|
|
rescue Rex::ConnectionError
|
2012-01-30 19:08:35 +00:00
|
|
|
vprint_error "#{rhost}:#{rport} Connection Error: #{$!}"
|
2010-02-16 18:05:51 +00:00
|
|
|
return :done
|
|
|
|
end
|
|
|
|
|
2010-02-05 15:20:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|