forked from p15670423/monkey
commit
6c28ff058a
|
@ -0,0 +1,12 @@
|
|||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
def get_host_from_network_location(network_location: str) -> str:
|
||||
"""
|
||||
URL structure is "<scheme>://<net_loc>/<path>;<params>?<query>#<fragment>" (https://tools.ietf.org/html/rfc1808.html)
|
||||
And the net_loc is "<user>:<password>@<host>:<port>" (https://tools.ietf.org/html/rfc1738#section-3.1)
|
||||
:param network_location: server network location
|
||||
:return: host part of the network location
|
||||
"""
|
||||
url = urlparse("http://" + network_location)
|
||||
return str(url.hostname)
|
|
@ -0,0 +1,12 @@
|
|||
from unittest import TestCase
|
||||
|
||||
from common.network.network_utils import get_host_from_network_location
|
||||
|
||||
|
||||
class TestNetworkUtils(TestCase):
|
||||
def test_remove_port_from_ip_string(self):
|
||||
assert get_host_from_network_location("127.0.0.1:12345") == "127.0.0.1"
|
||||
assert get_host_from_network_location("127.0.0.1:12345") == "127.0.0.1"
|
||||
assert get_host_from_network_location("127.0.0.1") == "127.0.0.1"
|
||||
assert get_host_from_network_location("www.google.com:8080") == "www.google.com"
|
||||
assert get_host_from_network_location("user:password@host:8080") == "host"
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
|||
|
||||
MAJOR = "1"
|
||||
MINOR = "8"
|
||||
PATCH = "1"
|
||||
PATCH = "2"
|
||||
build_file_path = Path(__file__).parent.joinpath("BUILD")
|
||||
with open(build_file_path, "r") as build_file:
|
||||
BUILD = build_file.read()
|
||||
|
|
|
@ -33,7 +33,7 @@ from infection_monkey.telemetry.attack.t1106_telem import T1106Telem
|
|||
from common.utils.attack_utils import ScanStatus, UsageEnum
|
||||
from common.version import get_version
|
||||
from infection_monkey.exploit.HostExploiter import HostExploiter
|
||||
from monkey_island.cc.network_utils import remove_port_from_ip_string
|
||||
from common.network.network_utils import get_host_from_network_location
|
||||
|
||||
MAX_DEPTH_REACHED_MESSAGE = "Reached max depth, shutting down"
|
||||
|
||||
|
@ -386,7 +386,7 @@ class InfectionMonkey(object):
|
|||
LOG.debug("default server set to: %s" % self._default_server)
|
||||
|
||||
def is_started_on_island(self):
|
||||
island_ip = remove_port_from_ip_string(self._default_server)
|
||||
island_ip = get_host_from_network_location(self._default_server)
|
||||
return is_running_on_server(island_ip) and WormConfiguration.depth == WormConfiguration.max_depth
|
||||
|
||||
def log_arguments(self):
|
||||
|
|
|
@ -5,7 +5,6 @@ import socket
|
|||
import struct
|
||||
import sys
|
||||
from typing import List
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from netifaces import interfaces, ifaddresses, AF_INET
|
||||
from ring import lru
|
||||
|
@ -86,8 +85,3 @@ def get_subnets():
|
|||
]
|
||||
)
|
||||
return subnets
|
||||
|
||||
|
||||
def remove_port_from_ip_string(ip_string: str) -> str:
|
||||
url = urlparse("http://" + ip_string)
|
||||
return str(url.hostname)
|
||||
|
|
Loading…
Reference in New Issue