From 21a2083903a1ff03a3a9d69740733f56b40971ac Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Apr 2021 08:03:11 -0400 Subject: [PATCH 01/23] build: Use official `deployment_scripts/config` in build_appimage.sh --- deployment_scripts/appimage/build_appimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index c85f6f81c..a1c384801 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -199,7 +199,7 @@ Run \`sudo -v\`, enter your password, and then re-run this script." exit 1 fi -config_url="https://raw.githubusercontent.com/mssalvatore/monkey/linux-deploy-binaries/deployment_scripts/config" +config_url="https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/config" setup_appdir From 638004cfb26102ff3c06a6b12f5db3f950375979 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Apr 2021 12:25:16 -0400 Subject: [PATCH 02/23] build: Build AppImage with appimagetool instead of appimage-builder --- deployment_scripts/appimage/.gitignore | 1 + deployment_scripts/appimage/AppRun | 41 ++++++++++ deployment_scripts/appimage/README.md | 5 +- deployment_scripts/appimage/build_appimage.sh | 74 ++++++++----------- .../appimage/monkey-island.desktop | 8 ++ 5 files changed, 83 insertions(+), 46 deletions(-) create mode 100644 deployment_scripts/appimage/.gitignore create mode 100755 deployment_scripts/appimage/AppRun create mode 100644 deployment_scripts/appimage/monkey-island.desktop diff --git a/deployment_scripts/appimage/.gitignore b/deployment_scripts/appimage/.gitignore new file mode 100644 index 000000000..5a7692e9a --- /dev/null +++ b/deployment_scripts/appimage/.gitignore @@ -0,0 +1 @@ +*.AppImage diff --git a/deployment_scripts/appimage/AppRun b/deployment_scripts/appimage/AppRun new file mode 100755 index 000000000..322f4a5d9 --- /dev/null +++ b/deployment_scripts/appimage/AppRun @@ -0,0 +1,41 @@ +#! /bin/bash + +# Export APPRUN if running from an extracted image +self="$(readlink -f -- $0)" +here="${self%/*}" +APPDIR="${APPDIR:-${here}}" + +# Export TCl/Tk +export TCL_LIBRARY="${APPDIR}/usr/share/tcltk/tcl8.4" +export TK_LIBRARY="${APPDIR}/usr/share/tcltk/tk8.4" +export TKPATH="${TK_LIBRARY}" + +# Export SSL certificate +export SSL_CERT_FILE="${APPDIR}/opt/_internal/certs.pem" + +# Call the entry point +for opt in "$@" +do + [ "${opt:0:1}" != "-" ] && break + if [[ "${opt}" =~ "I" ]] || [[ "${opt}" =~ "E" ]]; then + # Environment variables are disabled ($PYTHONHOME). Let's run in a safe + # mode from the raw Python binary inside the AppImage + "$APPDIR/opt/python3.7/bin/python3.7" "$@" + exit "$?" + fi +done + +# Get the executable name, i.e. the AppImage or the python binary if running from an +# extracted image +executable="${APPDIR}/opt/python3.7/bin/python3.7" +if [[ "${ARGV0}" =~ "/" ]]; then + executable="$(cd $(dirname ${ARGV0}) && pwd)/$(basename ${ARGV0})" +elif [[ "${ARGV0}" != "" ]]; then + executable=$(which "${ARGV0}") +fi + +# Wrap the call to Python in order to mimic a call from the source +# executable ($ARGV0), but potentially located outside of the Python +# install ($PYTHONHOME) +(PYTHONHOME="${APPDIR}/opt/python3.7" exec "/bin/bash" "${APPDIR}/usr/src/monkey_island/linux/run_appimage.sh") +exit "$?" diff --git a/deployment_scripts/appimage/README.md b/deployment_scripts/appimage/README.md index 37321378f..7a76a7275 100644 --- a/deployment_scripts/appimage/README.md +++ b/deployment_scripts/appimage/README.md @@ -18,10 +18,9 @@ NOTE: This script is intended to be run from a clean VM. You can also manually remove build artifacts by removing the following files and directories. - $HOME/.monkey_island (optional) -- $HOME/monkey-appdir +- $HOME/squashfs-root - $HOME/git/monkey -- $HOME/appimage/appimage-builder-cache -- $HOME/appimage/"Monkey\ Island-\*-x86-64.Appimage" +- $HOME/appimage/Infection_Monkey-x86_64.AppImage After removing the above files and directories, you can again execute `bash build_appimage.sh`. diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index a1c384801..81c08629a 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -1,7 +1,7 @@ #!/bin/bash -python_cmd="python3.7" -APPDIR="$HOME/monkey-appdir" +APPDIR="$HOME/squashfs-root" +CONFIG_URL="https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/config" INSTALL_DIR="$APPDIR/usr/src" GIT=$HOME/git @@ -33,16 +33,18 @@ log_message() { echo -e "DEPLOYMENT SCRIPT: $1" } -setup_appdir() { +setup_python_37_appdir() { + PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python3.7.9-cp37-cp37m-manylinux1_x86_64.AppImage" + PYTHON_APPIMAGE="python3.7.9_x86_64.AppImage" rm -rf "$APPDIR" || true - mkdir -p "$INSTALL_DIR" -} + curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL" -install_pip_37() { - pip_url=https://bootstrap.pypa.io/get-pip.py - curl $pip_url -o get-pip.py - ${python_cmd} get-pip.py - rm get-pip.py + chmod u+x "$PYTHON_APPIMAGE" + + ./"$PYTHON_APPIMAGE" --appimage-extract + rm "$PYTHON_APPIMAGE" + mv ./squashfs-root "$APPDIR" + mkdir -p "$INSTALL_DIR" } install_nodejs() { @@ -63,21 +65,14 @@ install_build_prereqs() { #monkey island prereqs sudo apt install -y curl libcurl4 python3.7 python3.7-dev openssl git build-essential moreutils - install_pip_37 install_nodejs } -install_appimage_builder() { - sudo pip3 install appimage-builder - - install_appimage_tool -} - install_appimage_tool() { APP_TOOL_BIN=$HOME/bin/appimagetool APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage - mkdir "$HOME"/bin + mkdir -p "$HOME"/bin curl -L -o "$APP_TOOL_BIN" "$APP_TOOL_URL" chmod u+x "$APP_TOOL_BIN" @@ -88,7 +83,7 @@ load_monkey_binary_config() { tmpfile=$(mktemp) log_message "downloading configuration" - curl -L -s -o "$tmpfile" "$config_url" + curl -L -s -o "$tmpfile" "$CONFIG_URL" log_message "loading configuration" source "$tmpfile" @@ -103,14 +98,14 @@ clone_monkey_repo() { branch=${2:-"develop"} git clone --single-branch --recurse-submodules -b "$branch" "${MONKEY_GIT_URL}" "${REPO_MONKEY_HOME}" 2>&1 || handle_error - chmod 774 -R "${MONKEY_HOME}" + chmod 774 -R "${REPO_MONKEY_HOME}" } copy_monkey_island_to_appdir() { cp "$REPO_MONKEY_SRC"/__init__.py "$INSTALL_DIR" cp "$REPO_MONKEY_SRC"/monkey_island.py "$INSTALL_DIR" - cp -r "$REPO_MONKEY_SRC"/common "$INSTALL_DIR" - cp -r "$REPO_MONKEY_SRC"/monkey_island "$INSTALL_DIR" + cp -r "$REPO_MONKEY_SRC"/common "$INSTALL_DIR/" + cp -r "$REPO_MONKEY_SRC"/monkey_island "$INSTALL_DIR/" cp ./run_appimage.sh "$INSTALL_DIR"/monkey_island/linux/ cp ./island_logger_config.json "$INSTALL_DIR"/ cp ./server_config.json.standard "$INSTALL_DIR"/monkey_island/cc/ @@ -128,7 +123,7 @@ install_monkey_island_python_dependencies() { # dependencies and should not be installed as a runtime requirement. cat "$requirements_island" | grep -Piv "virtualenv|pyinstaller" | sponge "$requirements_island" - ${python_cmd} -m pip install -r "${requirements_island}" --ignore-installed --prefix /usr --root="$APPDIR" || handle_error + "$APPDIR"/AppRun -m pip install -r "${requirements_island}" --ignore-installed || handle_error } download_monkey_agent_binaries() { @@ -170,22 +165,7 @@ build_frontend() { build_appimage() { log_message "Building AppImage" - appimage-builder --recipe monkey_island_builder.yml --log DEBUG --skip-appimage - - # There is a bug or unwanted behavior in appimage-builder that causes issues - # if 32-bit binaries are present in the appimage. To work around this, we: - # 1. Build the AppDir with appimage-builder and skip building the appimage - # 2. Add the 32-bit binaries to the AppDir - # 3. Build the AppImage with appimage-builder from the already-built AppDir - # - # Note that appimage-builder replaces the interpreter on the monkey agent binaries - # when building the AppDir. This is unwanted as the monkey agents may execute in - # environments where the AppImage isn't loaded. - # - # See https://github.com/AppImageCrafters/appimage-builder/issues/93 for more info. - download_monkey_agent_binaries - - appimage-builder --recipe monkey_island_builder.yml --log DEBUG --skip-build + ARCH="x86_64" appimagetool "$APPDIR" } if is_root; then @@ -199,18 +179,18 @@ Run \`sudo -v\`, enter your password, and then re-run this script." exit 1 fi -config_url="https://raw.githubusercontent.com/guardicore/monkey/develop/deployment_scripts/config" - -setup_appdir install_build_prereqs -install_appimage_builder +install_appimage_tool + +setup_python_37_appdir load_monkey_binary_config clone_monkey_repo "$@" copy_monkey_island_to_appdir +download_monkey_agent_binaries # Create folders log_message "Creating island dirs under $ISLAND_PATH" @@ -224,8 +204,16 @@ generate_ssl_cert build_frontend +unlink "$APPDIR"/python.png mkdir -p "$APPDIR"/usr/share/icons cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/monkey-icon.svg +ln -s "$APPDIR"/usr/share/icons/monkey-icon.svg "$APPDIR"/monkey-icon.svg + +unlink "$APPDIR"/python3.7.9.desktop +cp ./monkey-island.desktop "$APPDIR"/usr/share/applications +ln -s "$APPDIR"/usr/share/applications/monkey-island.desktop "$APPDIR"/monkey-island.desktop + +cp ./AppRun "$APPDIR" build_appimage diff --git a/deployment_scripts/appimage/monkey-island.desktop b/deployment_scripts/appimage/monkey-island.desktop new file mode 100644 index 000000000..07c01ea08 --- /dev/null +++ b/deployment_scripts/appimage/monkey-island.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Application +Name=Infection Monkey +Exec=bash +Comment=Infection Monkey FILL ME IN +Icon=monkey-icon +Categories=Development; +Terminal=true From 9f74127c5061ad0806042f89691c39f77a05eaaf Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Apr 2021 12:32:37 -0400 Subject: [PATCH 03/23] build: remove unnecessary python packages from appimage build --- deployment_scripts/appimage/build_appimage.sh | 6 +++--- deployment_scripts/appimage/run_appimage.sh | 14 ++------------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index 81c08629a..2aeb47b53 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -61,10 +61,10 @@ install_build_prereqs() { sudo apt upgrade # appimage-builder prereqs - sudo apt install -y python3 python3-pip python3-setuptools patchelf desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace + sudo apt install -y patchelf desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace - #monkey island prereqs - sudo apt install -y curl libcurl4 python3.7 python3.7-dev openssl git build-essential moreutils + # monkey island prereqs + sudo apt install -y curl libcurl4 openssl git build-essential moreutils install_nodejs } diff --git a/deployment_scripts/appimage/run_appimage.sh b/deployment_scripts/appimage/run_appimage.sh index 7738301cd..a903bc034 100644 --- a/deployment_scripts/appimage/run_appimage.sh +++ b/deployment_scripts/appimage/run_appimage.sh @@ -1,5 +1,6 @@ #!/bin/bash +PYTHON_CMD="$APPDIR/opt/python3.7/bin/python3.7" DOT_MONKEY=$HOME/.monkey_island/ configure_default_logging() { @@ -16,17 +17,6 @@ configure_default_server() { -# Detecting command that calls python 3.7 -python_cmd="" -if [[ $(python --version 2>&1) == *"Python 3.7"* ]]; then - python_cmd="python" -fi -if [[ $(python37 --version 2>&1) == *"Python 3.7"* ]]; then - python_cmd="python37" -fi -if [[ $(python3.7 --version 2>&1) == *"Python 3.7"* ]]; then - python_cmd="python3.7" -fi mkdir --mode=0700 --parents $DOT_MONKEY @@ -38,4 +28,4 @@ configure_default_server cd $APPDIR/usr/src ./monkey_island/bin/mongodb/bin/mongod --dbpath $DB_DIR & -${python_cmd} ./monkey_island.py --server-config $DOT_MONKEY/server_config.json --logger-config $DOT_MONKEY/island_logger_config.json +${PYTHON_CMD} ./monkey_island.py --server-config $DOT_MONKEY/server_config.json --logger-config $DOT_MONKEY/island_logger_config.json From 38a9cedeb281f6aae66199dc8ed3a121191c6244 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Apr 2021 12:34:36 -0400 Subject: [PATCH 04/23] build: Remove unnecessary mkdir in build_appimage.sh --- deployment_scripts/appimage/build_appimage.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index 2aeb47b53..5983808f7 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -192,10 +192,6 @@ clone_monkey_repo "$@" copy_monkey_island_to_appdir download_monkey_agent_binaries -# Create folders -log_message "Creating island dirs under $ISLAND_PATH" -mkdir -p "${MONGO_PATH}" || handle_error - install_monkey_island_python_dependencies install_mongodb From 312c98c784ea948a5430d7eeed976ce92e0b7f61 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Apr 2021 12:42:18 -0400 Subject: [PATCH 05/23] build: Organize appdir-specific tasks in setup_appdir() --- deployment_scripts/appimage/build_appimage.sh | 87 +++++++++++-------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index 5983808f7..0714e99cb 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -33,20 +33,6 @@ log_message() { echo -e "DEPLOYMENT SCRIPT: $1" } -setup_python_37_appdir() { - PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python3.7.9-cp37-cp37m-manylinux1_x86_64.AppImage" - PYTHON_APPIMAGE="python3.7.9_x86_64.AppImage" - rm -rf "$APPDIR" || true - curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL" - - chmod u+x "$PYTHON_APPIMAGE" - - ./"$PYTHON_APPIMAGE" --appimage-extract - rm "$PYTHON_APPIMAGE" - mv ./squashfs-root "$APPDIR" - mkdir -p "$INSTALL_DIR" -} - install_nodejs() { NODE_SRC=https://deb.nodesource.com/setup_12.x @@ -101,6 +87,37 @@ clone_monkey_repo() { chmod 774 -R "${REPO_MONKEY_HOME}" } +setup_appdir() { + setup_python_37_appdir + + copy_monkey_island_to_appdir + download_monkey_agent_binaries + + install_monkey_island_python_dependencies + install_mongodb + + generate_ssl_cert + build_frontend + + add_monkey_icon + add_desktop_file + add_apprun +} + +setup_python_37_appdir() { + PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python3.7.9-cp37-cp37m-manylinux1_x86_64.AppImage" + PYTHON_APPIMAGE="python3.7.9_x86_64.AppImage" + rm -rf "$APPDIR" || true + curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL" + + chmod u+x "$PYTHON_APPIMAGE" + + ./"$PYTHON_APPIMAGE" --appimage-extract + rm "$PYTHON_APPIMAGE" + mv ./squashfs-root "$APPDIR" + mkdir -p "$INSTALL_DIR" +} + copy_monkey_island_to_appdir() { cp "$REPO_MONKEY_SRC"/__init__.py "$INSTALL_DIR" cp "$REPO_MONKEY_SRC"/monkey_island.py "$INSTALL_DIR" @@ -163,6 +180,23 @@ build_frontend() { popd || handle_error } +add_monkey_icon() { + unlink "$APPDIR"/python.png + mkdir -p "$APPDIR"/usr/share/icons + cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/monkey-icon.svg + ln -s "$APPDIR"/usr/share/icons/monkey-icon.svg "$APPDIR"/monkey-icon.svg +} + +add_desktop_file() { + unlink "$APPDIR"/python3.7.9.desktop + cp ./monkey-island.desktop "$APPDIR"/usr/share/applications + ln -s "$APPDIR"/usr/share/applications/monkey-island.desktop "$APPDIR"/monkey-island.desktop +} + +add_apprun() { + cp ./AppRun "$APPDIR" +} + build_appimage() { log_message "Building AppImage" ARCH="x86_64" appimagetool "$APPDIR" @@ -183,33 +217,10 @@ fi install_build_prereqs install_appimage_tool -setup_python_37_appdir - - load_monkey_binary_config clone_monkey_repo "$@" -copy_monkey_island_to_appdir -download_monkey_agent_binaries - -install_monkey_island_python_dependencies - -install_mongodb - -generate_ssl_cert - -build_frontend - -unlink "$APPDIR"/python.png -mkdir -p "$APPDIR"/usr/share/icons -cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/monkey-icon.svg -ln -s "$APPDIR"/usr/share/icons/monkey-icon.svg "$APPDIR"/monkey-icon.svg - -unlink "$APPDIR"/python3.7.9.desktop -cp ./monkey-island.desktop "$APPDIR"/usr/share/applications -ln -s "$APPDIR"/usr/share/applications/monkey-island.desktop "$APPDIR"/monkey-island.desktop - -cp ./AppRun "$APPDIR" +setup_appdir build_appimage From 9d8fc489c998e376d80aaf205a8471a81f79f376 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Apr 2021 13:11:16 -0400 Subject: [PATCH 06/23] build: Move some constants to top of build_appimage.sh --- deployment_scripts/appimage/build_appimage.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index 0714e99cb..4603b27bd 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -13,6 +13,10 @@ ISLAND_PATH="$INSTALL_DIR/monkey_island" MONGO_PATH="$ISLAND_PATH/bin/mongodb" ISLAND_BINARIES_PATH="$ISLAND_PATH/cc/binaries" +NODE_SRC=https://deb.nodesource.com/setup_12.x +APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage +PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python3.7.9-cp37-cp37m-manylinux1_x86_64.AppImage" + is_root() { return "$(id -u)" } @@ -34,8 +38,6 @@ log_message() { } install_nodejs() { - NODE_SRC=https://deb.nodesource.com/setup_12.x - log_message "Installing nodejs" curl -sL $NODE_SRC | sudo -E bash - @@ -56,7 +58,6 @@ install_build_prereqs() { install_appimage_tool() { APP_TOOL_BIN=$HOME/bin/appimagetool - APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage mkdir -p "$HOME"/bin curl -L -o "$APP_TOOL_BIN" "$APP_TOOL_URL" @@ -105,7 +106,6 @@ setup_appdir() { } setup_python_37_appdir() { - PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python3.7.9-cp37-cp37m-manylinux1_x86_64.AppImage" PYTHON_APPIMAGE="python3.7.9_x86_64.AppImage" rm -rf "$APPDIR" || true curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL" From a58f310e6130e7c51e7c87c7d0152057cdf43262 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 12 Apr 2021 14:29:40 -0400 Subject: [PATCH 07/23] build: Address shellcheck warnings in run_appimage.sh --- deployment_scripts/appimage/run_appimage.sh | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/deployment_scripts/appimage/run_appimage.sh b/deployment_scripts/appimage/run_appimage.sh index a903bc034..d7945765a 100644 --- a/deployment_scripts/appimage/run_appimage.sh +++ b/deployment_scripts/appimage/run_appimage.sh @@ -1,31 +1,32 @@ #!/bin/bash -PYTHON_CMD="$APPDIR/opt/python3.7/bin/python3.7" -DOT_MONKEY=$HOME/.monkey_island/ +PYTHON_CMD="$APPDIR"/opt/python3.7/bin/python3.7 +DOT_MONKEY="$HOME"/.monkey_island/ configure_default_logging() { - if [ ! -f $DOT_MONKEY/island_logger_config.json ]; then - cp $APPDIR/usr/src/island_logger_config.json $DOT_MONKEY + if [ ! -f "$DOT_MONKEY"/island_logger_config.json ]; then + cp "$APPDIR"/usr/src/island_logger_config.json "$DOT_MONKEY" fi } configure_default_server() { - if [ ! -f $DOT_MONKEY/server_config.json ]; then - cp $APPDIR/usr/src/monkey_island/cc/server_config.json.standard $DOT_MONKEY/server_config.json + if [ ! -f "$DOT_MONKEY"/server_config.json ]; then + cp "$APPDIR"/usr/src/monkey_island/cc/server_config.json.standard "$DOT_MONKEY"/server_config.json fi } -mkdir --mode=0700 --parents $DOT_MONKEY +# shellcheck disable=SC2174 +mkdir --mode=0700 --parents "$DOT_MONKEY" -DB_DIR=$DOT_MONKEY/db -mkdir -p $DB_DIR +DB_DIR="$DOT_MONKEY"/db +mkdir --parents "$DB_DIR" configure_default_logging configure_default_server -cd $APPDIR/usr/src -./monkey_island/bin/mongodb/bin/mongod --dbpath $DB_DIR & -${PYTHON_CMD} ./monkey_island.py --server-config $DOT_MONKEY/server_config.json --logger-config $DOT_MONKEY/island_logger_config.json +cd "$APPDIR"/usr/src || exit 1 +./monkey_island/bin/mongodb/bin/mongod --dbpath "$DB_DIR" & +${PYTHON_CMD} ./monkey_island.py --server-config "$DOT_MONKEY"/server_config.json --logger-config "$DOT_MONKEY"/island_logger_config.json From 3b4bd7b08caa616ab5911bd5fc079cba8107737a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 13 Apr 2021 13:59:29 -0400 Subject: [PATCH 08/23] cc: Upload custom PBAs to data_dir instead of MONKEY_ISLAND_ABS_PATH --- .../monkey_island/cc/resources/pba_file_download.py | 4 ++-- .../monkey_island/cc/resources/pba_file_upload.py | 13 ++++++++----- .../monkey_island/cc/services/post_breach_files.py | 7 ++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/monkey/monkey_island/cc/resources/pba_file_download.py b/monkey/monkey_island/cc/resources/pba_file_download.py index aa5465b0d..4bb409eec 100644 --- a/monkey/monkey_island/cc/resources/pba_file_download.py +++ b/monkey/monkey_island/cc/resources/pba_file_download.py @@ -1,7 +1,7 @@ import flask_restful from flask import send_from_directory -from monkey_island.cc.services.post_breach_files import ABS_UPLOAD_PATH +import monkey_island.cc.environment.environment_singleton as env_singleton __author__ = "VakarisZ" @@ -13,4 +13,4 @@ class PBAFileDownload(flask_restful.Resource): # Used by monkey. can't secure. def get(self, path): - return send_from_directory(ABS_UPLOAD_PATH, path) + return send_from_directory(env_singleton.env.get_config().data_dir_abs_path, path) diff --git a/monkey/monkey_island/cc/resources/pba_file_upload.py b/monkey/monkey_island/cc/resources/pba_file_upload.py index 36f138f10..16d71cfeb 100644 --- a/monkey/monkey_island/cc/resources/pba_file_upload.py +++ b/monkey/monkey_island/cc/resources/pba_file_upload.py @@ -1,15 +1,16 @@ import copy import logging import os +from pathlib import Path import flask_restful from flask import Response, request, send_from_directory from werkzeug.utils import secure_filename +import monkey_island.cc.environment.environment_singleton as env_singleton from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.post_breach_files import ( - ABS_UPLOAD_PATH, PBA_LINUX_FILENAME_PATH, PBA_WINDOWS_FILENAME_PATH, ) @@ -29,7 +30,7 @@ class FileUpload(flask_restful.Resource): def __init__(self): # Create all directories on the way if they don't exist - ABS_UPLOAD_PATH.mkdir(parents=True, exist_ok=True) + Path(env_singleton.env.get_config().data_dir_abs_path).mkdir(parents=True, exist_ok=True) @jwt_required def get(self, file_type): @@ -43,7 +44,7 @@ class FileUpload(flask_restful.Resource): filename = ConfigService.get_config_value(copy.deepcopy(PBA_LINUX_FILENAME_PATH)) else: filename = ConfigService.get_config_value(copy.deepcopy(PBA_WINDOWS_FILENAME_PATH)) - return send_from_directory(ABS_UPLOAD_PATH, filename) + return send_from_directory(env_singleton.env.get_config().data_dir_abs_path, filename) @jwt_required def post(self, file_type): @@ -68,7 +69,7 @@ class FileUpload(flask_restful.Resource): PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH ) filename = ConfigService.get_config_value(filename_path) - file_path = ABS_UPLOAD_PATH.joinpath(filename) + file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename) try: if os.path.exists(file_path): os.remove(file_path) @@ -87,7 +88,9 @@ class FileUpload(flask_restful.Resource): :return: filename string """ filename = secure_filename(request_.files["filepond"].filename) - file_path = ABS_UPLOAD_PATH.joinpath(filename).absolute() + file_path = ( + Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename).absolute() + ) request_.files["filepond"].save(str(file_path)) ConfigService.set_config_value( (PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename diff --git a/monkey/monkey_island/cc/services/post_breach_files.py b/monkey/monkey_island/cc/services/post_breach_files.py index 660d48487..504522d9a 100644 --- a/monkey/monkey_island/cc/services/post_breach_files.py +++ b/monkey/monkey_island/cc/services/post_breach_files.py @@ -1,12 +1,11 @@ import logging import os -from pathlib import Path import monkey_island.cc.services.config __author__ = "VakarisZ" -from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH +import monkey_island.cc.environment.environment_singleton as env_singleton logger = logging.getLogger(__name__) @@ -15,8 +14,6 @@ PBA_WINDOWS_FILENAME_PATH = ["monkey", "post_breach", "PBA_windows_filename"] PBA_LINUX_FILENAME_PATH = ["monkey", "post_breach", "PBA_linux_filename"] UPLOADS_DIR_NAME = "userUploads" -ABS_UPLOAD_PATH = Path(MONKEY_ISLAND_ABS_PATH, "cc", UPLOADS_DIR_NAME) - def remove_PBA_files(): if monkey_island.cc.services.config.ConfigService.get_config(): @@ -33,7 +30,7 @@ def remove_PBA_files(): def remove_file(file_name): - file_path = os.path.join(ABS_UPLOAD_PATH, file_name) + file_path = os.path.join(env_singleton.env.get_config().data_dir_abs_path, file_name) try: if os.path.exists(file_path): os.remove(file_path) From aca4f8795fd5040c37b2a891bf2c9689f6ebcd44 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Apr 2021 13:22:43 -0400 Subject: [PATCH 09/23] build: Delete monkey_island_builder.yml This file was used by appimage-builder, which we are no longer using. --- .../appimage/monkey_island_builder.yml | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 deployment_scripts/appimage/monkey_island_builder.yml diff --git a/deployment_scripts/appimage/monkey_island_builder.yml b/deployment_scripts/appimage/monkey_island_builder.yml deleted file mode 100644 index 2c85c41d3..000000000 --- a/deployment_scripts/appimage/monkey_island_builder.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: 1 - -AppDir: - path: '../monkey-appdir' - - app_info: - id: org.guardicore.monkey-island - name: Monkey Island - icon: monkey-icon - version: 1.10.0 - exec: bin/bash - exec_args: "$APPDIR/usr/src/monkey_island/linux/run_appimage.sh" - - - apt: - arch: amd64 - sources: - - sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic main restricted - key_url: http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3B4FE6ACC0B21F32 - - sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic universe - - sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-security main restricted - - sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-security universe - - sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted - - sourceline: deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ bionic-updates universe - - - include: - - bash - - python3.7 - - runtime: - env: - PATH: '${APPDIR}/usr/bin:${PATH}' - PYTHONHOME: '${APPDIR}/usr' - PYTHONPATH: '${APPDIR}/usr/lib/python3.7/site-packages' - -AppImage: - update-information: None - sign-key: None - arch: x86_64 From 14096ae758d868c11644a169c7b0e466efa0643a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Apr 2021 13:25:37 -0400 Subject: [PATCH 10/23] build: Rename monkey-island.desktop -> infection-monkey.desktop --- deployment_scripts/appimage/build_appimage.sh | 4 ++-- .../{monkey-island.desktop => infection-monkey.desktop} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename deployment_scripts/appimage/{monkey-island.desktop => infection-monkey.desktop} (100%) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index 4603b27bd..b006e3102 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -189,8 +189,8 @@ add_monkey_icon() { add_desktop_file() { unlink "$APPDIR"/python3.7.9.desktop - cp ./monkey-island.desktop "$APPDIR"/usr/share/applications - ln -s "$APPDIR"/usr/share/applications/monkey-island.desktop "$APPDIR"/monkey-island.desktop + cp ./infection-monkey.desktop "$APPDIR"/usr/share/applications + ln -s "$APPDIR"/usr/share/applications/infection-monkey.desktop "$APPDIR"/infection-monkey.desktop } add_apprun() { diff --git a/deployment_scripts/appimage/monkey-island.desktop b/deployment_scripts/appimage/infection-monkey.desktop similarity index 100% rename from deployment_scripts/appimage/monkey-island.desktop rename to deployment_scripts/appimage/infection-monkey.desktop From 3e96b208342e387dc1ab5ba9fd31cb7f96c50a14 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Apr 2021 13:30:29 -0400 Subject: [PATCH 11/23] build: Rename appimage icon to infection-monkey.svg --- deployment_scripts/appimage/build_appimage.sh | 6 +++--- deployment_scripts/appimage/infection-monkey.desktop | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index b006e3102..fb9b8f0bc 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -82,7 +82,7 @@ clone_monkey_repo() { fi log_message "Cloning files from git" - branch=${2:-"develop"} + branch=${2:-"postgresql-workaround-2"} git clone --single-branch --recurse-submodules -b "$branch" "${MONKEY_GIT_URL}" "${REPO_MONKEY_HOME}" 2>&1 || handle_error chmod 774 -R "${REPO_MONKEY_HOME}" @@ -183,8 +183,8 @@ build_frontend() { add_monkey_icon() { unlink "$APPDIR"/python.png mkdir -p "$APPDIR"/usr/share/icons - cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/monkey-icon.svg - ln -s "$APPDIR"/usr/share/icons/monkey-icon.svg "$APPDIR"/monkey-icon.svg + cp "$REPO_MONKEY_SRC"/monkey_island/cc/ui/src/images/monkey-icon.svg "$APPDIR"/usr/share/icons/infection-monkey.svg + ln -s "$APPDIR"/usr/share/icons/infection-monkey.svg "$APPDIR"/infection-monkey.svg } add_desktop_file() { diff --git a/deployment_scripts/appimage/infection-monkey.desktop b/deployment_scripts/appimage/infection-monkey.desktop index 07c01ea08..93a2c0341 100644 --- a/deployment_scripts/appimage/infection-monkey.desktop +++ b/deployment_scripts/appimage/infection-monkey.desktop @@ -3,6 +3,6 @@ Type=Application Name=Infection Monkey Exec=bash Comment=Infection Monkey FILL ME IN -Icon=monkey-icon +Icon=infection-monkey Categories=Development; Terminal=true From 79e3c69ffb786f7cfbbfc4c01818b7abed7485d1 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Apr 2021 13:32:06 -0400 Subject: [PATCH 12/23] build: Fill in comment in AppImage .desktop file --- deployment_scripts/appimage/infection-monkey.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment_scripts/appimage/infection-monkey.desktop b/deployment_scripts/appimage/infection-monkey.desktop index 93a2c0341..5869ef187 100644 --- a/deployment_scripts/appimage/infection-monkey.desktop +++ b/deployment_scripts/appimage/infection-monkey.desktop @@ -2,7 +2,7 @@ Type=Application Name=Infection Monkey Exec=bash -Comment=Infection Monkey FILL ME IN +Comment=An automated breach and attack simulation platform Icon=infection-monkey Categories=Development; Terminal=true From 6218a476afcc936af5907327f4d9ddeb297d2153 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Apr 2021 14:43:43 -0400 Subject: [PATCH 13/23] build: remove appimage-builder prereqs --- deployment_scripts/appimage/build_appimage.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index fb9b8f0bc..53fdda072 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -48,9 +48,6 @@ install_build_prereqs() { sudo apt update sudo apt upgrade - # appimage-builder prereqs - sudo apt install -y patchelf desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace - # monkey island prereqs sudo apt install -y curl libcurl4 openssl git build-essential moreutils install_nodejs From 6ad68557fc4fa14607d7f0675e7d241a9a393d8e Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Apr 2021 14:44:02 -0400 Subject: [PATCH 14/23] build: switch appimage build branch to develop --- deployment_scripts/appimage/build_appimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment_scripts/appimage/build_appimage.sh b/deployment_scripts/appimage/build_appimage.sh index 53fdda072..fe3e89e0b 100755 --- a/deployment_scripts/appimage/build_appimage.sh +++ b/deployment_scripts/appimage/build_appimage.sh @@ -79,7 +79,7 @@ clone_monkey_repo() { fi log_message "Cloning files from git" - branch=${2:-"postgresql-workaround-2"} + branch=${2:-"develop"} git clone --single-branch --recurse-submodules -b "$branch" "${MONKEY_GIT_URL}" "${REPO_MONKEY_HOME}" 2>&1 || handle_error chmod 774 -R "${REPO_MONKEY_HOME}" From eb006f88bd25482ea6999764e6f3d9a933497de1 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Apr 2021 14:47:21 -0400 Subject: [PATCH 15/23] Update CHANGELOG.md for AppImage v2 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d675e0461..cc8ecd791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - PostgreSQL fingerprinter. #892 - A runtime-configurable option to specify a data directory where runtime configuration and other artifacts can be stored. #994 -- Scripts to build a prototype AppImage for Monkey Island. #1069 +- Scripts to build an AppImage for Monkey Island. #1069, #1090 ### Changed - server_config.json can be selected at runtime. #963 From 81860e97e7dcd3dc36c38dba89bef5157d23e76f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 06:26:24 -0400 Subject: [PATCH 16/23] build: move ./deployment_scripts/appimage -> ./appimage --- {deployment_scripts/appimage => appimage}/.gitignore | 0 {deployment_scripts/appimage => appimage}/AppRun | 0 {deployment_scripts/appimage => appimage}/README.md | 0 {deployment_scripts/appimage => appimage}/build_appimage.sh | 0 .../appimage => appimage}/infection-monkey.desktop | 0 .../appimage => appimage}/island_logger_config.json | 0 {deployment_scripts/appimage => appimage}/run_appimage.sh | 0 .../appimage => appimage}/server_config.json.standard | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename {deployment_scripts/appimage => appimage}/.gitignore (100%) rename {deployment_scripts/appimage => appimage}/AppRun (100%) rename {deployment_scripts/appimage => appimage}/README.md (100%) rename {deployment_scripts/appimage => appimage}/build_appimage.sh (100%) rename {deployment_scripts/appimage => appimage}/infection-monkey.desktop (100%) rename {deployment_scripts/appimage => appimage}/island_logger_config.json (100%) rename {deployment_scripts/appimage => appimage}/run_appimage.sh (100%) rename {deployment_scripts/appimage => appimage}/server_config.json.standard (100%) diff --git a/deployment_scripts/appimage/.gitignore b/appimage/.gitignore similarity index 100% rename from deployment_scripts/appimage/.gitignore rename to appimage/.gitignore diff --git a/deployment_scripts/appimage/AppRun b/appimage/AppRun similarity index 100% rename from deployment_scripts/appimage/AppRun rename to appimage/AppRun diff --git a/deployment_scripts/appimage/README.md b/appimage/README.md similarity index 100% rename from deployment_scripts/appimage/README.md rename to appimage/README.md diff --git a/deployment_scripts/appimage/build_appimage.sh b/appimage/build_appimage.sh similarity index 100% rename from deployment_scripts/appimage/build_appimage.sh rename to appimage/build_appimage.sh diff --git a/deployment_scripts/appimage/infection-monkey.desktop b/appimage/infection-monkey.desktop similarity index 100% rename from deployment_scripts/appimage/infection-monkey.desktop rename to appimage/infection-monkey.desktop diff --git a/deployment_scripts/appimage/island_logger_config.json b/appimage/island_logger_config.json similarity index 100% rename from deployment_scripts/appimage/island_logger_config.json rename to appimage/island_logger_config.json diff --git a/deployment_scripts/appimage/run_appimage.sh b/appimage/run_appimage.sh similarity index 100% rename from deployment_scripts/appimage/run_appimage.sh rename to appimage/run_appimage.sh diff --git a/deployment_scripts/appimage/server_config.json.standard b/appimage/server_config.json.standard similarity index 100% rename from deployment_scripts/appimage/server_config.json.standard rename to appimage/server_config.json.standard From e0fd620d9dcb3d9473a1cbdf6ae0b3346fd2cc30 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 06:29:47 -0400 Subject: [PATCH 17/23] build: Update appimage README since we switched from appimage-builder --- appimage/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/appimage/README.md b/appimage/README.md index 7a76a7275..b1c3010e4 100644 --- a/appimage/README.md +++ b/appimage/README.md @@ -2,8 +2,8 @@ ## About -This directory contains the necessary artifacts for building a prototype -monkey_island AppImage using appimage-builder. +This directory contains the necessary artifacts for building an Infection +Monkey AppImage ## Building an AppImage @@ -27,9 +27,9 @@ build_appimage.sh`. ## Running the AppImage -The build script will produce an AppImage executible named something like -`Monkey Island-VERSION-x86-64.AppImage`. Simply execute this file and you're -off to the races. +The build script will produce an AppImage executible named +`Infection_Monkey-x86_64.AppImage`. Simply execute this file and you're off to +the races. A new directory, `$HOME/.monkey_island` will be created to store runtime artifacts. From bc1f583e20d58083057b1b22e3623e5a1dffa3f7 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 07:37:07 -0400 Subject: [PATCH 18/23] appimage: remove unused $executable var from AppRun --- appimage/AppRun | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/appimage/AppRun b/appimage/AppRun index 322f4a5d9..1a39dddb6 100755 --- a/appimage/AppRun +++ b/appimage/AppRun @@ -25,17 +25,5 @@ do fi done -# Get the executable name, i.e. the AppImage or the python binary if running from an -# extracted image -executable="${APPDIR}/opt/python3.7/bin/python3.7" -if [[ "${ARGV0}" =~ "/" ]]; then - executable="$(cd $(dirname ${ARGV0}) && pwd)/$(basename ${ARGV0})" -elif [[ "${ARGV0}" != "" ]]; then - executable=$(which "${ARGV0}") -fi - -# Wrap the call to Python in order to mimic a call from the source -# executable ($ARGV0), but potentially located outside of the Python -# install ($PYTHONHOME) (PYTHONHOME="${APPDIR}/opt/python3.7" exec "/bin/bash" "${APPDIR}/usr/src/monkey_island/linux/run_appimage.sh") exit "$?" From 54754698fdaeee119f0b44ff10a66ebfc48aca30 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 07:48:32 -0400 Subject: [PATCH 19/23] appimage: remove unnecessary blank lines in run_appimage.sh --- appimage/run_appimage.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/appimage/run_appimage.sh b/appimage/run_appimage.sh index d7945765a..1c84b41f1 100644 --- a/appimage/run_appimage.sh +++ b/appimage/run_appimage.sh @@ -15,9 +15,6 @@ configure_default_server() { fi } - - - # shellcheck disable=SC2174 mkdir --mode=0700 --parents "$DOT_MONKEY" From 5a1a5fc6fe6aedce80650118890887d601d56729 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 11:37:10 -0400 Subject: [PATCH 20/23] cc: Set cwd when executing monkey binary from the island Since AppImages are read-only filesystems, the agent cannot create any files in `./`. Therefore, setting cwd in the `subprocess.Popen()` call will change CWD to a writable directory if `data_dir` is set. --- monkey/monkey_island/cc/resources/local_run.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/resources/local_run.py b/monkey/monkey_island/cc/resources/local_run.py index d9dfc0e39..2adc60cbe 100644 --- a/monkey/monkey_island/cc/resources/local_run.py +++ b/monkey/monkey_island/cc/resources/local_run.py @@ -30,14 +30,15 @@ def run_local_monkey(): if not result: return False, "OS Type not found" - monkey_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "binaries", result["filename"]) - target_path = os.path.join(env_singleton.env.get_config().data_dir_abs_path, result["filename"]) + src_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "binaries", result["filename"]) + dest_dir = env_singleton.env.get_config().data_dir_abs_path + dest_path = os.path.join(dest_dir, result["filename"]) # copy the executable to temp path (don't run the monkey from its current location as it may # delete itself) try: - copyfile(monkey_path, target_path) - os.chmod(target_path, stat.S_IRWXU | stat.S_IRWXG) + copyfile(src_path, dest_path) + os.chmod(dest_path, stat.S_IRWXU | stat.S_IRWXG) except Exception as exc: logger.error("Copy file failed", exc_info=True) return False, "Copy file failed: %s" % exc @@ -46,11 +47,11 @@ def run_local_monkey(): try: args = [ '"%s" m0nk3y -s %s:%s' - % (target_path, local_ip_addresses()[0], env_singleton.env.get_island_port()) + % (dest_path, local_ip_addresses()[0], env_singleton.env.get_island_port()) ] if sys.platform == "win32": args = "".join(args) - subprocess.Popen(args, shell=True).pid + subprocess.Popen(args, cwd=dest_dir, shell=True).pid except Exception as exc: logger.error("popen failed", exc_info=True) return False, "popen failed: %s" % exc From 159aa604d3ee36665c29be2316361ca3591fb848 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 12:19:36 -0400 Subject: [PATCH 21/23] appimage: add `-y` to `sudo apt upgrade` to avoid prompt --- appimage/build_appimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh index fe3e89e0b..114aa1c66 100755 --- a/appimage/build_appimage.sh +++ b/appimage/build_appimage.sh @@ -46,7 +46,7 @@ install_nodejs() { install_build_prereqs() { sudo apt update - sudo apt upgrade + sudo apt upgrade -y # monkey island prereqs sudo apt install -y curl libcurl4 openssl git build-essential moreutils From 66c5d9126659dbe77e784b403536acaad315bdd6 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 12:20:10 -0400 Subject: [PATCH 22/23] appimage: Fix CLI parameter for choosing branch. --- appimage/build_appimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh index 114aa1c66..797b5169a 100755 --- a/appimage/build_appimage.sh +++ b/appimage/build_appimage.sh @@ -79,7 +79,7 @@ clone_monkey_repo() { fi log_message "Cloning files from git" - branch=${2:-"develop"} + branch=${1:-"develop"} git clone --single-branch --recurse-submodules -b "$branch" "${MONKEY_GIT_URL}" "${REPO_MONKEY_HOME}" 2>&1 || handle_error chmod 774 -R "${REPO_MONKEY_HOME}" From f3439bb2c415c6202ead608077c330585e7e5653 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 15 Apr 2021 12:20:33 -0400 Subject: [PATCH 23/23] appimage: add log message when downloading Python3.7 AppImage --- appimage/build_appimage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh index 797b5169a..b389c67db 100755 --- a/appimage/build_appimage.sh +++ b/appimage/build_appimage.sh @@ -105,6 +105,8 @@ setup_appdir() { setup_python_37_appdir() { PYTHON_APPIMAGE="python3.7.9_x86_64.AppImage" rm -rf "$APPDIR" || true + + log_message "downloading Python3.7 Appimage" curl -L -o "$PYTHON_APPIMAGE" "$PYTHON_APPIMAGE_URL" chmod u+x "$PYTHON_APPIMAGE"