Metasploit failed to connect to the Database: FIXED

metasploit failed to connect to database - featured

Welcome back, fellow hackers! I recently had the Metasploit fail to connect to the Database on the ParrotSec  OS version 4.2.2. I use multiple instances of ParrotSec, and I had the exact same issue on all of them. I don’t know if that is a thing on Kali Linux as well, but for ParrotSec, the reason this happens is that PostgreSQL is not listening on port 5432, which Metasploit requires, but on port 5433. If you don’t fix this, the search function of Metasploit will take a very long to show results.

So what we need to do is, change the port on PostgreSQL. I’ll show you how to do that.

Table of Contents

Step 1 - Starting and Checking PostgreSQL

First, we need to make sure PostgreSQL is running.

Terminalbash
sudo service postgresql start

Next, we are going to check which port PostgreSQL is using.

Terminalbash
sudo ss -lntp | grep post
Metasploit Failed to connect to the database

Now I already fixed it for my OS, but if you see port 5433 here instead of 5432, you know that you have the error I described above. Now we are going to fix that.

Step 2 - Updating the PostgreSQL config

First, run the following command to double-check the port that is being used in the config right now.

Make sure you adjust the PostgreSQL version to the actual installed version. So after typing /etc/postgresql/ hit the TAB button to see your installed version. As of October 2018, that’s version 10.

Terminalbash
sudo grep "port =" /etc/postgresql/10/main/postgresql.conf
metasploit failed to connect to the database

You will probably see port = 5433 here now. As I said, I already fixed it for myself.

Now we are going to change that in the config.

You can either go ahead and use nano to edit the file:

Terminalbash
sudo nano /etc/postgresql/10/main/postgresql.conf

Find the entry for port = 5433 and change it to 5432, hit CTRL+O to save and CTRL + X to leave, or you can just run the following command:

Terminalbash
sudo sed -i 's/\(port = \)5433/\15432/' /etc/postgresql/10/main/postgresql.conf

As I said above, make sure you adjust the PostgreSQL version to the one you have installed (after /etc/postgresql/YOURVERSIONHERE).

Step 3 - Restarting PostgreSQL and re-initialize the Metasploit Database

As the last step, we need to restart PostgreSQL and re-initialize our Metasploit Database.

Terminalbash
sudo service postgresql restart
metasploit failed to connect to the database

After you have followed all of those steps, you should have solved the Metasploit Failed to connect to the Database error. Let me know in the comments below if that worked out for you. Want to learn more about Metasploit? Check out my other tutorials.

whoami

Stefan

Stefan founded Ceos3c in 2016 and has spent a decade teaching cybersecurity, Linux, and web development through hands-on tutorials. He builds and ships real products while sharing his journey: ProofSwap.me, XPMetric.com, and EasyEarningsTracker.com. Find him on YouTube (youtube.com/stefanrows) and X (@StefanRows).

whoami

Stefan

Stefan founded Ceos3c in 2016 and has spent a decade teaching cybersecurity, Linux, and web development through hands-on tutorials. He builds and ships real products while sharing his journey: ProofSwap.me, XPMetric.com, and EasyEarningsTracker.com. Find him on YouTube (youtube.com/stefanrows) and X (@StefanRows).

2 thoughts on “Metasploit failed to connect to the Database: FIXED”

Comments are closed. I keep the discussion here because the answers still help.