Results 1 to 16 of 16

Thread: No connection to Database for metasploit after update - solution

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    2014-Aug
    Posts
    1

    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.

  2. #2
    Join Date
    2013-Mar
    Posts
    9
    Hi Ulairi,

    Thanks for this temporary solution. it worked and helped me.

    Hope this issue will be fixed soon.

  3. #3
    Join Date
    2013-Mar
    Location
    Brazil
    Posts
    52
    Thx!

    I hope the solution comes this week.

  4. #4
    Join Date
    2013-Mar
    Location
    milano
    Posts
    301

    Quote Originally Posted by Ulairi View Post
    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
    Last edited by zimmaro; 2014-09-08 at 09:11.

  5. #5
    Join Date
    2014-Sep
    Posts
    1
    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.

  6. #6
    Join Date
    2013-Mar
    Posts
    9
    Quote Originally Posted by phlucas View Post
    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,

  7. #7
    Join Date
    2013-Mar
    Location
    milano
    Posts
    301
    Quote Originally Posted by oliv66 View Post
    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
    Last edited by zimmaro; 2014-09-08 at 09:28.

  8. #8
    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/communi...ting-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.).
    Code:
    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
    Code:
    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
    Last edited by g0tmi1k; 2014-09-16 at 10:17.
    This is a Kali-Linux support forum - not general IT/infosec help.

    Useful Commands: OS, Networking, Hardware, Wi-Fi
    Troubleshooting: Kali-Linux Installation, Repository, Wi-Fi Cards (Official Docs)
    Hardware: Recommended 802.11 Wireless Cards

    Documentation: http://docs.kali.org/ (Offline PDF version)
    Bugs Reporting & Tool Requests: https://bugs.kali.org/
    Kali Tool List, Versions & Man Pages: https://tools.kali.org/

  9. #9
    Join Date
    2013-Mar
    Posts
    9
    Thanks G0m1k. It worked for me by copying the database file.

  10. #10
    Join Date
    2015-Aug
    Posts
    2
    "db_connect -y /etc/dradis/database.yml" it would be working for every kali 2.0 user.

  11. #11
    Quote Originally Posted by zabeehullah View Post
    "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
    Code:
    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
    This is a Kali-Linux support forum - not general IT/infosec help.

    Useful Commands: OS, Networking, Hardware, Wi-Fi
    Troubleshooting: Kali-Linux Installation, Repository, Wi-Fi Cards (Official Docs)
    Hardware: Recommended 802.11 Wireless Cards

    Documentation: http://docs.kali.org/ (Offline PDF version)
    Bugs Reporting & Tool Requests: https://bugs.kali.org/
    Kali Tool List, Versions & Man Pages: https://tools.kali.org/

  12. #12
    Join Date
    2014-Oct
    Posts
    7
    Quote Originally Posted by g0tmi1k View Post
    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
    Code:
    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..

    Code:
    [-] 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!!

  13. #13
    Join Date
    2014-Oct
    Posts
    7
    Hey, after 2 days i've found the solution here.

    https://forums.kali.org/showthread.p...mitage-problem

    tks, it worked.

  14. #14
    Join Date
    2016-Feb
    Posts
    6
    What if someone has already used "db_connect -y /etc/dradis/database.yml" ?
    How can they revert the changes?

  15. #15
    Join Date
    2016-May
    Posts
    7
    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

  16. #16
    Join Date
    2016-Sep
    Posts
    2
    Quote Originally Posted by Ulairi View Post
    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.

Similar Threads

  1. setoolkit + metasploit database
    By zurek in forum General Archive
    Replies: 2
    Last Post: 2013-12-17, 20:18
  2. Metasploit update: IP connection failure
    By Swift in forum TroubleShooting Archive
    Replies: 1
    Last Post: 2013-11-23, 10:45

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •