Example #1
0
def main():
    from tornado.wsgi import WSGIContainer
    from tornado.httpserver import HTTPServer
    from tornado.ioloop import IOLoop

    mongo_url = os.environ.get('MONGO_URL', env.get_mongo_url())

    while not is_db_server_up(mongo_url):
        logger.info('Waiting for MongoDB server')
        time.sleep(1)

    populate_exporter_list()
    app = init_app(mongo_url)
    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'))
    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')
            })
        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()))

        IOLoop.instance().start()
Example #2
0
File: config.py Project: wau/monkey
 def set_server_ips_in_config(config):
     ips = local_ip_addresses()
     config["cnc"]["servers"]["command_servers"] = [
         "%s:%d" % (ip, env.get_island_port()) for ip in ips
     ]
     config["cnc"]["servers"]["current_server"] = "%s:%d" % (
         ips[0], env.get_island_port())
Example #3
0
def start_island_server(should_setup_only):
    from tornado.wsgi import WSGIContainer
    from tornado.httpserver import HTTPServer
    from tornado.ioloop import IOLoop

    mongo_url = os.environ.get('MONGO_URL', env.get_mongo_url())
    wait_for_mongo_db_server(mongo_url)
    assert_mongo_db_version(mongo_url)

    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')

    setup()

    if should_setup_only:
        logger.warning("Setup only flag passed. Exiting.")
        return

    if env.is_debug():
        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', crt_path),
                                     'keyfile':
                                     os.environ.get('SERVER_KEY', key_path)
                                 })
        http_server.listen(env.get_island_port())
        log_init_info()
        IOLoop.instance().start()
Example #4
0
def log_init_info():
    logger.info(
        'Monkey Island Server is running. Listening on the following URLs: {}'.format(
            ", ".join(["https://{}:{}".format(x, env.get_island_port()) for x in local_ip_addresses()])
        )
    )
    MonkeyDownload.log_executable_hashes()
Example #5
0
def run_local_monkey():
    import platform
    import subprocess
    import stat

    # get the monkey executable suitable to run on the server
    result = get_monkey_executable(platform.system().lower(), platform.machine().lower())
    if not result:
        return False, "OS Type not found"

    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:
        copyfile(monkey_path, target_path)
        os.chmod(target_path, stat.S_IRWXU | stat.S_IRWXG)
    except Exception as exc:
        logger.error('Copy file failed', exc_info=True)
        return False, "Copy file failed: %s" % exc

    # run the monkey
    try:
        args = ['"%s" m0nk3y -s %s:%s' % (target_path, local_ip_addresses()[0], env.get_island_port())]
        if sys.platform == "win32":
            args = "".join(args)
        pid = subprocess.Popen(args, shell=True).pid
    except Exception as exc:
        logger.error('popen failed', exc_info=True)
        return False, "popen failed: %s" % exc

    return True, "pis: %s" % pid