Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/1.8.0 fix deb python version #609

Merged
merged 15 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion monkey/monkey_island/deb-package/DEBIAN_MONGO/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Homepage: https://www.infectionmonkey.com
Priority: optional
Version: 1.0
Description: Guardicore Infection Monkey Island installation package
Depends: openssl, python3-pip, python3-dev
Depends: openssl, python3.7-dev, python3.7-venv, python3-venv, build-essential
40 changes: 34 additions & 6 deletions monkey/monkey_island/deb-package/DEBIAN_MONGO/postinst
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
#!/bin/bash

# See the "Depends" field of the control file for what packages this scripts depends on.
# Here are the explanations for the current deps:
# Dependency - Why is it required
## openssl - Server certificate generation
## python3.7-dev - Server runtime
## python3.7-venv - For creating virtual env to install all the server pip deps (don't want to pollute system python)
## python3-venv - python3.7-venv doesn't work without it since you need ensure-pip
## build-essential - for compiling python dependencies that don't come in a pre-compiled wheel, like `netifaces`

echo "Installing Monkey Island (Infection Monkey server)..."

MONKEY_FOLDER=/var/monkey
INSTALLATION_FOLDER=/var/monkey/monkey_island/installation
PYTHON_FOLDER=/var/monkey/monkey_island/bin/python
PYTHON_VERSION=python3.7

# Prepare python virtualenv
pip3 install virtualenv --no-index --find-links file://$INSTALLATION_FOLDER
python3 -m virtualenv -p python3 ${PYTHON_FOLDER}

# install pip requirements
# This is using the apt package `python3.7-venv` which is listed in the `control` file as a dependency.
# See https://packages.debian.org/stable/python/python3.7-venv
echo "Using $(command -v $PYTHON_VERSION) as the base for virtualenv creation"
$PYTHON_VERSION -m venv ${PYTHON_FOLDER}
# shellcheck disable=SC1090
source ${PYTHON_FOLDER}/bin/activate

echo "Installing Python dependencies using $(command -v pip)..."
# First, make sure that pip is updated
${PYTHON_FOLDER}/bin/python -m pip install --upgrade pip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ran source above, why are you fully qualifying your python command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Then install the dependecies from the pre-downloaded whl and tar.gz file
${PYTHON_FOLDER}/bin/python -m pip install -r $MONKEY_FOLDER/monkey_island/requirements.txt --no-index --find-links file://$INSTALLATION_FOLDER

deactivate

# remove installation folder and unnecessary files
rm -rf ${INSTALLATION_FOLDER}
rm -f ${MONKEY_FOLDER}/monkey_island/requirements.txt

echo "Installing mongodb..."
${MONKEY_FOLDER}/monkey_island/install_mongo.sh ${MONKEY_FOLDER}/monkey_island/bin/mongodb

if [ -d "/etc/systemd/network" ]; then
Expand All @@ -25,11 +47,17 @@ if [ -d "/etc/systemd/network" ]; then
systemctl enable monkey-island
fi

${MONKEY_FOLDER}/monkey_island/create_certificate.sh ${MONKEY_FOLDER}/monkey_island/
echo "Creating server certificate..."
${MONKEY_FOLDER}/monkey_island/create_certificate.sh ${MONKEY_FOLDER}/monkey_island/cc

echo "Starting services..."
service monkey-island start
service monkey-mongo start

echo Monkey Island installation ended
echo ""
echo "Monkey Island installation ended."
echo "The server should be accessible soon via https://<server_ip>:5000/"
echo "To check the Island's status, run 'sudo service monkey-island status'"
echo ""

exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13 changes: 13 additions & 0 deletions monkey/monkey_island/linux/create_certificate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@

server_root=${1:-"./cc"}

echo "Creating server cetificate. Server root: $server_root"
# We override the RANDFILE determined by default openssl.cnf
# This is a known issue with the current version of openssl on Ubuntu 18.04 - once they release
# a new version, we can delete this command. See
# https://github.com/openssl/openssl/commit/0f58220973a02248ca5c69db59e615378467b9c8#diff-8ce6aaad88b10ed2b3b4592fd5c8e03a
# for more details.
dd bs=1024 count=2 </dev/urandom >~/.rnd
chmod 666 ~/.rnd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you don't have permissions to ~ or if the file exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9687b22

The user which runs ./create_cert will have access to their own ~ folder in enough of the cases that I'm willing to leave this in. No other workaround that doesn't involve carrying openssl with us or messing with worse things in the system that I could fine.


echo "Generating key in $server_root/server.key"
openssl genrsa -out "$server_root"/server.key 2048
echo "Generating csr in $server_root/server.csr"
openssl req -new -key "$server_root"/server.key -out "$server_root"/server.csr -subj "/C=GB/ST=London/L=London/O=Global Security/OU=Monkey Department/CN=monkey.com"
echo "Generating certificate in $server_root/server.crt"
openssl x509 -req -days 366 -in "$server_root"/server.csr -signkey "$server_root"/server.key -out $server_root/server.crt

# Shove some new random data into the file to override the original seed.
dd bs=1024 count=2 </dev/urandom >~/.rnd
1 change: 0 additions & 1 deletion monkey/monkey_island/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pytest
bson
python-dateutil
tornado
werkzeug
Expand Down