From 347833d6199671b480a3fbf869e91cfe4d2695a2 Mon Sep 17 00:00:00 2001 From: itsikkes Date: Fri, 27 May 2016 01:06:56 +0300 Subject: [PATCH] add tunnels visualization tunnel information is sent to island and appears on the map: blue - tunnel, red - expolit --- chaos_monkey/monkey.py | 1 + monkey_island/cc/admin/ui/js/monkeys-admin.js | 27 +++++++++++++++---- monkey_island/cc/main.py | 12 +++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/chaos_monkey/monkey.py b/chaos_monkey/monkey.py index 020097c64..c4f2a6f09 100644 --- a/chaos_monkey/monkey.py +++ b/chaos_monkey/monkey.py @@ -75,6 +75,7 @@ class ChaosMonkey(object): self._default_server = WormConfiguration.current_server LOG.debug("default server: %s" % self._default_server) + ControlClient.send_telemetry("tunnel", ControlClient.proxies.get('https')) if WormConfiguration.collect_system_info: LOG.debug("Calling system info collection") diff --git a/monkey_island/cc/admin/ui/js/monkeys-admin.js b/monkey_island/cc/admin/ui/js/monkeys-admin.js index 8867f064d..e0eb46a07 100644 --- a/monkey_island/cc/admin/ui/js/monkeys-admin.js +++ b/monkey_island/cc/admin/ui/js/monkeys-admin.js @@ -42,9 +42,11 @@ function initAdmin() { nodes = []; edges = []; + createEdges(); + createTunnels(); var data = { nodes: createNodes(), - edges: createEdges() + edges: edges }; var options = { @@ -119,7 +121,9 @@ function updateMonkeys() { if(new_monkeys.length > 0) { - network.setData({nodes: nodes, edges: createEdges()}); + createEdges(); + createTunnels(); + network.setData({nodes: nodes, edges: edges}); } window.setTimeout(updateMonkeys, 10000); @@ -173,7 +177,7 @@ function createEdges() { parent = getMonkeyByGuid(monkey.parent); if(parent && !edgeExists([parent.id, monkey.id])) { - edges.push({from: parent.id, to: monkey.id, arrows:'middle'}); + edges.push({from: parent.id, to: monkey.id, arrows:'middle', color: 'red'}); } } } @@ -181,6 +185,20 @@ function createEdges() { return edges; } +function createTunnels() { + for (var i = 0; i < monkeys.length; i++) { + var monkey = monkeys[i]; + if(monkey.tunnel_guid) { + tunnel = getMonkeyByGuid(monkey.tunnel_guid); + + if(tunnel && !edgeExists([monkey.id, tunnel.id])) { + edges.push({from: monkey.id, to: tunnel.id, arrows:'middle', color:'blue'}); + } + } + } + + return edges; +} /** * Builds node description @@ -510,8 +528,7 @@ function edgeExists(link) { for (var i = 0; i < edges.length; i++) { var from = edges[i].from; var to = edges[i].to; - if ((from == link[0] && to == link[1]) || - (from == link[1] && to == link[0])) { + if (from == link[0] && to == link[1]) { return true; } } diff --git a/monkey_island/cc/main.py b/monkey_island/cc/main.py index ee9a79d83..f11f4552a 100644 --- a/monkey_island/cc/main.py +++ b/monkey_island/cc/main.py @@ -151,6 +151,18 @@ class Telemetry(restful.Resource): if 1 == len(update_parent): update_parent[0]['parent'] = telemetry_json['monkey_guid'] mongo.db.monkey.update({"guid": update_parent[0]['guid']}, {"$set": update_parent[0]}, upsert=False) + elif telemetry_json.get('telem_type') == 'tunnel': + if telemetry_json['data']: + host = telemetry_json['data'].split(":")[-2].replace("//", "") + tunnel_host = mongo.db.monkey.find_one({"ip_addresses": host}) + mongo.db.monkey.update({"guid": telemetry_json['monkey_guid']}, + {'$set': {'tunnel_guid': tunnel_host.get('guid')}}, + upsert=True) + else: + mongo.db.monkey.update({"guid": telemetry_json['monkey_guid']}, + {'$unset': {'tunnel_guid':''}}, + upsert=True) + except: pass