forked from p34709852/monkey
internet check now uses https instead of icmp
This commit is contained in:
parent
e256ad3ee5
commit
91b459f286
|
@ -9,7 +9,7 @@ from requests.exceptions import ConnectionError
|
|||
import infection_monkey.monkeyfs as monkeyfs
|
||||
import infection_monkey.tunnel as tunnel
|
||||
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.tcp import TcpProxy
|
||||
|
||||
|
@ -19,9 +19,6 @@ requests.packages.urllib3.disable_warnings()
|
|||
|
||||
LOG = logging.getLogger(__name__)
|
||||
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):
|
||||
|
|
|
@ -8,6 +8,10 @@ import itertools
|
|||
import netifaces
|
||||
from subprocess import check_output
|
||||
from random import randint
|
||||
|
||||
import requests
|
||||
from requests import ConnectionError
|
||||
|
||||
from common.network.network_range import CidrRange
|
||||
|
||||
try:
|
||||
|
@ -16,6 +20,10 @@ except NameError:
|
|||
long = int # Python 3
|
||||
|
||||
|
||||
# Timeout for monkey connections
|
||||
TIMEOUT = 15
|
||||
|
||||
|
||||
def get_host_subnets():
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
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
|
||||
:return: boolean depending on internet access
|
||||
"""
|
||||
ping_str = "-n 1" if sys.platform.startswith("win") else "-c 1"
|
||||
for host in services:
|
||||
if os.system("ping " + ping_str + " " + host) == 0:
|
||||
try:
|
||||
requests.get("https://%s" % (host,), timeout=TIMEOUT)
|
||||
return True
|
||||
except ConnectionError:
|
||||
# Failed connecting
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue