Advertisement
opexxx

msf_install.sh

Feb 23rd, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 31.42 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. KVER=`uname -a`
  4. # Variable to know if Homebrew should be installed
  5. MSFPASS=`openssl rand -hex 16`
  6. #Variable with time of launch used for log names
  7. NOW=$(date +"-%b-%d-%y-%H%M%S")
  8. IGCC=1
  9. INSTALL=1
  10. RVM=1
  11.  
  12. function print_good ()
  13. {
  14.     echo -e "\x1B[01;32m[*]\x1B[0m $1"
  15. }
  16. ########################################
  17.  
  18. function print_error ()
  19. {
  20.     echo -e "\x1B[01;31m[*]\x1B[0m $1"
  21. }
  22. ########################################
  23.  
  24. function print_status ()
  25. {
  26.     echo -e "\x1B[01;34m[*]\x1B[0m $1"
  27. }
  28. ########################################
  29.  
  30. function check_root
  31. {
  32.     if [ "$(id -u)" != "0" ]; then
  33.         print_error "This step must be ran as root"
  34.         exit 1
  35.     fi
  36. }
  37. ########################################
  38.  
  39. function install_armitage_osx
  40. {
  41.     if [ -e /usr/bin/curl ]; then
  42.         print_status "Downloading latest version of Armitage"
  43.         echo "---- Downloading the latest version of Armitage ---" >> $LOGFILE 2>&1
  44.         curl -# -o /tmp/armitage.tgz http://www.fastandeasyhacking.com/download/armitage-latest.tgz && print_good "Finished"
  45.         if [ $? -eq 1 ] ; then
  46.             echo "---- Failed to download the latest version of armitage ----" >> $LOGFILE 2>&1
  47.             print_error "Failed to download the latest version of Armitage make sure you"
  48.             print_error "are connected to the internert and can reach http://www.fastandeasyhacking.com"
  49.             return 1
  50.         else
  51.             print_status "Decompressing package to /usr/local/share/armitage"
  52.             echo "---- Decompressing the latest version of Armitage ----" >> $LOGFILE 2>&1
  53.             tar -xvzf /tmp/armitage.tgz -C /usr/local/share >> $LOGFILE 2>&1
  54.         if [ $? -eq 1 ] ; then
  55.             print_error "Was unable to decompress the latest version of Armitage"
  56.             echo "---- Decompression of Armitage failed ----" >> $LOGFILE 2>&1
  57.             return 1
  58.         fi
  59.     fi
  60.  
  61.     # Check if links exists and if they do not create them
  62.     if [ ! -e /usr/local/bin/armitage ]; then
  63.         print_status "Creating link for Armitage in /usr/local/bin/armitage"
  64.         echo "---- Creating launch script for Armitage and linking it ----" >> $LOGFILE 2>&1
  65.         sh -c "echo java -jar /usr/local/share/armitage/armitage.jar \$\* > /usr/local/share/armitage/armitage"
  66.         if [ $? -eq 1 ] ; then
  67.             print_error "Failed to create Armitage launch script"
  68.             return 1
  69.         fi
  70.         ln -s /usr/local/share/armitage/armitage /usr/local/bin/armitage
  71.         if [ $? -eq 1 ] ; then
  72.             print_error "Failed to link Armitage launch script"
  73.             return 1
  74.         fi
  75.     else
  76.     print_good "Armitage is already linked to /usr/local/bin/armitage"
  77.     sh -c "echo java -jar /usr/local/share/armitage/armitage.jar \$\* > /usr/local/share/armitage/armitage"
  78.     fi
  79.         if [ ! -e /usr/local/bin/teamserver ]; then
  80.             print_status "Creating link for Teamserver in /usr/local/bin/teamserver"
  81.             ln -s /usr/local/share/armitage/teamserver /usr/local/bin/teamserver
  82.             perl -pi -e 's/armitage.jar/\/usr\/local\/share\/armitage\/armitage.jar/g' /usr/local/share/armitage/teamserver
  83.         else
  84.             print_good "Teamserver is already linked to /usr/local/bin/teamserver"
  85.             perl -pi -e 's/armitage.jar/\/usr\/local\/share\/armitage\/armitage.jar/g' /usr/local/share/armitage/teamserver
  86.         fi
  87.         print_good "Finished"
  88.     fi
  89. }
  90. ########################################
  91.  
  92. function check_for_brew_osx
  93. {
  94.     print_status "Verifying that Homebrew is installed:"
  95.     if [ -e /usr/local/bin/brew ]; then
  96.         print_good "Homebrew is installed on the system, updating formulas."
  97.         /usr/local/bin/brew update >> $LOGFILE 2>&1
  98.         print_good "Finished updating formulas"
  99.         brew tap homebrew/versions >> $LOGFILE 2>&1
  100.         print_status "Verifying that the proper paths are set"
  101.  
  102.         if [ -d ~/.bash_profile ]; then
  103.             if [ "$(grep ":/usr/local/sbin" ~/.bash_profile -q)" ]; then
  104.                 print_good "Paths are properly set"
  105.             else
  106.                 print_status "Setting the path for homebrew"
  107.                 echo PATH=/usr/local/bin:/usr/local/sbin:$PATH >> ~/.bash_profile
  108.                 source  ~/.bash_profile
  109.             fi
  110.         else
  111.             echo PATH=/usr/local/bin:/usr/local/sbin:$PATH >> ~/.bash_profile
  112.             source  ~/.bash_profile
  113.         fi
  114.     else
  115.  
  116.         print_status "Installing Homebrew"
  117.         /usr/bin/ruby -e "$(curl -fsSkL raw.github.com/Homebrew/homebrew/go/install)"
  118.         if [ "$(grep ":/usr/local/sbin" ~/.bash_profile -q)" ]; then
  119.             print_good "Paths are properly set"
  120.         else
  121.             print_status "Setting the path for homebrew"
  122.             echo PATH=/usr/local/bin:/usr/local/sbin:$PATH >> ~/.bash_profile
  123.             source  ~/.bash_profile
  124.         fi
  125.     fi
  126. }
  127. ########################################
  128.  
  129. function check_dependencies_osx
  130. {
  131.     # Get a list of all the packages installed on the system
  132.     PKGS=`pkgutil --pkgs`
  133.     print_status "Verifying that Development Tools and Java are installed:"
  134.     if [[ $PKGS =~ 'com.apple.pkg.JavaForMacOSX' || $PKGS =~ com.oracle.jdk* ]] ; then
  135.         print_good "Java is installed."
  136.     else
  137.         print_error "Java is not installed on this system."
  138.         print_error "Run the command java in Terminal and install Java"
  139.         exit 1
  140.     fi
  141.  
  142.     if [[ $PKGS =~ com.apple.pkg.XcodeMAS ]] ; then
  143.         print_good "Xcode is installed."
  144.     else
  145.         print_error "Xcode is not installed on this system. Install from the Apple AppStore."
  146.         exit 1
  147.     fi
  148.  
  149.     if [[ $PKGS =~ com.apple.pkg.DeveloperToolsCLI || $PKGS =~ com.apple.pkg.CLTools_Executables ]] ; then
  150.         print_good "Command Line Development Tools is intalled."
  151.     else
  152.         print_error "Command Line Development Tools is not installed on this system."
  153.         exit 1
  154.     fi
  155. }
  156. ########################################
  157.  
  158. function install_ruby_osx
  159. {
  160.     print_status "Checking if Ruby 1.9.3 is installed, if not installing it."
  161.     if [ -d /usr/local/Cellar/ruby193 ] && [ -L /usr/local/bin/ruby ]; then
  162.         print_good "Correct version of Ruby is installed."
  163.     else
  164.         print_status "Installing Ruby 1.9.3"
  165.         brew tap homebrew/versions >> $LOGFILE 2>&1
  166.         brew install homebrew/versions/ruby193 >> $LOGFILE 2>&1
  167.         echo PATH=/usr/local/opt/ruby193/bin:$PATH >> ~/.bash_profile
  168.         source  ~/.bash_profile
  169.     fi
  170.     print_status "Installing the bundler and SQLite3 Gems"
  171.     gem install bundler sqlite3 >> $LOGFILE 2>&1
  172. }
  173. ########################################
  174.  
  175. function install_nmap_osx
  176. {
  177.     print_status "Checking if Nmap is installed, using Homebrew to install it if not."
  178.     if [ -d /usr/local/Cellar/nmap ] && [ -L /usr/local/bin/nmap ]; then
  179.         print_good "Nmap is installed."
  180.     else
  181.         print_status "Installing Nmap"
  182.         brew install nmap >> $LOGFILE 2>&1
  183.     fi
  184. }
  185. ########################################
  186.  
  187. function install_postgresql_osx
  188. {
  189.     print_status "Checking if PostgreSQL is installed, using Homebrew to install it if not."
  190.     echo "#### POSTGRESQL INSTALLATION ####" >> $LOGFILE 2>&1
  191.     if [ -d /usr/local/Cellar/postgresql ] && [ -L /usr/local/bin/postgres ]; then
  192.         print_good "PostgreSQL is installed."
  193.     else
  194.         print_status "Installing PostgreSQL"
  195.         echo "---- Installing PostgreSQL ----" >> $LOGFILE 2>&1
  196.         brew install postgresql --without-osso-uuid >> $LOGFILE 2>&1
  197.         if [ $? -eq 0 ]; then
  198.             echo "---- Installation of PostgreSQL successful----" >> $LOGFILE 2>&1
  199.             print_good "Installation of PostgreSQL was successful"
  200.             echo "---- Initiating the PostgreSQL Database ----" >> $LOGFILE 2>&1
  201.             print_status "Initiating postgres"
  202.             initdb /usr/local/var/postgres >> $LOGFILE 2>&1
  203.             if [ $? -eq 0 ]; then
  204.                 print_good "Database initiation was successful"
  205.                 echo "---- Initiation of PostgreSQL successful----" >> $LOGFILE 2>&1
  206.             fi
  207.  
  208.             # Getting the Postgres version so as to configure startup of the databse
  209.             PSQLVER=`psql --version | cut -d " " -f3`
  210.             echo "---- Postgres Version $PSQLVER ----" >> $LOGFILE 2>&1
  211.             print_status "Configuring the database engine to start at logon"
  212.             echo "---- Starting PostgreSQL Server ----" >> $LOGFILE 2>&1
  213.             pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start >> $LOGFILE 2>&1
  214.             mkdir -p ~/Library/LaunchAgents
  215.             ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
  216.             # Give enough time for the database to start for the first time
  217.             sleep 5
  218.             #launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  219.             print_status "Creating the MSF Database user msf with the password provided"
  220.             echo "---- Postgres Version $PSQLVER ----" >> $LOGFILE 2>&1
  221.             echo "---- Creating Metasploit DB user ----" >> $LOGFILE 2>&1
  222.             psql postgres -c "create role msf login password '$MSFPASS'" >> $LOGFILE 2>&1
  223.             if [ $? -eq 0 ]; then
  224.                 print_good "Metasploit Role named msf has been created."
  225.                 echo "---- Creation of Metasploit user was successful ----" >> $LOGFILE 2>&1
  226.             else
  227.                 print_error "Failed to create the msf role"
  228.                 echo "---- Creation of Metasploit user failed ----" >> $LOGFILE 2>&1
  229.             fi
  230.             print_status "Creating msf database and setting the owner to msf user"
  231.             echo "---- Creating Metasploit Database and assigning the role ----" >> $LOGFILE 2>&1
  232.              createdb -O msf msf -h localhost >> $LOGFILE 2>&1
  233.             if [ $? -eq 0 ]; then
  234.                 print_good "Metasploit Databse named msf has been created."
  235.                 echo "---- Database creation was successful ----" >> $LOGFILE 2>&1
  236.             else
  237.                 print_error "Failed to create the msf database."
  238.                 echo "---- Database creation failed ----" >> $LOGFILE 2>&1
  239.             fi
  240.         fi
  241.     fi
  242. }
  243. ########################################
  244.  
  245. function install_msf_osx
  246. {
  247.     print_status "Installing Metasploit Framework from the GitHub Repository"
  248.     if [[ ! -d /usr/local/share/metasploit-framework ]]; then
  249.         print_status "Cloning latest version of Metasploit Framework"
  250.         git clone https://github.com/rapid7/metasploit-framework.git /usr/local/share/metasploit-framework >> $LOGFILE 2>&1
  251.         print_status "Linking Metasploit commands."
  252.         cd /usr/local/share/metasploit-framework
  253.         for MSF in $(ls msf*); do
  254.             print_status "linking $MSF command"
  255.         ln -s /usr/local/share/metasploit-framework/$MSF /usr/local/bin/$MSF
  256.         done
  257.         print_status "Creating Database configuration YAML file."
  258.         echo 'production:
  259. adapter: postgresql
  260. database: msf
  261. username: msf
  262. password: $MSFPASS
  263. host: 127.0.0.1
  264. port: 5432
  265. pool: 75
  266. timeout: 5' > /usr/local/share/metasploit-framework/database.yml
  267.         print_status "setting environment variable in system profile. Password will be requiered"
  268.         sudo sh -c "echo export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml >> /etc/profile"
  269.         echo "export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml" >> ~/.bash_profile
  270.         source /etc/profile
  271.         source ~/.bash_profile
  272.         cd /usr/local/share/metasploit-framework
  273.         if [[ $RVM -eq 0 ]]; then
  274.             print_status "Installing required ruby gems by Framework using bundler on RVM Ruby"
  275.             ~/.rvm/bin/rvm 1.9.3 do bundle install  >> $LOGFILE 2>&1
  276.         else
  277.             print_status "Installing required ruby gems by Framework using bundler on System Ruby"
  278.             bundle install  >> $LOGFILE 2>&1
  279.         fi
  280.         print_status "Starting Metasploit so as to populate the database."
  281.         if [[ $RVM -eq 0 ]]; then
  282.             ~/.rvm/bin/rvm 1.9.3 do ruby /usr/local/share/metasploit-framework/msfconsole -q -x "exit" >> $LOGFILE 2>&1
  283.         else
  284.             /usr/local/share/metasploit-framework/msfconsole -q -x "exit" >> $LOGFILE 2>&1
  285.             print_status "Finished Metasploit installation"
  286.         fi
  287.     else
  288.         print_status "Metasploit already present."
  289.     fi
  290. }
  291. ########################################
  292.  
  293. function install_plugins_osx
  294. {
  295.     print_status "Installing additional Metasploit plugins"
  296.     print_status "Installing Pentest plugin"
  297.     curl -# -o /usr/local/share/metasploit-framework/plugins/pentest.rb https://raw.github.com/darkoperator/Metasploit-Plugins/master/pentest.rb
  298.     if [ $? -eq 0 ]; then
  299.         print_good "The pentest plugin has been installed."
  300.     else
  301.         print_error "Failed to install the pentest plugin."
  302.     fi
  303.     print_status "Installing DNSRecon Import plugin"
  304.     curl -# -o /usr/local/share/metasploit-framework/plugins/dnsr_import.rb https://raw.github.com/darkoperator/dnsrecon/master/msf_plugin/dnsr_import.rb
  305.     if [ $? -eq 0 ]; then
  306.         print_good "The dnsr_import plugin has been installed."
  307.     else
  308.         print_error "Failed to install the dnsr_import plugin."
  309.     fi
  310. }
  311. #######################################
  312.  
  313. function install_deps_deb
  314. {
  315.     print_status "Installing dependencies for Metasploit Framework"
  316.     sudo apt-get -y update  >> $LOGFILE 2>&1
  317.     sudo apt-get -y 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 sqlite3 libgdbm-dev libncurses5-dev libtool bison libffi-dev>> $LOGFILE 2>&1
  318.     if [ $? -eq 1 ] ; then
  319.         echo "---- Failed to download and install dependencies ----" >> $LOGFILE 2>&1
  320.         print_error "Failed to download and install the dependencies for running Metasploit Framework"
  321.         print_error "Make sure you have the proper permissions and able to download and install packages"
  322.         print_error "for the distribution you are using."
  323.         exit 1
  324.     fi
  325.     print_status "Finished installing the dependencies."
  326.     print_status "Installing base Ruby Gems"
  327.     sudo gem install wirble sqlite3 bundler >> $LOGFILE 2>&1
  328.     if [ $? -eq 1 ] ; then
  329.         echo "---- Failed to download and install base Ruby Gems ----" >> $LOGFILE 2>&1
  330.         print_error "Failed to download and install Ruby Gems for running Metasploit Framework"
  331.         exit 1
  332.     fi
  333.     print_status "Finished installing the base gems."
  334. }
  335. #######################################
  336.  
  337. function install_nmap_linux
  338. {
  339.     if [[ ! -e /usr/local/bin/nmap ]]; then
  340.         print_status "Downloading and Compiling the latest version of Nmap"
  341.         print_status "Downloading from SVN the latest version of Nmap"
  342.         cd /usr/src
  343.         echo "---- Downloading the latest version of NMap via SVN ----" >> $LOGFILE 2>&1
  344.         sudo svn co https://svn.nmap.org/nmap >> $LOGFILE 2>&1
  345.     if [ $? -eq 1 ] ; then
  346.         print_error "Failed to download the latest version of Nmap"
  347.         return 1
  348.     fi
  349.     cd nmap
  350.     print_status "Configuring Nmap"
  351.     echo "---- Configuring Nmap settings ----" >> $LOGFILE 2>&1
  352.     sudo ./configure >> $LOGFILE 2>&1
  353.     print_status "Compiling the latest version of Nmap"
  354.     echo "---- Compiling NMap from source ----" >> $LOGFILE 2>&1
  355.     sudo make >> $LOGFILE 2>&1
  356.     if [ $? -eq 1 ] ; then
  357.         print_error "Failed to compile Nmap"
  358.         return 1
  359.     fi
  360.     print_status "Installing the latest version of Nmap"
  361.     echo "---- Installing Nmap ----" >> $LOGFILE 2>&1
  362.     sudo make install >> $LOGFILE 2>&1
  363.     if [ $? -eq 1 ] ; then
  364.         print_error "Failed to install Nmap"
  365.         return 1
  366.     fi
  367.         sudo make clean  >> $LOGFILE 2>&1
  368.     else
  369.         print_status "Nmap is already installed on the system"
  370.     fi
  371. }
  372. #######################################
  373.  
  374. function configure_psql_deb
  375. {
  376.     print_status "Creating the MSF Database user msf with the password provided"
  377.     if [ "$(id -u)" != "0" ]; then
  378.         MSFEXIST="$(sudo su - postgres -c "psql postgres -tAc \"SELECT 1 FROM pg_roles WHERE rolname='msf'\"")"
  379.     else
  380.         MSFEXIST="$(su - postgres -c "psql postgres -tAc \"SELECT 1 FROM pg_roles WHERE rolname='msf'\"")"
  381.     fi
  382.     if [[ ! $MSFEXIST -eq 1 ]]; then
  383.         if [ "$(id -u)" != "0" ]; then
  384.             sudo -u postgres psql postgres -c "create role msf login password '$MSFPASS'"  >> $LOGFILE 2>&1
  385.         else
  386.             su - postgres -c "psql postgres -c \"create role msf login password '$MSFPASS'\""  >> $LOGFILE 2>&1
  387.         fi
  388.  
  389.         if [ $? -eq 0 ]; then
  390.             print_good "Metasploit Role named msf has been created."
  391.         else
  392.         print_error "Failed to create the msf role"
  393.         fi
  394.     else
  395.         print_status "The msf role already exists."
  396.     fi
  397.  
  398.     if [ "$(id -u)" != "0" ]; then
  399.         DBEXIST="$(sudo su postgres -c "psql postgres -l | grep msf")"
  400.     else
  401.         DBEXIST="$(su - postgres -c "psql postgres -l | grep msf")"
  402.     fi
  403.  
  404.     if [[ ! $DBEXIST ]]; then
  405.         print_status "Creating msf database and setting the owner to msf user"
  406.         if [ "$(id -u)" != "0" ]; then
  407.             sudo -u postgres psql postgres -c "CREATE DATABASE msf OWNER msf;" >> $LOGFILE 2>&1
  408.         else
  409.             su - postgres -c "psql postgres -c \"CREATE DATABASE msf OWNER msf;\"" >> $LOGFILE 2>&1
  410.         fi
  411.  
  412.         if [ $? -eq 0 ]; then
  413.             print_good "Metasploit database named msf has been created."
  414.         else
  415.             print_error "Failed to create the msf database."
  416.         fi
  417.     else
  418.         print_status "The msf database already exists."
  419.     fi
  420. }
  421. #######################################
  422.  
  423. function install_msf_linux
  424. {
  425.     print_status "Installing Metasploit Framework from the GitHub Repository"
  426.  
  427.     if [[ ! -d /usr/local/share/metasploit-framework ]]; then
  428.         print_status "Cloning latest version of Metasploit Framework"
  429.         if [ "$(id -u)" != "0" ]; then
  430.             sudo git clone https://github.com/rapid7/metasploit-framework.git /usr/local/share/metasploit-framework >> $LOGFILE 2>&1
  431.         else
  432.             git clone https://github.com/rapid7/metasploit-framework.git /usr/local/share/metasploit-framework >> $LOGFILE 2>&1
  433.         fi
  434.  
  435.         print_status "Linking metasploit commands."
  436.         cd /usr/local/share/metasploit-framework
  437.         for MSF in $(ls msf*); do
  438.             print_status "linking $MSF command"
  439.             if [ "$(id -u)" != "0" ]; then
  440.                 sudo ln -s /usr/local/share/metasploit-framework/$MSF /usr/local/bin/$MSF
  441.             else
  442.                 ln -s /usr/local/share/metasploit-framework/$MSF /usr/local/bin/$MSF
  443.             fi
  444.         done
  445.         print_status "Creating Database configuration YAML file."
  446.         if [ "$(id -u)" != "0" ]; then
  447.             sudo sh -c "echo 'production:
  448.  adapter: postgresql
  449.  database: msf
  450.  username: msf
  451.  password: $MSFPASS
  452.  host: 127.0.0.1
  453.  port: 5432
  454.  pool: 75
  455.  timeout: 5' > /usr/local/share/metasploit-framework/database.yml"
  456.         else
  457.             sh -c "echo 'production:
  458.  adapter: postgresql
  459.  database: msf
  460.  username: msf
  461.  password: $MSFPASS
  462.  host: 127.0.0.1
  463.  port: 5432
  464.  pool: 75
  465.  timeout: 5' > /usr/local/share/metasploit-framework/database.yml"
  466.         fi
  467.         print_status "setting environment variable in system profile. Password will be requiered"
  468.         sudo sh -c "echo export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml >> /etc/environment"
  469.         echo "export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml" >> ~/.bashrc
  470.         PS1='$ '
  471.         source ~/.bashrc
  472.  
  473.         cd /usr/local/share/metasploit-framework
  474.         if [[ $RVM -eq 0 ]]; then
  475.             print_status "Installing required ruby gems by Framework using bundler on RVM Ruby"
  476.             ~/.rvm/bin/rvm 1.9.3 do bundle install  >> $LOGFILE 2>&1
  477.         else
  478.             print_status "Installing required ruby gems by Framework using bundler on System Ruby"
  479.             sudo bundle install  >> $LOGFILE 2>&1
  480.         fi
  481.         print_status "Starting Metasploit so as to populate the database."
  482.         if [[ $RVM -eq 0 ]]; then
  483.             ~/.rvm/bin/rvm 1.9.3 do ruby /usr/local/share/metasploit-framework/msfconsole -q -x "exit" >> $LOGFILE 2>&1
  484.         else
  485.             /usr/local/share/metasploit-framework/msfconsole -q -x "exit" >> $LOGFILE 2>&1
  486.             print_status "Finished Metasploit installation"
  487.         fi
  488.     else
  489.         print_status "Metasploit already present."
  490.     fi
  491. }
  492. #######################################
  493.  
  494. function install_plugins_linux
  495. {
  496.     print_status "Installing additional Metasploit plugins"
  497.     print_status "Installing pentest plugin"
  498.     sudo curl -# -o /usr/local/share/metasploit-framework/plugins/pentest.rb https://raw.github.com/darkoperator/Metasploit-Plugins/master/pentest.rb
  499.     if [ $? -eq 0 ]; then
  500.         print_good "The pentest plugin has been installed."
  501.     else
  502.         print_error "Failed to install the pentest plugin."
  503.     fi
  504.     print_status "Installing DNSRecon Import plugin"
  505.     sudo curl -# -o /usr/local/share/metasploit-framework/plugins/dnsr_import.rb https://raw.github.com/darkoperator/dnsrecon/master/msf_plugin/dnsr_import.rb
  506.     if [ $? -eq 0 ]; then
  507.         print_good "The dnsr_import plugin has been installed."
  508.     else
  509.         print_error "Failed to install the dnsr_import plugin."
  510.     fi
  511. }
  512. #######################################
  513.  
  514. function install_armitage_linux
  515. {
  516.     if [ -e /usr/bin/curl ]; then
  517.         print_status "Downloading latest version of Armitage"
  518.         curl -# -o /tmp/armitage.tgz http://www.fastandeasyhacking.com/download/armitage-latest.tgz && print_good "Finished"
  519.         if [ $? -eq 1 ] ; then
  520.             print_error "Failed to download the latest version of Armitage make sure you"
  521.             print_error "are connected to the internet and can reach http://www.fastandeasyhacking.com"
  522.         else
  523.             print_status "Decompressing package to /usr/local/share/armitage"
  524.             sudo tar -xvzf /tmp/armitage.tgz -C /usr/local/share >> $LOGFILE 2>&1
  525.         fi
  526.  
  527.         # Check if links exists and if they do not create them
  528.         if [ ! -e /usr/local/bin/armitage ]; then
  529.             print_status "Creating link for Armitage in /usr/local/bin/armitage"
  530.             sudo sh -c "echo java -jar /usr/local/share/armitage/armitage.jar \$\* > /usr/local/share/armitage/armitage"
  531.             sudo ln -s /usr/local/share/armitage/armitage /usr/local/bin/armitage
  532.         else
  533.             print_good "Armitage is already linked to /usr/local/bin/armitage"
  534.             sudo sh -c "echo java -jar /usr/local/share/armitage/armitage.jar \$\* > /usr/local/share/armitage/armitage"
  535.         fi
  536.  
  537.         if [ ! -e /usr/local/bin/teamserver ]; then
  538.             print_status "Creating link for Teamserver in /usr/local/bin/teamserver"
  539.             sudo ln -s /usr/local/share/armitage/teamserver /usr/local/bin/teamserver
  540.             sudo perl -pi -e 's/armitage.jar/\/usr\/local\/share\/armitage\/armitage.jar/g' /usr/local/share/armitage/teamserver
  541.         else
  542.             print_good "Teamserver is already linked to /usr/local/bin/teamserver"
  543.             sudo perl -pi -e 's/armitage.jar/\/usr\/local\/share\/armitage\/armitage.jar/g' /usr/local/share/armitage/teamserver
  544.         fi
  545.         print_good "Finished"
  546.     fi
  547. }
  548. #######################################
  549.  
  550. function usage ()
  551. {
  552.     echo "Script for Installing Metasploit Framework"
  553.     echo "By Carlos_Perez[at]darkoperator.com"
  554.     echo "Ver 0.1.5"
  555.     echo ""
  556.     echo "-i                :Install Metasploit Framework."
  557.     echo "-p <password>     :password for Metasploit databse msf user. If not provided a random one is generated for you."
  558.     echo "-r                :Installs Ruby using Ruby Version Manager."
  559.     echo "-h                :This help message"
  560. }
  561.  
  562. function install_ruby_rvm
  563. {
  564.  
  565.     if [[ ! -e ~/.rvm/scripts/rvm ]]; then
  566.         print_status "Installing RVM"
  567.  
  568.         bash < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) >> $LOGFILE 2>&1
  569.         PS1='$ '
  570.         if [[ $OSTYPE =~ darwin ]]; then
  571.             source ~/.bash_profile
  572.         else
  573.             source ~/.bashrc
  574.         fi
  575.  
  576.         if [[ $OSTYPE =~ darwin ]]; then
  577.             print_status "Installing Ruby"
  578.             ~/.rvm/bin/rvm install 1.9.3 --autolibs=4 --verify-downloads 1 >> $LOGFILE 2>&1
  579.         else
  580.             ~/.rvm/bin/rvm install 1.9.3 --autolibs=4 --verify-downloads 1 >> $LOGFILE 2>&1
  581.         fi
  582.  
  583.         if [[ $? -eq 0 ]]; then
  584.             print_good "Installation of Ruby 1.9.3 was successful"
  585.  
  586.             ~/.rvm/bin/rvm use 1.9.3 --default >> $LOGFILE 2>&1
  587.             print_status "Installing base gems"
  588.             ~/.rvm/bin/rvm 1.9.3 do gem install sqlite3 bundler >> $LOGFILE 2>&1
  589.             if [[ $? -eq 0 ]]; then
  590.                 print_good "Base gems in the RVM Ruby have been installed."
  591.             else
  592.                 print_error "Base Gems for the RVM Ruby have failed!"
  593.                 exit 1
  594.             fi
  595.         else
  596.             print_error "Was not able to install Ruby 1.9.3!"
  597.             exit 1
  598.         fi
  599.     else
  600.         print_status "RVM is already installed"
  601.         if [[ "$( ls -1 ~/.rvm/rubies/)" =~ ruby-1.9.3-p... ]]; then
  602.             print_status "Ruby for Metasploit is already installed"
  603.         else
  604.             PS1='$ '
  605.             if [[ $OSTYPE =~ darwin ]]; then
  606.                 source ~/.bash_profile
  607.             else
  608.                 source ~/.bashrc
  609.             fi
  610.  
  611.             print_status "Installing Ruby 1.9.3 under the name metasploit"
  612.             ~/.rvm/bin/rvm install 1.9.3  --autolibs=4 --verify-downloads 1  >> $LOGFILE 2>&1
  613.             if [[ $? -eq 0 ]]; then
  614.                 print_good "Installation of Ruby 1.9.3 was successful"
  615.  
  616.                 ~/.rvm/bin/rvm use 1.9.3 --default >> $LOGFILE 2>&1
  617.                 print_status "Installing base gems"
  618.                 ~/.rvm/bin/rvm 1.9.3 do gem install sqlite3 bundler >> $LOGFILE 2>&1
  619.                 if [[ $? -eq 0 ]]; then
  620.                     print_good "Base gems in the RVM Ruby have been installed."
  621.                 else
  622.                     print_error "Base Gems for the RVM Ruby have failed!"
  623.                     exit 1
  624.                 fi
  625.             else
  626.                 print_error "Was not able to install Ruby 1.9.3!"
  627.                 exit 1
  628.             fi
  629.         fi
  630.     fi
  631. }
  632. #### MAIN ###
  633. [[ ! $1 ]] && { usage; exit 0; }
  634. #Variable with log file location for trobleshooting
  635. LOGFILE="/tmp/msfinstall$NOW.log"
  636. while getopts "irp:h" options; do
  637.     case $options in
  638.         p ) MSFPASS=$OPTARG;;
  639.         i ) INSTALL=0;;
  640.         h ) usage;;
  641.         r ) RVM=0;;
  642.         \? ) usage
  643.         exit 1;;
  644.         * ) usage
  645.         exit 1;;
  646.  
  647.     esac
  648. done
  649.  
  650. if [ $INSTALL -eq 0 ]; then
  651.     print_status "Log file with command output and errors $LOGFILE"
  652.     if [[ "$KVER" =~ Darwin ]]; then
  653.         check_dependencies_osx
  654.         check_for_brew_osx
  655.         install_ruby_osx
  656.         if [[ $RVM -eq 0 ]]; then
  657.             install_ruby_rvm
  658.         fi
  659.         install_nmap_osx
  660.         install_postgresql_osx
  661.         install_msf_osx
  662.         install_armitage_osx
  663.         install_plugins_osx
  664.  
  665.         print_status "#################################################################"
  666.         print_status "### YOU NEED TO RELOAD YOUR PROFILE BEFORE USE OF METASPLOIT!   ###"
  667.         print_status "### RUN source ~/.bash_profile                                  ###"
  668.         if [[ $RVM -eq 0 ]]; then
  669.             print_status "###                                                             ###"
  670.             print_status "### INSTALLATION WAS USING RVM, SET 1.9.3 AS DEFAULT            ###"
  671.             print_status "### RUN rvm use 1.9.3 --default                                 ###"
  672.             print_status "###                                                             ###"
  673.         fi
  674.         print_status "###################################################################"
  675.  
  676.     elif [[ "$KVER" =~ buntu ]]; then
  677.         install_deps_deb
  678.  
  679.         if [[ $RVM -eq 0 ]]; then
  680.             install_ruby_rvm
  681.         fi
  682.  
  683.         install_nmap_linux
  684.         configure_psql_deb
  685.         install_msf_linux
  686.         install_plugins_linux
  687.         install_armitage_linux
  688.         print_status "##################################################################"
  689.         print_status "### YOU NEED TO RELOAD YOUR PROFILE BEFORE USE OF METASPLOIT!  ###"
  690.         print_status "### RUN source ~/.bashrc                                       ###"
  691.         if [[ $RVM -eq 0 ]]; then
  692.             print_status "###                                                            ###"
  693.             print_status "### INSTALLATION WAS USING RVM SET 1.9.3-metasploit AS DEFAULT ###"
  694.             print_status "### RUN rvm use 1.9.3 --default                                ###"
  695.         fi
  696.         print_status "### When launching teamserver and armitage with sudo use the   ###"
  697.         print_status "### use the -E option to make sure the MSF Database variable   ###"
  698.         print_status "### is properly set.                                           ###"
  699.         print_status "###                                                            ###"
  700.         print_status "##################################################################"
  701.  
  702.     elif [[ "$KVER" =~ Debian ]]; then
  703.         if [[ "$(cat /etc/debian_version )" =~ 7.0  ]]; then
  704.             if [[ $( cat /etc/apt/sources.list | grep -E '^deb cdrom' ) ]]; then
  705.                 print_error "Source in /etc/apt/sources.list is set to CD or DVD"
  706.                 print_error "Comment out the line and only use network sources."
  707.                 exit 1
  708.             fi
  709.             install_deps_deb
  710.  
  711.             if [[ $RVM -eq 0 ]]; then
  712.                 install_ruby_rvm
  713.             fi
  714.  
  715.             install_nmap_linux
  716.             configure_psql_deb
  717.             install_msf_linux
  718.             install_plugins_linux
  719.             install_armitage_linux
  720.             print_status "##################################################################"
  721.             print_status "### YOU NEED TO RELOAD YOUR PROFILE BEFORE USE OF METASPLOIT!  ###"
  722.             print_status "### RUN source ~/.bashrc                                       ###"
  723.             if [[ $RVM -eq 0 ]]; then
  724.                 print_status "###                                                            ###"
  725.                 print_status "### INSTALLATION WAS USING RVM SET 1.9.3-metasploit AS DEFAULT ###"
  726.                 print_status "### RUN rvm use 1.9.3 default                                  ###"
  727.             fi
  728.             print_status "### When launching teamserver and armitage with sudo use the   ###"
  729.             print_status "### use the -E option to make sure the MSF Database variable   ###"
  730.             print_status "### is properly set.                                           ###"
  731.             print_status "###                                                            ###"
  732.             print_status "##################################################################"
  733.         else
  734.             print_error "This version of Debian is not supported. Only Debian 7.0 is supported"
  735.         fi
  736.     else
  737.         print_error "The script does not support this platform at this moment."
  738.         exit 1
  739.     fi
  740. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement