├── README.md └── msf_install.sh /README.md: -------------------------------------------------------------------------------- 1 | MSF-Installer 2 | ============= 3 | 4 | Script to help with installing and configuring Metasploit Framework, Armitage and the Plugins I have written on OSX and Linux 5 | -------------------------------------------------------------------------------- /msf_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | KVER=`uname -a` 4 | # Variable to know if Homebrew should be installed 5 | MSFPASS=`openssl rand -base64 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 | 11 | function print_good () 12 | { 13 | echo -e "\x1B[01;32m[*]\x1B[0m $1" 14 | } 15 | ######################################## 16 | 17 | function print_error () 18 | { 19 | echo -e "\x1B[01;31m[*]\x1B[0m $1" 20 | } 21 | ######################################## 22 | 23 | function print_status () 24 | { 25 | echo -e "\x1B[01;34m[*]\x1B[0m $1" 26 | } 27 | ######################################## 28 | 29 | function check_root 30 | { 31 | if [ "$(id -u)" != "0" ]; then 32 | print_error "This step mus be ran as root" 33 | exit 1 34 | fi 35 | } 36 | ######################################## 37 | 38 | function install_armitage_osx 39 | { 40 | if [ -e /usr/bin/curl ]; then 41 | print_status "Downloading latest version of Armitage" 42 | curl -# -o /tmp/armitage.tgz http://www.fastandeasyhacking.com/download/armitage-latest.tgz && print_good "Finished" 43 | if [ $? -eq 1 ] ; then 44 | print_error "Failed to download the latest version of Armitage make sure you" 45 | print_error "are connected to the intertet and can reach http://www.fastandeasyhacking.com" 46 | else 47 | print_status "Decompressing package to /opt/armitage" 48 | tar -xvzf /tmp/armitage.tgz -C /usr/local/ 49 | fi 50 | 51 | # Check if links exists and if they do not create them 52 | if [ ! -e /usr/local/bin/armitage ]; then 53 | print_status "Linking Armitage in /usr/local/bin/armitage" 54 | echo java -jar /usr/local/share/armitage/armitage.jar \$\* > /usr/local/bin/armitage 55 | else 56 | print_good "Armitage is already linked to /usr/local/bin/armitage" 57 | fi 58 | 59 | if [ ! -e /usr/local/bin/teamserver ]; then 60 | print_status "CopyingTeamserver in /usr/local/bin/teamserver" 61 | ln -s /usr/local/armitage/teamserver /usr/local/bin/teamserver 62 | perl -pi -e 's/armitage.jar/\/usr\/local\/share\/armitage\/armitage.jar/g' /usr/local/share/armitage/teamserver 63 | else 64 | print_good "Teamserver is already linked to /usr/local/bin/teamserver" 65 | fi 66 | fi 67 | } 68 | ######################################## 69 | 70 | function check_for_brew_osx 71 | { 72 | print_status "Verifiying that Homebrew is installed:" 73 | if [ -e /usr/local/bin/brew ]; then 74 | print_good "Homebrew is installed on the system, updating formulas." 75 | /usr/local/bin/brew update 2>&1 76 | print_good "Finished updating formulas" 77 | brew tap homebrew/versions 78 | print_status "Verifying that the proper paths are set" 79 | 80 | if [ -d ~/.bash_profile ]; then 81 | if [ "$(grep ":/usr/local/sbin" ~/.bash_profile -q)" ]; then 82 | print_good "Paths are properly set" 83 | else 84 | print_status "Setting the path for homebrew" 85 | echo PATH=/usr/local/bin:/usr/local/sbin:$PATH >> ~/.bash_profile 86 | source ~/.bash_profile 87 | fi 88 | else 89 | echo PATH=/usr/local/bin:/usr/local/sbin:$PATH >> ~/.bash_profile 90 | source ~/.bash_profile 91 | fi 92 | else 93 | 94 | print_status "Installing Homebrew" 95 | /usr/bin/ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" 96 | if [ "$(grep ":/usr/local/sbin" ~/.bash_profile -q)" ]; then 97 | print_good "Paths are properly set" 98 | else 99 | print_status "Setting the path for homebrew" 100 | echo PATH=/usr/local/bin:/usr/local/sbin:$PATH >> ~/.bash_profile 101 | source ~/.bash_profile 102 | fi 103 | 104 | fi 105 | } 106 | ######################################## 107 | 108 | function check_dependencies_osx 109 | { 110 | # Get a list of all the packages installed on the system 111 | PKGS=`pkgutil --pkgs` 112 | print_status "Verifiying that Development Tools and Java are installed:" 113 | if $(echo "$PKGS" | grep -q Java) ; then 114 | print_good "Java is intalled." 115 | else 116 | print_error "Java is not installed on this system." 117 | exit 1 118 | fi 119 | 120 | if $(echo "$PKGS" | grep -q Xcode) ; then 121 | print_good "Xcode is intalled." 122 | else 123 | print_error "Xcode is not installed on this system. Install from the App AppStore." 124 | exit 1 125 | fi 126 | 127 | if $(echo "$PKGS" | grep -q com.apple.pkg.DeveloperToolsCLI) ; then 128 | print_good "Command Line Development Tools is intalled." 129 | else 130 | print_error "Command Line Development Tools is not installed on this system." 131 | exit 1 132 | fi 133 | } 134 | ######################################## 135 | 136 | function install_gcc_osx 137 | { 138 | print_status "Checking if the GNU GCC Compiler is installed if not installing it." 139 | if [ -d /usr/local/Cellar/ ] && [ -L /usr/local/bin/gcc-4.8 ]; then 140 | print_good "Latest version of the GNU GCC is installed." 141 | else 142 | print_status "Installing version 4.8 of the GNU GCC Compiler" 143 | brew install homebrew/versions/gcc48 144 | fi 145 | 146 | print_status "Checking if GCC is set as the CC Compiler." 147 | if [[ ! "$(cat ~/.bash_profile)" =~ "CC=/usr/local/bin/gcc-4.8" ]]; then 148 | print_status "GCC is not set as the default CC Compiler." 149 | print_status "Setting GCC as the default CC Compiler." 150 | echo export CC=/usr/local/bin/gcc-4.7 >> ~/.bash_profile 151 | print_good "GCC set as the defult CC Compiler" 152 | else 153 | print_good "GCC is already set as the default CC Compiler." 154 | fi 155 | 156 | print_status "Checking GCC is set to compile for x86_64." 157 | if [[ ! "$(cat ~/.bash_profile)" =~ "x86_64" ]]; then 158 | print_status "x86_64 is not set as the default architecture." 159 | print_status "Setting x86_64 as the default architecture." 160 | echo export ARCHFLAGS=\"-arch x86_64\" >> ~/.bash_profile 161 | print_good "x86_64 set as the defult architecture" 162 | else 163 | print_good "x86_64 is already set as the default architecture." 164 | fi 165 | 166 | } 167 | ######################################## 168 | 169 | function install_ruby_osx 170 | { 171 | print_status "Checking if Ruby 1.9.3 is installed if not installing it." 172 | if [ -d /usr/local/Cellar/ruby193 ] && [ -L /usr/local/bin/ruby ]; then 173 | print_good "Correct version of Ruby is installed." 174 | else 175 | print_status "Installing Ruby 1.9.3" 176 | brew tap homebrew/versions 177 | brew install homebrew/versions/ruby193 178 | echo PATH=/usr/local/opt/ruby193/bin:$PATH >> ~/.bash_profile 179 | source ~/.bash_profile 180 | fi 181 | print_status "Inatlling the bundler and SQLite3 Gems" 182 | gem install bundler sqlite3 183 | } 184 | ######################################## 185 | 186 | function install_nmap_osx 187 | { 188 | print_status "Checking if Nmap is installed using Homebrew if not installing it." 189 | if [ -d /usr/local/Cellar/nmap ] && [ -L /usr/local/bin/nmap ]; then 190 | print_good "NMap is installed." 191 | else 192 | print_status "Installing nmap" 193 | brew install nmap 194 | fi 195 | } 196 | ######################################## 197 | 198 | function install_postgresql_osx 199 | { 200 | print_status "Checking if PostgreSQL is installed using Homebrew if not installing it." 201 | if [ -d /usr/local/Cellar/postgresql ] && [ -L /usr/local/bin/postgres ]; then 202 | print_good "PostgreSQL is installed." 203 | else 204 | print_status "Installing PostgresQL" 205 | brew install postgresql 206 | if [ $? -eq 0 ]; then 207 | print_good "Installtion of PostgreSQL was successful" 208 | print_status "Initiating postgres" 209 | initdb /usr/local/var/postgres 210 | if [ $? -eq 0 ]; then 211 | print_good "Database initiation was successful" 212 | fi 213 | 214 | # Getting the Postgres version so as to configure startup of the databse 215 | PSQLVER=`psql --version | cut -d " " -f3` 216 | 217 | print_status "Configuring the database engine to start at logon" 218 | pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start 219 | mkdir -p ~/Library/LaunchAgents 220 | ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents 221 | # Give enough time for the database to start for the first time 222 | sleep 5 223 | #launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 224 | print_status "Creating the MSF Database user msf with the password provided" 225 | psql postgres -c "create role msf login password '$MSFPASS'" 226 | if [ $? -eq 0 ]; then 227 | print_good "Metasploit Role named msf has been created." 228 | else 229 | print_error "Failed to create the msf role" 230 | fi 231 | print_status "Creating msf database and setting the owner to msf user" 232 | createdb -O msf msf -h localhost 233 | if [ $? -eq 0 ]; then 234 | print_good "Metasploit Databse named msf has been created." 235 | else 236 | print_error "Failed to create the msf database." 237 | fi 238 | fi 239 | fi 240 | } 241 | ######################################## 242 | 243 | function install_msf_osx 244 | { 245 | print_status "Installing Metasploit Framework from the GitHub Repository" 246 | print_status "Cloning latest version of Metasploit Framework" 247 | git clone https://github.com/rapid7/metasploit-framework.git /usr/local/share/metasploit-framework 248 | print_status "Linking metasploit commands." 249 | cd /usr/local/share/metasploit-framework 250 | for MSF in $(ls msf*); do 251 | print_status "linking $MSF command" 252 | ln -s /usr/local/share/metasploit-framework/$MSF /usr/local/bin/$MSF 253 | done 254 | print_status "Creating Database configuration YAML file." 255 | echo 'production: 256 | adapter: postgresql 257 | database: msf 258 | username: msf 259 | password: $MSFPASS 260 | host: 127.0.0.1 261 | port: 5432 262 | pool: 75 263 | timeout: 5' > /usr/local/share/metasploit-framework/database.yml 264 | print_status "setting environment variable in system profile. Password will be requiered" 265 | sudo sh -c "echo export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml >> /etc/profile" 266 | echo "export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml" >> ~/.bash_profile 267 | source /etc/profile 268 | source ~/.bash_profile 269 | print_status "Installing required ruby gems by Framework using bundler" 270 | cd /usr/local/share/metasploit-framework 271 | bundle install 272 | print_status "Starting Metasploit so as to populate de database." 273 | /usr/local/share/metasploit-framework/msfconsole -q -x "exit" 274 | } 275 | ######################################## 276 | 277 | function install_plugins 278 | { 279 | print_status "Installing addiotional Metasploit plugins" 280 | print_status "Installing Pentest plugin" 281 | curl -# -o /usr/local/share/metasploit-framework/plugins/pentest.rb https://raw.github.com/darkoperator/Metasploit-Plugins/master/pentest.rb 282 | if [ $? -eq 0 ]; then 283 | print_good "The pentest plugin has been installed." 284 | else 285 | print_error "Failed to install the pentest plugin." 286 | fi 287 | print_status "Installing DNSRecon Import plugin" 288 | curl -# -o /usr/local/share/metasploit-framework/plugins/dnsr_import.rb https://raw.github.com/darkoperator/dnsrecon/master/msf_plugin/dnsr_import.rb 289 | if [ $? -eq 0 ]; then 290 | print_good "The dnsr_import plugin has been installed." 291 | else 292 | print_error "Failed to install the dnsr_import plugin." 293 | fi 294 | } 295 | ####################################### 296 | 297 | function install_deps_deb 298 | { 299 | print_status "Installing dependencies for Metasploit Framework" 300 | sudo apt-get -y update 301 | 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 #>> $LOGFILE 302 | print_status "Installing base Ruby Gems" 303 | sudo gem install wirble sqlite3 bundler #>> $LOGFILE 304 | } 305 | ####################################### 306 | 307 | function install_nmap_linux 308 | { 309 | print_status "Downloading and Compiling the latest version if Nmap" 310 | print_status "Downloading from SVN the latest version of Nmap" 311 | cd /usr/src 312 | sudo svn co https://svn.nmap.org/nmap #>> $LOGFILE 313 | cd nmap 314 | print_status "Configuring Nmap" 315 | sudo ./configure #>> $LOGFILE 316 | print_status "Compiling the latest version of Nmap" 317 | sudo make #>> $LOGFILE 318 | print_status "Installing the latest version of Nmap" 319 | sudo make install #>> $LOGFILE 320 | sudo make clean #>> $LOGFILE 321 | } 322 | ####################################### 323 | 324 | function configure_psql_deb 325 | { 326 | print_status "Creating the MSF Database user msf with the password provided" 327 | sudo -u postgres psql postgres -c "create role msf login password '$MSFPASS'" 328 | if [ $? -eq 0 ]; then 329 | print_good "Metasploit Role named msf has been created." 330 | else 331 | print_error "Failed to create the msf role" 332 | fi 333 | print_status "Creating msf database and setting the owner to msf user" 334 | sudo -u postgres psql postgres -c "CREATE DATABASE msf OWNER msf;" 335 | if [ $? -eq 0 ]; then 336 | print_good "Metasploit Databse named msf has been created." 337 | else 338 | print_error "Failed to create the msf database." 339 | fi 340 | } 341 | ####################################### 342 | 343 | function install_msf_linux 344 | { 345 | print_status "Installing Metasploit Framework from the GitHub Repository" 346 | print_status "Cloning latest version of Metasploit Framework" 347 | sudo git clone https://github.com/rapid7/metasploit-framework.git /usr/local/share/metasploit-framework #>> $LOGFILE 348 | print_status "Linking metasploit commands." 349 | cd /usr/local/share/metasploit-framework 350 | for MSF in $(ls msf*); do 351 | print_status "linking $MSF command" 352 | sudo ln -s /usr/local/share/metasploit-framework/$MSF /usr/local/bin/$MSF 353 | done 354 | print_status "Creating Database configuration YAML file." 355 | sudo sh -c "echo 'production: 356 | adapter: postgresql 357 | database: msf 358 | username: msf 359 | password: $MSFPASS 360 | host: 127.0.0.1 361 | port: 5432 362 | pool: 75 363 | timeout: 5' > /usr/local/share/metasploit-framework/database.yml" 364 | print_status "setting environment variable in system profile. Password will be requiered" 365 | sudo sh -c "echo export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml >> /etc/environment" 366 | echo "export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml" >> ~/.bashrc 367 | PS1='$ ' 368 | source ~/.bashrc 369 | print_status "Installing required ruby gems by Framework using bundler" 370 | cd /usr/local/share/metasploit-framework 371 | sudo bundle install #>> $LOGFILE 372 | print_status "Starting Metasploit so as to populate de database." 373 | /usr/local/share/metasploit-framework/msfconsole -q -x "exit" 374 | } 375 | ####################################### 376 | 377 | function install_plugins_linux 378 | { 379 | print_status "Installing addiotional Metasploit plugins" 380 | print_status "Installing Pentest plugin" 381 | sudo curl -# -o /usr/local/share/metasploit-framework/plugins/pentest.rb https://raw.github.com/darkoperator/Metasploit-Plugins/master/pentest.rb 382 | if [ $? -eq 0 ]; then 383 | print_good "The pentest plugin has been installed." 384 | else 385 | print_error "Failed to install the pentest plugin." 386 | fi 387 | print_status "Installing DNSRecon Import plugin" 388 | sudo curl -# -o /usr/local/share/metasploit-framework/plugins/dnsr_import.rb https://raw.github.com/darkoperator/dnsrecon/master/msf_plugin/dnsr_import.rb 389 | if [ $? -eq 0 ]; then 390 | print_good "The dnsr_import plugin has been installed." 391 | else 392 | print_error "Failed to install the dnsr_import plugin." 393 | fi 394 | } 395 | ####################################### 396 | 397 | function install_armitage_linux 398 | { 399 | if [ -e /usr/bin/curl ]; then 400 | print_status "Downloading latest version of Armitage" 401 | curl -# -o /tmp/armitage.tgz http://www.fastandeasyhacking.com/download/armitage-latest.tgz && print_good "Finished" 402 | if [ $? -eq 1 ] ; then 403 | print_error "Failed to download the latest version of Armitage make sure you" 404 | print_error "are connected to the intertet and can reach http://www.fastandeasyhacking.com" 405 | else 406 | print_status "Decompressing package to /opt/armitage" 407 | sudo tar -xvzf /tmp/armitage.tgz -C /usr/local/share 408 | fi 409 | 410 | # Check if links exists and if they do not create them 411 | if [ ! -e /usr/local/bin/armitage ]; then 412 | print_status "Creating link for Armitage in /usr/local/bin/armitage" 413 | sudo sh -c "echo java -jar /usr/local/share/armitage/armitage.jar \$\* > /usr/local/share/armitage/armitage" 414 | sudo ln -s /usr/local/share/armitage/armitage /usr/local/bin/armitage 415 | else 416 | print_good "Armitage is already linked to /usr/local/bin/armitage" 417 | fi 418 | 419 | if [ ! -e /usr/local/bin/teamserver ]; then 420 | print_status "Creating link for Teamserver in /usr/local/bin/teamserver" 421 | sudo ln -s /usr/local/share/armitage/teamserver /usr/local/bin/teamserver 422 | sudo perl -pi -e 's/armitage.jar/\/usr\/local\/share\/armitage\/armitage.jar/g' /usr/local/share/armitage/teamserver 423 | else 424 | print_good "Teamserver is already linked to /usr/local/bin/teamserver" 425 | fi 426 | fi 427 | } 428 | ####################################### 429 | 430 | function usage () 431 | { 432 | echo "Scritp for Installing Metasploit Framework" 433 | echo "By Carlos_Perez[at]darkoperator.com" 434 | echo "Ver 0.1.2" 435 | echo "" 436 | echo "-i :Install Metasploit Framework." 437 | echo "-p :password for MEtasploit databse msf user. If not provided a roandom one is generated for you." 438 | echo "-g :Install GNU GCC (Not necessary uless you wish to compile and install ruby 1.8.7 in OSX" 439 | echo "-h :This help message" 440 | } 441 | 442 | 443 | #### MAIN ### 444 | [[ ! $1 ]] && { usage; exit 0; } 445 | #Variable with log file location for trobleshooting 446 | LOGFILE="/tmp/msfinstall$NOW.log" 447 | while getopts "igp:h" options; do 448 | case $options in 449 | p ) MSFPASS=$OPTARG;; 450 | i ) INSTALL=0;; 451 | g ) IGCC=0;; 452 | h ) usage;; 453 | \? ) usage 454 | exit 1;; 455 | * ) usage 456 | exit 1;; 457 | 458 | esac 459 | done 460 | 461 | if [ $INSTALL -eq 0 ]; then 462 | if [[ "$KVER" =~ Darwin ]]; then 463 | check_dependencies_osx 464 | check_for_brew_osx 465 | install_ruby_osx 466 | install_nmap_osx 467 | install_postgresql_osx 468 | install_msf_osx 469 | install_armitage_osx 470 | install_plugins 471 | 472 | if [ $IGCC -eq 0 ]; then 473 | install_gcc_osx 474 | fi 475 | print_status "#################################################################" 476 | print_status "### YOU NEED TO RELOAD YOUR PROFILE BEFORE USE OF METASPLOIT! ###" 477 | print_status "### RUN source ~/.bash_profile ###" 478 | print_status "#################################################################" 479 | 480 | elif [[ "$KVER" =~ buntu ]]; then 481 | install_deps_deb 482 | install_nmap_linux 483 | configure_psql_deb 484 | install_msf_linux 485 | install_plugins_linux 486 | install_armitage_linux 487 | print_status "#################################################################" 488 | print_status "### YOU NEED TO RELOAD YOUR PROFILE BEFORE USE OF METASPLOIT! ###" 489 | print_status "### RUN source ~/.bashrc ###" 490 | print_status "#################################################################" 491 | else 492 | print_error "The script does not support this platform at this moment." 493 | exit 1 494 | fi 495 | fi --------------------------------------------------------------------------------