From bd6653954848c9a1b24c3b1f740b9447dc93ed52 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 28 Jul 2021 15:51:27 -0400 Subject: [PATCH 1/3] Build: Remove AppImage package from dist/ in appimage/clean.sh --- build_scripts/appimage/clean.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build_scripts/appimage/clean.sh b/build_scripts/appimage/clean.sh index ee9303a10..6ce76cd32 100755 --- a/build_scripts/appimage/clean.sh +++ b/build_scripts/appimage/clean.sh @@ -9,3 +9,4 @@ rm -rf "$HOME/git/monkey" rm -rf "$HOME/.monkey_island" rm -rf "$APPIMAGE_DIR/squashfs-root" rm "$APPIMAGE_DIR"/Infection_Monkey*x86_64.AppImage +rm "$APPIMAGE_DIR/../dist/Infection_Monkey*x86_64.AppImage" From c53730a6c3e87f399537a38b13dd973fed5791f8 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 28 Jul 2021 15:52:17 -0400 Subject: [PATCH 2/3] Build: Remove .tgz from dist in docker/clean.sh --- build_scripts/docker/clean.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build_scripts/docker/clean.sh b/build_scripts/docker/clean.sh index 82c769c02..7a5c5a677 100755 --- a/build_scripts/docker/clean.sh +++ b/build_scripts/docker/clean.sh @@ -11,3 +11,4 @@ rm -rf "$DOCKER_DIR/monkey" rm -rf "$DOCKER_DIR/tgz" rm "$DOCKER_DIR"/dk.monkeyisland.*.tar rm "$DOCKER_DIR"/infection_monkey_docker*.tgz +rm "$DOCKER_DIR"/../dist/infection_monkey_docker*.tgz From 11488365e89d4a7ac319d61b75fe1e7764b2d93f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 28 Jul 2021 15:54:20 -0400 Subject: [PATCH 3/3] Build: Package the AppImage with linuxdeploy Fixes #1355 Fixes #1362 --- build_scripts/appimage/appimage.sh | 101 ++++++++---------- .../appimage/infection-monkey.desktop | 2 +- 2 files changed, 45 insertions(+), 58 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index c1cf3b922..d55418df7 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -1,20 +1,25 @@ #!/bin/bash -APP_TOOL_URL=https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage +LINUXDEPLOY_URL="https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" PYTHON_VERSION="3.7.11" PYTHON_APPIMAGE_URL="https://github.com/niess/python-appimage/releases/download/python3.7/python${PYTHON_VERSION}-cp37-cp37m-manylinux1_x86_64.AppImage" APPIMAGE_DIR="$(realpath $(dirname $BASH_SOURCE[0]))" +APPDIR="$APPIMAGE_DIR/squashfs-root" +BUILD_DIR="$APPDIR/usr/src" + +ICON_PATH="$BUILD_DIR/monkey_island/cc/ui/src/images/monkey-icon.svg" +MONGO_PATH="$BUILD_DIR/monkey_island/bin/mongodb" source "$APPIMAGE_DIR/../common.sh" install_package_specific_build_prereqs() { - log_message "Installing appimagetool" + log_message "Installing linuxdeploy" WORKSPACE_BIN_DIR="$1/bin" - APP_TOOL_BIN="$WORKSPACE_BIN_DIR/appimagetool" + LINUXDEPLOY_BIN="$WORKSPACE_BIN_DIR/linuxdeploy" mkdir -p "$WORKSPACE_BIN_DIR" - curl -L -o "$APP_TOOL_BIN" "$APP_TOOL_URL" - chmod u+x "$APP_TOOL_BIN" + curl -L -o "$LINUXDEPLOY_BIN" "$LINUXDEPLOY_URL" + chmod u+x "$LINUXDEPLOY_BIN" PATH=$PATH:$WORKSPACE_BIN_DIR } @@ -22,28 +27,24 @@ install_package_specific_build_prereqs() { setup_build_dir() { local agent_binary_dir=$1 local monkey_repo=$2 - local appdir=$APPIMAGE_DIR/squashfs-root - local build_dir="$appdir/usr/src" pushd $APPIMAGE_DIR - setup_python_37_appdir $build_dir + setup_python_37_appdir - mkdir -p "$build_dir" + mkdir -p "$BUILD_DIR" - copy_monkey_island_to_build_dir "$monkey_repo/monkey" $build_dir - copy_server_config_to_build_dir $build_dir - add_agent_binaries_to_build_dir "$agent_binary_dir" "$build_dir" + copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$BUILD_DIR" + copy_server_config_to_build_dir + add_agent_binaries_to_build_dir "$agent_binary_dir" "$BUILD_DIR" - install_monkey_island_python_dependencies "$appdir" "$build_dir" - install_mongodb "$build_dir" + install_monkey_island_python_dependencies + install_mongodb - generate_ssl_cert "$build_dir" - build_frontend "$build_dir" + generate_ssl_cert "$BUILD_DIR" + build_frontend "$BUILD_DIR" - add_monkey_icon "$appdir" "$monkey_repo" - add_desktop_file "$appdir" - add_apprun "$appdir" + remove_python_appdir_artifacts popd } @@ -61,75 +62,61 @@ setup_python_37_appdir() { } copy_server_config_to_build_dir() { - cp "$APPIMAGE_DIR"/server_config.json.standard "$1"/monkey_island/cc/server_config.json + cp "$APPIMAGE_DIR"/server_config.json.standard "$BUILD_DIR"/monkey_island/cc/server_config.json } install_monkey_island_python_dependencies() { - local appdir=$1 - local build_dir=$2 log_message "Installing island requirements" log_message "Installing pipenv" - "$appdir"/AppRun -m pip install pipenv || handle_error + "$APPDIR"/AppRun -m pip install pipenv || handle_error - requirements_island="$build_dir/monkey_island/requirements.txt" - generate_requirements_from_pipenv_lock "$appdir" "$build_dir" "$requirements_island" + requirements_island="$BUILD_DIR/monkey_island/requirements.txt" + generate_requirements_from_pipenv_lock "$requirements_island" log_message "Installing island python requirements" - "$appdir"/AppRun -m pip install -r "${requirements_island}" --ignore-installed || handle_error + "$APPDIR"/AppRun -m pip install -r "${requirements_island}" --ignore-installed || handle_error } generate_requirements_from_pipenv_lock () { - local appdir=$1 - local build_dir=$2 - local requirements_island=$3 + local requirements_island=$1 log_message "Generating a requirements.txt file with 'pipenv lock -r'" - pushd "$build_dir/monkey_island" - "$appdir"/AppRun -m pipenv --python "$appdir/AppRun" lock -r > "$requirements_island" || handle_error + pushd "$BUILD_DIR/monkey_island" + "$APPDIR"/AppRun -m pipenv --python "$APPDIR/AppRun" lock -r > "$requirements_island" || handle_error popd } + install_mongodb() { - local build_dir=$1 - local mongo_path="$build_dir/monkey_island/bin/mongodb" log_message "Installing MongoDB" - mkdir -p "$mongo_path" - "$build_dir/monkey_island/linux/install_mongo.sh" "${mongo_path}" || handle_error + mkdir -p "$MONGO_PATH" + "$BUILD_DIR/monkey_island/linux/install_mongo.sh" "${MONGO_PATH}" || handle_error } -add_monkey_icon() { - local appdir=$1 - local monkey_repo=$2 - - unlink "$appdir"/python.png - mkdir -p "$appdir"/usr/share/icons - cp "$monkey_repo"/monkey/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() { - local appdir=$1 - - unlink "$appdir"/python*.desktop - cp ./infection-monkey.desktop "$appdir"/usr/share/applications - ln -s "$appdir"/usr/share/applications/infection-monkey.desktop "$appdir"/infection-monkey.desktop -} - -add_apprun() { - cp ./AppRun "$1" +remove_python_appdir_artifacts() { + rm "$APPDIR"/python.png + rm "$APPDIR"/python*.desktop + rm "$APPDIR"/AppRun } build_package() { local version=$1 local dist_dir=$2 + log_message "Building AppImage" pushd "$APPIMAGE_DIR" - ARCH="x86_64" appimagetool "$APPIMAGE_DIR/squashfs-root" - apply_version_to_appimage "$version" + ARCH="x86_64" linuxdeploy \ + --appdir "$APPIMAGE_DIR/squashfs-root" \ + --icon-file "$ICON_PATH" \ + --desktop-file "$APPIMAGE_DIR/infection-monkey.desktop" \ + --custom-apprun "$APPIMAGE_DIR/AppRun" \ + --deploy-deps-only="$MONGO_PATH/bin/mongod"\ + --output appimage + apply_version_to_appimage "$version" move_package_to_dist_dir $dist_dir popd diff --git a/build_scripts/appimage/infection-monkey.desktop b/build_scripts/appimage/infection-monkey.desktop index 5869ef187..dcefbb51a 100644 --- a/build_scripts/appimage/infection-monkey.desktop +++ b/build_scripts/appimage/infection-monkey.desktop @@ -3,6 +3,6 @@ Type=Application Name=Infection Monkey Exec=bash Comment=An automated breach and attack simulation platform -Icon=infection-monkey +Icon=monkey-icon Categories=Development; Terminal=true