rapid7 / metasploit-framework

Metasploit Framework
https://www.metasploit.com/
Other
32.92k stars 13.72k forks source link

Use mysql database? #19145

Open FalcoGer opened 2 weeks ago

FalcoGer commented 2 weeks ago

Summary

I run a lot of services, but only MSF requires a postgresql database. I would like to get rid of it to save on the memory, storage and cpu overhead and use the existing mysql database.

How do i switch from using a postgresql database to mysql? I wish to use an existing, remote database and not create a local one.

Relevant information

Suppose I have my database on server.lan (192.168.1.5), running on the default mysql port of tcp 3306. the username on that mysql server is is 'msf', the password is 'p4ssw0rd', the database is 'metasploitdb'.

I can not find information on these subjects:

  1. how to configure msf to use that remote server
  2. how to prevent msf from trying to create a local database in ~/.msf4/db/ (i have a workaround in place where i have an empty, normal file with permissions 000, but it throws an error every time i execute an msf command)
  3. how to create the relevant tables, keys, indexes and constraints on the remote mysql server's database

Whenever I look up anything remotely resembling this information I either get how to use the postgresql database (but not a remote one, only a local one) or how to attack or enumerate a remote mysql server, not how to use it as a datastore for msf.

If this is not possible, is there some alternative? Maybe some sort of compatibility layer that pretends to be a postgresql server but instead translates the queries to mysql and forwards them to a mysql server instead? I tried looking for something like that but came up only with database migration tools. The best I could find was the mysql_fdw plugin for postgresql, but if possible I'd like to eliminate postgres entirely.

adfoster-r7 commented 2 weeks ago

There's no official support for MySQL as the database out of the box with Metasploit; you might be able to change the configuration file here and have it work: https://github.com/rapid7/metasploit-framework/blob/master/config/database.yml.example - which should be here ~/.msf4/database.yml

To run "remotely", the host field can be the IP of your target machine - https://github.com/rapid7/metasploit-framework/blob/d6b45658e0f6a789d9a26a4a5913cd770278c556/config/database.yml.example#L12

You might have to configure firewalls etc; you'll also need to run the database setup yourself. You might have to follow these steps too: bundle exec rake db:create db:migrate db:seed

adfoster-r7 commented 2 weeks ago

You can also run postgres remotely, via TCP - in the same vein as above

FalcoGer commented 2 weeks ago

I did set the host value in database.yaml. And it does connect to the remote host, but still every time i start msfconsole or msfvenom it tries to initialize a local database in ~/.msf4/db. It's quite annoying. I guess I'll just live with the error message.

adfoster-r7 commented 2 weeks ago

Pull requests are welcome :+1: