-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathmsf_install.sh
executable file
·495 lines (454 loc) · 17.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
#!/bin/bash
KVER=`uname -a`
# Variable to know if Homebrew should be installed
MSFPASS=`openssl rand -base64 16`
#Variable with time of launch used for log names
NOW=$(date +"-%b-%d-%y-%H%M%S")
IGCC=1
INSTALL=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 mus be ran as root"
exit 1
fi
}
########################################
function install_armitage_osx
{
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 intertet and can reach http://www.fastandeasyhacking.com"
else
print_status "Decompressing package to /opt/armitage"
tar -xvzf /tmp/armitage.tgz -C /usr/local/
fi
# Check if links exists and if they do not create them
if [ ! -e /usr/local/bin/armitage ]; then
print_status "Linking Armitage in /usr/local/bin/armitage"
echo java -jar /usr/local/share/armitage/armitage.jar \$\* > /usr/local/bin/armitage
else
print_good "Armitage is already linked to /usr/local/bin/armitage"
fi
if [ ! -e /usr/local/bin/teamserver ]; then
print_status "CopyingTeamserver in /usr/local/bin/teamserver"
ln -s /usr/local/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"
fi
fi
}
########################################
function check_for_brew_osx
{
print_status "Verifiying 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 2>&1
print_good "Finished updating formulas"
brew tap homebrew/versions
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/mxcl/homebrew/go)"
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 "Verifiying that Development Tools and Java are installed:"
if $(echo "$PKGS" | grep -q Java) ; then
print_good "Java is intalled."
else
print_error "Java is not installed on this system."
exit 1
fi
if $(echo "$PKGS" | grep -q Xcode) ; then
print_good "Xcode is intalled."
else
print_error "Xcode is not installed on this system. Install from the App AppStore."
exit 1
fi
if $(echo "$PKGS" | grep -q com.apple.pkg.DeveloperToolsCLI) ; 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_gcc_osx
{
print_status "Checking if the GNU GCC Compiler is installed if not installing it."
if [ -d /usr/local/Cellar/ ] && [ -L /usr/local/bin/gcc-4.8 ]; then
print_good "Latest version of the GNU GCC is installed."
else
print_status "Installing version 4.8 of the GNU GCC Compiler"
brew install homebrew/versions/gcc48
fi
print_status "Checking if GCC is set as the CC Compiler."
if [[ ! "$(cat ~/.bash_profile)" =~ "CC=/usr/local/bin/gcc-4.8" ]]; then
print_status "GCC is not set as the default CC Compiler."
print_status "Setting GCC as the default CC Compiler."
echo export CC=/usr/local/bin/gcc-4.7 >> ~/.bash_profile
print_good "GCC set as the defult CC Compiler"
else
print_good "GCC is already set as the default CC Compiler."
fi
print_status "Checking GCC is set to compile for x86_64."
if [[ ! "$(cat ~/.bash_profile)" =~ "x86_64" ]]; then
print_status "x86_64 is not set as the default architecture."
print_status "Setting x86_64 as the default architecture."
echo export ARCHFLAGS=\"-arch x86_64\" >> ~/.bash_profile
print_good "x86_64 set as the defult architecture"
else
print_good "x86_64 is already set as the default architecture."
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
brew install homebrew/versions/ruby193
echo PATH=/usr/local/opt/ruby193/bin:$PATH >> ~/.bash_profile
source ~/.bash_profile
fi
print_status "Inatlling the bundler and SQLite3 Gems"
gem install bundler sqlite3
}
########################################
function install_nmap_osx
{
print_status "Checking if Nmap is installed using Homebrew if not installing it."
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
fi
}
########################################
function install_postgresql_osx
{
print_status "Checking if PostgreSQL is installed using Homebrew if not installing it."
if [ -d /usr/local/Cellar/postgresql ] && [ -L /usr/local/bin/postgres ]; then
print_good "PostgreSQL is installed."
else
print_status "Installing PostgresQL"
brew install postgresql
if [ $? -eq 0 ]; then
print_good "Installtion of PostgreSQL was successful"
print_status "Initiating postgres"
initdb /usr/local/var/postgres
if [ $? -eq 0 ]; then
print_good "Database initiation was successful"
fi
# Getting the Postgres version so as to configure startup of the databse
PSQLVER=`psql --version | cut -d " " -f3`
print_status "Configuring the database engine to start at logon"
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
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"
psql postgres -c "create role msf login password '$MSFPASS'"
if [ $? -eq 0 ]; then
print_good "Metasploit Role named msf has been created."
else
print_error "Failed to create the msf role"
fi
print_status "Creating msf database and setting the owner to msf user"
createdb -O msf msf -h localhost
if [ $? -eq 0 ]; then
print_good "Metasploit Databse named msf has been created."
else
print_error "Failed to create the msf database."
fi
fi
fi
}
########################################
function install_msf_osx
{
print_status "Installing Metasploit Framework from the GitHub Repository"
print_status "Cloning latest version of Metasploit Framework"
git clone https://github.com/rapid7/metasploit-framework.git /usr/local/share/metasploit-framework
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
print_status "Installing required ruby gems by Framework using bundler"
cd /usr/local/share/metasploit-framework
bundle install
print_status "Starting Metasploit so as to populate de database."
/usr/local/share/metasploit-framework/msfconsole -q -x "exit"
}
########################################
function install_plugins
{
print_status "Installing addiotional 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
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
print_status "Installing base Ruby Gems"
sudo gem install wirble sqlite3 bundler #>> $LOGFILE
}
#######################################
function install_nmap_linux
{
print_status "Downloading and Compiling the latest version if Nmap"
print_status "Downloading from SVN the latest version of Nmap"
cd /usr/src
sudo svn co https://svn.nmap.org/nmap #>> $LOGFILE
cd nmap
print_status "Configuring Nmap"
sudo ./configure #>> $LOGFILE
print_status "Compiling the latest version of Nmap"
sudo make #>> $LOGFILE
print_status "Installing the latest version of Nmap"
sudo make install #>> $LOGFILE
sudo make clean #>> $LOGFILE
}
#######################################
function configure_psql_deb
{
print_status "Creating the MSF Database user msf with the password provided"
sudo -u postgres psql postgres -c "create role msf login password '$MSFPASS'"
if [ $? -eq 0 ]; then
print_good "Metasploit Role named msf has been created."
else
print_error "Failed to create the msf role"
fi
print_status "Creating msf database and setting the owner to msf user"
sudo -u postgres psql postgres -c "CREATE DATABASE msf OWNER msf;"
if [ $? -eq 0 ]; then
print_good "Metasploit Databse named msf has been created."
else
print_error "Failed to create the msf database."
fi
}
#######################################
function install_msf_linux
{
print_status "Installing Metasploit Framework from the GitHub Repository"
print_status "Cloning latest version of Metasploit Framework"
sudo git clone https://github.com/rapid7/metasploit-framework.git /usr/local/share/metasploit-framework #>> $LOGFILE
print_status "Linking metasploit commands."
cd /usr/local/share/metasploit-framework
for MSF in $(ls msf*); do
print_status "linking $MSF command"
sudo ln -s /usr/local/share/metasploit-framework/$MSF /usr/local/bin/$MSF
done
print_status "Creating Database configuration YAML file."
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"
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
print_status "Installing required ruby gems by Framework using bundler"
cd /usr/local/share/metasploit-framework
sudo bundle install #>> $LOGFILE
print_status "Starting Metasploit so as to populate de database."
/usr/local/share/metasploit-framework/msfconsole -q -x "exit"
}
#######################################
function install_plugins_linux
{
print_status "Installing addiotional 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 intertet and can reach http://www.fastandeasyhacking.com"
else
print_status "Decompressing package to /opt/armitage"
sudo tar -xvzf /tmp/armitage.tgz -C /usr/local/share
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"
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"
fi
fi
}
#######################################
function usage ()
{
echo "Scritp for Installing Metasploit Framework"
echo "By Carlos_Perez[at]darkoperator.com"
echo "Ver 0.1.2"
echo ""
echo "-i :Install Metasploit Framework."
echo "-p <password> :password for MEtasploit databse msf user. If not provided a roandom one is generated for you."
echo "-g :Install GNU GCC (Not necessary uless you wish to compile and install ruby 1.8.7 in OSX"
echo "-h :This help message"
}
#### MAIN ###
[[ ! $1 ]] && { usage; exit 0; }
#Variable with log file location for trobleshooting
LOGFILE="/tmp/msfinstall$NOW.log"
while getopts "igp:h" options; do
case $options in
p ) MSFPASS=$OPTARG;;
i ) INSTALL=0;;
g ) IGCC=0;;
h ) usage;;
\? ) usage
exit 1;;
* ) usage
exit 1;;
esac
done
if [ $INSTALL -eq 0 ]; then
if [[ "$KVER" =~ Darwin ]]; then
check_dependencies_osx
check_for_brew_osx
install_ruby_osx
install_nmap_osx
install_postgresql_osx
install_msf_osx
install_armitage_osx
install_plugins
if [ $IGCC -eq 0 ]; then
install_gcc_osx
fi
print_status "#################################################################"
print_status "### YOU NEED TO RELOAD YOUR PROFILE BEFORE USE OF METASPLOIT! ###"
print_status "### RUN source ~/.bash_profile ###"
print_status "#################################################################"
elif [[ "$KVER" =~ buntu ]]; then
install_deps_deb
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 ###"
print_status "#################################################################"
else
print_error "The script does not support this platform at this moment."
exit 1
fi
fi