forked from p15670423/monkey
Merge pull request #298 from guardicore/hotfix/fix-binary-download
all monkey_island references are now absolute
This commit is contained in:
commit
8322178711
|
@ -28,6 +28,7 @@ from monkey_island.cc.resources.root import Root
|
||||||
from monkey_island.cc.resources.telemetry import Telemetry
|
from monkey_island.cc.resources.telemetry import Telemetry
|
||||||
from monkey_island.cc.resources.telemetry_feed import TelemetryFeed
|
from monkey_island.cc.resources.telemetry_feed import TelemetryFeed
|
||||||
from monkey_island.cc.services.config import ConfigService
|
from monkey_island.cc.services.config import ConfigService
|
||||||
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||||
|
|
||||||
__author__ = 'Barak'
|
__author__ = 'Barak'
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ def serve_static_file(static_path):
|
||||||
if static_path.startswith('api/'):
|
if static_path.startswith('api/'):
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
try:
|
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:
|
except NotFound:
|
||||||
# Because react uses various urls for same index page, this is probably the user's intention.
|
# Because react uses various urls for same index page, this is probably the user's intention.
|
||||||
if static_path == HOME_FILE:
|
if static_path == HOME_FILE:
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
__author__ = 'itay.mizeretz'
|
||||||
|
|
||||||
|
MONKEY_ISLAND_ABS_PATH = os.path.join(os.getcwd(), 'monkey_island')
|
|
@ -4,12 +4,14 @@ import os
|
||||||
from Crypto import Random
|
from Crypto import Random
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
|
|
||||||
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||||
|
|
||||||
__author__ = "itay.mizeretz"
|
__author__ = "itay.mizeretz"
|
||||||
|
|
||||||
|
|
||||||
class Encryptor:
|
class Encryptor:
|
||||||
_BLOCK_SIZE = 32
|
_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):
|
def __init__(self):
|
||||||
self._load_key()
|
self._load_key()
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from monkey_island.cc.environment import standard
|
from monkey_island.cc.environment import standard
|
||||||
from monkey_island.cc.environment import aws
|
from monkey_island.cc.environment import aws
|
||||||
from monkey_island.cc.environment import password
|
from monkey_island.cc.environment import password
|
||||||
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||||
|
|
||||||
__author__ = 'itay.mizeretz'
|
__author__ = 'itay.mizeretz'
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ ENV_DICT = {
|
||||||
|
|
||||||
|
|
||||||
def load_server_configuration_from_file():
|
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()
|
config_content = f.read()
|
||||||
return json.loads(config_content)
|
return json.loads(config_content)
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,9 @@ if BASE_PATH not in sys.path:
|
||||||
sys.path.insert(0, BASE_PATH)
|
sys.path.insert(0, BASE_PATH)
|
||||||
|
|
||||||
from monkey_island.cc.island_logger import json_setup_logging
|
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.
|
# 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)
|
default_level=logging.DEBUG)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -37,12 +38,16 @@ def main():
|
||||||
|
|
||||||
populate_exporter_list()
|
populate_exporter_list()
|
||||||
app = init_app(mongo_url)
|
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():
|
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:
|
else:
|
||||||
http_server = HTTPServer(WSGIContainer(app),
|
http_server = HTTPServer(WSGIContainer(app),
|
||||||
ssl_options={'certfile': os.environ.get('SERVER_CRT', 'monkey_island/cc/server.crt'),
|
ssl_options={'certfile': os.environ.get('SERVER_CRT', crt_path),
|
||||||
'keyfile': os.environ.get('SERVER_KEY', 'monkey_island/cc/server.key')})
|
'keyfile': os.environ.get('SERVER_KEY', key_path)})
|
||||||
http_server.listen(env.get_island_port())
|
http_server.listen(env.get_island_port())
|
||||||
logger.info(
|
logger.info(
|
||||||
'Monkey Island Server is running on https://{}:{}'.format(local_ip_addresses()[0], env.get_island_port()))
|
'Monkey Island Server is running on https://{}:{}'.format(local_ip_addresses()[0], env.get_island_port()))
|
||||||
|
|
|
@ -10,12 +10,14 @@ from monkey_island.cc.environment.environment import env
|
||||||
from monkey_island.cc.resources.monkey_download import get_monkey_executable
|
from monkey_island.cc.resources.monkey_download import get_monkey_executable
|
||||||
from monkey_island.cc.services.node import NodeService
|
from monkey_island.cc.services.node import NodeService
|
||||||
from monkey_island.cc.utils import local_ip_addresses
|
from monkey_island.cc.utils import local_ip_addresses
|
||||||
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||||
|
|
||||||
__author__ = 'Barak'
|
__author__ = 'Barak'
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def run_local_monkey():
|
def run_local_monkey():
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -26,8 +28,8 @@ def run_local_monkey():
|
||||||
if not result:
|
if not result:
|
||||||
return False, "OS Type not found"
|
return False, "OS Type not found"
|
||||||
|
|
||||||
monkey_path = os.path.join(os.getcwd(), 'monkey_island', 'cc', 'binaries', result['filename'])
|
monkey_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries', result['filename'])
|
||||||
target_path = os.path.join(os.getcwd(), 'monkey_island', 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)
|
# copy the executable to temp path (don't run the monkey from its current location as it may delete itself)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -5,6 +5,8 @@ import os
|
||||||
import flask_restful
|
import flask_restful
|
||||||
from flask import request, send_from_directory
|
from flask import request, send_from_directory
|
||||||
|
|
||||||
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||||
|
|
||||||
__author__ = 'Barak'
|
__author__ = 'Barak'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -70,7 +72,7 @@ class MonkeyDownload(flask_restful.Resource):
|
||||||
|
|
||||||
# Used by monkey. can't secure.
|
# Used by monkey. can't secure.
|
||||||
def get(self, path):
|
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.
|
# Used by monkey. can't secure.
|
||||||
def post(self):
|
def post(self):
|
||||||
|
@ -81,7 +83,7 @@ class MonkeyDownload(flask_restful.Resource):
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
# change resulting from new base path
|
# 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):
|
if os.path.isfile(real_path):
|
||||||
result['size'] = os.path.getsize(real_path)
|
result['size'] = os.path.getsize(real_path)
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue