Merge pull request #524 from guardicore/bugfix/handle_missing_curl_wget

Bugfix/handle missing curl wget fixes #503
This commit is contained in:
Shay Nehmad 2020-01-19 11:51:47 +02:00 committed by GitHub
commit 1477190d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 66 deletions

View File

@ -1,9 +1,13 @@
#!/bin/bash #!/bin/bash
source config source config
exists() {
command -v "$1" >/dev/null 2>&1
}
# Setup monkey either in dir required or current dir # Setup monkey either in dir required or current dir
monkey_home=${1:-`pwd`} monkey_home=${1:-$(pwd)}
if [[ $monkey_home == `pwd` ]]; then if [[ $monkey_home == $(pwd) ]]; then
monkey_home="$monkey_home/$MONKEY_FOLDER_NAME" monkey_home="$monkey_home/$MONKEY_FOLDER_NAME"
fi fi
@ -15,12 +19,12 @@ ISLAND_BINARIES_PATH="$ISLAND_PATH/cc/binaries"
INFECTION_MONKEY_DIR="$monkey_home/monkey/infection_monkey" INFECTION_MONKEY_DIR="$monkey_home/monkey/infection_monkey"
MONKEY_BIN_DIR="$INFECTION_MONKEY_DIR/bin" MONKEY_BIN_DIR="$INFECTION_MONKEY_DIR/bin"
handle_error () { handle_error() {
echo "Fix the errors above and rerun the script" echo "Fix the errors above and rerun the script"
exit 1 exit 1
} }
log_message () { log_message() {
echo -e "\n\n-------------------------------------------" echo -e "\n\n-------------------------------------------"
echo -e "DEPLOYMENT SCRIPT: $1" echo -e "DEPLOYMENT SCRIPT: $1"
echo -e "-------------------------------------------\n" echo -e "-------------------------------------------\n"
@ -33,37 +37,40 @@ if [[ $? != 0 ]]; then
fi fi
if [[ ! -d ${monkey_home} ]]; then if [[ ! -d ${monkey_home} ]]; then
mkdir -p ${monkey_home} mkdir -p "${monkey_home}"
fi fi
git --version &>/dev/null if ! exists git; then
git_available=$?
if [[ ${git_available} != 0 ]]; then
echo "Please install git and re-run this script" echo "Please install git and re-run this script"
exit 1 exit 1
fi fi
if ! exists wget; then
echo 'Your system does have wget, please install and re-run this script'
exit 1
fi
log_message "Cloning files from git" log_message "Cloning files from git"
branch=${2:-"develop"} branch=${2:-"develop"}
if [[ ! -d "$monkey_home/monkey" ]]; then # If not already cloned if [[ ! -d "$monkey_home/monkey" ]]; then # If not already cloned
git clone --single-branch -b $branch ${MONKEY_GIT_URL} ${monkey_home} 2>&1 || handle_error git clone --single-branch -b "$branch" "${MONKEY_GIT_URL}" "${monkey_home}" 2>&1 || handle_error
chmod 774 -R ${monkey_home} chmod 774 -R "${monkey_home}"
fi fi
# Create folders # Create folders
log_message "Creating island dirs under $ISLAND_PATH" log_message "Creating island dirs under $ISLAND_PATH"
mkdir -p ${MONGO_PATH} mkdir -p "${MONGO_PATH}"
mkdir -p ${ISLAND_BINARIES_PATH} || handle_error mkdir -p "${ISLAND_BINARIES_PATH}" || handle_error
# Detecting command that calls python 3.7 # Detecting command that calls python 3.7
python_cmd="" python_cmd=""
if [[ `python --version 2>&1` == *"Python 3.7"* ]]; then if [[ $(python --version 2>&1) == *"Python 3.7"* ]]; then
python_cmd="python" python_cmd="python"
fi fi
if [[ `python37 --version 2>&1` == *"Python 3.7"* ]]; then if [[ $(python37 --version 2>&1) == *"Python 3.7"* ]]; then
python_cmd="python37" python_cmd="python37"
fi fi
if [[ `python3.7 --version 2>&1` == *"Python 3.7"* ]]; then if [[ $(python3.7 --version 2>&1) == *"Python 3.7"* ]]; then
python_cmd="python3.7" python_cmd="python3.7"
fi fi
@ -92,7 +99,7 @@ ${python_cmd} -m pip install --user --upgrade -r ${requirements} || handle_error
log_message "Installing monkey requirements" log_message "Installing monkey requirements"
sudo apt-get install libffi-dev upx libssl-dev libc++1 sudo apt-get install libffi-dev upx libssl-dev libc++1
cd ${monkey_home}/monkey/infection_monkey || handle_error cd "${monkey_home}"/monkey/infection_monkey || handle_error
${python_cmd} -m pip install -r requirements.txt --user --upgrade || handle_error ${python_cmd} -m pip install -r requirements.txt --user --upgrade || handle_error
# Download binaries # Download binaries
@ -105,21 +112,23 @@ wget -c -N -P ${ISLAND_BINARIES_PATH} ${WINDOWS_64_BINARY_URL}
chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_32_BINARY_NAME" chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_32_BINARY_NAME"
chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_64_BINARY_NAME" chmod a+x "$ISLAND_BINARIES_PATH/$LINUX_64_BINARY_NAME"
# Get machine type/kernel version # Get machine type/kernel version
kernel=`uname -m` kernel=$(uname -m)
linux_dist=`lsb_release -a 2> /dev/null` linux_dist=$(lsb_release -a 2>/dev/null)
# If a user haven't installed mongo manually check if we can install it with our script # If a user haven't installed mongo manually check if we can install it with our script
log_message "Installing MongoDB" log_message "Installing MongoDB"
${ISLAND_PATH}/linux/install_mongo.sh ${MONGO_PATH} || handle_error "${ISLAND_PATH}"/linux/install_mongo.sh ${MONGO_PATH} || handle_error
log_message "Installing openssl" log_message "Installing openssl"
sudo apt-get install openssl sudo apt-get install openssl
# Generate SSL certificate # Generate SSL certificate
log_message "Generating certificate" log_message "Generating certificate"
cd ${ISLAND_PATH} cd "${ISLAND_PATH}" || {
echo "cd failed"
exit 1
}
openssl genrsa -out cc/server.key 2048 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 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 openssl x509 -req -days 366 -in cc/server.csr -signkey cc/server.key -out cc/server.crt
@ -137,20 +146,19 @@ log_message "Generating front end"
npm run dist npm run dist
# Making dir for binaries # Making dir for binaries
mkdir ${MONKEY_BIN_DIR} mkdir "${MONKEY_BIN_DIR}"
# Download sambacry binaries # Download sambacry binaries
log_message "Downloading 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_64_BINARY_URL}"
wget -c -N -P ${MONKEY_BIN_DIR} ${SAMBACRY_32_BINARY_URL} wget -c -N -P "${MONKEY_BIN_DIR}" "${SAMBACRY_32_BINARY_URL}"
# Download traceroute binaries # Download traceroute binaries
log_message "Downloading traceroute binaries" log_message "Downloading traceroute binaries"
wget -c -N -P ${MONKEY_BIN_DIR} ${TRACEROUTE_64_BINARY_URL} wget -c -N -P "${MONKEY_BIN_DIR}" "${TRACEROUTE_64_BINARY_URL}"
wget -c -N -P ${MONKEY_BIN_DIR} ${TRACEROUTE_32_BINARY_URL} wget -c -N -P "${MONKEY_BIN_DIR}" "${TRACEROUTE_32_BINARY_URL}"
sudo chmod +x "${monkey_home}"/monkey/infection_monkey/build_linux.sh
sudo chmod +x ${monkey_home}/monkey/infection_monkey/build_linux.sh
log_message "Deployment script finished." log_message "Deployment script finished."
exit 0 exit 0

View File

@ -1,40 +1,58 @@
#!/bin/bash #!/bin/bash
export os_version_monkey=$(cat /etc/issue) exists() {
command -v "$1" >/dev/null 2>&1
}
os_version_monkey=$(cat /etc/issue)
export os_version_monkey
MONGODB_DIR=$1 # If using deb, this should be: /var/monkey/monkey_island/bin/mongodb MONGODB_DIR=$1 # If using deb, this should be: /var/monkey/monkey_island/bin/mongodb
if [[ ${os_version_monkey} == "Ubuntu 16.04"* ]] ; if [[ ${os_version_monkey} == "Ubuntu 16.04"* ]]; then
then
echo Detected Ubuntu 16.04 echo Detected Ubuntu 16.04
export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.6.12.tgz" export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.6.12.tgz"
elif [[ ${os_version_monkey} == "Ubuntu 18.04"* ]] ; elif [[ ${os_version_monkey} == "Ubuntu 18.04"* ]]; then
then
echo Detected Ubuntu 18.04 echo Detected Ubuntu 18.04
export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.0.tgz" export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.0.tgz"
elif [[ ${os_version_monkey} == "Debian GNU/Linux 8"* ]] ; elif [[ ${os_version_monkey} == "Debian GNU/Linux 8"* ]]; then
then
echo Detected Debian 8 echo Detected Debian 8
export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.6.12.tgz" export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian81-3.6.12.tgz"
elif [[ ${os_version_monkey} == "Debian GNU/Linux 9"* ]] ; elif [[ ${os_version_monkey} == "Debian GNU/Linux 9"* ]]; then
then
echo Detected Debian 9 echo Detected Debian 9
export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-3.6.12.tgz" export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-3.6.12.tgz"
else else
echo Unsupported OS echo Unsupported OS
exit -1 exit 1
fi fi
TEMP_MONGO=$(mktemp -d) TEMP_MONGO=$(mktemp -d)
pushd ${TEMP_MONGO} pushd "${TEMP_MONGO}" || {
wget ${tgz_url} -O mongodb.tgz echo "Pushd failed"
tar -xf mongodb.tgz exit 1
popd }
mkdir -p ${MONGODB_DIR}/bin if exists wget; then
mkdir -p ${MONGODB_DIR}/db wget ${tgz_url} -O mongodb.tgz
cp ${TEMP_MONGO}/mongodb-*/bin/mongod ${MONGODB_DIR}/bin/mongod else
cp ${TEMP_MONGO}/mongodb-*/LICENSE-Community.txt ${MONGODB_DIR}/ if exists curl; then
chmod a+x ${MONGODB_DIR}/bin/mongod curl --output mongodb.tgz ${tgz_url}
rm -r ${TEMP_MONGO} else
echo 'Your system has neither curl nor wget, exiting'
exit 1
fi
fi
tar -xf mongodb.tgz
popd || {
echo "popd failed"
exit 1
}
mkdir -p "${MONGODB_DIR}"/bin
mkdir -p "${MONGODB_DIR}"/db
cp "${TEMP_MONGO}"/mongodb-*/bin/mongod "${MONGODB_DIR}"/bin/mongod
cp "${TEMP_MONGO}"/mongodb-*/LICENSE-Community.txt "${MONGODB_DIR}"/
chmod a+x "${MONGODB_DIR}"/bin/mongod
rm -r "${TEMP_MONGO}"
exit 0 exit 0