View Full Version : No connection to Database for metasploit after update - solution
Hi there,
Connection to the postgresql database doesn't work for metasploit after the last updates.
You can check that from msfconsole by typing : db_status which shows : postgresql selected, no connection
As a temporary solution (I hope ;-)), you can, from the msfconsole, type : db_connect -y /opt/metasploit/apps/pro/ui/config/database.yml
This is automatically rebuild the cache and get you connected to the database.
Hope that helps someone out there.
Hi Ulairi,
Thanks for this temporary solution. it worked and helped me.
Hope this issue will be fixed soon.
PePeLeGal
2014-09-01, 17:07
Thx!
I hope the solution comes this week.
Hi there,
Connection to the postgresql database doesn't work for metasploit after the last updates.
You can check that from msfconsole by typing : db_status which shows : postgresql selected, no connection
As a temporary solution (I hope ;-)), you can, from the msfconsole, type : db_connect -y /opt/metasploit/apps/pro/ui/config/database.yml
This is automatically rebuild the cache and get you connected to the database.
Hope that helps someone out there.
TNX! for fast-fix!!
in one of my kali-machine(a week-ago i've created my-new-database && db_connect-to-it..&& worked) BUT your Fast-Fix ES MEJOR!!!!!;)
http://www.imagestime.com/show.php/972630_1.PNG.html
I had this same error from a brand-new install (Kali 1.0.9 ISO image). I installed it a couple of times thinking that I must have done something to screw it up. When that didn't work, I did an "apt-get purge metasploit" followed by an "apt-get install metasploit", but that didn't fix it. I then tried Ulairi's solution, but got a "file not found" error message when I tried connecting. I then manually went to the folder "/opt/metasploit/apps/pro/ui/config/" and found that there weren't any YML files. However, there was the familiar looking file, "database.yml.example". I copied this file to "database.yml", and the db_connect worked and all seems well, now.
I'm not sure where in the install/configuration steps this database is supposed to be created or renamed, but it's not happening.
I had this same error from a brand-new install (Kali 1.0.9 ISO image). I installed it a couple of times thinking that I must have done something to screw it up. When that didn't work, I did an "apt-get purge metasploit" followed by an "apt-get install metasploit", but that didn't fix it. I then tried Ulairi's solution, but got a "file not found" error message when I tried connecting. I then manually went to the folder "/opt/metasploit/apps/pro/ui/config/" and found that there weren't any YML files. However, there was the familiar looking file, "database.yml.example". I copied this file to "database.yml", and the db_connect worked and all seems well, now.
I'm not sure where in the install/configuration steps this database is supposed to be created or renamed, but it's not happening.
it didn't work for me.
Please could you post your database.yml?
Thanks in advance,
it didn't work for me.
Please could you post your database.yml?
Thanks in advance,
hi :)
if this can be a possibily help && the "the-FIX" by Ulairi(tnx worked in my kali) not """worked""can try this:
this is the OLD procedure USED in bt5-r3 to create a NEW database in postgresql to worked with metasploit...&& worked fine in ONE of my kali's machine
root@bt:~# apt-get install postgresql ###optional or no need#######
root@bt:~# sudo apt-get install libpgsql-ruby #####optional or no need#####
root@bt:~# sudo su postgres
sh-4.1$ createuser root -P
could not change directory to "/root"
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
sh-4.1$ createdb --owner=root metasploit
could not change directory to "/root"
exit
sh-4.1$ exit
exit
root@bt:~# msfconsole
msf > db_driver postgresql Using database driver postgresql ####optional or no need##
msf > db_connect root:
[email protected]:5432/metasploit
db_workspace -a MyProject
*] Added workspace: MyProject
msf > db_nmap 192.168.1.165 -sS -O Nmap: Starting Nmap .................................................. .................................................. ..........
.................................................. .................................................. ......................
................................
the work is perfect (FOR ME)
bye
This all came about with the release of 4.10. Rapid7 is aware of the 'aftermath' of it. For more information ~ https://community.rapid7.com/community/metasploit/blog/2014/08/25/not-reinventing-the-wheel
In short, you need to tell Metasploit the database location if you upgrade. (If you do a fresh install, its been fixed).
Method one - point to the database (you can copy or soft-link. I prefer to soft-link.).
ln -sf /opt/metasploit/apps/pro/ui/config/database.yml /root/.msf4/database.yml
#cp /opt/metasploit/apps/pro/ui/config/database.yml /root/.msf4/database.yml
OR
Method two - use an alias when starting up msfconsole
file=/root/.bash_aliases; [ -e $file ]
grep -q '^alias msfconsole' $file 2>/dev/null || echo -e '\n### Metasploit\nalias msfconsole="msfconsole db_connect -y /opt/metasploit/apps/pro/ui/config/database.yml"\n' >> $file
source $file
Thanks G0m1k. It worked for me by copying the database file.
zabeehullah
2015-08-15, 15:58
"db_connect -y /etc/dradis/database.yml" it would be working for every kali 2.0 user. :)
"db_connect -y /etc/dradis/database.yml" it would be working for every kali 2.0 user. :)
DO NOT DO THIS..
This is linking the use of a 3rd party application (database) into Metasploit & progresql.
If you are using Kali 2 or kali rolling, use msfdb init
root@kali:~# msfdb init
Creating database user 'msf'
Enter password for new role:
Enter it again:
Creating databases 'msf' and 'msf_test'
Creating configuration file in /usr/share/metasploit-framework/config/database.yml
Creating initial database schema
root@kali:~#
As you can see - it will create the database file for you /usr/share/metasploit-framework/config/database.yml
...if something goes wrong, msfdb reinit
What if someone has already used "db_connect -y /etc/dradis/database.yml" ?
How can they revert the changes?
DO NOT DO THIS..
This is linking the use of a 3rd party application (database) into Metasploit & progresql.
If you are using Kali 2 or kali rolling, use msfdb init
root@kali:~# msfdb init
Creating database user 'msf'
Enter password for new role:
Enter it again:
Creating databases 'msf' and 'msf_test'
Creating configuration file in /usr/share/metasploit-framework/config/database.yml
Creating initial database schema
root@kali:~#
As you can see - it will create the database file for you /usr/share/metasploit-framework/config/database.yml
...if something goes wrong, msfdb reinit
I'm facing this problem, and i did all that.. but the connection keep failing..
[-] Failed to connect to the database: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
_---------.
.' ####### ;."
.---,. ;@ @@`; .---,..
." @@@@@'.,'@@ @@@@@',.'@@@@ ".
'-.@@@@@@@@@@@@@ @@@@@@@@@@@@@ @;
`.@@@@@@@@@@@@ @@@@@@@@@@@@@@ .'
"--'.@@@ -.@ @ ,'- .'--"
".@' ; @ @ `. ;'
|@@@@ @@@ @ .
' @@@ @@ @@ ,
`.@@@@ @@ .
',@@ @ ; _____________
( 3 C ) /|___ / Metasploit! \
;@'. __*__,." \|--- \_____________/
'(.,...."/
Taking notes in notepad? Have Metasploit Pro track & report
your progress and findings -- learn more on http://rapid7.com/metasploit
=[ metasploit v4.11.5-2016010401 ]
+ -- --=[ 1517 exploits - 875 auxiliary - 257 post ]
+ -- --=[ 437 payloads - 37 encoders - 8 nops ]
+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]
msf > db_status
postgresql selected, no connection
:\ tks!!
Hey, after 2 days i've found the solution here.
https://forums.kali.org/showthread.php?28954-Kali-v2-0-msfdb-postgresql-armitage-problem
tks, it worked.
dmcxdavid
2016-06-12, 17:07
this is what i use in kali linux rolling hope it helps
sudo service postgresql start
sudo msfconsole
msf>db_connect postgresql
hope it works
iNSiG9FiX
2016-10-06, 08:04
Hope that helps someone out there.
Thank you very much for this post. Even though it's several years old, it solved a problem I had today. And thank you to Kali Linux forums, for leaving old posts like these that are still very helpful.