diff --git a/monkey/common/cloud/aws_instance.py b/monkey/common/cloud/aws_instance.py index 40d7c622c..e7d1b2361 100644 --- a/monkey/common/cloud/aws_instance.py +++ b/monkey/common/cloud/aws_instance.py @@ -1,6 +1,7 @@ import json import re -import urllib2 +import urllib.request +import urllib.error import logging @@ -25,18 +26,18 @@ class AwsInstance(object): self.account_id = None try: - self.instance_id = urllib2.urlopen( + self.instance_id = urllib.request.urlopen( AWS_LATEST_METADATA_URI_PREFIX + 'meta-data/instance-id', timeout=2).read() self.region = self._parse_region( - urllib2.urlopen(AWS_LATEST_METADATA_URI_PREFIX + 'meta-data/placement/availability-zone').read()) - except urllib2.URLError as e: - logger.debug("Failed init of AwsInstance while getting metadata: {}".format(e.message)) + urllib.request.urlopen(AWS_LATEST_METADATA_URI_PREFIX + 'meta-data/placement/availability-zone').read()) + except urllib.error.URLError as e: + logger.debug("Failed init of AwsInstance while getting metadata: {}".format(e)) try: self.account_id = self._extract_account_id( - urllib2.urlopen( + urllib.request.urlopen( AWS_LATEST_METADATA_URI_PREFIX + 'dynamic/instance-identity/document', timeout=2).read()) - except urllib2.URLError as e: + except urllib.error.URLError as e: logger.debug("Failed init of AwsInstance while getting dynamic instance data: {}".format(e)) @staticmethod diff --git a/monkey/infection_monkey/model/victim_host_generator_test.py b/monkey/infection_monkey/model/victim_host_generator_test.py index 102014d45..3a159f245 100644 --- a/monkey/infection_monkey/model/victim_host_generator_test.py +++ b/monkey/infection_monkey/model/victim_host_generator_test.py @@ -17,8 +17,8 @@ class VictimHostGeneratorTester(TestCase): generator = VictimHostGenerator(test_ranges, '10.0.0.1', []) victims = generator.generate_victims(chunk_size) for i in range(5): # quickly check the equally sided chunks - self.assertEqual(len(victims.next()), chunk_size) - victim_chunk_last = victims.next() + self.assertEqual(len(next(victims)), chunk_size) + victim_chunk_last = next(victims) self.assertEqual(len(victim_chunk_last), 1) def test_remove_blocked_ip(self): diff --git a/monkey/infection_monkey/network/network_scanner.py b/monkey/infection_monkey/network/network_scanner.py index 1a3d615a5..50fd21b4d 100644 --- a/monkey/infection_monkey/network/network_scanner.py +++ b/monkey/infection_monkey/network/network_scanner.py @@ -85,7 +85,7 @@ class NetworkScanner(object): return results = pool.map(self.scan_machine, victim_chunk) - resulting_victims = filter(lambda x: x is not None, results) + resulting_victims = [x for x in results if x is not None] for victim in resulting_victims: LOG.debug("Found potential victim: %r", victim) victims_count += 1 diff --git a/monkey/infection_monkey/transport/http.py b/monkey/infection_monkey/transport/http.py index 6610e082d..eb1e5d355 100644 --- a/monkey/infection_monkey/transport/http.py +++ b/monkey/infection_monkey/transport/http.py @@ -3,7 +3,7 @@ import os.path import select import socket import threading -import urllib.request, urllib.parse, urllib.error +import urllib from logging import getLogger from urllib.parse import urlsplit diff --git a/monkey/infection_monkey/utils/auto_new_user.py b/monkey/infection_monkey/utils/auto_new_user.py index e749020d6..0a34d93c0 100644 --- a/monkey/infection_monkey/utils/auto_new_user.py +++ b/monkey/infection_monkey/utils/auto_new_user.py @@ -4,7 +4,7 @@ import abc logger = logging.getLogger(__name__) -class AutoNewUser: +class AutoNewUser(metaclass=abc.ABCMeta): """ RAII object to use for creating and using a new user. Use with `with`. User will be created when the instance is instantiated. @@ -19,7 +19,6 @@ class AutoNewUser: # Logged off and deleted ... """ - __metaclass__ = abc.ABCMeta def __init__(self, username, password): self.username = username diff --git a/monkey/monkey_island/requirements.txt b/monkey/monkey_island/requirements.txt index ee66bb797..49c1e37a5 100644 --- a/monkey/monkey_island/requirements.txt +++ b/monkey/monkey_island/requirements.txt @@ -1,6 +1,6 @@ bson python-dateutil -tornado==5.1.1 +tornado werkzeug jinja2 markupsafe @@ -10,10 +10,9 @@ flask Flask-Pymongo Flask-Restful Flask-JWT -jsonschema==2.6.0 +jsonschema netifaces ipaddress -enum34 pycryptodome boto3 botocore