forked from mitre/caldera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·266 lines (233 loc) · 9.26 KB
/
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
#!/bin/bash
CALDERA_DIR=$(pwd)
USER=$(printf '%s\n' "${SUDO_USER:-$USER}")
CRITICAL=1
WARNING=0
CRITICAL_FAIL=0
WARNING_FAIL=0
function installed() {
echo "[+] $1 installed"
echo "[+] $1 installed">>install_log.txt
}
function failed() {
echo "[x] "$1" FAILED to install"
echo "[x] "$1" FAILED to install">>install_log.txt
echo " - command: $2">>install_log.txt
}
function install_wrapper() {
echo "[-] Checking for $1"
which $2
if [[ $? != 0 ]]; then
echo "[-] Installing $1"
if eval $3; then
installed "$1"
else
failed "$1" "$3"
if [[ $4 == 1 ]]; then
CRITICAL_FAIL=1
else
WARNING_FAIL=1
fi
fi
else
echo "[+] "$1" already installed"
echo "[+] "$1" already installed">>install_log.txt
fi
}
function initialize_log() {
echo "CALDERA install log">install_log.txt
}
function extra_error() {
if [[ $? == 0 ]]; then
installed "$2"
else
failed "$2" "$1"
if [[ $3 == 1 ]]; then
CRITICAL_FAIL=1
echo $CRITICAL_FAIL
else
WARNING_FAIL=1
fi
fi
}
function run_uprivileged() {
su - "$USER" -c "$1"
extra_error "$1" "$2" "$3"
}
function all_install_go_dependencies() {
echo "[-] Installing on GO dependencies"
go get "github.com/google/go-github/github"
extra_error "go get github.com/google/go-github/github" "GO github" $WARNING
go get "golang.org/x/oauth2"
extra_error "go get golang.org/x/oauth2" "GO oath2" $WARNING
}
function all_install_python_requirements() {
echo "[-] Setting up Python venv"
run_uprivileged "pip3 -q install --user virtualenv" "Python virtualenv" $CRITICAL
run_uprivileged "virtualenv -q -p python3 $CALDERA_DIR/calderaenv" "Caldera python venv" $CRITICAL
run_uprivileged "$CALDERA_DIR/calderaenv/bin/pip -q install -r $CALDERA_DIR/requirements.txt" "Caldera python requirements" $CRITICAL
}
function all_build_documentation() {
echo "[-] Building documentation"
run_uprivileged "$CALDERA_DIR/calderaenv/bin/sphinx-build -b html $CALDERA_DIR/docs $CALDERA_DIR/docs/_build" "sphinx documentation" $WARNING
}
function darwin_install_homebrew() {
install_wrapper "Homebrew" brew "/usr/bin/ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"" $CRITICAL
}
function darwin_install_go() {
install_wrapper "GO" go "brew install go" $WARNING
}
function darwin_install_mingw() {
install_wrapper "MinGW" x86_64-w64-mingw32-gcc "brew install mingw-w64" $WARNING
}
function darwin_install_python() {
install_wrapper "Python" python3 "brew install python" $CRITICAL
}
function darwin_install_or_upgrade_gcc() {
if brew ls --versions "gcc" >/dev/null; then
brew upgrade "gcc"
else
install_wrapper "GCC" gcc "brew install gcc" $WARNING
fi
}
function kali_install_go() {
install_wrapper "GO" go "apt-get install -y golang-go" $WARNING
}
function kali_install_python() {
install_wrapper "Python" python3 "apt-get install -y python3.8 python3.8-dev python3.8-venv" $WARNING
install_wrapper "Pip" pip3 "apt-get install -y python3-pip" $CRITICAL
}
function ubuntu_install_go() {
install_wrapper "GO" go "apt-get install -y software-properties-common && add-apt-repository -y ppa:longsleep/golang-backports && apt-get update -y && apt-get install -y golang-go" $WARNING
}
function ubuntu_install_gcc() {
install_wrapper "GCC" gcc "apt-get install -y build-essential" $WARNING
}
function ubuntu_install_mingw() {
install_wrapper "MinGW" x86_64-w64-mingw32-gcc "apt-get install -y mingw-w64" $WARNING
}
function ubuntu_install_python() {
install_wrapper "Python" python3 "apt-get install -y software-properties-common && add-apt-repository -y ppa:deadsnakes/ppa && apt-get update -y && apt-get install -y python3.7" $CRITICAL
install_wrapper "Pip" pip3 "apt-get install -y python3-pip" $CRITICAL
}
function centos_install_core_tools() {
install_wrapper "Core" wget "yum update -y && yum install -y epel-release && yum install -y wget" $CRITICAL
}
function centos_install_go() {
install_wrapper "GO" go "yum update -y && wget --no-check-certificate https://dl.google.com/go/go1.13.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.13.linux-amd64.tar.gz && export PATH=$PATH:/usr/local/go/bin && ln -fs /usr/local/go/bin/go /usr/bin/go && source ~/.bash_profile" $WARNING
}
function centos_install_gcc() {
install_wrapper "GCC" gcc "yum install -y gcc" $WARNING
}
function centos_install_mingw() {
install_wrapper "MinGW" x86_64-w64-mingw32-gcc "yum install -y mingw64-gcc" $WARNING
}
function centos_install_python() {
install_wrapper "Python" python3 "yum install -y gcc openssl-devel bzip2-devel libffi libffi-devel && cd /root && wget --no-check-certificate https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz && tar xzf Python-3.8.0.tgz && cd Python-3.8.0 && ./configure --enable-optimizations && make altinstall && rm -f /root/Python-3.8.0.tgz && ln -fs /usr/local/bin/python3.8 /usr/bin/python3 && ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3 && ln -fs /usr/local/bin/virtualenv /usr/bin/virtualenv && cd $CALDERA_DIR" $CRITICAL
}
function bash_set_random_conf_data_linux() {
echo "[-] Generating Random Values"
sed -i.backup "s/ADMIN123/$(cat /proc/sys/kernel/random/uuid)/g" $CALDERA_DIR/conf/default.yml
extra_error "sed -i.backup \"s/ADMIN123/$(cat /proc/sys/kernel/random/uuid)/g\" $CALDERA_DIR/conf/default.yml" "caldera random api_keys" $WARNING
sed -i.backup "s/REPLACE_WITH_RANDOM_VALUE/$(cat /proc/sys/kernel/random/uuid)/g" $CALDERA_DIR/conf/default.yml
extra_error "sed -i.backup \"s/REPLACE_WITH_RANDOM_VALUE/$(cat /proc/sys/kernel/random/uuid)/g\" $CALDERA_DIR/conf/default.yml" "caldera random crypt_salt" $WARNING
echo "[+] Random Values added to default.yml"
}
function bash_set_random_conf_data_darwin() {
echo "[-] Generating Random Values"
sed -i.backup "s/ADMIN123/$(uuidgen)/g" $CALDERA_DIR/conf/default.yml
extra_error "sed -i.backup \"s/ADMIN123/$(uuidgen)/g\" $CALDERA_DIR/conf/default.yml" "caldera random api_keys" $WARNING
sed -i.backup "s/REPLACE_WITH_RANDOM_VALUE/$(uuidgen)/g" $CALDERA_DIR/conf/default.yml
extra_error "sed -i.backup \"s/REPLACE_WITH_RANDOM_VALUE/$(uuidgen)/g\" $CALDERA_DIR/conf/default.yml" "caldera random crypt_salt" $WARNING
echo "[+] Random Values added to default.yml"
}
function display_welcome_msg() {
if [[ $CRITICAL_FAIL == 1 ]]; then
echo "[x] Caldera installer FAILED to install critical components"
echo "[x] See install_log.txt for details"
elif [[ $WARNING_FAIL == 1 ]]; then
echo "[x] Caldera installer FAILED to install optional components"
echo "[x] Caldera may run with degraded functionality"
echo "[x] See install_log.txt for details"
echo "[+] Caldera environment built"
echo "[+] Start the server by copy pasting these commands into the terminal"
echo " source calderaenv/bin/activate"
echo " python server.py"
else
echo "[+] Caldera environment built"
echo "[+] Start the server by copy pasting these commands into the terminal"
echo " source calderaenv/bin/activate"
echo " python server.py"
fi
}
function darwin() {
[[ $EUID -ne 0 ]] && echo "You must run the script with sudo." && exit 1
echo "[-] Installing on OS X..."
initialize_log
darwin_install_homebrew
darwin_install_go
darwin_install_or_upgrade_gcc
darwin_install_mingw
darwin_install_python
bash_set_random_conf_data_darwin
all_install_go_dependencies
all_install_python_requirements
all_build_documentation
display_welcome_msg
}
function ubuntu() {
[[ $EUID -ne 0 ]] && echo "You must run the script with sudo." && exit 1
echo "[-] Installing on Ubuntu (Debian)..."
initialize_log
ubuntu_install_go
ubuntu_install_gcc
ubuntu_install_mingw
ubuntu_install_python
bash_set_random_conf_data_linux
all_install_go_dependencies
all_install_python_requirements
all_build_documentation
display_welcome_msg
}
function kali() {
[[ $EUID -ne 0 ]] && echo "You must run the script with sudo." && exit 1
echo "[-] Installing on Kali (Debian)..."
initialize_log
kali_install_go
ubuntu_install_gcc
ubuntu_install_mingw
kali_install_python
bash_set_random_conf_data_linux
all_install_go_dependencies
all_install_python_requirements
all_build_documentation
display_welcome_msg
}
function centos() {
[[ $EUID -ne 0 ]] && echo "You must run the script with sudo." && exit 1
echo "[-] Installing on CentOS (RedHat)..."
initialize_log
centos_install_core_tools
centos_install_go
centos_install_gcc
centos_install_mingw
centos_install_python
bash_set_random_conf_data_linux
all_install_go_dependencies
all_install_python_requirements
all_build_documentation
display_welcome_msg
}
if [[ "$(uname)" == *"Darwin"* ]]; then
darwin
elif [[ "$(lsb_release -d)" == *"Ubuntu"* ]]; then
ubuntu
elif [[ "$(cat /etc/centos-release 2>/dev/null)" == *"CentOS"* ]]; then
centos
elif [[ "$(lsb_release -d)" == *"Fedora"* ]]; then
centos
elif [[ "$(lsb_release -d)" == *"Kali"* ]]; then
kali
else
echo "OS not supported. Supported OS are Ubuntu, Centos, Fedora and Kali." && exit 1
fi