Thursday, February 6, 2014

How to Install Metasploit on Mavericks 10.9.1 (in 2014)

I've been struggling with getting Metasploit installed in my Mavericks (10.9.1) based MacBook Pro. The instructions I found weren't lining up with my experience, so I thought I'd write up my experience and how I was able to get it installed.

My instructions are from my experience, but I got a lot of help from resources such as DarkOperator's instructions here:

http://www.darkoperator.com/installing-metasploit-framewor/

He developed a script to a bunch of this work for you, however, I haven't tried it. I noticed that it is using an older version of ruby in the 1.9.3 tree.
https://github.com/darkoperator/MSF-Installer/blob/master/msf_install.sh

1. Install Xcode on Mavericks 10.9.1

Go to https://developer.apple.com/xcode/ to download and install. Move to Step #2, unless you want to read through my experience.

Other sites will tell you to install the command line tools by using the command line (don't do this yet):

xcode-select --install

When you do this, it looks promising:


But it will eventually fail with the following message:

"Can't install the software because it is not currently available from the Software Update server."

Other sites will also tell you that you need to check the "Command Line Tools" box in the XCode Preferences/Downloads tab. Notice it doesn't exist in XCode 5.


Turns out, you don't need to install the command line tools, as they're included with XCode 5 (reading comments from this thread: http://www.computersnyou.com/2025/2013/06/install-command-line-tools-in-osx-10-9-mavericks-how-to/) . Verify they're installed by checking for gcc and g++.



CGMbPR:~ cgrant$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
CGMbPR:~ cgrant$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0


Thread model: posix

2. Install homebrew.

The install URL for homebrew has been updated, so use this on the command line:


ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"


I did the following, so you don't have to. If you tried to use the URL listed on many other guides, you'd see this:



CGMbPR:~ cgrant$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
-e:6: syntax error, unexpected '<'
 ^
-e:7: syntax error, unexpected '<'
 ^
-e:9: syntax error, unexpected '<'
   
     ^
-e:10: syntax error, unexpected '<'
   
     ^
-e:10: syntax error, unexpected tIDENTIFIER, expecting end-of-input
   
                                              ^


3. Install wget (and git, maybe?)

Run this on the command line (no sudo required):

brew install wget

I had installed the full installer for Mac OSX for the native Github client prior to starting this install, which I believe installed the command line versions of git, so I didn't actually run the brew version. I also didn't change the path to make the /usr/local/bin versions come first in the search path. It doesn't seem to have caused any issues yet. So, I didn't install brew-managed git, but if you wanted to or hadn't installed git yet you should execute this:

brew install git


4. Install Ruby Version Manager (rvm) and ruby 2.1.0, apparently

Run this on the command line (no sudo required):

\curl -#L https://get.rvm.io | bash -s stable --autolibs=3 --ruby

This is what it looked like for me:



CGMbPR:~ cgrant$ \curl -#L https://get.rvm.io | bash -s stable --autolibs=3 --ruby
######################################################################## 100.0%
Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz

Installing RVM to /Users/cgrant/.rvm/
    Adding rvm PATH line to /Users/cgrant/.profile /Users/cgrant/.bashrc /Users/cgrant/.zshrc.
    Adding rvm loading line to /Users/cgrant/.bash_profile /Users/cgrant/.zlogin.
Installation of RVM in /Users/cgrant/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/cgrant/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# Chris Grant,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: http://rvm.io/help and https://twitter.com/rvm_io

rvm 1.25.15 (stable) by Wayne E. Seguin , Michal Papis [https://rvm.io/]

Searching for binary rubies, this might take some time.
Found remote file https://rvm.io/binaries/osx/10.9/x86_64/ruby-2.1.0.tar.bz2
Checking requirements for osx.
Installing requirements for osx.
Updating system.
Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba.....
Certificates in '/usr/local/etc/openssl/cert.pem' already are up to date.
Requirements installation successful.
ruby-2.1.0 - #configure
ruby-2.1.0 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 9475k  100 9475k    0     0   661k      0  0:00:14  0:00:14 --:--:-- 1346k
ruby-2.1.0 - #validate archive
ruby-2.1.0 - #extract
ruby-2.1.0 - #validate binary
ruby-2.1.0 - #setup
ruby-2.1.0 - #making binaries executable.
ruby-2.1.0 - #downloading rubygems-2.2.1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  401k  100  401k    0     0   215k      0  0:00:01  0:00:01 --:--:--  215k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.1.0 - #extracting rubygems-2.2.1.
ruby-2.1.0 - #removing old rubygems.
ruby-2.1.0 - #installing rubygems-2.2.1............
ruby-2.1.0 - #gemset created /Users/cgrant/.rvm/gems/ruby-2.1.0@global
ruby-2.1.0 - #importing gemset /Users/cgrant/.rvm/gemsets/global.gems.....
ruby-2.1.0 - #generating global wrappers.
ruby-2.1.0 - #gemset created /Users/cgrant/.rvm/gems/ruby-2.1.0
ruby-2.1.0 - #importing gemsetfile /Users/cgrant/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.1.0 - #generating default wrappers.
Updating certificates in '/etc/openssl/cert.pem'.
mkdir: /etc/openssl: Permission denied
cgrant password required for 'mkdir -p /etc/openssl': 
Creating alias default for ruby-2.1.0.
Recording alias default for ruby-2.1.0.
Creating default links/files

  * To start using RVM you need to run `source /Users/cgrant/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.


CGMbPR:~ cgrant$ source /Users/cgrant/.rvm/scripts/rvm


5. Install the rest of ruby

This first step took quite a while.
rvm requirements

Here's what it looked like for me:


The guide I was looking at suggested I run the following, which I did.


brew install autoconf automake libtool libyaml readline libksba openssl

Everything was installed already.



The next step was to run this command:

rvm install ruby-1.9.3-p392

I skipped this step because it looked like ruby-2.1.0 was installed earlier. (**Turns out ruby-1.9.3 is required for metasploit, although this isn't the most current version. I cover this later.**)

rvm gemset create msf



Other sites would have you run the following command, but looks like I have 2.1.0 installed so I modified it appropriately.

Unused:

rvm use ruby-1.9.3-p392@msf --default

Changed, used:
rvm use ruby-2.1.0@msf --default




Verify the install with the following command:
ruby -v



6. Installing metasploit

So, I did the following:

sudo su
cd /opt
git clone https://github.com/rapid7/metasploit-framework.git msf


CGMbPR:~ cgrant$ sudo su
sh-3.2# cd /opt
sh-3.2# git clone https://github.com/rapid7/metasploit-framework.git msf
Cloning into 'msf'...
remote: Reusing existing pack: 232980, done.
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 232985 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (232985/232985), 198.63 MiB | 436.00 KiB/s, done.
Resolving deltas: 100% (163073/163073), done.
Checking connectivity... done

Checking out files: 100% (6515/6515), done.


7. "bundle install" - ruby gems

As I understand it, running bundle install installs the necessary ruby gems. This didn't work for me out of the gate.

 

This is the error you get when you don't have Postgresql installed first.

8) Install and Configure Postgresql

brew install postgresql --without-ossp-uuid


As it told me to do, I ran the link command to start postgresql on login:


ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

I then fired up postgresql

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

You then need to create a user for metasploit to use for the database:

createuser msf -P -h localhost

Then create a database called msf with msf as the owner

createdb -O msf msf -h localhost



9) Finish the ruby gems needed for metasploit to function

Then we need to finish with the gems metasploit needs to use.

gem install pg sqlite3 msgpack activerecord redcarpet rspec simplecov yard bundler





A little while later...


10) Linking metasploit to Postgres


First edit the Postgres configuration file:

sudo vi /opt/msf/config/database.yml


Add the following to the file and save

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


11) making sure the shell environment is set up

source /etc/profile
source ~/.bash_profile

12) executing Metasploit, or so I thought

/opt/msf isnt' in my path so I'll execute it from the directory

I changed directories and it tells me ruby-1.9.3-p484 isn't installed


13) installing ruby-1.9.3-p484


Well, I'll see if I can take the shortcut route and just install ruby 1.9.3-p484 even though ruby-2.1.0 was installed earlier.

rvm install ruby-1.9.3-p484


14) execute msfconsole again...bundle install



Okay, so now one of the gems isn't installed.

Executing

bundle install



15) Okay, executing msfconsole again...and it worked!



It worked! I freaked out a little first, then I realized that this was by design. All good!

Just to make sure...execute msfconsole again:


SUCCESS!!!

Okay, maybe that was just a fluke:

Execute msfconsole again:


Looks like its working...



No comments:

Post a Comment