From f60cdd116b49f9dc3b88e2db578c163905bdd621 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 18 Oct 2019 09:10:14 +0300 Subject: [PATCH] Replaced six package usages with py3 --- monkey/common/network/network_range.py | 3 +-- monkey/infection_monkey/network/tools.py | 2 -- monkey/monkey_island/cc/services/config.py | 5 ++--- monkey/monkey_island/cc/services/reporting/report.py | 11 +++++------ .../telemetry/zero_trust_tests/segmentation.py | 6 ++---- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/monkey/common/network/network_range.py b/monkey/common/network/network_range.py index 21a1fa83b..7393ceda2 100644 --- a/monkey/common/network/network_range.py +++ b/monkey/common/network/network_range.py @@ -4,7 +4,6 @@ import struct from abc import ABCMeta, abstractmethod import ipaddress -from six import text_type import logging __author__ = 'itamar' @@ -78,7 +77,7 @@ class CidrRange(NetworkRange): def __init__(self, cidr_range, shuffle=True): super(CidrRange, self).__init__(shuffle=shuffle) self._cidr_range = cidr_range.strip() - self._ip_network = ipaddress.ip_network(text_type(self._cidr_range), strict=False) + self._ip_network = ipaddress.ip_network(str(self._cidr_range), strict=False) def __repr__(self): return "" % (self._cidr_range,) diff --git a/monkey/infection_monkey/network/tools.py b/monkey/infection_monkey/network/tools.py index 8fcc2892e..075babb60 100644 --- a/monkey/infection_monkey/network/tools.py +++ b/monkey/infection_monkey/network/tools.py @@ -7,8 +7,6 @@ import struct import time import re -from six.moves import range - from infection_monkey.pyinstaller_utils import get_binary_file_path from infection_monkey.utils.environment import is_64bit_python diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index a6759b15b..2d38b6498 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -3,7 +3,6 @@ import collections import functools import logging from jsonschema import Draft4Validator, validators -from six import string_types import monkey_island.cc.services.post_breach_files from monkey_island.cc.database import mongo @@ -236,7 +235,7 @@ class ConfigService: keys = [config_arr_as_array[2] for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS] for key in keys: - if isinstance(flat_config[key], collections.Sequence) and not isinstance(flat_config[key], string_types): + if isinstance(flat_config[key], collections.Sequence) and not isinstance(flat_config[key], str): # Check if we are decrypting ssh key pair if flat_config[key] and isinstance(flat_config[key][0], dict) and 'public_key' in flat_config[key][0]: flat_config[key] = [ConfigService.decrypt_ssh_key_pair(item) for item in flat_config[key]] @@ -257,7 +256,7 @@ class ConfigService: parent_config_arr = config_arr config_arr = config_arr[config_key_part] - if isinstance(config_arr, collections.Sequence) and not isinstance(config_arr, string_types): + if isinstance(config_arr, collections.Sequence) and not isinstance(config_arr, str): for i in range(len(config_arr)): # Check if array of shh key pairs and then decrypt if isinstance(config_arr[i], dict) and 'public_key' in config_arr[i]: diff --git a/monkey/monkey_island/cc/services/reporting/report.py b/monkey/monkey_island/cc/services/reporting/report.py index 0d2b6858d..01be940c4 100644 --- a/monkey/monkey_island/cc/services/reporting/report.py +++ b/monkey/monkey_island/cc/services/reporting/report.py @@ -5,7 +5,6 @@ import logging import ipaddress from bson import json_util from enum import Enum -from six import text_type from common.network.network_range import NetworkRange from common.network.segmentation_utils import get_ip_in_src_and_not_in_dst @@ -396,7 +395,7 @@ class ReportService: return \ [ - ipaddress.ip_interface(text_type(network['addr'] + '/' + network['netmask'])).network + ipaddress.ip_interface(str(network['addr'] + '/' + network['netmask'])).network for network in network_info['data']['network_info']['networks'] ] @@ -409,7 +408,7 @@ class ReportService: monkey_subnets = ReportService.get_monkey_subnets(monkey['guid']) for subnet in monkey_subnets: for ip in island_ips: - if ipaddress.ip_address(text_type(ip)) in subnet: + if ipaddress.ip_address(str(ip)) in subnet: found_good_ip = True break if found_good_ip: @@ -438,7 +437,7 @@ class ReportService: ip_in_src = None ip_in_dst = None for ip_addr in monkey['ip_addresses']: - if source_subnet_range.is_in_range(text_type(ip_addr)): + if source_subnet_range.is_in_range(str(ip_addr)): ip_in_src = ip_addr break @@ -447,7 +446,7 @@ class ReportService: continue for ip_addr in monkey['ip_addresses']: - if target_subnet_range.is_in_range(text_type(ip_addr)): + if target_subnet_range.is_in_range(str(ip_addr)): ip_in_dst = ip_addr break @@ -483,7 +482,7 @@ class ReportService: scans.rewind() # If we iterated over scans already we need to rewind. for scan in scans: target_ip = scan['data']['machine']['ip_addr'] - if target_subnet_range.is_in_range(text_type(target_ip)): + if target_subnet_range.is_in_range(str(target_ip)): monkey = NodeService.get_monkey_by_guid(scan['monkey_guid']) cross_segment_ip = get_ip_in_src_and_not_in_dst(monkey['ip_addresses'], source_subnet_range, diff --git a/monkey/monkey_island/cc/services/telemetry/zero_trust_tests/segmentation.py b/monkey/monkey_island/cc/services/telemetry/zero_trust_tests/segmentation.py index 50e60e493..b4efd3c3a 100644 --- a/monkey/monkey_island/cc/services/telemetry/zero_trust_tests/segmentation.py +++ b/monkey/monkey_island/cc/services/telemetry/zero_trust_tests/segmentation.py @@ -1,5 +1,4 @@ import itertools -from six import text_type from common.data.zero_trust_consts import STATUS_FAILED, EVENT_TYPE_MONKEY_NETWORK, STATUS_PASSED from common.network.network_range import NetworkRange @@ -34,8 +33,7 @@ def test_segmentation_violation(current_monkey, target_ip): ) -def is_segmentation_violation(current_monkey, target_ip, source_subnet, target_subnet): - # type: (Monkey, str, str, str) -> bool +def is_segmentation_violation(current_monkey: Monkey, target_ip: str, source_subnet: str, target_subnet: str) -> bool: """ Checks is a specific communication is a segmentation violation. :param current_monkey: The source monkey which originated the communication. @@ -49,7 +47,7 @@ def is_segmentation_violation(current_monkey, target_ip, source_subnet, target_s source_subnet_range = NetworkRange.get_range_obj(source_subnet) target_subnet_range = NetworkRange.get_range_obj(target_subnet) - if target_subnet_range.is_in_range(text_type(target_ip)): + if target_subnet_range.is_in_range(str(target_ip)): cross_segment_ip = get_ip_in_src_and_not_in_dst( current_monkey.ip_addresses, source_subnet_range,