0

I currently have 3 versions of postgres installed, 14, 15, 16. All 3 are actively running and can be accessed from user postgres on ports 5432, 5433, and 5434.

When running sudo msfdb status it outputs:

● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; preset: disabled)
     Active: active (exited) since Thu 2024-06-27 10:40:16 PDT; 7min ago
 Invocation: f09e52a11c184d548b6ecdb50ffaee5f
    Process: 51345 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 51345 (code=exited, status=0/SUCCESS)

Jun 27 10:40:16 DESKTOP-BNBDO4K systemd[1]: Starting postgresql.service - PostgreSQL RDBMS...
Jun 27 10:40:16 DESKTOP-BNBDO4K systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.

COMMAND    PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
postgres 51292 postgres    5u  IPv4 44585817      0t0  TCP localhost:5432 (LISTEN)

UID          PID    PPID  C STIME TTY      STAT   TIME CMD
postgres   51292       1  0 10:40 ?        Ss     0:00 /usr/lib/postgresql/14/bin/postgres -D /var/lib/postgresql/14/mai

[+] Detected configuration file (/usr/share/metasploit-framework/config/database.yml)

Indicating that it's using version 14. I ran sudo msfdb reinit several times with the follwing result:

[i] Database already started
[+] Dropping databases 'msf'
[+] Dropping databases 'msf_test'
[+] Dropping database user 'msf'
[+] Deleting configuration file /usr/share/metasploit-framework/config/database.yml
[+] Stopping database
[+] Starting database
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schema
rake aborted!
ActiveRecord::ConnectionNotEstablished: connection to server at "127.0.0.1", port 5432 failed: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
SSL SYSCALL error: Connection reset by peer
connection to server at "127.0.0.1", port 5432 failed: FATAL:  the database system is in recovery mode
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in `rescue in new_client'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_handling.rb:280:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/tasks/database_tasks.rb:262:in `migrate'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/railties/databases.rake:92:in `block (2 levels) in <top (required)>'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'

Caused by:
PG::ConnectionBad: connection to server at "127.0.0.1", port 5432 failed: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
SSL SYSCALL error: Connection reset by peer
connection to server at "127.0.0.1", port 5432 failed: FATAL:  the database system is in recovery mode
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/pg-1.5.4/lib/pg/connection.rb:696:in `async_connect_or_reset'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/pg-1.5.4/lib/pg/connection.rb:824:in `connect_to_hosts'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/pg-1.5.4/lib/pg/connection.rb:759:in `new'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/pg-1.5.4/lib/pg.rb:63:in `connect'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/connection_handling.rb:280:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/tasks/database_tasks.rb:262:in `migrate'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.8/lib/active_record/railties/databases.rake:92:in `block (2 levels) in <top (required)>'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

It seems to be able to delete the old data, create some new tables, but fails once adding the schema. I'm not familiar with postgres, but it would seem to me that recovery mode would also disable creating tables?

Whenever I try to connect to the db using credentials provided my msfdb status, it returns a similar error: From msfconsole

[-] Failed to connect to the Postgres data service: connection to server at "127.0.0.1", port 5432 failed: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
SSL SYSCALL error: Connection reset by peer
connection to server at "127.0.0.1", port 5432 failed: FATAL:  the database system is in recovery mode

From psql:

└─$ psql -U msf -d msf
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "msf"

I haven't modified my pg_hba.conf. But here's the output:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

I had issues with peer connections earlier on, which prompted me to try to run this command.

I'd also like to point out that I can connect to the database by switching to user postgres via root which gives me superuser access. Another last detail is that I'm running on WSL2 as my OS rather than a native install. This shouldn't have an effect on the commands or process, but I thought I'd point it out.

All 3 db versions are empty, so I'm open to deleting if necessary.

New contributor
Aarav is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

You must log in to answer this question.

Browse other questions tagged .