NeosLab.com
Metasploit

How to Install Metasploit Framework on Ubuntu 16.04 LTS and Debian 7

This tutorial covers the installation of Metasploit Framework Project on Ubuntu Linux LTS. If you do not wish to run the Open Source version or set up a development environment and do not mind giving your e-mail address to Rapid7 for marketing we would recommend downloading their commercial installer from Metasploit for Metasploit Express and Pro.

If you prefer an all in one installer only for framework the Metasploit team offers nightly built installers at Github.com making a quick setup a breeze if you do not plan to pull separate branches to test experimental code or do development.

INSTALL ORACLE JAVA 8

We start by adding the Oracle Java Package source

$ sudo add-apt-repository -y ppa:webupd8team/java

Once added we can install the latest version

$ sudo apt-get update
$ sudo apt-get -y install oracle-java8-installer

INSTALLING DEPENDENCIES

We start by making sure that we have the latest packages by updating the system using apt-get:

$ sudo apt-get update
$ sudo apt-get upgrade

Now that we know that we are running an updated system we can install all the dependent packages that are needed by Metasploit Framework:

$ sudo apt-get install build-essential libreadline-dev libssl-dev libpq5 libpq-dev libreadline5 libsqlite3-dev libpcap-dev git-core autoconf postgresql pgadmin3 curl zlib1g-dev libxml2-dev libxslt1-dev vncviewer libyaml-dev curl zlib1g-dev
INSTALLING A PROPER VERSION OF RUBY

The distribution sadly does not comes by default with a proper version of Ruby for us to use with Metasploit Framework and we will have to download and compile a proper one. There 2 mains ways recommended for this are using RVM or rbenv (Do not install both choose one or the other). If installing using RVM be warned that symlinks will not work do to the way it places the binary stubs of the metasploit-framework gem.

Installing Ruby using RVM:

$ curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
$ curl -L https://get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/rvm
$ echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
$ source ~/.bashrc
$ RUBYVERSION=$(wget https://raw.githubusercontent.com/rapid7/metasploit-framework/master/.ruby-version -q -O - )
$ rvm install $RUBYVERSION
$ rvm use $RUBYVERSION --default
$ ruby -v

Installing Ruby using rbenv:

$ cd ~
$ git clone git://github.com/sstephenson/rbenv.git .rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ exec $SHELL
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
# sudo plugin so we can run Metasploit as root with "rbenv sudo msfconsole" 
$ git clone git://github.com/dcarley/rbenv-sudo.git ~/.rbenv/plugins/rbenv-sudo
$ exec $SHELL
$ RUBYVERSION=$(wget https://raw.githubusercontent.com/rapid7/metasploit-framework/master/.ruby-version -q -O - )
$ rbenv install $RUBYVERSION
$ rbenv global $RUBYVERSION
$ ruby -v
INSTALLING NMAP

One of the external tools that Metasploit uses for scanning that is not included with the sources is Nmap. Here we will cover downloading the latest source code for Nmap, compiling and installing:

$ mkdir ~/Development
$ cd ~/Development
$ git clone https://github.com/nmap/nmap.git
$ cd nmap 
$ ./configure
$ make
$ sudo make install
$ make clean
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 and Armitage use to connect to the database.

$ createuser msf -P -S -R -D
$ createdb -O msf msf
$ exit
$ exit

If you experience problems with the database setup this Fedora guide offers a good guide for troubleshooting and setup https://fedoraproject.org/wiki/Metasploit_Postgres_Setup.

INSTALLING METASPLOIT FRAMEWORK

We will download the latest version of Metasploit Framework via Git so we can use msfupdate to keep it updated:

$ cd /opt
$ sudo git clone https://github.com/rapid7/metasploit-framework.git
$ sudo chown -R `whoami` /opt/metasploit-framework
$ cd metasploit-framework

Install using bundler the required gems and versions:

$ cd metasploit-framework
# If using RVM set the default gem set that is create when you navigate in to the folder
$ rvm --default use ruby-${RUByVERSION}@metasploit-framework
$ gem install bundler
$ bundle install

Lets create the links to the commands so we can use them under any user and not being under the framework folder, for this we need to be in the metasploit-framework folder if not already in it:

$ cd metasploit-framework
$ sudo bash -c 'for MSF in $(ls msf*); do ln -s /opt/metasploit-framework/$MSF /usr/local/bin/$MSF;done'
INSTALLING ARMITAGE
$ curl -# -o /tmp/armitage.tgz http://www.fastandeasyhacking.com/download/armitage150813.tgz
$ sudo tar -xvzf /tmp/armitage.tgz -C /opt
$ sudo ln -s /opt/armitage/armitage /usr/local/bin/armitage
$ sudo ln -s /opt/armitage/teamserver /usr/local/bin/teamserver
$ sudo sh -c "echo java -jar /opt/armitage/armitage.jar \$\* > /opt/armitage/armitage"
$ sudo perl -pi -e 's/armitage.jar/\/opt\/armitage\/armitage.jar/g' /opt/armitage/teamserver

Lets create the database.yml file that will contain the configuration parameters that will be use by framework:

$ sudo nano /opt/metasploit-framework/config/database.yml

Copy the YAML entries and make sure you provide the password you entered in the user creating step in the password field for the database:

production:
adapter: postgresql
database: msf
username: msf
password: 
host: 127.0.0.1
port: 5432
pool: 75
timeout: 5

Create and environment variable so it is loaded by Armitage and by msfconsole when running and load the variable in to your current shell:

$ sudo sh -c "echo export MSF_DATABASE_CONFIG=/opt/metasploit-framework/config/database.yml >> /etc/profile"
$ source /etc/profile
FIRST RUN

Now we are ready to run Metasploit for the first time. Our recommendation is to run it first under a regular user so the folders will be created under your home directory with the proper permissions. First time it runs it will create the entries needed by Metasploit in the database so it will take a while to load.

$ msfconsole

Related posts

How to Create Metasploit Payload

neoslab

How to Use Metasploit for Beginners

neoslab

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Hey Wait!
Did you know ? You can build your Cyber security or IT career for FREE !
Make yourself happy, join our 8,000 members and receive FREE every day our latest tutorials and webinars to your mailbox!
Yes, Send it Over!
No Thanks!
close-link