From 0411811fe5b3bbc55602c58badd9c85466d5786a Mon Sep 17 00:00:00 2001 From: cclauss Date: Tue, 22 May 2018 10:13:18 +0200 Subject: [PATCH] from six import string_types, text_type, xrange (#128) * from six import string_types, text_type, xrange --- common/network/network_range.py | 3 ++- infection_monkey/monkey.py | 1 + infection_monkey/requirements.txt | 3 ++- monkey_island/cc/services/config.py | 3 ++- monkey_island/cc/services/report.py | 6 ++++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/network/network_range.py b/common/network/network_range.py index 0173b5810..a2142ce0e 100644 --- a/common/network/network_range.py +++ b/common/network/network_range.py @@ -4,6 +4,7 @@ import struct from abc import ABCMeta, abstractmethod import ipaddress +from six import text_type __author__ = 'itamar' @@ -65,7 +66,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(unicode(self._cidr_range), strict=False) + self._ip_network = ipaddress.ip_network(text_type(self._cidr_range), strict=False) def __repr__(self): return "" % (self._cidr_range,) diff --git a/infection_monkey/monkey.py b/infection_monkey/monkey.py index b36569b78..8ad1baf8c 100644 --- a/infection_monkey/monkey.py +++ b/infection_monkey/monkey.py @@ -12,6 +12,7 @@ from control import ControlClient from model import DELAY_DELETE_CMD from network.firewall import app as firewall from network.network_scanner import NetworkScanner +from six.moves import xrange from system_info import SystemInfoCollector from system_singleton import SystemSingleton from windows_upgrader import WindowsUpgrader diff --git a/infection_monkey/requirements.txt b/infection_monkey/requirements.txt index bd7689886..d5c1455dd 100644 --- a/infection_monkey/requirements.txt +++ b/infection_monkey/requirements.txt @@ -10,8 +10,9 @@ odict paramiko psutil==3.4.2 PyInstaller +six ecdsa netifaces mock nose -ipaddress \ No newline at end of file +ipaddress diff --git a/monkey_island/cc/services/config.py b/monkey_island/cc/services/config.py index ebcf2a3ea..2ee29f3e9 100644 --- a/monkey_island/cc/services/config.py +++ b/monkey_island/cc/services/config.py @@ -2,6 +2,7 @@ import copy import collections import functools from jsonschema import Draft4Validator, validators +from six import string_types from cc.database import mongo from cc.encryptor import encryptor @@ -978,7 +979,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], basestring): + if isinstance(flat_config[key], collections.Sequence) and not isinstance(flat_config[key], string_types): flat_config[key] = [encryptor.dec(item) for item in flat_config[key]] else: flat_config[key] = encryptor.dec(flat_config[key]) diff --git a/monkey_island/cc/services/report.py b/monkey_island/cc/services/report.py index f77e96dd9..902664d63 100644 --- a/monkey_island/cc/services/report.py +++ b/monkey_island/cc/services/report.py @@ -1,6 +1,8 @@ import ipaddress from enum import Enum +from six import text_type + from cc.database import mongo from cc.services.config import ConfigService from cc.services.edge import EdgeService @@ -282,7 +284,7 @@ class ReportService: return \ [ - ipaddress.ip_interface(unicode(network['addr'] + '/' + network['netmask'])).network + ipaddress.ip_interface(text_type(network['addr'] + '/' + network['netmask'])).network for network in network_info['data']['network_info']['networks'] ] @@ -295,7 +297,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(unicode(ip)) in subnet: + if ipaddress.ip_address(text_type(ip)) in subnet: found_good_ip = True break if found_good_ip: