Skip to content

Commit

Permalink
Merge pull request #298 from guardicore/hotfix/fix-binary-download
Browse files Browse the repository at this point in the history
all monkey_island references are now absolute
  • Loading branch information
itaymmguardicore authored Apr 14, 2019
2 parents 740af9c + d4e42cb commit 8322178
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion monkey/monkey_island/cc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from monkey_island.cc.resources.telemetry import Telemetry
from monkey_island.cc.resources.telemetry_feed import TelemetryFeed
from monkey_island.cc.services.config import ConfigService
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH

__author__ = 'Barak'

Expand All @@ -39,7 +40,7 @@ def serve_static_file(static_path):
if static_path.startswith('api/'):
raise NotFound()
try:
return send_from_directory(os.path.join(os.getcwd(), 'monkey_island/cc/ui/dist'), static_path)
return send_from_directory(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/ui/dist'), static_path)
except NotFound:
# Because react uses various urls for same index page, this is probably the user's intention.
if static_path == HOME_FILE:
Expand Down
5 changes: 5 additions & 0 deletions monkey/monkey_island/cc/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

__author__ = 'itay.mizeretz'

MONKEY_ISLAND_ABS_PATH = os.path.join(os.getcwd(), 'monkey_island')
4 changes: 3 additions & 1 deletion monkey/monkey_island/cc/encryptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from Crypto import Random
from Crypto.Cipher import AES

from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH

__author__ = "itay.mizeretz"


class Encryptor:
_BLOCK_SIZE = 32
_DB_PASSWORD_FILENAME = "monkey_island/cc/mongo_key.bin"
_DB_PASSWORD_FILENAME = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/mongo_key.bin')

def __init__(self):
self._load_key()
Expand Down
4 changes: 3 additions & 1 deletion monkey/monkey_island/cc/environment/environment.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
import logging
import os

from monkey_island.cc.environment import standard
from monkey_island.cc.environment import aws
from monkey_island.cc.environment import password
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH

__author__ = 'itay.mizeretz'

Expand All @@ -21,7 +23,7 @@


def load_server_configuration_from_file():
with open('monkey_island/cc/server_config.json', 'r') as f:
with open(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/server_config.json'), 'r') as f:
config_content = f.read()
return json.loads(config_content)

Expand Down
13 changes: 9 additions & 4 deletions monkey/monkey_island/cc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
sys.path.insert(0, BASE_PATH)

from monkey_island.cc.island_logger import json_setup_logging
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
# This is here in order to catch EVERYTHING, some functions are being called on imports the log init needs to be on top.
json_setup_logging(default_path=os.path.join(BASE_PATH, 'cc', 'island_logger_default_config.json'),
json_setup_logging(default_path=os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'island_logger_default_config.json'),
default_level=logging.DEBUG)
logger = logging.getLogger(__name__)

Expand All @@ -37,12 +38,16 @@ def main():

populate_exporter_list()
app = init_app(mongo_url)

crt_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.crt')
key_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.key')

if env.is_debug():
app.run(host='0.0.0.0', debug=True, ssl_context=('monkey_island/cc/server.crt', 'monkey_island/cc/server.key'))
app.run(host='0.0.0.0', debug=True, ssl_context=(crt_path, key_path))
else:
http_server = HTTPServer(WSGIContainer(app),
ssl_options={'certfile': os.environ.get('SERVER_CRT', 'monkey_island/cc/server.crt'),
'keyfile': os.environ.get('SERVER_KEY', 'monkey_island/cc/server.key')})
ssl_options={'certfile': os.environ.get('SERVER_CRT', crt_path),
'keyfile': os.environ.get('SERVER_KEY', key_path)})
http_server.listen(env.get_island_port())
logger.info(
'Monkey Island Server is running on https://{}:{}'.format(local_ip_addresses()[0], env.get_island_port()))
Expand Down
6 changes: 4 additions & 2 deletions monkey/monkey_island/cc/resources/local_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from monkey_island.cc.resources.monkey_download import get_monkey_executable
from monkey_island.cc.services.node import NodeService
from monkey_island.cc.utils import local_ip_addresses
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH

__author__ = 'Barak'

import logging
logger = logging.getLogger(__name__)


def run_local_monkey():
import platform
import subprocess
Expand All @@ -26,8 +28,8 @@ def run_local_monkey():
if not result:
return False, "OS Type not found"

monkey_path = os.path.join(os.getcwd(), 'monkey_island', 'cc', 'binaries', result['filename'])
target_path = os.path.join(os.getcwd(), 'monkey_island', result['filename'])
monkey_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries', result['filename'])
target_path = os.path.join(MONKEY_ISLAND_ABS_PATH, result['filename'])

# copy the executable to temp path (don't run the monkey from its current location as it may delete itself)
try:
Expand Down
6 changes: 4 additions & 2 deletions monkey/monkey_island/cc/resources/monkey_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import flask_restful
from flask import request, send_from_directory

from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH

__author__ = 'Barak'

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -70,7 +72,7 @@ class MonkeyDownload(flask_restful.Resource):

# Used by monkey. can't secure.
def get(self, path):
return send_from_directory('binaries', path)
return send_from_directory(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries'), path)

# Used by monkey. can't secure.
def post(self):
Expand All @@ -81,7 +83,7 @@ def post(self):

if result:
# change resulting from new base path
real_path = os.path.join("monkey_island", "cc", 'binaries', result['filename'])
real_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", 'binaries', result['filename'])
if os.path.isfile(real_path):
result['size'] = os.path.getsize(real_path)
return result
Expand Down

0 comments on commit 8322178

Please sign in to comment.