Thursday, May 29, 2014

How to resolve factory girl 4.2.0 conflict with ruby 1.9.2 during metasploit framework installation





  In this post,I'm going to share one of the problem that I face during the installation of Metasploit framework from Github on my system .You can check my full installation post here .

Before I go into details. please find below program term and short explanation that is used associated with Ruby.Please click the link for more information.

bundler =Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed .Please check it out here


gems=RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of gems, and a server for distributing them. Please refer here for details



rbenv = rbenv is  a program to pick a Ruby version for your application and guarantee that your development environment matches production .Please refer here for more information .


This problem happen when I want to install the required gems and related version to make it work on my system


factory girl (4.2.0) error
--------------------------------
shark_attack@Positive-Space:/opt/metasploit-framework$ sudo bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
Using rake (10.1.0)
Using i18n (0.6.5)
Using multi_json (1.0.4)
Using activesupport (3.2.14)
Using builder (3.0.4)
Using activemodel (3.2.14)
Using arel (3.0.2)
Using tzinfo (0.3.37)
Using activerecord (3.2.14)
Using bcrypt-ruby (3.1.2)
Using database_cleaner (1.1.1)
Using diff-lcs (1.2.4)
Gem::InstallError: factory_girl requires Ruby version >= 1.9.2.
An error occurred while installing factory_girl (4.2.0), and Bundler cannot continue.
Make sure that `gem install factory_girl -v '4.2.0'` succeeds before bundling.
shark_attack@Positive-Space:/opt/metasploit-framework$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]
shark_attack@Positive-Space:/opt/metasploit-framework$ gem -v
1.8.11
shark_attack@Positive-Space:/opt/metasploit-framework$ clear


  factory girl require ruby version 1.9.2 while on my system I use ruby version 1.9.3 . After a quick run through the online manual, I found out that the need to rehash  ruby to make it work with my system. Below are steps on how I do it.


Steps summary



1)Install gem bundler
2)Install rbenv

3)rehash ruby
4)bundle install


Steps


1)Install gem bundler.


shark_attack@Positive-Space:/opt/metasploit-framework$ sudo bundle install 
shark_attack@Positive-Space:/opt/metasploit-framework$ sudo gem install bundler
Fetching: bundler-1.5.3.gem (100%)
Successfully installed bundler-1.5.3
1 gem installed
Installing ri documentation for bundler-1.5.3...
Installing RDoc documentation for bundler-1.5.3...
shark_attack@Positive-Space:/opt/metasploit-framework$ rbenv rehash
The program 'rbenv' is currently not installed.  To run 'rbenv' please ask your administrator to install the package 'rbenv'


2)Install rbenv

shark_attack@Positive-Space:/opt/metasploit-framework$

shark_attack@Positive-Space:/opt/metasploit-framework$ sudo apt-get install rbenv
Reading package lists... Done
Building dependency tree   
Reading state information... Done
The following NEW packages will be installed:
  rbenv
0 to upgrade, 1 to newly install, 0 to remove and 2 not to upgrade.
Need to get 15.3 kB of archives.
After this operation, 79.9 kB of additional disk space will be used.
Get:1 http://au.archive.ubuntu.com/ubuntu/ precise/universe rbenv all 0.1.2+git20100922-1 [15.3 kB]
Fetched 15.3 kB in 0s (22.7 kB/s)
Selecting previously unselected package rbenv.
(Reading database ... 275787 files and directories currently installed.)
Unpacking rbenv (from .../rbenv_0.1.2+git20100922-1_all.deb) ...
Processing triggers for man-db ...
Setting up rbenv (0.1.2+git20100922-1) ...
shark_attack@Positive-Space:/opt/metasploit-framework$ clear


3)rehash ruby

shark_attack@Positive-Space:/opt/metasploit-framework$rbenv rehash


4)Run bundle install

shark_attack@Positive-Space:/opt/metasploit-framework$
shark_attack@Positive-Space:/opt/metasploit-framework$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
/var/lib/gems/1.9.1/gems/bundler-1.5.3/lib/bundler.rb:295: warning: Insecure world writable dir /home/shark_attack in PATH, mode 040766
Installing rake (10.1.0)
Installing i18n (0.6.5)
Installing multi_json (1.0.4)
Installing activesupport (3.2.14)
Installing builder (3.0.4)
Installing activemodel (3.2.14)
Installing arel (3.0.2)
Installing tzinfo (0.3.37)
Installing activerecord (3.2.14)
Installing bcrypt-ruby (3.1.2)
Installing database_cleaner (1.1.1)
Installing diff-lcs (1.2.4)
Installing factory_girl (4.2.0)
Installing fivemat (1.2.1)
Installing json (1.8.0)
Installing pg (0.16.0)
Installing metasploit_data_models (0.16.9)
Installing mini_portile (0.5.1)
Installing msgpack (0.5.5)
Installing network_interface (0.0.1)
Installing nokogiri (1.6.0)
Installing packetfu (1.1.9)
Installing pcaprub (0.11.3)
Installing redcarpet (3.0.0)
Installing robots (0.10.1)
Installing rspec-core (2.14.5)
Installing rspec-expectations (2.14.2)
Installing rspec-mocks (2.14.3)
Installing rspec (2.14.1)
Installing shoulda-matchers (2.3.0)
Installing simplecov-html (0.5.3)
Installing simplecov (0.5.4)
Installing timecop (0.6.3)
Installing yard (0.8.7)
Using bundler (1.5.3)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
shark_attack@Positive-Space:/opt/metasploit-framework$ clear






Wednesday, May 28, 2014

How to install metasploit framework from Github on Ubuntu



   In this post, I'm going to share How to install metasploit framework from Github on Ubuntu 12.04.Some reference of installing metasploit,I got from here. I have added some steps which I think will make it more easier than the published post.


 The installation process doesn't go well for me as my system have some compatibility issue as you will see in the video .I will do a separate post on it. Below are steps taken to do the installation


Steps summary

1) Update system
2) Install metasploit dependencies
3) (OPTIONAL) Install nmap
4) Download metasploit framework from Github
5) Install gems and version required by metasploit
6) Run metasploit framework
7) Create and connect the database with metasploit
8) Test and optimize metasploit search function
9) Add the  metasploit folder to your system environment


Steps


1)Update and upgrade system

1.1)update system
shark_attack@Positive-Space:~$sudo apt-get update


update system
 1.2)upgrade system
shark_attack@Positive-Space:~$sudo apt-get update

upgrade system


 2)Install  metasploit required dependencies

2.1)Install Ruby 1.9.3 and other dependencies

shark_attack@Positive-Space:~$sudo apt-get install build-essential libreadline-dev libssl-dev libpq5 libpq-dev libreadline5 libsqlite3-dev libpcap-dev openjdk-7-jre subversion git-core autoconf postgresql pgadmin3 curl zlib1g-dev libxml2-dev libxslt1-dev vncviewer libyaml-dev ruby1.9.3

Install Ruby dependencies


 2.2) Install Ruby libraries that metasploit depend on

 shark_attack@Positive-Space:~$sudo gem install wirble sqlite3 bundler


Install Ruby libraries that metasploit depend

 3)(OPTIONAL) Install nmap
Install NMAP if you still don't use one on your system

 shark_attack@Positive-Space:~$sudo apt-get install nmap


Install nmap
4)Download metasploit framework from Github to your system


 shark_attack@Positive-Space:~$cd /opt
 shark_attack@Positive-Space:~$git clone https://github.com/rapid7/metasploit-framework.git


Dowloading metasploit framework to /opt

 5) Install gems and version required by metasploit.
After finish downloading, go to metasploit folder

shark_attack@Positive-Space:~$cd /opt/metasploit-framework
shark_attack@Positive-Space:/opt/metasploit-framework$sudo bundle install

go to metasploit folder

install bundle
 NOTE: My system have problem installing the gems . It trigger  "girl friday" error as shown in the video. Please check my next post on how I resolve it .I will not share details how to do it in this post .You can see it in this video though :-)

 6)Run metasploit framework .
It might take few minutes for first time loading .

 shark_attack@Positive-Space:~$./msfconsole


run metasploit


Metasploit
 7)Create and connect the database with metasploit

7.1)Create user and postgres database . Make sure you remember what you type in when you create the user and database information.


shark_attack@Positive-Space:~$su -s
root@Positive-Space:~$su postgres
postgres@Positive-Space:/home/shark_attack$ createuser msf -P -S -R -D
postgres@Positive-Space:/home/shark_attack$ createdb -0 msf msf


creating user and db information


7.2)Connect database . msf4 folder will be in your home folder after you run metasploit for the first time.
Go to ./msf4 folder

shark_attack@Positive-Space:~$cd .msf4 
shark_attack@Positive-Space:~/.msf4$


.msf4 folder


7.3)Create a file name "database.yml" and key in the  detail informations that you have created before .Make sure all the details are correct including the password.

shark_attack@Positive-Space:~/.msf4$nano database.yml


 key in your database and user detail as how you configured .




adapter: postgresql

database: msf

password: shark_attack

username: msf

pool: 75

host: 127.0.0.1
port: 5432

timeout: 5







type the db and user info
save it

database.yml in msf4 folder



8)Test  and optimize metasploit search function


8.1)run metasploit framework  from your console and check the database status once it finish load .Remember to run as sudo . It might take few minutes to load the first time

shark_attack@Positive-Space:/opt/metasploit-framework$ sudo ./msfconsole



msf>db_status


checking database status


8.2) This step is just something that I notice doesn't work on my system in which ,whenever I  try to use the search  on metasploit, it will give an error  "Database not connected or cache not built,using slow search" .  It took few minutes to search anything.To resolve this issue, I rebuild the db cache by typing below command .

msf>db_rebuild_cache

Database not connected or cache not built


rebuilding the cache



That's it for today. If you are looking on how to install Kali Linux in Ubuntu ,please visit here.