diff --git a/monkey/monkey_island/deb-package/DEBIAN/control b/monkey/monkey_island/deb-package/DEBIAN/control index b31daa1945f..2693afbd9bc 100644 --- a/monkey/monkey_island/deb-package/DEBIAN/control +++ b/monkey/monkey_island/deb-package/DEBIAN/control @@ -5,4 +5,4 @@ Homepage: http://www.guardicore.com Priority: optional Version: 1.0 Description: Guardicore Infection Monkey Island installation package -Depends: openssl, python-pip, python-dev, mongodb +Depends: openssl, python-pip, python-dev diff --git a/monkey/monkey_island/deb-package/DEBIAN/postinst b/monkey/monkey_island/deb-package/DEBIAN/postinst index c113b34d5bf..8efc19bbbcb 100644 --- a/monkey/monkey_island/deb-package/DEBIAN/postinst +++ b/monkey/monkey_island/deb-package/DEBIAN/postinst @@ -9,16 +9,15 @@ pip2 install virtualenv --no-index --find-links file://$INSTALLATION_FOLDER virtualenv -p python2.7 ${PYTHON_FOLDER} # install pip requirements -${PYTHON_FOLDER}/bin/python -m pip install -r $MONKEY_FOLDER/monkey_island/pip_requirements.txt --no-index --find-links file://$INSTALLATION_FOLDER +${PYTHON_FOLDER}/bin/python -m pip install -r $MONKEY_FOLDER/monkey_island/requirements.txt --no-index --find-links file://$INSTALLATION_FOLDER # remove installation folder and unnecessary files rm -rf ${INSTALLATION_FOLDER} -rm -f ${MONKEY_FOLDER}/monkey_island/pip_requirements.txt +rm -f ${MONKEY_FOLDER}/monkey_island/requirements.txt -cp ${MONKEY_FOLDER}/monkey_island/ubuntu/* /etc/init/ if [ -d "/etc/systemd/network" ]; then - cp ${MONKEY_FOLDER}/monkey_island/ubuntu/systemd/*.service /lib/systemd/system/ - chmod +x ${MONKEY_FOLDER}/monkey_island/ubuntu/systemd/start_server.sh + cp ${MONKEY_FOLDER}/monkey_island/service/systemd/*.service /lib/systemd/system/ + chmod +x ${MONKEY_FOLDER}/monkey_island/service/systemd/start_server.sh systemctl daemon-reload systemctl enable monkey-island fi diff --git a/monkey/monkey_island/deb-package/DEBIAN_MONGO/postinst b/monkey/monkey_island/deb-package/DEBIAN_MONGO/postinst new file mode 100644 index 00000000000..76e57caa3d4 --- /dev/null +++ b/monkey/monkey_island/deb-package/DEBIAN_MONGO/postinst @@ -0,0 +1,35 @@ +#!/bin/bash + +MONKEY_FOLDER=/var/monkey +INSTALLATION_FOLDER=/var/monkey/monkey_island/installation +PYTHON_FOLDER=/var/monkey/monkey_island/bin/python + +# Prepare python virtualenv +pip2 install virtualenv --no-index --find-links file://$INSTALLATION_FOLDER +virtualenv -p python2.7 ${PYTHON_FOLDER} + +# install pip requirements +${PYTHON_FOLDER}/bin/python -m pip install -r $MONKEY_FOLDER/monkey_island/requirements.txt --no-index --find-links file://$INSTALLATION_FOLDER + +# remove installation folder and unnecessary files +rm -rf ${INSTALLATION_FOLDER} +rm -f ${MONKEY_FOLDER}/monkey_island/requirements.txt + +${MONKEY_FOLDER}/monkey_island/install_mongo.sh ${MONKEY_FOLDER}/monkey_island/bin/mongodb + +if [ -d "/etc/systemd/network" ]; then + cp ${MONKEY_FOLDER}/monkey_island/service/systemd/*.service /lib/systemd/system/ + chmod +x ${MONKEY_FOLDER}/monkey_island/service/systemd/start_server.sh + systemctl daemon-reload + systemctl enable monkey-mongo + systemctl enable monkey-island +fi + +${MONKEY_FOLDER}/monkey_island/create_certificate.sh + +service monkey-island start +service monkey-mongo start + +echo Monkey Island installation ended + +exit 0 \ No newline at end of file diff --git a/monkey/monkey_island/deb-package/DEBIAN_MONGO/prerm b/monkey/monkey_island/deb-package/DEBIAN_MONGO/prerm new file mode 100644 index 00000000000..dabdbd2fa74 --- /dev/null +++ b/monkey/monkey_island/deb-package/DEBIAN_MONGO/prerm @@ -0,0 +1,11 @@ +#!/bin/sh + +service monkey-island stop || true +service monkey-mongo stop || true + +[ -f "/lib/systemd/system/monkey-island.service" ] && rm -f /lib/systemd/system/monkey-island.service +[ -f "/lib/systemd/system/monkey-mongo.service" ] && rm -f /lib/systemd/system/monkey-mongo.service + +rm -r -f /var/monkey + +exit 0 \ No newline at end of file diff --git a/monkey/monkey_island/deb-package/monkey_island_pip_requirements.txt b/monkey/monkey_island/deb-package/monkey_island_pip_requirements.txt deleted file mode 100644 index 4f6ea54ec12..00000000000 --- a/monkey/monkey_island/deb-package/monkey_island_pip_requirements.txt +++ /dev/null @@ -1,19 +0,0 @@ -python-dateutil -tornado -werkzeug -jinja2 -markupsafe -itsdangerous -click -flask -Flask-Pymongo -Flask-Restful -Flask-JWT -jsonschema -netifaces -ipaddress -enum34 -pycryptodome -boto3 -awscli -virtualenv \ No newline at end of file diff --git a/monkey/monkey_island/linux/ubuntu/systemd/monkey-island.service b/monkey/monkey_island/deb-package/service/systemd/monkey-island.service similarity index 64% rename from monkey/monkey_island/linux/ubuntu/systemd/monkey-island.service rename to monkey/monkey_island/deb-package/service/systemd/monkey-island.service index b6a5365740d..e1dea878a30 100644 --- a/monkey/monkey_island/linux/ubuntu/systemd/monkey-island.service +++ b/monkey/monkey_island/deb-package/service/systemd/monkey-island.service @@ -4,7 +4,7 @@ After=network.target [Service] Type=simple -ExecStart=/var/monkey/monkey_island/ubuntu/systemd/start_server.sh +ExecStart=/var/monkey/monkey_island/service/systemd/start_server.sh [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/monkey/monkey_island/linux/ubuntu/systemd/start_server.sh b/monkey/monkey_island/deb-package/service/systemd/start_server.sh similarity index 100% rename from monkey/monkey_island/linux/ubuntu/systemd/start_server.sh rename to monkey/monkey_island/deb-package/service/systemd/start_server.sh diff --git a/monkey/monkey_island/deb-package/service_mongo/systemd/monkey-island.service b/monkey/monkey_island/deb-package/service_mongo/systemd/monkey-island.service new file mode 100644 index 00000000000..aa609f068ba --- /dev/null +++ b/monkey/monkey_island/deb-package/service_mongo/systemd/monkey-island.service @@ -0,0 +1,11 @@ +[Unit] +Description=Monkey Island Service +Wants=monkey-mongo.service +After=network.target + +[Service] +Type=simple +ExecStart=/var/monkey/monkey_island/service/systemd/start_server.sh + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/monkey/monkey_island/deb-package/service_mongo/systemd/monkey-mongo.service b/monkey/monkey_island/deb-package/service_mongo/systemd/monkey-mongo.service new file mode 100644 index 00000000000..b786e0abb75 --- /dev/null +++ b/monkey/monkey_island/deb-package/service_mongo/systemd/monkey-mongo.service @@ -0,0 +1,12 @@ +[Unit] +Description=Monkey Island Mongo Service +After=network.target + +[Service] +ExecStart=/var/monkey/monkey_island/bin/mongodb/bin/mongod --quiet --dbpath /var/monkey/monkey_island/db +KillMode=process +Restart=always +ExecStop=/var/monkey/monkey_island/bin/mongodb/bin/mongod --shutdown + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/monkey/monkey_island/linux/install_mongo.sh b/monkey/monkey_island/linux/install_mongo.sh new file mode 100644 index 00000000000..a00a2078bbf --- /dev/null +++ b/monkey/monkey_island/linux/install_mongo.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +export os_version_monkey=$(cat /etc/issue) +MONGODB_DIR=$1 # If using deb, this should be: /var/monkey/monkey_island/bin/mongodb + +if [[ $os_version_monkey == "Ubuntu 16.04"* ]] ; +then + echo Detected Ubuntu 16.04 + export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.6.12.tgz" +elif [[ $os_version_monkey == "Ubuntu 18.04"* ]] ; +then + echo Detected Ubuntu 18.04 + export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.0.8.tgz" +elif [[ $os_version_monkey == "Debian GNU/Linux 8"* ]] ; +then + echo Detected Debian 8 + 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"* ]] ; +then + echo Detected Debian 9 + export tgz_url="https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-3.6.12.tgz" +else + echo Unsupported OS + exit -1 +fi + +TEMP_MONGO=$(mktemp -d) +pushd $TEMP_MONGO +wget $tgz_url -O mongodb.tgz +tar -xf mongodb.tgz +popd + +mkdir -p $MONGODB_DIR/bin +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 \ No newline at end of file diff --git a/monkey/monkey_island/linux/ubuntu/monkey-island.conf b/monkey/monkey_island/linux/ubuntu/monkey-island.conf deleted file mode 100644 index e7dfc4d21da..00000000000 --- a/monkey/monkey_island/linux/ubuntu/monkey-island.conf +++ /dev/null @@ -1,18 +0,0 @@ -description "Monkey Island Service" - -start on runlevel [2345] -stop on runlevel [!2345] - -respawn -respawn limit unlimited - -script - chdir /var/monkey - exec monkey_island/bin/python/bin/python monkey_island.py -end script - -post-stop script - if [ -n $UPSTART_EVENTS ]; then - exec sleep 2 - fi -end script \ No newline at end of file diff --git a/monkey/monkey_island/requirements.txt b/monkey/monkey_island/requirements.txt index 147f3481c37..0203a1cea76 100644 --- a/monkey/monkey_island/requirements.txt +++ b/monkey/monkey_island/requirements.txt @@ -18,4 +18,6 @@ boto3 awscli bson cffi -PyInstaller \ No newline at end of file +PyInstaller +virtualenv +wheel \ No newline at end of file