Skip to content
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

msfdb init not working with ports other than 5432 #17017

Closed
kalsowerus opened this issue Sep 14, 2022 · 4 comments
Closed

msfdb init not working with ports other than 5432 #17017

kalsowerus opened this issue Sep 14, 2022 · 4 comments
Labels
bug Stale Marks an issue as stale, to be closed if no action is taken

Comments

@kalsowerus
Copy link

kalsowerus commented Sep 14, 2022

Steps to reproduce

How'd you do it?

  1. If the msfdb database has not been configured yet (after sudo msfdb delete)
  2. Configure PostgreSQL to run on a Port other than 5432 (ex. 5433) port = 5433 in /etc/postgresl/14/main/postgresql.conf
  3. Restart the PostgreSQL service sudo service postgresql restart
  4. sudo PGPORT=5433 msfdb reinit

Expected behavior

What should happen?

The database should be configured.

Current behavior

What happens instead?

msfdb cannot connect to the database.

Metasploit version

Framework Version: 6.2.15-dev

Additional Information

Distributor ID: Kali
Description: Kali GNU/Linux Rolling
Release: 2022.3
Codename: kali-rolling

WSL2 VM in Windows 11

PostgreSQL: psql (PostgreSQL) 14.5 (Debian 14.5-1)


sudo -u postgres psql -p 5433 works, so database is up and responsive.


Log from sudo PGPORT=5433 msfdb reinit:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] Starting database
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] Deleting configuration file /usr/share/metasploit-framework/config/database.yml
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[i] Database already stopped
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] Starting database
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] Creating database user 'msf'
Error: PostgreSQL version 13 is not installed
[+] Creating databases 'msf'
Error: PostgreSQL version 13 is not installed
[+] Creating databases 'msf_test'
Error: PostgreSQL version 13 is not installed
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schema
rake aborted!
ActiveRecord::NoDatabaseError: connection to server at "127.0.0.1", port 5433 failed: FATAL:  password authentication failed for user "msf"
connection to server at "127.0.0.1", port 5433 failed: FATAL:  password authentication failed for user "msf"
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_handling.rb:283:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'

Caused by:
PG::ConnectionBad: connection to server at "127.0.0.1", port 5433 failed: FATAL:  password authentication failed for user "msf"
connection to server at "127.0.0.1", port 5433 failed: FATAL:  password authentication failed for user "msf"
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:609:in `async_connect_or_reset'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:761:in `connect_internal'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:737:in `block (2 levels) in connect_to_hosts'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:735:in `each'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:735:in `block in connect_to_hosts'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:721:in `each'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:721:in `each_with_index'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:721:in `connect_to_hosts'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg/connection.rb:672:in `new'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/pg-1.4.3/lib/pg.rb:69:in `connect'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/connection_handling.rb:283:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.6.1/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Because WSL2 does not boot linux with systemd as init system some of the Errors above are to be expected.
This is what a successful run looks like, with the database running on port 5432. sudo PGPORT=5432 msfdb reinit:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] Starting database
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] Deleting configuration file /usr/share/metasploit-framework/config/database.yml
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[i] Database already stopped
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] Starting database
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[+] 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
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.
@kalsowerus kalsowerus added the bug label Sep 14, 2022
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Sep 21, 2022

You have an issue when setting the environment variable, I believe this should work:

sudo bash -c 'export PGPORT=5000; msfdb reinit'

Or

sudo PGPORT=5000 msfdb reinit

But not:

sudo msfdb PGPORT=5433 reinit

Let me know if I misunderstood though 👍

@kalsowerus
Copy link
Author

@adfoster-r7 my bad, I mistyped the command in my issue, it should have been sudo PGPORT=5433 msfdb reinit in the first place. I also tried sudo bash -c 'export PGPORT=5433; msfdb reinit' and that caused the same error.

@github-actions
Copy link

Hi!

This issue has been left open with no activity for a while now.

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 30 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

@github-actions github-actions bot added the Stale Marks an issue as stale, to be closed if no action is taken label Oct 24, 2022
@github-actions
Copy link

Hi again!

It’s been 60 days since anything happened on this issue, so we are going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Stale Marks an issue as stale, to be closed if no action is taken
Projects
None yet
Development

No branches or pull requests

2 participants