-
Notifications
You must be signed in to change notification settings - Fork 3
/
install
executable file
·454 lines (334 loc) · 12.2 KB
/
install
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
#!/usr/bin/env bash
# BeEF/install
# install
# Install BeEF
# Based on: https://github.com/beefproject/beef/wiki/Installation
# Tested on:
# Kali:
# 2018.1
# Debian:
# 9 (stretch)
set -eo pipefail
# -e exit if any command returns non-zero status code
# -o pipefail force pipelines to fail on first non-zero status code
# Cannot use -u, it causes 'source ${HOME}/.rvm/scripts/rvm' to fail
# Error: ${HOME}/.rvm/scripts/functions/support/: line 182: _system_name: unound variable
### Define Colours ###
# Solarized colors, taken from http://git.io/solarized-colors
tput sgr0;
# reset colors
readonly BOLD=$(tput bold)
readonly RESET=$(tput sgr0)
readonly RED=$(tput setaf 1)
readonly YELLOW=$(tput setaf 136)
readonly GREEN=$(tput setaf 64)
readonly VIOLET=$(tput setaf 61)
### END Colours ###
readonly FATAL="${RED}FATAL${RESET}"
readonly WARNING="${YELLOW}WARNING${RESET}"
readonly PASS="${GREEN}PASS${RESET}"
readonly INFO="${VIOLET}INFO${RESET}"
### UTILITY FUNCTIONS ###
function check_compatibility {
# Check if Distribution is Kali or Debian
# If Kali check if version is 2018.1
# If Debian check if version 9 (stretch)
# Set target_os to Kali or Debian
declare -r kali_supported_version="2018.1"
declare -r debian_supported_version="9"
local distribution_id
local os_version_id
distribution_id="$(lsb_release -i | awk '{print $3}')"
os_version_id="$(grep "VERSION_ID" /etc/os-release | awk -F '"' '{print $2}')"
target_os=""
echo -e "[${INFO}] Checking OS compatability"
if [[ "${distribution_id}" == "Kali" ]]; then
echo -e "[${INFO}] Checking Kali version compatability"
if [[ ! "${os_version_id}" == "${kali_supported_version}" ]]; then
echo -e "[${WARNING}] Only tested on Kali Rolling ${kali_supported_version}"
target_os="Kali"
sleep 2
else
echo -e "[${PASS}] Successfully completed compatability check"
target_os="Kali"
fi
elif [[ "${distribution_id}" == "Debian" ]]; then
echo -e "[${INFO}] Checking Debian version compatability"
if [[ ! "${os_version_id}" == "${debian_supported_version}" ]]; then
echo -e "[${WARNING}] Only tested on Debian ${debian_supported_version}"
target_os="Debian"
sleep 2
else
echo -e "[${PASS}] Successfully completed compatability check"
target_os="Debian"
fi
else
echo -e "[${FATAL}] Only tested on Kali/ Debian"
exit 1
fi
}
function check_ruby_version_manager {
ruby_version_manager=""
# rvm or rbenv
local ruby_version_manager_choice=" "
# rvm or rbenv
install_rvm_bool="n"
# Boolean y/n
version_manager_fix
if [ -z "$(command -v rvm)" ] && [ -z "$(command -v rbenv)" ]; then
# Check if RVM or rbenv are present
echo -e "[${WARNING}] No Ruby version manager installed"
echo -e "[${WARNING}] Using a version manager like RVM or rbenv is highly recommended"
echo -e "[${INFO}] If you'd like to manually install rbenv see: \
\\n https://github.com/rbenv/rbenv#installation \
\\n https://gist.github.com/0xmachos/3cb7d989facbe8dc568b8d4912846a81"
echo -e "[${INFO}] This script can automtically install RVM"
# If no version manager ask user if they want to install RVM
echo -en "[${INFO}] Do you want to install RVM? (y/N) "
read -r install_rvm_bool
if [[ "${install_rvm_bool}" =~ ^(y|Y)$ ]]; then
# If the user answers yes then call install_rvm
echo -e "[${PASS}] $USER has chosen to install RVM"
install_rvm_bool="y"
else
echo -e "[${FATAL}] $USER has chosen not to install RVM"
echo -e "[${FATAL}] Install RVM or rbenv then rerun this script"
exit 1
fi
elif [ -n "$(command -v rvm)" ] && [ -n "$(command -v rbenv)" ]; then
# Check if both RVM and rbenv are present
echo -e "[${WARNING}] Mutiple Ruby version managers installed: RVM and rbenv"
echo -e "[${INFO}] This script prefers RVM over rbenv"
# If both installed ask the user if they want to continue with RVM
# This script prefers RVM to rbenv
echo -en "[${INFO}] Do you want to continue using RVM or rbenv? (rvm/rbenv) "
read -r ruby_version_manager_choice
# Loop untill the user answers one of rvm/RVM/rbenv/RBENV
while ! [[ "${ruby_version_manager_choice}" =~ ^(rvm|RVM|rbenv|RBENV)$ ]];
do
echo -en "[${INFO}] Do you want to continue using RVM or rbenv? (rvm/rbenv) "
unset ruby_version_manager_choice
read -r ruby_version_manager_choice
done
if [[ "${ruby_version_manager_choice}" =~ ^(rvm|RVM)$ ]]; then
# If users answers RVM/rvm then set ruby_version_manager to rvm
# ruby_version_manager is queried in main
ruby_version_manager="rvm"
echo -e "[${PASS}] $USER has chosen to continue using RVM"
elif [[ "${ruby_version_manager_choice}" =~ ^(rbenv|RBENV)$ ]]; then
ruby_version_manager="rbenv"
echo -e "[${PASS}] $USER has chosen to continue using rbenv"
fi
elif [ -n "$(command -v rvm)" ]; then
# Check if RVM is installed and set ruby_version_manager
# ruby_version_manager is queried in main
ruby_version_manager="rvm"
echo -e "[${PASS}] ${ruby_version_manager} already installed"
elif [ -n "$(command -v rbenv)" ]; then
# Check if rbenv is installed and set ruby_version_manager
# ruby_version_manager is queried in main
ruby_version_manager="rbenv"
echo -e "[${PASS}] ${ruby_version_manager} already installed"
else
# Totally fucked it
echo -e "[${FATAL}] Unknown error in 'check_ruby_version_manager'"
exit 1
fi
}
function rvm_fix {
if [[ "${target_os}" == "Kali" ]]; then
# shellcheck disable=SC1091
source "/etc/profile.d/rvm.sh"
elif [[ "${target_os}" == "Debian" ]]; then
# shellcheck disable=SC1090
source "${HOME}/.rvm/scripts/rvm"
else
echo -e "[${FATAL}] Compatibility issue"
exit 1
fi
}
function rbenv_fix {
"$HOME"/.rbenv/bin/rbenv init
}
function version_manager_fix {
if [[ -z "${ruby_version_manager}" ]]; then
# Try both ¯\_(ツ)_/¯
set +e
# DISABLE: exit if any command returns non-zero status code
# One of these will likely exit 1 because only one version manager should be present
rvm_fix >/dev/null 2>&1
rbenv_fix >/dev/null 2>&1
# ENABLE: exit if any command returns non-zero status code
set -e
elif [[ "${ruby_version_manager}" == "rvm" ]]; then
rvm_fix
elif [[ "${ruby_version_manager}" == "rbenv" ]]; then
rbenv_fix
else
# Totally fucked it
echo -e "[${FATAL}] Unknown error in 'version_manager_fix'"
exit 1
fi
}
### END UTILITY FUNCTIONS ###
function install_dependencies {
# Install required dependencies via apt-get
# TODO: Check target_os to install different deps depending on the OS
local all_deps=(curl git nodejs python3 python3-pip \
build-essential openssl libreadline-dev zlib1g \
zlib1g-dev libssl1.0-dev libyaml-dev libsqlite3-0 \
libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \
autoconf libc6-dev libncurses5-dev automake libtool \
bison)
local needed_deps=()
for package in "${all_deps[@]}"; do
if ! dpkg-query -W -f='${Status}' "${package}" 2>/dev/null | grep -q 'install ok installed'; then
needed_deps+=("${package}")
fi
done
if ! [ ${#needed_deps[@]} -eq 0 ]; then
echo -e "[${INFO}] Installing ${#needed_deps[@]} dependencies via apt-get"
sleep 2
sudo apt-get -qq update
else
echo -e "[${PASS}] All dependencies already installed"
return 0
fi
for package in "${needed_deps[@]}"; do
echo -e "[${INFO}] Installing ${package}"
if ! sudo apt-get -qq install -y "${package}" >/dev/null; then
echo -e "[${FATAL}] Failed to install ${package}"
exit 1
fi
done
# Clean up any redundant dependencies
sudo apt-get -qq autoremove -y >/dev/null
echo -e "[${PASS}] Dependencies installed"
return 0
}
function install_rvm {
# Fetch RVM PGP signing key, add it to keyring
# Install RVM via https://get.rvm.io
if gpg --list-keys | grep -q "409B6B1796C275462A1703113804BB82D39DC0E3" && gpg --list-keys | grep -q "7D2BAF1CF37B13E2069D6956105BD0E739499BDB"; then
echo -e "[${PASS}] RVM signing key already in keyring"
else
echo -e "[${INFO}] Getting RVM signing key"
if curl -sSL https://rvm.io/mpapis.asc | gpg --import - && curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -; then
echo -e "[${PASS}] Successfully imported RVM signing keys"
else
echo -e "[${FATAL}] Failed to get or import RVM signing keys"
exit 1
fi
fi
echo -e "[${INFO}] Installing RVM"
if curl -sSL https://get.rvm.io | bash -s stable ; then
ruby_version_manager="rvm"
echo -e "[${PASS}] Installed RVM"
else
echo -e "[${FATAL}] Failed to install RVM"
exit 1
fi
# shellcheck disable=SC2016
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> "$HOME/.bashrc"
}
function rvm_install_ruby {
# Install Ruby ${ruby_version} via RVM
# Set Ruby ${ruby_version} as default for RVM
version_manager_fix
if rvm list default | grep -q "${ruby_version}" ; then
echo -e "[${PASS}] RVM default Ruby version already ${ruby_version}"
else
echo -e "[${INFO}] Installing Ruby ${ruby_version}"
if rvm install "${ruby_version}" ; then
echo -e "[${PASS}] Ruby ${ruby_version} installed"
if rvm use "${ruby_version}" -- default ; then
echo -e "[${PASS}] Set ${ruby_version} as RVM default"
else
echo -e "[${FATAL}] Failed to set ${ruby_version} as RVM default"
exit 1
fi
else
echo -e "[${FATAL}] Failed to install Ruby ${ruby_version}"
exit 1
fi
fi
}
function rbenv_install_ruby {
# Install Ruby ${ruby_version} via rbenv
version_manager_fix
if rbenv version | grep -q "${ruby_version}" ; then
echo -e "[${PASS}] rbenv Ruby version already ${ruby_version}"
else
echo -e "[${INFO}] Installing Ruby ${ruby_version} via rbenv"
if rbenv install "${ruby_version}" ; then
rbenv global "${ruby_version}"
echo -e "[${PASS}] Ruby ${ruby_version} installed via rbenv"
else
echo -e "[${FATAL}] Failed to install Ruby ${ruby_version} via rbenv"
exit 1
fi
fi
}
function get_beef {
# Check for existing 'beef' directory
# Rename existing 'beef' directory
# Clone github.com/beefproject/beef into 'beef'
local move_time
local old_beef_dir_name
move_time=$(date +%b%d-%H:%M-%Z)
old_beef_dir_name="beef.old.${move_time}"
if [ -d "beef" ]; then
echo -e "[${INFO}] Renaming existing 'beef' directory to '${old_beef_dir_name}'"
mv -f "beef" "${old_beef_dir_name}"
fi
echo -e "[${INFO}] Cloning BeEF source into 'beef'"
if git clone "git://github.com/beefproject/beef.git"; then
echo -e "[${PASS}] Successfully cloned BeEF source into 'beef'"
else
echo -e "[${FATAL}] Failed to clone BeEF source into 'beef'"
exit 1
fi
}
function install_beef {
# Change directory to 'beef'
# Source '/etc/profile.d/rvm.sh' again just to be sure
# Install Bundler via gem
# Install BeEF via bundle[r]
(
cd "beef" || exit
version_manager_fix
echo -e "[${INFO}] Installing Bundler"
if gem install bundler ; then
echo -e "[${PASS}] Successfully installed bundler"
else
echo -e "[${FATAL}] Failed to install bundler"
exit 1
fi
echo -e "[${INFO}] Installing BeEF"
if bundle install --without test development ; then
echo -e "[${PASS}] Successfully installed BeEF"
else
echo -e "[${FATAL}] Failed to install BeEF"
exit 1
fi
)
echo -e "[${WARNING}] Before running './beef' you will need to execute 'source $HOME/.rvm/scripts/rvm'"
echo -e "[${WARNING}] In rare cases you will need to reopen your terminal window"
}
function main {
declare -r ruby_version="2.5.1"
check_compatibility
check_ruby_version_manager
install_dependencies
if [[ "${install_rvm_bool}" = "y" ]]; then
install_rvm
fi
if [[ "${ruby_version_manager}" == "rvm" ]] ; then
rvm_install_ruby
elif [[ "${ruby_version_manager}" == "rbenv" ]]; then
rbenv_install_ruby
fi
get_beef
install_beef
}
main "$@"