Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/postgres/postgres_sql.rb
19850 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::Postgres
8
include Msf::OptionalSession::PostgreSQL
9
10
def initialize(info = {})
11
super(
12
update_info(
13
info,
14
'Name' => 'PostgreSQL Server Generic Query',
15
'Description' => %q{
16
This module will allow for simple SQL statements to be executed against a
17
PostgreSQL instance given the appropriate credentials.
18
},
19
'Author' => [ 'todb' ],
20
'License' => MSF_LICENSE,
21
'References' => [
22
[ 'URL', 'https://www.postgresql.org' ]
23
],
24
'Notes' => {
25
'Stability' => [CRASH_SAFE],
26
'SideEffects' => [IOC_IN_LOGS],
27
'Reliability' => []
28
}
29
)
30
)
31
end
32
33
def auxiliary_commands
34
{ 'select' => 'Run a select query (a LIMIT clause is probably a really good idea)' }
35
end
36
37
def cmd_select(*args)
38
datastore['SQL'] = "select #{args.join(' ')}"
39
run
40
end
41
42
def rhost
43
datastore['RHOST']
44
end
45
46
def rport
47
datastore['RPORT']
48
end
49
50
def run
51
self.postgres_conn = session.client if session
52
ret = postgres_query(datastore['SQL'], datastore['RETURN_ROWSET'])
53
case ret.keys[0]
54
when :conn_error
55
print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
56
when :sql_error
57
print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"
58
when :complete
59
vprint_good "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Command complete."
60
end
61
postgres_logout if postgres_conn && session.blank?
62
end
63
end
64
65