internet check now uses https instead of icmp

This commit is contained in:
itay 2019-04-22 18:22:51 +03:00
parent e256ad3ee5
commit 91b459f286
2 changed files with 16 additions and 7 deletions

View File

@ -9,7 +9,7 @@ from requests.exceptions import ConnectionError
import infection_monkey.monkeyfs as monkeyfs import infection_monkey.monkeyfs as monkeyfs
import infection_monkey.tunnel as tunnel import infection_monkey.tunnel as tunnel
from infection_monkey.config import WormConfiguration, GUID from infection_monkey.config import WormConfiguration, GUID
from infection_monkey.network.info import local_ips, check_internet_access from infection_monkey.network.info import local_ips, check_internet_access, TIMEOUT
from infection_monkey.transport.http import HTTPConnectProxy from infection_monkey.transport.http import HTTPConnectProxy
from infection_monkey.transport.tcp import TcpProxy from infection_monkey.transport.tcp import TcpProxy
@ -19,9 +19,6 @@ requests.packages.urllib3.disable_warnings()
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
DOWNLOAD_CHUNK = 1024 DOWNLOAD_CHUNK = 1024
# random number greater than 5,
# to prevent the monkey from just waiting forever to try and connect to an island before going elsewhere.
TIMEOUT = 15
class ControlClient(object): class ControlClient(object):

View File

@ -8,6 +8,10 @@ import itertools
import netifaces import netifaces
from subprocess import check_output from subprocess import check_output
from random import randint from random import randint
import requests
from requests import ConnectionError
from common.network.network_range import CidrRange from common.network.network_range import CidrRange
try: try:
@ -16,6 +20,10 @@ except NameError:
long = int # Python 3 long = int # Python 3
# Timeout for monkey connections
TIMEOUT = 15
def get_host_subnets(): def get_host_subnets():
""" """
Returns a list of subnets visible to host (omitting loopback and auto conf networks) Returns a list of subnets visible to host (omitting loopback and auto conf networks)
@ -124,14 +132,18 @@ def get_free_tcp_port(min_range=1000, max_range=65535):
def check_internet_access(services): def check_internet_access(services):
""" """
Checks if any of the services are accessible, over ICMP Checks if any of the services are accessible, over HTTPS
:param services: List of IPs/hostnames :param services: List of IPs/hostnames
:return: boolean depending on internet access :return: boolean depending on internet access
""" """
ping_str = "-n 1" if sys.platform.startswith("win") else "-c 1"
for host in services: for host in services:
if os.system("ping " + ping_str + " " + host) == 0: try:
requests.get("https://%s" % (host,), timeout=TIMEOUT)
return True return True
except ConnectionError:
# Failed connecting
pass
return False return False