Guide to Installing Metasploit 4 and Armitage on Mac OSX Lion

About Night Lion Security

Night Lion Security specializes in providing both government and private businesses with solutions to effectively manage risk and protect critical data. It is our mission to deploy tactical vulnerability identification capabilities which will allow our clients to rapidly respond and protect themselves against new and unknown cyber threats.

After many hours of trial and error, I have been able to put together a guide to getting Metasploit 4 and Armitage working properly on Mac OSX. I would also like to give a tremendous amount of credit to BrianCanFixIT @ Faulty Logic. His blog post on setting up Armitage helped me through the missing piece of getting the PostgreSQL database up and running properly.

Prerequisites

  1. Install XCode (I am running v4.2)

PostgreSQL Installation

  1. Download and Install PostgreSQL via the free GUI installer.
  2. Setup your root PostgreSQL password during installation.
  3. Launch the newly installed PGAdmin III application.
  4. Connect (double click) on the local PostgreSQL database and enter your root password when prompted.
  5. Under the PostgreSQL drop down, right click on “Login Roles”, and select “New Login Role”
  6. Set the role name to msfuser.
  7. Click on the definition tab, and set the password as msfpassword.
  8. Click OK to continue.
  9. Next, right click on the databases list, and select “New Database”.
  10. Set the name to metasploitdb, and set the owner to msfuser.
  11. Press OK, and we’re done. You can close PGAdmin.

MacPorts

  1. Download and install MacPorts from http://www.macports.org/install.php
  2. Good Tip: add “/opt/local” to your spotlight privacy settings to avoid excessive compile times & unnecessary indexing by spotlight.
    (System Preferences->Spotlight->Privacy->”+”)
  3. Quit terminal & relaunch to accept new path settings added by MacPorts

Install Ruby, RubyGems (PostgreSQL and MsgPack)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Run as Root
sudo bash
 
# Update MacPorts
port selfupdate
 
#Install Ruby
port install ruby19 +nosuffix
 
# Install PostgreSQL gem connector (64bit Systems)
env ARCHFLAGS='-arch x86_64' gem install pg -- --with-opt-include=/Library/PostgreSQL/9.1/include/ --with-opt-lib=/Library/PostgreSQL/9.1/lib/
 
#Install Ruby Msgpack
port install msgpack
 
#Install the gem MSGPACK
gem install msgpack
 
# Add Ruby to your path
export PATH=/opt/msf3:$PATH
 
# Ensure that /opt/local/bin appears before /usr/bin, else edit ~/.bash_profile file and source it
echo $PATH

Metasploit 4 Installation

1
2
3
4
5
6
7
# Download Metasploit via Subversion
sudo svn co https://www.metasploit.com/svn/framework3/trunk/ /opt/local/msf/
 
# Create a system link to the msf applications
# This is done because including it in your path configuration doesn't seem to work. 
 
sudo ln -s /opt/local/msf/msf* /opt/local/bin

Configure the Metasploit Database

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
# Create the configuration directory
sudo mkdir /opt/local/config
 
# Create/Edit the following file 
sudo vi /opt/local/config/database.yml
 
# Include the following in your database.yml file
 
# These settings are for the database used by the Metasploit Framework
# unstable tree included in this installer, not the commercial editions.
#
 
production:
  adapter: "postgresql"
  database: "metasploitdb"
  username: "msfuser"
  password: "msfpassword"
  port: 5432
  host: "localhost"
  pool: 256
  timeout: 5

Running Metasploit and Armitage

1
2
3
4
5
6
7
8
9
 
# Include the database location in your config
export MSF_DATABASE_CONFIG=/opt/local/config/database.yml
 
# Launch Metasploit
sudo msfrpcd -U msfuser2 -P msfpassword2 -t Msg
 
# Launch Armitage
sudo armitage

Enjoy!

  • Encrypto

    Can’t you just install Metasploit from Macports since it installs all the dependencies and doesn’t postgresql come already installed in Lion? I know that on the Rapid seven site they give these instructions here to install…. a little different…..https://community.rapid7.com/docs/DOC-1037

    • NightLion

       There doesn’t seem to be a direct download for Mac OSX.

  • S

    I followed all of the steps and it seems to work but I am hitting a vague and random error.

    This ring a bell?

    msf > db_nmap localhost
    [*] Nmap: Starting Nmap 5.51 ( http://nmap.org ) at 2012-01-18 12:48 PST
    [*] Nmap: Nmap scan report for localhost (127.0.0.1)
    [*] Nmap: Host is up (0.000027s latency).
    [*] Nmap: Not shown: 997 closed ports
    [*] Nmap: PORT STATE SERVICE
    [*] Nmap: 22/tcp open ssh
    [*] Nmap: 631/tcp open ipp
    [*] Nmap: 5432/tcp open postgresql
    [*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 5.47 seconds
    [-] Error while running command db_nmap: (): couldn’t parse YAML at line 17 column 14

    I have searched a bit but all I can find reference to is something possible with encodings being off.

    Any ideas?

  • Etoiles

    I successful followed all the steps but at the, whle looking forward enjoying metasploit I got this error message “sudo: msfrpcd: command not found”
    does somebody have any Idea what is the problem and I can solve it?

    Etoiles

  • Etoiles

    I successful followed all the steps but at the End, while looking forward enjoying metasploit I got this error message “sudo: msfrpcd: command not found”
    does somebody have any Idea what is the problem and I can solve it?
    Etoiles

    • http://www.nightlion.net NightLion

      Are you typing sudo: or sudo? There should not be a colon. If you type msfrpcd at the command prompt and nothing happens, then metasploit is not in your environment path. “sudo ln -s /opt/local/msf/msf* /opt/local/bin” should do the trick for you. Alternatively, edit your .bash_profile file and add the path to your MSF installation.

  • Witik

    when running msfrpcd, after a few seconds I get this error:

    /opt/local/msf/lib/rex/socket/comm/local.rb:197:in `rescue in create_by_type’: The address is already in use (0.0.0.0:55553). (Rex::AddressInUse)
    from /opt/local/msf/lib/rex/socket/comm/local.rb:191:in `create_by_type’
    from /opt/local/msf/lib/rex/socket/comm/local.rb:32:in `create’
    from /opt/local/msf/lib/rex/socket.rb:46:in `create_param’
    from /opt/local/msf/lib/rex/socket/tcp_server.rb:38:in `create_param’
    from /opt/local/msf/lib/rex/socket/tcp_server.rb:28:in `create’
    from /opt/local/msf/lib/rex/proto/http/server.rb:134:in `start’
    from /opt/local/msf/lib/rex/service_manager.rb:80:in `start’
    from /opt/local/msf/lib/rex/service_manager.rb:24:in `start’
    from /opt/local/msf/lib/msf/core/rpc/v10/service.rb:59:in `start’
    from /opt/local/msf/plugins/msgrpc.rb:97:in `run’
    from /opt/local/bin/msfrpcd:110:in `’

    also, when I start armitage, and I fill in the fields and click connect, it says:

    org.postgresql.util.PSQLException: ERROR: relation “workspaces” does not exist
    Position: 24

  • Cypher

    I have the same issue as Witik. When I try to run Metasploit I get this message about 5 seconds later:

    /opt/local/msf/lib/rex/socket/comm/local.rb:197:in `rescue in create_by_type’: The address is already in use (0.0.0.0:55553). (Rex::AddressInUse)
    from /opt/local/msf/lib/rex/socket/comm/local.rb:191:in `create_by_type’
    from /opt/local/msf/lib/rex/socket/comm/local.rb:32:in `create’
    from /opt/local/msf/lib/rex/socket.rb:46:in `create_param’
    from /opt/local/msf/lib/rex/socket/tcp_server.rb:38:in `create_param’
    from /opt/local/msf/lib/rex/socket/tcp_server.rb:28:in `create’
    from /opt/local/msf/lib/rex/proto/http/server.rb:134:in `start’
    from /opt/local/msf/lib/rex/service_manager.rb:80:in `start’
    from /opt/local/msf/lib/rex/service_manager.rb:24:in `start’
    from /opt/local/msf/lib/msf/core/rpc/v10/service.rb:59:in `start’
    from /opt/local/msf/plugins/msgrpc.rb:97:in `run’
    from /opt/local/bin/msfrpcd:110:in `’

    Then when I try to run Armitage and fill in the details I get:
    org.postgresql.util.PSQLException: ERROR: relation “workspaces” does not exist
    Position: 24

    If someone could give me a hand would be great!

    Thanks

  • Cypher

    Ok, the errors I talked about before are not there anymore. Seems like the first one about running metasploit was caused by the fact that metasploit was already running (reboot your mac and run the command again, then you won’t get the error mentioned).

    The second error is not there anymore either, after creating a link to the armitage tool like this:
    sudo ln -s /opt/local/msf/armitage /opt/local/bin

    Then “sudo armitage” works and I can put in the details, only now I get to see a popup window with the same msg as before:
    Could not connect to database,

    org.postgresql.util.PSQLException: ERROR: relation “workspaces” does not exist
    Position: 24

    Any ideas?

    • http://www.nightlion.net NightLion

      Try running MSFCONSOLE or MSFGUI first. That might create the initial workspace.

      • Manu

        i have the same problem. And i first run the console, and also use it.

        but with armitage i get that error.

  • Witik

    Cool, that fixed that issue, tnx! :D

    but now after trying an nmap scan I get

    “[-] The nmap executable could not be found”

    -.-’

  • freddys6

    I try my best doing all the steps, then i get this while loading

    javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

    nothing happens after that.

    any idea what’s going on?

  • Adam

    When i try to install Ruby i have this error message :

    Error: Requested variants “+doc+nosuffix” do not match original selection “+doc”.Please use the same variants again, perform ‘port clean ruby19′ or specify the force option (-f).Error: Status 1 encountered during processing.

  • Ashish Bhangale

    @ Night Lion Security
    Awesome, Nice work Keep it up ..
    And i learned lots of things from this video http://www.securitytube.net/video/2750 maybe you like it. vivek done a fantastic job. must watch.