-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use PostgreSQL session type for Postgres modules #18706
Use PostgreSQL session type for Postgres modules #18706
Conversation
Testing Steps And Outputs Pt. 1
|
Testing Steps And Outputs Pt. 2
|
vprint_status "#{ip}:#{port} Postgres - querying with '#{sql}'" | ||
vprint_status "#{rhost}:#{rport} Postgres - querying with '#{sql}'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to leave these as ip
and port
no?
you have this above:
ip = opts[:server] || rhost
port = opts[:port] || rport
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After having a look at this, I think this should be rhost and rport. ip
and port
are defined outside the scope of this function.
print_good output if datastore['DISPLAY_RESULTS'] | ||
end | ||
|
||
def get_schema | ||
ignored_databases = datastore['IGNORED_DATABASES'].split(',').map(&:strip) | ||
pg_schema = [] | ||
database_names = smart_query('SELECT datname FROM pg_database').to_a.flatten | ||
database_names = session ? [session.client.params['database']] : smart_query('SELECT datname FROM pg_database').to_a.flatten |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this return the same for both cases? I thought session.client.params['database']
would return the database you're connected to whereas the query gets all the database names in the cluster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct; but when connecting through a session, only the currently connected DB can be dumped. We cannot switch databases when using a session either, because doing so requires opening a new socket and re-authenticating. This might not work in the case of getting the initial shell through a previous exploit, or when the creds expire etc. This change allows us to dump the database without having to change more code throughout the rest of the module.
#vuln_version doesn't seem to work | ||
#return unless vuln_version? | ||
return unless vuln_version? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you figure out what the issues were? 👀
0247b50
to
0f9e20c
Compare
0f9e20c
to
0cf4d6a
Compare
return :not_exists if match_error | ||
|
||
# Default to something sane | ||
:not_exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return :not_exists if match_error | |
# Default to something sane | |
:not_exists | |
:not_exists |
I think this can be simplified?
at the minute you're returning :not_exists
if match_error
is truthy...and then if it's not truthy you end up returning :not_exists
anyway
it actually kinda makes the whole match_error
bit pointless since it doesn't matter whether it finds the error or not, do you know what makes use of this return value? that might give us a clue as to what was intended here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to change it to something else, maybe :failed
or whatever a good alternative would be 👍
The return value is being used in:
def load_extension?(language)
case load_procedural_language(language, 'LANGUAGE')
when ...
when ...
end
Testing
|
29cdb7f
to
b2e3e92
Compare
@@ -121,6 +121,14 @@ def initialize(database, user, password=nil, uri = nil) | |||
end | |||
end | |||
|
|||
def address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want to circle back to renaming this to the lexicon similar to peer used elsewhere in metasploit, and other languages
Example ruby snippets:
>> s = TCPSocket.new('127.0.0.1', 5000)
=> #<TCPSocket:fd 18, AF_INET, 127.0.0.1, 52847>
>> s.peeraddr
=> ["AF_INET", 5000, "127.0.0.1", "127.0.0.1"]
>> s.local_address
=> #<Addrinfo: 127.0.0.1:52847 TCP>
Example Python snippets:
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> result = s.connect(('127.0.0.1', 5000))
>>> s.getpeername()
('127.0.0.1', 5000)
>>> s.getsockname()
('127.0.0.1', 52883)
7f41ff0
to
e71bd70
Compare
e71bd70
to
30fc29e
Compare
Msf::Opt::RHOST(nil, false), | ||
Msf::Opt::RPORT(5432, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context, these options were initially added here: 23a9938#diff-5479394bb6dd61d2ac4fc96ae36d29cf5b52e3b7687b7b6c714cbe53b273c4cb
But seemed to be removed here: 2c60780#diff-5479394bb6dd61d2ac4fc96ae36d29cf5b52e3b7687b7b6c714cbe53b273c4cb
Release NotesUpdates multiple PostgreSQL modules to now work with PostgreSQL sessions. This functionality is behind a feature flag which can be enabled with |
This PR is a continuation of #18663.
This PR changes over Postgres modules so that they are able to target an RHOST/RHOSTS or a PostgreSQL session.
For testing of this PR, I recommend setting up a Metasploitable2 VM which runs Postgres 8.3.1, Docker using
postgres:16
orpostgres:16.1
(latest as of this PR), and9.2.3
(needs a custom Dockerfile setup, described below).Overview
Setup
Docker - Postgres 16/16.x
Docker - Postgres 9.2.3
auxiliary/scanner/postgres/postgres_dbname_flag_injection
(all the previous versions are present here):wget
calls to not use certificates (they're out of date):docker-entrypoint.sh
:9.2.3
as that's the version we used, but you can uselatest
or anything else:Metasploitable2 VM
Verification
Follow the testing steps in the comment below.
msfconsole