Skip to content

Commit 8322178

Browse files
Merge pull request #298 from guardicore/hotfix/fix-binary-download
all monkey_island references are now absolute
2 parents 740af9c + d4e42cb commit 8322178

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed

monkey/monkey_island/cc/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from monkey_island.cc.resources.telemetry import Telemetry
2929
from monkey_island.cc.resources.telemetry_feed import TelemetryFeed
3030
from monkey_island.cc.services.config import ConfigService
31+
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
3132

3233
__author__ = 'Barak'
3334

@@ -39,7 +40,7 @@ def serve_static_file(static_path):
3940
if static_path.startswith('api/'):
4041
raise NotFound()
4142
try:
42-
return send_from_directory(os.path.join(os.getcwd(), 'monkey_island/cc/ui/dist'), static_path)
43+
return send_from_directory(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/ui/dist'), static_path)
4344
except NotFound:
4445
# Because react uses various urls for same index page, this is probably the user's intention.
4546
if static_path == HOME_FILE:

monkey/monkey_island/cc/consts.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
3+
__author__ = 'itay.mizeretz'
4+
5+
MONKEY_ISLAND_ABS_PATH = os.path.join(os.getcwd(), 'monkey_island')

monkey/monkey_island/cc/encryptor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from Crypto import Random
55
from Crypto.Cipher import AES
66

7+
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
8+
79
__author__ = "itay.mizeretz"
810

911

1012
class Encryptor:
1113
_BLOCK_SIZE = 32
12-
_DB_PASSWORD_FILENAME = "monkey_island/cc/mongo_key.bin"
14+
_DB_PASSWORD_FILENAME = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/mongo_key.bin')
1315

1416
def __init__(self):
1517
self._load_key()

monkey/monkey_island/cc/environment/environment.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import json
22
import logging
3+
import os
34

45
from monkey_island.cc.environment import standard
56
from monkey_island.cc.environment import aws
67
from monkey_island.cc.environment import password
8+
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
79

810
__author__ = 'itay.mizeretz'
911

@@ -21,7 +23,7 @@
2123

2224

2325
def load_server_configuration_from_file():
24-
with open('monkey_island/cc/server_config.json', 'r') as f:
26+
with open(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc/server_config.json'), 'r') as f:
2527
config_content = f.read()
2628
return json.loads(config_content)
2729

monkey/monkey_island/cc/main.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
sys.path.insert(0, BASE_PATH)
1313

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

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

3839
populate_exporter_list()
3940
app = init_app(mongo_url)
41+
42+
crt_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.crt')
43+
key_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.key')
44+
4045
if env.is_debug():
41-
app.run(host='0.0.0.0', debug=True, ssl_context=('monkey_island/cc/server.crt', 'monkey_island/cc/server.key'))
46+
app.run(host='0.0.0.0', debug=True, ssl_context=(crt_path, key_path))
4247
else:
4348
http_server = HTTPServer(WSGIContainer(app),
44-
ssl_options={'certfile': os.environ.get('SERVER_CRT', 'monkey_island/cc/server.crt'),
45-
'keyfile': os.environ.get('SERVER_KEY', 'monkey_island/cc/server.key')})
49+
ssl_options={'certfile': os.environ.get('SERVER_CRT', crt_path),
50+
'keyfile': os.environ.get('SERVER_KEY', key_path)})
4651
http_server.listen(env.get_island_port())
4752
logger.info(
4853
'Monkey Island Server is running on https://{}:{}'.format(local_ip_addresses()[0], env.get_island_port()))

monkey/monkey_island/cc/resources/local_run.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
from monkey_island.cc.resources.monkey_download import get_monkey_executable
1111
from monkey_island.cc.services.node import NodeService
1212
from monkey_island.cc.utils import local_ip_addresses
13+
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
1314

1415
__author__ = 'Barak'
1516

1617
import logging
1718
logger = logging.getLogger(__name__)
1819

20+
1921
def run_local_monkey():
2022
import platform
2123
import subprocess
@@ -26,8 +28,8 @@ def run_local_monkey():
2628
if not result:
2729
return False, "OS Type not found"
2830

29-
monkey_path = os.path.join(os.getcwd(), 'monkey_island', 'cc', 'binaries', result['filename'])
30-
target_path = os.path.join(os.getcwd(), 'monkey_island', result['filename'])
31+
monkey_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries', result['filename'])
32+
target_path = os.path.join(MONKEY_ISLAND_ABS_PATH, result['filename'])
3133

3234
# copy the executable to temp path (don't run the monkey from its current location as it may delete itself)
3335
try:

monkey/monkey_island/cc/resources/monkey_download.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import flask_restful
66
from flask import request, send_from_directory
77

8+
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
9+
810
__author__ = 'Barak'
911

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

7173
# Used by monkey. can't secure.
7274
def get(self, path):
73-
return send_from_directory('binaries', path)
75+
return send_from_directory(os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries'), path)
7476

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

8284
if result:
8385
# change resulting from new base path
84-
real_path = os.path.join("monkey_island", "cc", 'binaries', result['filename'])
86+
real_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", 'binaries', result['filename'])
8587
if os.path.isfile(real_path):
8688
result['size'] = os.path.getsize(real_path)
8789
return result

0 commit comments

Comments
 (0)