Skip to content

Commit

Permalink
Update postgres_schemadump to work correctly against a session after …
Browse files Browse the repository at this point in the history
…login logic change
  • Loading branch information
sjanusz-r7 committed Feb 2, 2024
1 parent 341e379 commit 7f41ff0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/auxiliary/scanner/postgres/postgres_schemadump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def initialize
end

def run_host(_ip)
print_status 'When targeting a session, only the current database can be dumped.' if session
if session
print_status 'When targeting a session, only the current database can be dumped.'
self.postgres_conn = session.client
end

pg_schema = get_schema
pg_schema.each do |db|
report_note(
Expand Down Expand Up @@ -70,7 +74,7 @@ def get_schema
tmp_db = {}
tmp_db['DBName'] = database_name
tmp_db['Tables'] = []
postgres_login({ database: database_name })
postgres_login({ database: database_name }) unless session
tmp_tblnames = smart_query("SELECT c.relname, n.nspname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname NOT IN ('pg_catalog','pg_toast') AND pg_catalog.pg_table_is_visible(c.oid);")
if tmp_tblnames && !tmp_tblnames.empty?
tmp_tblnames.each do |tbl_row|
Expand Down

0 comments on commit 7f41ff0

Please sign in to comment.