Armitage on Kali: How to resolve “Could not connect to the Metasploit database” error

Armitage is an extension written in Java for the free Metasploit command and control (C2) framework. It adds a GUI and the ability the collaborate with other penetration testers in a red team engagement.

It’s also included in Kali Linux. It can be installed with the simple command apt install armitage.

During my installation of Armitage on my Kali VM, I ran into an error when starting the Armitage teamserver:

The error in question

The error indicates that the Metasploit database (msfdb) isn’t running. Sounds easy enough to fix. Most Armitage installation guides say to run sudo msfdb init before trying to run the teamserver.

The metasploit database is already started
Uh oh…

As you can see, that wasn’t my problem. The msfdb was already running. It doesn’t help that the Armitage website www.fastandeasyhacking.com no longer resolves.

After ensuring that the postgresql service was started with systemctl start postgresql, I spent a long time looking for an answer. but didn’t find any dedicated resources that helped. That’s why I’m writing this article.

Eventually I found the answer buried deep in the comments on a Stack Overflow question.

The secret sauce

When the Armitage teamserver is starting, it tries to connect to the Metasploit database where it’s installed by default. Since we’re on Kali Linux, Metasploit has been configured differently than the defaults. It’s trying to connect to a database where there is none.

Instead, we need to specify the true location of the database. We can do so by setting the environment variable MSF_DATABASE_CONFIG to the path of database.yml.

export MSF_DATABASE_CONFIG=/usr/share/metasploit-framework/config/database.yml

If you’d like, you can check to make sure this was successful. The following command should output the path you just set:

echo $MSF_DATABASE_CONFIG

How do I find the path to database.yml?

The path in my example above is where the Metasploit database initialized database.yml. You can find your own path quite easily.

Start by checking the database status:

sudo msfdb status

If the database has already been initialized and there’s a valid database.yml file, the output from that command will indicate it’s location. If it cannot detect the file, you can delete and reinitialize the database with this command:

sudo msfdb reinit

The output will indicate the location of the newly created database.yml.

Run the teamserver

Once the MSF_DATABASE_CONFIG variable is set, the postgresql service is started, and msfdb is running, you can start the Armitage teamserver!