def get_monkey_island_monkey(): ip_addresses = local_ip_addresses() for ip_address in ip_addresses: monkey = NodeService.get_monkey_by_ip(ip_address) if monkey is not None: return monkey return None
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())
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) 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()
def get_cross_segment_issues(): issues = [] island_ips = local_ip_addresses() for monkey in mongo.db.monkey.find({'tunnel': { '$exists': False }}, { 'tunnel': 1, 'guid': 1, 'hostname': 1 }): found_good_ip = False monkey_subnets = ReportService.get_monkey_subnets(monkey['guid']) for subnet in monkey_subnets: for ip in island_ips: if ipaddress.ip_address(unicode(ip)) in subnet: found_good_ip = True break if found_good_ip: break if not found_good_ip: issues.append({ 'type': 'cross_segment', 'machine': monkey['hostname'], 'networks': [str(subnet) for subnet in monkey_subnets], 'server_networks': [str(subnet) for subnet in get_subnets()] }) return issues
def get(self, action=None): if not action: action = request.args.get('action') if not action: return jsonify(ip_addresses=local_ip_addresses(), mongo=str(mongo.db), completed_steps=self.get_completed_steps()) elif action == "reset": mongo.db.config.drop() mongo.db.monkey.drop() mongo.db.telemetry.drop() mongo.db.node.drop() mongo.db.edge.drop() ConfigService.init_config() return jsonify(status='OK') elif action == "killall": mongo.db.monkey.update({'dead': False}, { '$set': { 'config.alive': False, 'modifytime': datetime.now() } }, upsert=False, multi=True) return jsonify(status='OK') else: return make_response(400, {'error': 'unknown action'})
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('binaries', result['filename']) target_path = os.path.join(os.getcwd(), 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: return False, "Copy file failed: %s" % exc # run the monkey try: args = [ "%s m0nk3y -s %s:%s" % (target_path, local_ip_addresses()[0], ISLAND_PORT) ] if sys.platform == "win32": args = "".join(args) pid = subprocess.Popen(args, shell=True).pid except Exception as exc: return False, "popen failed: %s" % exc return True, "pis: %s" % pid
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('binaries', result['filename']) target_path = os.path.join(os.getcwd(), 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: return False, "Copy file failed: %s" % exc # run the monkey try: args = ['"%s" m0nk3y -s %s:%s' % (target_path, local_ip_addresses()[0], ISLAND_PORT)] if sys.platform == "win32": args = "".join(args) pid = subprocess.Popen(args, shell=True).pid except Exception as exc: return False, "popen failed: %s" % exc return True, "pis: %s" % pid
def get_monkey_group(monkey): if len(set(monkey["ip_addresses"]).intersection(local_ip_addresses())) != 0: monkey_type = "island_monkey" else: monkey_type = "manual" if NodeService.get_monkey_manual_run(monkey) else "monkey" monkey_os = NodeService.get_monkey_os(monkey) monkey_running = "" if monkey["dead"] else "_running" return "%s_%s%s" % (monkey_type, monkey_os, monkey_running)
def get_cross_segment_issues(): issues = [] island_ips = local_ip_addresses() for monkey in mongo.db.monkey.find({'tunnel': {'$exists': False}}, {'tunnel': 1, 'guid': 1, 'hostname': 1}): found_good_ip = False monkey_subnets = ReportService.get_monkey_subnets(monkey['guid']) for subnet in monkey_subnets: for ip in island_ips: if ipaddress.ip_address(unicode(ip)) in subnet: found_good_ip = True break if found_good_ip: break if not found_good_ip: issues.append( {'type': 'cross_segment', 'machine': monkey['hostname'], 'networks': [str(subnet) for subnet in monkey_subnets], 'server_networks': [str(subnet) for subnet in get_subnets()]} ) return issues
if BASE_PATH not in sys.path: sys.path.insert(0, BASE_PATH) from cc.app import init_app from cc.utils import local_ip_addresses from cc.island_config import DEFAULT_MONGO_URL, ISLAND_PORT, DEBUG_SERVER from cc.database import is_db_server_up if __name__ == '__main__': from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop mongo_url = os.environ.get('MONGO_URL', DEFAULT_MONGO_URL) while not is_db_server_up(mongo_url): print('Waiting for MongoDB server') time.sleep(1) app = init_app(mongo_url) if DEBUG_SERVER: app.run(host='0.0.0.0', debug=True, ssl_context=('server.crt', 'server.key')) else: http_server = HTTPServer(WSGIContainer(app), ssl_options={'certfile': os.environ.get('SERVER_CRT', 'server.crt'), 'keyfile': os.environ.get('SERVER_KEY', 'server.key')}) http_server.listen(ISLAND_PORT) print('Monkey Island C&C Server is running on https://{}:{}'.format(local_ip_addresses()[0], ISLAND_PORT)) IOLoop.instance().start()
def get_monkey_island_node(): island_node = NodeService.get_monkey_island_pseudo_net_node() island_node["ip_addresses"] = local_ip_addresses() island_node["domain_name"] = socket.gethostname() return island_node
from cc.app import init_app from cc.utils import local_ip_addresses from cc.island_config import DEFAULT_MONGO_URL, ISLAND_PORT from cc.database import is_db_server_up if __name__ == '__main__': from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop mongo_url = os.environ.get('MONGO_URL', DEFAULT_MONGO_URL) while not is_db_server_up(mongo_url): print('Waiting for MongoDB server') time.sleep(1) app = init_app(mongo_url) http_server = HTTPServer(WSGIContainer(app), ssl_options={ 'certfile': os.environ.get('SERVER_CRT', 'server.crt'), 'keyfile': os.environ.get('SERVER_KEY', 'server.key') }) http_server.listen(ISLAND_PORT) print('Monkey Island C&C Server is running on https://{}:{}'.format( local_ip_addresses()[0], ISLAND_PORT)) IOLoop.instance().start() # app.run(host='0.0.0.0', debug=True, ssl_context=('server.crt', 'server.key'))
if __name__ == '__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): print('Waiting for MongoDB server') time.sleep(1) app = init_app(mongo_url) if env.is_debug(): app.run(host='0.0.0.0', debug=True, ssl_context=('server.crt', 'server.key')) else: http_server = HTTPServer(WSGIContainer(app), ssl_options={ 'certfile': os.environ.get('SERVER_CRT', 'server.crt'), 'keyfile': os.environ.get('SERVER_KEY', 'server.key') }) http_server.listen(env.get_island_port()) print('Monkey Island Server is running on https://{}:{}'.format( local_ip_addresses()[0], env.get_island_port())) IOLoop.instance().start()
def get_server_info(): return jsonify(ip_addresses=local_ip_addresses(), mongo=str(mongo.db), completed_steps=Root.get_completed_steps())
if BASE_PATH not in sys.path: sys.path.insert(0, BASE_PATH) from cc.app import init_app from cc.utils import local_ip_addresses from cc.environment.environment import env from cc.database import is_db_server_up if __name__ == '__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): print('Waiting for MongoDB server') time.sleep(1) app = init_app(mongo_url) if env.is_debug(): app.run(host='0.0.0.0', debug=True, ssl_context=('server.crt', 'server.key')) else: http_server = HTTPServer(WSGIContainer(app), ssl_options={'certfile': os.environ.get('SERVER_CRT', 'server.crt'), 'keyfile': os.environ.get('SERVER_KEY', 'server.key')}) http_server.listen(env.get_island_port()) print('Monkey Island Server is running on https://{}:{}'.format(local_ip_addresses()[0], env.get_island_port())) IOLoop.instance().start()
def get_monkey_island_node(): island_node = NodeService.get_monkey_island_pseudo_net_node() island_node["ip_addresses"] = local_ip_addresses() return island_node
def get_monkey_label(monkey): label = monkey["hostname"] + " : " + monkey["ip_addresses"][0] ip_addresses = local_ip_addresses() if len(set(monkey["ip_addresses"]).intersection(ip_addresses)) > 0: label = "MonkeyIsland - " + label return label
if BASE_PATH not in sys.path: sys.path.insert(0, BASE_PATH) from cc.app import init_app from cc.utils import local_ip_addresses from cc.environment.environment import env from cc.database import is_db_server_up if __name__ == '__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): print('Waiting for MongoDB server') time.sleep(1) app = init_app(mongo_url) if env.is_debug(): app.run(host='0.0.0.0', debug=True, ssl_context=('server.crt', 'server.key')) else: http_server = HTTPServer(WSGIContainer(app), ssl_options={'certfile': os.environ.get('SERVER_CRT', 'server.crt'), 'keyfile': os.environ.get('SERVER_KEY', 'server.key')}) http_server.listen(env.get_island_port()) print('Monkey Island C&C Server is running on https://{}:{}'.format(local_ip_addresses()[0], env.get_island_port())) IOLoop.instance().start()
def set_server_ips_in_config(config): ips = local_ip_addresses() config["cnc"]["servers"]["command_servers"] = ["%s:%d" % (ip, ISLAND_PORT) for ip in ips] config["cnc"]["servers"]["current_server"] = "%s:%d" % (ips[0], ISLAND_PORT)
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())