From 678db40e254515a8bb6d22359e3de99b78fdf99a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 27 Jan 2022 12:56:40 -0500 Subject: [PATCH] Agent: Check for spaces in IP or domain names socket.gethostbyname() may return different results on different systems when provided with an IP address that contains a space. This depends on python version or other environmental factors. For example: System 1: >>> socket.gethostbyname('172.60 .9.109') Traceback (most recent call last): File "", line 1, in socket.gaierror: [Errno -2] Name or service not known >>> socket.gethostbyname('172.17 .9.109') Traceback (most recent call last): File "", line 1, in socket.gaierror: [Errno -2] Name or service not known System 2: >>> socket.gethostbyname('172.60 .9.109') '172.0.0.60' To remedy this, this commit adds a check to verify that the IP/domain does not contain a space, as a space is an illegal character in either. --- monkey/common/network/network_range.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monkey/common/network/network_range.py b/monkey/common/network/network_range.py index 326e365ce..63c7feba5 100644 --- a/monkey/common/network/network_range.py +++ b/monkey/common/network/network_range.py @@ -192,6 +192,9 @@ class SingleIpRange(NetworkRange): # The most common use case is to enter ip/range into "Scan IP/subnet list" domain_name = None + if " " in string_: + raise ValueError(f'"{string_}" is not a valid IP address or domain name.') + # Try casting user's input as IP try: ip = ipaddress.ip_address(string_).exploded