forked from owtf/owtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·360 lines (302 loc) · 9.96 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
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
#!/usr/bin/env sh
#set -e
SCRIPT_DIR="$(pwd -P)/scripts"
OWTF_DIR="${HOME}/.owtf"
ROOT_DIR="$(dirname $SCRIPT_DIR)/owtf"
CWD="$(dirname $ROOT_DIR)"
os=${OSTYPE//[0-9.-]*/}
. ${SCRIPT_DIR}/platform_config.sh
export NVM_DIR="${HOME}/.nvm"
# ======================================
# ESSENTIAL
# ======================================
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }
if [ ! -f "${CWD}/Makefile" ]; then
die "Exiting: no Makefile found"
fi
[ -d $OWTF_DIR ] || mkdir $OWTF_DIR
# ======================================
# COLORS
# ======================================
bold=$(tput bold)
reset=$(tput sgr0)
danger=${bold}$(tput setaf 1) # red
warning=${bold}$(tput setaf 3) # yellow
info=${bold}$(tput setaf 6) # cyan
normal=${bold}$(tput setaf 7) # white
# =======================================
# Default variables
# =======================================
user_agent='Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/15.0'
action="init"
certs_folder="${OWTF_DIR}/proxy/certs"
ca_cert="${OWTF_DIR}/proxy/certs/ca.crt"
ca_key="${OWTF_DIR}/proxy/certs/ca.key"
ca_pass_file="${OWTF_DIR}/proxy/certs/ca_pass.txt"
ca_key_pass="$(openssl rand -base64 16)"
postgres_server_ip="127.0.0.1"
db_name="owtf_db"
db_user="owtf_db_user"
db_pass="jgZKW33Q+HZk8rqylZxaPg1lbuNGHJhgzsq3gBKV32g="
postgres_server_port=5432
postgres_version="$(psql --version 2>&1 | tail -1 | awk '{print $3}' | $SED_CMD 's/\./ /g' | awk '{print $1 "." $2}')"
# =======================================
# COMMON FUNCTIONS
# =======================================
if [[ "$(cat /proc/1/cgroup 2> /dev/null | grep docker | wc -l)" > 0 ]] || [ -f /.dockerenv ]; then
IS_DOCKER=1
else
IS_DOCKER=0
fi
create_directory() {
if [ ! -d $1 ]; then
mkdir -p $1;
return 1
else
return 0
fi
}
check_sudo() {
timeout 2 sudo id && sudo=1 || sudo=0
return $sudo
}
check_root() {
if [ $EUID -eq 0 ]; then
return 1
else
return 0
fi
}
install_in_dir() {
tmp=$PWD
if [ $(create_directory $1) ]; then
cd $1
echo "Running command $2 in $1"
$2
else
echo "${warning}[!] Directory $1 already exists, so skipping installation for this${reset}"
fi
cd $tmp
}
check_debian() {
if [ -f "/etc/debian_version" ]; then
debian=1
else
debian=0
fi
return $debian
}
copy_dirs() {
dest=$2
src=$1
if [ ! -d $dest ]; then
cp -r $src $dest
else
echo "${warning}[!] Skipping copying directory $(basename $src) ${reset}"
fi
}
# =======================================
# PROXY CERTS SETUP
# =======================================
proxy_setup() {
if [ ! -f ${ca_cert} ]; then
# If ca.crt is absent then all the old signed certs have to be wiped clean first
if [ -d ${certs_folder} ]; then
rm -r ${certs_folder}
fi
mkdir -p ${certs_folder}
# A file is created which consists of CA password
if [ -f ${ca_pass_file} ]; then
rm ${ca_pass_file}
fi
echo $ca_key_pass >> $ca_pass_file
openssl genrsa -des3 -passout pass:${ca_key_pass} -out "$ca_key" 4096
openssl req -new -x509 -days 3650 -subj "/C=US/ST=Pwnland/L=OWASP/O=OWTF/CN=MiTMProxy" -passin pass:${ca_key_pass} \
-key "$ca_key" -out "$ca_cert"
echo "${warning}[!] Don't forget to add the $ca_cert as a trusted CA in your browser${reset}"
else
echo "${info}[*] '${ca_cert}' already exists. Nothing done.${reset}"
fi
}
# =======================================
# DATABASE setup
# =======================================
# Check if postgresql service is running or not
postgresql_check_running_status() {
postgres_ip_status=$(get_postgres_server_ip)
if [ -z "$postgres_ip_status" ]; then
echo "${info}PostgreSQL server is not running.${reset}"
echo "${info}Please start the PostgreSQL server and rerun.${reset}"
echo "${info}For Kali/Debian like systems, try sudo service postgresql start or sudo systemctl start postgresql ${reset}"
echo "${info}For macOS, use pg_ctl -D /usr/local/var/postgres start ${reset}"
else
echo "${info}[+] PostgreSQL server is running ${postgres_server_ip}:${postgres_server_port} :)${reset}"
fi
}
# returns postgresql service IP
get_postgres_server_ip() {
if [ $os == "darwin" ]; then
echo "$(lsof -i -n -P | grep TCP | grep postgres | sed 's/\s\+/ /g' | cut -d ' ' -f4 | cut -d ':' -f1 | uniq)"
else
echo "$(sudo netstat -lptn | grep "^tcp " | grep postgres | sed 's/\s\+/ /g' | cut -d ' ' -f4 | cut -d ':' -f1)"
fi
}
postgresql_create_user() {
if [ $os == "darwin" ]; then
psql postgres -c "CREATE USER $db_user WITH PASSWORD '$db_pass';"
else
sudo su postgres -c "psql -c \"CREATE USER $db_user WITH PASSWORD '$db_pass'\""
fi
}
postgres_alter_user_password() {
if [ $os == "darwin" ]; then
psql postgres -tc "ALTER USER $db_user WITH PASSWORD '$db_pass';"
else
sudo su postgres -c "psql postgres -tc \"ALTER USER $db_user WITH PASSWORD '$db_pass'\""
fi
}
postgresql_create_db() {
if [ $os == "darwin" ]; then
psql postgres -c "CREATE DATABASE $db_name WITH OWNER $db_user ENCODING 'utf-8' TEMPLATE template0;"
else
sudo su postgres -c "psql -c \"CREATE DATABASE $db_name WITH OWNER $db_user ENCODING 'utf-8' TEMPLATE template0;\""
fi
}
postgresql_check_user() {
cmd="$(psql -l | grep -w $db_name | grep -w $db_user | wc -l | xargs)"
if [ "$cmd" != "0" ]; then
return 1
else
return 0
fi
}
postgresql_drop_user() {
if [ $os == "darwin" ]; then
psql postgres -c "DROP USER $db_user"
else
sudo su postgres -c "psql -c \"DROP USER $db_user\""
fi
}
postgresql_drop_db() {
if [ $os == "darwin" ]; then
psql postgres -c "DROP DATABASE $db_name"
else
sudo su postgres -c "psql -c \"DROP DATABASE $db_name\""
fi
}
postgresql_check_db() {
cmd="$(psql -l | grep -w $db_name | wc -l | xargs)"
if [ "$cmd" != "0" ]; then
return 1
else
return 0
fi
}
db_setup() {
# Check if the postgres server is running or not.
postgresql_check_running_status
# postgres server is running perfectly fine begin with db_setup.
# Create a user $db_user if it does not exist
if [ postgresql_check_user == 1 ]; then
echo "${info}[+] User $db_user already exist.${reset}"
# User $db_user already exist in postgres database change the password
continue
else
# Create new user $db_user with password $db_pass
postgresql_create_user
fi
# Create database $db_name if it does not exist.
if [ postgresql_check_db == 1 ]; then
echo "${info}[+] Database $db_name already exist.${reset}"
continue
else
# Either database does not exists or the owner of database is not $db_user
# Create new database $db_name with owner $db_user
postgresql_create_db
fi
}
# ======================================
# KALI install
# ======================================
kali_install() {
echo "${info}[*] Install Kali linux specific dependencies...${reset}"
make install-dependencies
echo "${info}[*] Installing required tools...${reset}"
make opt-tools
make web-tools
sh "$SCRIPT_DIR/kali/install.sh"
}
# ======================================
# SETUP WEB INTERFACE DEPENDENCIES
# ======================================
ui_setup() {
# Download community written templates for export report functionality.
if [ ! -d "${ROOT_DIR}/webapp/src/containers/Report/templates" ]; then
echo "${warning} Templates not found, fetching the latest ones...${reset}"
git clone https://github.com/owtf/templates.git "$ROOT_DIR/webapp/src/containers/Report/templates"
fi
if [ ! -d ${NVM_DIR} ]; then
# Instead of using apt-get to install npm we will nvm to install npm because apt-get installs older-version of node
echo "${normal}[*] Installing npm using nvm.${reset}"
wget https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh -O /tmp/install_nvm.sh
bash /tmp/install_nvm.sh
rm -rf /tmp/install_nvm.sh
fi
# Setup nvm and install node
. ${NVM_DIR}/nvm.sh
echo "${normal}[*] Installing NPM...${reset}"
nvm install node
nvm alias default node
echo "${normal}[*] npm successfully installed.${reset}"
# Installing webpack and gulp globally so that it can used by command line to build the bundle.
npm install -g yarn
# Installing node dependencies
echo "${normal}[*] Installing node dependencies.${reset}"
TMP_DIR=${PWD}
cd ${ROOT_DIR}/webapp
yarn --silent
echo "${normal}[*] Yarn dependencies successfully installed.${reset}"
# Building the ReactJS project
echo "${normal}[*] Building using webpack.${reset}"
yarn build &> /dev/null
echo "${normal}[*] Build successful${reset}"
cd ${TMP_DIR}
}
#========================================
cat << EOF
_____ _ _ _ _____ _____
| | | | |_ _| __|
| | | | | | | | | __|
|_____|_____| |_| |__|
@owtfp
http://owtf.org
EOF
echo "${info}[*] Thanks for installing OWTF! ${reset}"
echo "${info}[!] There will be lot of output, please be patient :)${reset}"
# Copy git hooks
echo "${info}[*] Installing pre-commit and black for git hooks...${reset}"
pip install pre-commit==1.8.2
pip install black==18.4a3
pre-commit install
# Copy all necessary directories
for dir in ${ROOT_DIR}/data/*; do
copy_dirs "$dir" "${OWTF_DIR}/$(basename $OWTF_DIR/$dir)"
done
if [ ! "$(uname)" == "Darwin" ]; then
check_sudo > /dev/null
fi
proxy_setup
if [ "$IS_DOCKER" -eq "0" ]; then
db_setup
else
echo "${info}Running inside Docker, no need to configure DB"
fi
ui_setup
if [ "$(check_debian)" == "1" ]; then
kali_install
fi
make post-install
echo "${info}[*] Finished!${reset}"
echo "${info}[*] Start OWTF by running cd path/to/pentest/directory; owtf${reset}"