Recently with the release of Metasploit 4.5 the developers changed they way the framework is updated, previously it used to be done via ‘svn’, but due to various reasons it has been changed to be updated via ‘git’.
Also the developers chose to change the ‘Community’ version somewhat, they removed a large chunk of code that was kinda duplicated, this and other changes has altered the update frequency of the framework. The Community version now only receives updated modules etc on a weekly basis as the updates are QA’ed in the same way the Pro version is. The Community version also has to be activated to allow it to be updated also.
There is a way still to allow developers, pentesters or guys who just want the latest version. It follows the the ‘old way’ were the framework shipped without the database, but with support to connect to one.
I’ll show you here how to set up the git version of the framework, I did this on my pentesting laptop which runs Arch Linux, but as the framework is written in ‘ruby’ it should follow the same for any distro.
First off we need to install git, if you don’t already have it installed
sudo pacman -S git
Next run the next few commands as root
sudo su cd /opt git clone git://github.com/rapid7/metasploit-framework.git /opt/framework
This will clone the whole framework repository into the /opt/framework folder
Next step, we need to setup the database, postgresql, I used the following how to on the Arch Linux wiki, to complete the first parts of the setup – https://wiki.archlinux.org/index.php/Postgresql, extract below.
Install postgresql
pacman -S postgresql
Configure the PGROOT
Edit the /etc/conf.d/postgresql configuration file. If you don’t know what value to use, just uncomment the line starting with “PGROOT” (the default directory is /var/lib/postgres). – I did just as this says.
Create the file tmpfiles.d for /run/postgresql:
systemd-tmpfiles --create postgresql.conf
Create the data directory (acordingly with the PGROOT variable set before in the config file)
mkdir /var/lib/postgres/data
Set /var/lib/postgres/data ownership to user ‘postgres’
chown -c postgres:postgres /var/lib/postgres/data
As user ‘postgres’ start the database (see first paragraph of this document for instructions on how to become a postgres user):
su - postgres initdb -D '/var/lib/postgres/data'
Start PostgreSQL – have to do this as ‘root’
systemctl start postgresql
(Optional) Add PostgreSQL to the list of daemons that start on system startup
systemctl enable postgresql
Next we need to configure the database, I used a lot of info here that I found in a blog post from the awesome Carlos Perez – http://www.darkoperator.com/installing-metasploit-in-ubunt/
Configuring Postgre SQL Server
We start by switching to the postgres user so we can create the user and database that we will use for Metasploit
sudo -s su postgres
Now we create the user and Database, do record the database that you gave to the user since it will be used in the database.yml file that Metasploit use to connect to the database.
createuser msf -P -S -R -D createdb -O msf msf exit exit
Now we have a database and user etc we need a database.yml file so he framework can connect up to it,
cd /opt/framework touch database.yml nano database.yml
now paste the below into the empty databse.yml file and save it.
production: adapter: postgresql database: msf username: msf password: host: 127.0.0.1 port: 5432 pool: 75 timeout: 5
Remember to enter the password you gave the msf database user into the database.yml file.
OK now we are almost there, this is a new bit to that the framework devs have added to the git version.
gem install bundler bundle install
This will pull in all the required dependencies for metasploit framework. H D Moore himself passed this on.
Next lets create an environment variable so it is loaded by msfconsole when running and load the variable in to your current shell:
sudo echo export MSF_DATABASE_CONFIG=/opt/framework/database.yml >> /etc/profile source /etc/profile
Strangley I couldn’t get the framework to recognise this variable, possibly because I’m using Arch, so I put this little script together that runs the framework and postgresql etc
systemctl start postgresql ./msfconsole -y database.yml systemctl stop postgresql exit
Next we need to install the pcaprub gem so we can use the portscanning modules:
cd /opt/framework/external/pcaprub sudo ruby extconf.rb && sudo make && sudo make install
Now we’re ready to run msfconsole
./msfconsole
Forgot to mention that you also need ruby installed – I use a system wide installation of ruby 1.9.3 using rvm, which can be installed by following this https://rvm.io/rvm/install/
Hopefully you have a working msfconsole with the database connected, you can check this by entering ‘hosts’ and the console should show that there are no hosts in the database or that the database is not connected.
To update the framework you run the usual ‘msfupdate’ command or issue a ‘git pull’ from inside the /opt/framework folder.
Thanks. This helped a lot in Arch Linux. Would be great to enhance the Arch wiki because the AUR packages weren’t working for me and git seems to be more up to date.
also…I had to gem install msgpack to get armitage to work. Thanks again
Greate article! Helped me out heaps, Especially since Rapid7 is migrating to Git entirely.
Note, however that ‘git clone git://github.com/rapid7/metasploit-framework.git /framework’ will clone to ‘/framework’ not ‘/opt/framework’ regardless of what directory you are working from.
‘git clone git://github.com/rapid7/metasploit-framework.git /opt/framework’ will create the desired path.
However I cannot speak exclusively for all users. Just for Arch linux as root. Can’t imagine why it would work differently though.
Definitely should migrate this article to arch wiki as many new arch users will find this useful.
I’d also like to add that there is no ‘installation’ that occurs after the clone. This is why ./msfconsole is required from the /opt/framework directory. Being an ex-backtrack user I like to just be able to punch in msfconsole or armitage or whatever function I’m after. To do this you can export the path.
ie. ‘export PATH=$PATH:/opt/framework’
However, I like to keep all my executable scripts in ‘/usr/local/bin’ and so I moved it there. so far no issues, but Armitage does not seem to connect to msfconsole, and this was a similar issue with the install from the AUR I had. I am prompted that the RPC is unreachable. Any thoughts?
Hi I understand what you are saying that you want to just type ‘msfconsole’ and have it run the application, this relies on having the postgres database running from start up, which is something I didn’t want, hence running the script framework.sh.
However there is a way to achieve your requirements:
1. set postrges to start up automatically, via systemctl enable postgresql command I mention in the post
2. The following command which is taken from Carlos Perez blog;
bash -c 'for MSF in $(ls msf*); do ln -s /opt/metasploit-framework/$MSF /usr/local/bin/$MSF;done'
ln -s /opt/metasploit-framework/armitage /usr/local/bin/armitage
These 2 commands will create symlinks to /usr/local/bin, run them from inside the /opt/framework folder.
This will fix armitage too.
Regarding the git pull command from your first comment;
you should cd /opt before the git pull, and then this will create the framework folder under /opt
Thanks for your comments
Dave