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