2018-12-10 19:08:59 +08:00
|
|
|
#!/bin/bash
|
|
|
|
source config
|
|
|
|
|
2020-01-05 04:55:00 +08:00
|
|
|
exists() {
|
|
|
|
command -v "$1" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2018-12-10 19:08:59 +08:00
|
|
|
# Setup monkey either in dir required or current dir
|
2020-01-05 04:55:00 +08:00
|
|
|
monkey_home=${1:-$(pwd)}
|
|
|
|
if [[ $monkey_home == $(pwd) ]]; then
|
|
|
|
monkey_home="$monkey_home/$MONKEY_FOLDER_NAME"
|
2018-12-10 19:08:59 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# We can set main paths after we know the home dir
|
|
|
|
ISLAND_PATH="$monkey_home/monkey/monkey_island"
|
|
|
|
MONKEY_COMMON_PATH="$monkey_home/monkey/common/"
|
|
|
|
MONGO_PATH="$ISLAND_PATH/bin/mongodb"
|
|
|
|
ISLAND_BINARIES_PATH="$ISLAND_PATH/cc/binaries"
|
2019-10-09 16:23:20 +08:00
|
|
|
INFECTION_MONKEY_DIR="$monkey_home/monkey/infection_monkey"
|
|
|
|
MONKEY_BIN_DIR="$INFECTION_MONKEY_DIR/bin"
|
2018-12-10 19:08:59 +08:00
|
|
|
|
2020-01-05 04:55:00 +08:00
|
|
|
handle_error() {
|
|
|
|
echo "Fix the errors above and rerun the script"
|
|
|
|
exit 1
|
2018-12-10 19:08:59 +08:00
|
|
|
}
|
|
|
|
|
2020-01-05 04:55:00 +08:00
|
|
|
log_message() {
|
|
|
|
echo -e "\n\n-------------------------------------------"
|
|
|
|
echo -e "DEPLOYMENT SCRIPT: $1"
|
|
|
|
echo -e "-------------------------------------------\n"
|
2018-12-10 19:08:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sudo -v
|
|
|
|
if [[ $? != 0 ]]; then
|
2020-01-05 04:55:00 +08:00
|
|
|
echo "You need root permissions for some of this script operations. Quiting."
|
|
|
|
exit 1
|
2018-12-10 19:08:59 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d ${monkey_home} ]]; then
|
2020-01-05 04:55:00 +08:00
|
|
|
mkdir -p ${monkey_home}
|
2018-12-10 19:08:59 +08:00
|
|
|
fi
|
|
|
|
|
2020-01-17 01:54:02 +08:00
|
|
|
if ! exists git; then
|
2020-01-05 04:55:00 +08:00
|
|
|
echo "Please install git and re-run this script"
|
|
|
|
exit 1
|
2018-12-10 19:08:59 +08:00
|
|
|
fi
|
|
|
|
|
2020-01-17 01:54:02 +08:00
|
|
|
if ! exists wget; then
|
|
|
|
echo 'Your system does have wget, please install and re-run this script'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-12-10 19:08:59 +08:00
|
|
|
log_message "Cloning files from git"
|
|
|
|
branch=${2:-"develop"}
|
|
|
|
if [[ ! -d "$monkey_home/monkey" ]]; then # If not already cloned
|
2020-01-05 04:55:00 +08:00
|
|
|
git clone --single-branch -b $branch ${MONKEY_GIT_URL} ${monkey_home} 2>&1 || handle_error
|
|
|
|
chmod 774 -R ${monkey_home}
|
2018-12-10 19:08:59 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create folders
|
|
|
|
log_message "Creating island dirs under $ISLAND_PATH"
|
2019-10-09 16:23:20 +08:00
|
|
|
mkdir -p ${MONGO_PATH}
|
2018-12-10 19:08:59 +08:00
|
|
|
mkdir -p ${ISLAND_BINARIES_PATH} || handle_error
|
|
|
|
|
2019-10-09 16:23:20 +08:00
|
|
|
# Detecting command that calls python 3.7
|
|
|
|
python_cmd=""
|
2020-01-05 04:55:00 +08:00
|
|
|
if [[ $(python --version 2>&1) == *"Python 3.7"* ]]; then
|
2019-10-09 16:23:20 +08:00
|
|
|
python_cmd="python"
|
|
|
|
fi
|
2020-01-05 04:55:00 +08:00
|
|
|
if [[ $(python37 --version 2>&1) == *"Python 3.7"* ]]; then
|
2019-10-09 16:23:20 +08:00
|
|
|
python_cmd="python37"
|
|
|
|
fi
|
2020-01-05 04:55:00 +08:00
|
|
|
if [[ $(python3.7 --version 2>&1) == *"Python 3.7"* ]]; then
|
2019-10-09 16:23:20 +08:00
|
|
|
python_cmd="python3.7"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${python_cmd} == "" ]]; then
|
|
|
|
log_message "Python 3.7 command not found. Installing python 3.7."
|
2019-10-23 20:11:58 +08:00
|
|
|
sudo add-apt-repository ppa:deadsnakes/ppa
|
2019-11-18 18:53:20 +08:00
|
|
|
sudo apt-get update
|
2019-10-23 20:11:58 +08:00
|
|
|
sudo apt install python3.7
|
2019-10-09 16:23:20 +08:00
|
|
|
log_message "Python 3.7 is now available with command 'python3.7'."
|
|
|
|
python_cmd="python3.7"
|
2018-12-10 19:08:59 +08:00
|
|
|
fi
|
|
|
|
|
2018-12-11 23:07:45 +08:00
|
|
|
log_message "Updating package list"
|
|
|
|
sudo apt-get update
|
|
|
|
|
|
|
|
log_message "Installing pip"
|
2019-10-09 16:23:20 +08:00
|
|
|
sudo apt install python3-pip
|
|
|
|
${python_cmd} -m pip install pip
|
2018-12-11 23:07:45 +08:00
|
|
|
|
2019-10-17 23:06:01 +08:00
|
|
|
log_message "Install python3.7-dev"
|
|
|
|
sudo apt-get install python3.7-dev
|
|
|
|
|
2018-12-10 19:08:59 +08:00
|
|
|
log_message "Installing island requirements"
|
2019-02-04 16:35:39 +08:00
|
|
|
requirements="$ISLAND_PATH/requirements.txt"
|
2019-10-09 16:23:20 +08:00
|
|
|
${python_cmd} -m pip install --user --upgrade -r ${requirements} || handle_error
|
2018-12-10 19:08:59 +08:00
|
|
|
|
2019-10-23 15:17:47 +08:00
|
|
|
log_message "Installing monkey requirements"
|
|
|
|
sudo apt-get install libffi-dev upx libssl-dev libc++1
|
|
|
|
cd ${monkey_home}/monkey/infection_monkey || handle_error
|
2019-11-26 19:22:56 +08:00
|
|
|
${python_cmd} -m pip install -r requirements.txt --user --upgrade || handle_error
|
2019-10-23 15:17:47 +08:00
|
|
|
|
2018-12-10 19:08:59 +08:00
|
|
|
# Download binaries
|
|
|
|
log_message "Downloading binaries"
|
|
|
|
wget -c -N -P ${ISLAND_BINARIES_PATH} ${LINUX_32_BINARY_URL}
|
|
|
|
wget -c -N -P ${ISLAND_BINARIES_PATH} ${LINUX_64_BINARY_URL}
|
|
|
|
wget -c -N -P ${ISLAND_BINARIES_PATH} ${WINDOWS_32_BINARY_URL}
|
|
|
|
wget -c -N -P ${ISLAND_BINARIES_PATH} ${WINDOWS_64_BINARY_URL}
|
|
|
|
# Allow them to be executed
|
|
|
|
chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_32_BINARY_NAME"
|
|
|
|
chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_64_BINARY_NAME"
|
2019-05-11 23:33:32 +08:00
|
|
|
|
2018-12-10 19:08:59 +08:00
|
|
|
# Get machine type/kernel version
|
2020-01-05 04:55:00 +08:00
|
|
|
kernel=$(uname -m)
|
|
|
|
linux_dist=$(lsb_release -a 2>/dev/null)
|
2018-12-10 19:08:59 +08:00
|
|
|
|
|
|
|
# If a user haven't installed mongo manually check if we can install it with our script
|
2019-05-09 21:29:05 +08:00
|
|
|
log_message "Installing MongoDB"
|
2019-10-09 16:23:20 +08:00
|
|
|
${ISLAND_PATH}/linux/install_mongo.sh ${MONGO_PATH} || handle_error
|
2018-12-10 19:08:59 +08:00
|
|
|
|
|
|
|
log_message "Installing openssl"
|
|
|
|
sudo apt-get install openssl
|
|
|
|
|
|
|
|
# Generate SSL certificate
|
|
|
|
log_message "Generating certificate"
|
2019-10-24 15:02:50 +08:00
|
|
|
cd ${ISLAND_PATH}
|
|
|
|
openssl genrsa -out cc/server.key 2048
|
|
|
|
openssl req -new -key cc/server.key -out cc/server.csr -subj "/C=GB/ST=London/L=London/O=Global Security/OU=Monkey Department/CN=monkey.com"
|
|
|
|
openssl x509 -req -days 366 -in cc/server.csr -signkey cc/server.key -out cc/server.crt
|
2018-12-10 19:08:59 +08:00
|
|
|
|
2019-10-09 16:23:20 +08:00
|
|
|
# Update node
|
|
|
|
log_message "Installing nodejs"
|
2019-10-24 16:17:10 +08:00
|
|
|
cd "$ISLAND_PATH/cc/ui" || handle_error
|
2019-11-18 18:53:20 +08:00
|
|
|
sudo apt-get install curl
|
2019-10-24 16:17:10 +08:00
|
|
|
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
|
2019-10-09 16:23:20 +08:00
|
|
|
sudo apt-get install -y nodejs
|
2019-10-24 16:17:10 +08:00
|
|
|
npm install sass-loader node-sass webpack --save-dev
|
2019-10-09 16:23:20 +08:00
|
|
|
npm update
|
2018-12-11 23:07:45 +08:00
|
|
|
|
2018-12-10 19:08:59 +08:00
|
|
|
log_message "Generating front end"
|
|
|
|
npm run dist
|
|
|
|
|
2019-10-09 16:23:20 +08:00
|
|
|
# Making dir for binaries
|
|
|
|
mkdir ${MONKEY_BIN_DIR}
|
|
|
|
|
|
|
|
# Download sambacry binaries
|
|
|
|
log_message "Downloading sambacry binaries"
|
|
|
|
wget -c -N -P ${MONKEY_BIN_DIR} ${SAMBACRY_64_BINARY_URL}
|
|
|
|
wget -c -N -P ${MONKEY_BIN_DIR} ${SAMBACRY_32_BINARY_URL}
|
|
|
|
|
|
|
|
# Download traceroute binaries
|
2019-10-23 19:46:59 +08:00
|
|
|
log_message "Downloading traceroute binaries"
|
2019-10-09 16:23:20 +08:00
|
|
|
wget -c -N -P ${MONKEY_BIN_DIR} ${TRACEROUTE_64_BINARY_URL}
|
|
|
|
wget -c -N -P ${MONKEY_BIN_DIR} ${TRACEROUTE_32_BINARY_URL}
|
|
|
|
|
2019-01-24 20:32:19 +08:00
|
|
|
sudo chmod +x ${monkey_home}/monkey/infection_monkey/build_linux.sh
|
2018-12-10 19:08:59 +08:00
|
|
|
|
|
|
|
log_message "Deployment script finished."
|
2019-02-04 16:35:39 +08:00
|
|
|
exit 0
|