From 84496dd3f5b8ccb8e65db132b8c16f1c40b14535 Mon Sep 17 00:00:00 2001 From: itsikkes Date: Tue, 28 Jun 2016 11:13:24 +0300 Subject: [PATCH] Added internet access check Shown in the monkey properties in the island --- chaos_monkey/config.py | 2 ++ chaos_monkey/control.py | 3 ++- chaos_monkey/network/info.py | 8 ++++++++ monkey_island/cc/admin/ui/js/monkeys-admin.js | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/chaos_monkey/config.py b/chaos_monkey/config.py index 2913e4da7..ff53da35b 100644 --- a/chaos_monkey/config.py +++ b/chaos_monkey/config.py @@ -137,6 +137,8 @@ class Configuration(object): retry_failed_explotation = True + internet_services = ["www.guardicore.com", "www.google.com"] + ########################### # scanners config ########################### diff --git a/chaos_monkey/control.py b/chaos_monkey/control.py index 58328b274..c2939ec95 100644 --- a/chaos_monkey/control.py +++ b/chaos_monkey/control.py @@ -3,7 +3,7 @@ import logging import requests import platform import monkeyfs -from network.info import local_ips +from network.info import local_ips, check_internet_access from socket import gethostname from config import WormConfiguration, GUID from transport.tcp import TcpProxy @@ -38,6 +38,7 @@ class ControlClient(object): 'hostname': hostname, 'ip_addresses': local_ips(), 'description': " ".join(platform.uname()), + 'internet_access': check_internet_access(WormConfiguration.internet_services), 'config': WormConfiguration.as_dict(), 'parent': parent} diff --git a/chaos_monkey/network/info.py b/chaos_monkey/network/info.py index 7de568b48..09c484605 100644 --- a/chaos_monkey/network/info.py +++ b/chaos_monkey/network/info.py @@ -1,3 +1,4 @@ +import os import sys import socket import struct @@ -58,3 +59,10 @@ def get_free_tcp_port(min_range=1000, max_range=65535): return port return None + +def check_internet_access(services): + ping_str = "-n 1" if sys.platform.startswith("win") else "-c 1" + for host in services: + if os.system("ping " + ping_str + " " + host) == 0: + return True + return False diff --git a/monkey_island/cc/admin/ui/js/monkeys-admin.js b/monkey_island/cc/admin/ui/js/monkeys-admin.js index 3cc3db334..baf3c81ed 100644 --- a/monkey_island/cc/admin/ui/js/monkeys-admin.js +++ b/monkey_island/cc/admin/ui/js/monkeys-admin.js @@ -269,6 +269,7 @@ function buildMonkeyDescription(monkey) { var html = " " + monkey.hostname + "
" + " " + monkey.description + "
" + + " " + monkey.internet_access + "
" + "
" for (var i = 0; i < monkey.ip_addresses.length; i++) {