# Metasploit on FreeBSD ("no database driver installed")



## MarcoB (Jun 2, 2018)

Is there anyone here that successfully uses security/metasploit on FreeBSD?
The port installs and runs, and also postgresql is running. But metasploit just doesn't connect to the database. When running msfconsole I get:


```
root@yokozuna:~ # msfconsole
                                                  
     ,           ,
    /             \
   ((__---,,,---__))
      (_) O O (_)_________
         \ _ /            |\
          o_o \   M S F   | \
               \   _____  |  *
                |||   WW|||
                |||     |||


       =[ metasploit v4.16.57-dev                         ]
+ -- --=[ 1767 exploits - 1005 auxiliary - 307 post       ]
+ -- --=[ 537 payloads - 41 encoders - 10 nops            ]
+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]

[4mmsf[0m [0m>
```

But metasploit doesn't connect to a database:

```
[4mmsf[0m [0m> db_status
[-] No database driver installed. Try 'gem install pg'
```

The suggested `gem install pg` doesn't work either:

```
[4mmsf[0m [0m> gem install pg
[*] exec: gem install pg

Building native extensions. This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

    current directory: /usr/local/lib/ruby/gems/2.4/gems/pg-1.0.0/ext
/usr/local/bin/ruby24 -r ./siteconf20180602-31634-1qgflo4.rb extconf.rb
/usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/spec_set.rb:91:in `block in materialize': Could not find pg-1.0.0 in any of the sources (Bundler::GemNotFound)
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/spec_set.rb:85:in `map!'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/spec_set.rb:85:in `materialize'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/definition.rb:171:in `specs'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/definition.rb:238:in `specs_for'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/definition.rb:227:in `requested_specs'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/runtime.rb:108:in `block in definition_method'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/runtime.rb:20:in `setup'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler.rb:107:in `setup'
        from /usr/local/lib/ruby/gems/2.4/gems/bundler-1.16.2/lib/bundler/setup.rb:20:in `<top (required)>'
        from /usr/local/lib/ruby/site_ruby/2.4/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /usr/local/lib/ruby/site_ruby/2.4/rubygems/core_ext/kernel_require.rb:59:in `require'

extconf failed, exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.4/gems/pg-1.0.0 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.4/extensions/amd64-freebsd-11/2.4/pg-1.0.0/gem_make.out
```

So does anyone know what to do to use metasploit in FreeBSD?


----------



## timypcr (Jun 3, 2018)

Never used metasploit on FreeBSD perhaps try using pkgng


```
pkg install rubygem-pg-1.0.0
```

A  quick online ports search shows a few pg versions and other related PostgreSQL/ruby packages when searching for "PostgreSQL" may want to go through them to see if anything works.

Good luck!


----------



## unitrunker (Jun 3, 2018)

Confirmed. It's a bug. Please open an issue:

https://github.com/rapid7/metasploit-framework


----------



## MarcoB (Jun 3, 2018)

timypcr said:


> Never used metasploit on FreeBSD perhaps try using pkgng
> 
> 
> ```
> ...



Afaik all required dependencies are installed, including databases/rubygem-pg.


----------



## MarcoB (Jun 3, 2018)

unitrunker said:


> Confirmed. It's a bug. Please open an issue:
> 
> https://github.com/rapid7/metasploit-framework



I think it's a FreeBSD ports issue, so I filed a bugreport on https://bugs.freebsd.org/bugzilla


----------



## unitrunker (Jun 5, 2018)

Building from ports yields the exact same error.


----------



## talsamon (Jun 5, 2018)

I never worked with metasploit (on FreeBSD). But I tried it now.
I got another error:

```
Failed to connect to the database: ActiveRecord::ConnectionNotEstablished
```
I did not got the "No database driver installed" error.
I am not sure, but I think both my error and the error above could be a config-error.

Could someone post the configure steps for metasploit? (maybe, I overlooked something).

Edit:
Seems it was an error in .msf4/database.yml.
Now I  got the same error.


----------



## MarcoB (Mar 29, 2020)

I am playing with metasploit again and saw this old post. Solved it so thought I post this follow-up.
The database connection problem is due to the metasploit database not being initialized. A `msfdb init` or `msfdb reinit` (as user) solved this.
Other needed command is `bundle install` (as root) in the /usr/local/share/metasploit directory, to install needed gems.


----------



## unitrunker (Mar 30, 2020)

I can run 

$ msfdb start
$ msfconsole

I still get the "no database support" error.

Typing 'db_status' from the console returns 'No database driver installed.'


----------



## MarcoB (Mar 30, 2020)

Do you have PostgreSQL up and running?


----------



## unitrunker (Mar 30, 2020)

Thats what 'msfdb start' does.

The PKG doesn't install postgresql11 - server. I had to install that manually - which fixed the msfdb init error.

msfconsole does not see the postgresql service started by msfdb.


----------

