Fix or noqa some python linter errors
Also, replace os.path with Path
This commit is contained in:
parent
d9dbb6fcfa
commit
910e8355f9
|
@ -91,16 +91,14 @@ class MonkeyIslandRequests(object):
|
||||||
return requests.patch(self.addr + url, # noqa: DUO123
|
return requests.patch(self.addr + url, # noqa: DUO123
|
||||||
data=data,
|
data=data,
|
||||||
headers=self.get_jwt_header(),
|
headers=self.get_jwt_header(),
|
||||||
verify=False
|
verify=False)
|
||||||
)
|
|
||||||
|
|
||||||
@_Decorators.refresh_jwt_token
|
@_Decorators.refresh_jwt_token
|
||||||
def delete(self, url):
|
def delete(self, url):
|
||||||
return requests.delete( # noqa: DOU123
|
return requests.delete( # noqa: DOU123
|
||||||
self.addr + url,
|
self.addr + url,
|
||||||
headers=self.get_jwt_header(),
|
headers=self.get_jwt_header(),
|
||||||
verify=False
|
verify=False)
|
||||||
)
|
|
||||||
|
|
||||||
@_Decorators.refresh_jwt_token
|
@_Decorators.refresh_jwt_token
|
||||||
def get_jwt_header(self):
|
def get_jwt_header(self):
|
||||||
|
|
|
@ -28,7 +28,7 @@ class NetworkRange(object, metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
base_range = self.get_range()
|
base_range = self.get_range()
|
||||||
if self._shuffle:
|
if self._shuffle:
|
||||||
random.shuffle(base_range)
|
random.shuffle(base_range) # noqa: DUO102
|
||||||
|
|
||||||
for x in base_range:
|
for x in base_range:
|
||||||
yield self._number_to_ip(x)
|
yield self._number_to_ip(x)
|
||||||
|
|
|
@ -89,7 +89,7 @@ class InfectionMonkey(object):
|
||||||
if self._opts.depth is not None:
|
if self._opts.depth is not None:
|
||||||
WormConfiguration._depth_from_commandline = True
|
WormConfiguration._depth_from_commandline = True
|
||||||
WormConfiguration.depth = self._opts.depth
|
WormConfiguration.depth = self._opts.depth
|
||||||
LOG.debug(f"Setting propagation depth from command line")
|
LOG.debug("Setting propagation depth from command line")
|
||||||
LOG.debug(f"Set propagation depth to {WormConfiguration.depth}")
|
LOG.debug(f"Set propagation depth to {WormConfiguration.depth}")
|
||||||
|
|
||||||
self._keep_running = True
|
self._keep_running = True
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from Crypto import Random
|
# PyCrypto is deprecated, but we use pycryptodome, which uses the exact same imports but it maintained
|
||||||
from Crypto.Cipher import AES
|
from Crypto import Random # noqa: DOU133
|
||||||
|
from Crypto.Cipher import AES # noqa: DOU133
|
||||||
|
|
||||||
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from common.cloud.aws.aws_instance import AwsInstance
|
from common.cloud.aws.aws_instance import AwsInstance
|
||||||
from monkey_island.cc.environment import Environment
|
from monkey_island.cc.environment import Environment
|
||||||
from monkey_island.cc.resources.auth.auth_user import User
|
|
||||||
|
|
||||||
__author__ = 'itay.mizeretz'
|
__author__ = 'itay.mizeretz'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
env = None
|
|
||||||
|
|
||||||
import monkey_island.cc.resources.auth.user_store as user_store
|
import monkey_island.cc.resources.auth.user_store as user_store
|
||||||
from monkey_island.cc.environment import (EnvironmentConfig, aws, password,
|
from monkey_island.cc.environment import (EnvironmentConfig, aws, password,
|
||||||
standard, testing)
|
standard, testing)
|
||||||
|
@ -22,6 +20,8 @@ ENV_DICT = {
|
||||||
TESTING: testing.TestingEnvironment
|
TESTING: testing.TestingEnvironment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
env = None
|
||||||
|
|
||||||
|
|
||||||
def set_env(env_type: str, env_config: EnvironmentConfig):
|
def set_env(env_type: str, env_config: EnvironmentConfig):
|
||||||
global env
|
global env
|
||||||
|
|
|
@ -112,4 +112,3 @@ class TestEnvironment(TestCase):
|
||||||
self.assertTrue(method())
|
self.assertTrue(method())
|
||||||
else:
|
else:
|
||||||
self.assertFalse(method())
|
self.assertFalse(method())
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class TestEnvironmentConfig(TestCase):
|
||||||
|
|
||||||
def test_get_server_config_file_path(self):
|
def test_get_server_config_file_path(self):
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
server_file_path = MONKEY_ISLAND_ABS_PATH + "\cc\server_config.json"
|
server_file_path = MONKEY_ISLAND_ABS_PATH + r"\cc\server_config.json"
|
||||||
else:
|
else:
|
||||||
server_file_path = MONKEY_ISLAND_ABS_PATH + "/cc/server_config.json"
|
server_file_path = MONKEY_ISLAND_ABS_PATH + "/cc/server_config.json"
|
||||||
self.assertEqual(EnvironmentConfig.get_config_file_path(), server_file_path)
|
self.assertEqual(EnvironmentConfig.get_config_file_path(), server_file_path)
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import os.path
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
from pathlib import Path
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
MINIMUM_MONGO_DB_VERSION_REQUIRED = "4.2.0"
|
# Add the monkey_island directory to the path, to make sure imports that don't start with "monkey_island." work.
|
||||||
|
MONKEY_ISLAND_DIR_BASE_PATH = str(Path(__file__).parent.parent)
|
||||||
|
if str(MONKEY_ISLAND_DIR_BASE_PATH) not in sys.path:
|
||||||
|
sys.path.insert(0, MONKEY_ISLAND_DIR_BASE_PATH)
|
||||||
|
|
||||||
BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH # noqa: E402
|
||||||
|
from monkey_island.cc.island_logger import json_setup_logging # noqa: E402
|
||||||
if BASE_PATH not in sys.path:
|
|
||||||
sys.path.insert(0, BASE_PATH)
|
|
||||||
|
|
||||||
from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH
|
|
||||||
from monkey_island.cc.island_logger import json_setup_logging
|
|
||||||
|
|
||||||
# This is here in order to catch EVERYTHING, some functions are being called on imports the log init needs to be on top.
|
# This is here in order to catch EVERYTHING, some functions are being called on imports the log init needs to be on top.
|
||||||
json_setup_logging(default_path=os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'island_logger_default_config.json'),
|
json_setup_logging(default_path=Path(MONKEY_ISLAND_ABS_PATH, 'cc', 'island_logger_default_config.json'),
|
||||||
default_level=logging.DEBUG)
|
default_level=logging.DEBUG)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
import monkey_island.cc.environment.environment_singleton as env_singleton # noqa: E402
|
||||||
from common.version import get_version
|
from common.version import get_version # noqa: E402
|
||||||
from monkey_island.cc.app import init_app
|
from monkey_island.cc.app import init_app # noqa: E402
|
||||||
from monkey_island.cc.bootloader_server import BootloaderHttpServer
|
from monkey_island.cc.bootloader_server import BootloaderHttpServer # noqa: E402
|
||||||
from monkey_island.cc.database import get_db_version, is_db_server_up
|
from monkey_island.cc.database import get_db_version, is_db_server_up # noqa: E402
|
||||||
from monkey_island.cc.network_utils import local_ip_addresses
|
from monkey_island.cc.network_utils import local_ip_addresses # noqa: E402
|
||||||
from monkey_island.cc.resources.monkey_download import MonkeyDownload
|
from monkey_island.cc.resources.monkey_download import MonkeyDownload # noqa: E402
|
||||||
from monkey_island.cc.services.reporting.exporter_init import \
|
from monkey_island.cc.services.reporting.exporter_init import populate_exporter_list # noqa: E402
|
||||||
populate_exporter_list
|
from monkey_island.cc.setup import setup # noqa: E402
|
||||||
from monkey_island.cc.setup import setup
|
|
||||||
|
|
||||||
|
MINIMUM_MONGO_DB_VERSION_REQUIRED = "4.2.0"
|
||||||
|
|
||||||
|
|
||||||
def main(should_setup_only=False):
|
def main(should_setup_only=False):
|
||||||
|
@ -54,8 +54,8 @@ def start_island_server(should_setup_only):
|
||||||
populate_exporter_list()
|
populate_exporter_list()
|
||||||
app = init_app(mongo_url)
|
app = init_app(mongo_url)
|
||||||
|
|
||||||
crt_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.crt')
|
crt_path = str(Path(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.crt'))
|
||||||
key_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.key')
|
key_path = str(Path(MONKEY_ISLAND_ABS_PATH, 'cc', 'server.key'))
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ class Monkey(Document):
|
||||||
try:
|
try:
|
||||||
_ = Monkey.get_single_monkey_by_id(object_id)
|
_ = Monkey.get_single_monkey_by_id(object_id)
|
||||||
return True
|
return True
|
||||||
except:
|
except: # noqa: E722
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -77,7 +77,7 @@ class TestMonkey(IslandTestCase):
|
||||||
self.assertIsNotNone(Monkey.get_single_monkey_by_id(a_monkey.id))
|
self.assertIsNotNone(Monkey.get_single_monkey_by_id(a_monkey.id))
|
||||||
|
|
||||||
# Raise on non-existent monkey
|
# Raise on non-existent monkey
|
||||||
with pytest.raises(MonkeyNotFoundError) as e_info:
|
with pytest.raises(MonkeyNotFoundError) as _:
|
||||||
_ = Monkey.get_single_monkey_by_id("abcdefabcdefabcdefabcdef")
|
_ = Monkey.get_single_monkey_by_id("abcdefabcdefabcdefabcdef")
|
||||||
|
|
||||||
def test_get_os(self):
|
def test_get_os(self):
|
||||||
|
|
|
@ -15,5 +15,5 @@ class IslandLog(flask_restful.Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
try:
|
try:
|
||||||
return IslandLogService.get_log_file()
|
return IslandLogService.get_log_file()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error('Monkey Island logs failed to download', exc_info=True)
|
logger.error('Monkey Island logs failed to download', exc_info=True)
|
||||||
|
|
|
@ -217,7 +217,8 @@ class ConfigService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_server_ips_in_config(config):
|
def set_server_ips_in_config(config):
|
||||||
ips = local_ip_addresses()
|
ips = local_ip_addresses()
|
||||||
config["internal"]["island_server"]["command_servers"] = ["%s:%d" % (ip, env_singleton.env.get_island_port()) for ip in ips]
|
config["internal"]["island_server"]["command_servers"] = \
|
||||||
|
["%s:%d" % (ip, env_singleton.env.get_islaned_port()) for ip in ips]
|
||||||
config["internal"]["island_server"]["current_server"] = "%s:%d" % (ips[0], env_singleton.env.get_island_port())
|
config["internal"]["island_server"]["current_server"] = "%s:%d" % (ips[0], env_singleton.env.get_island_port())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
from monkey_island.cc.models.edge import Edge
|
|
||||||
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
|
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
|
||||||
from monkey_island.cc.services.edge.edge import RIGHT_ARROW, EdgeService
|
from monkey_island.cc.services.edge.edge import RIGHT_ARROW, EdgeService
|
||||||
from monkey_island.cc.testing.IslandTestCase import IslandTestCase
|
from monkey_island.cc.testing.IslandTestCase import IslandTestCase
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
from monkey_island.cc.models import Monkey
|
from monkey_island.cc.models import Monkey
|
||||||
from monkey_island.cc.models.edge import Edge
|
|
||||||
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
|
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
|
||||||
from monkey_island.cc.services.edge.edge import EdgeService
|
from monkey_island.cc.services.edge.edge import EdgeService
|
||||||
from monkey_island.cc.services.node import NodeService
|
from monkey_island.cc.services.node import NodeService
|
||||||
|
|
|
@ -3,13 +3,11 @@ from datetime import datetime, timedelta
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
from mongoengine import DoesNotExist
|
|
||||||
|
|
||||||
import monkey_island.cc.services.log
|
import monkey_island.cc.services.log
|
||||||
from monkey_island.cc import models
|
from monkey_island.cc import models
|
||||||
from monkey_island.cc.database import mongo
|
from monkey_island.cc.database import mongo
|
||||||
from monkey_island.cc.models import Monkey
|
from monkey_island.cc.models import Monkey
|
||||||
from monkey_island.cc.models.edge import Edge
|
|
||||||
from monkey_island.cc.network_utils import is_local_ips, local_ip_addresses
|
from monkey_island.cc.network_utils import is_local_ips, local_ip_addresses
|
||||||
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
|
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
|
||||||
from monkey_island.cc.services.edge.edge import EdgeService
|
from monkey_island.cc.services.edge.edge import EdgeService
|
||||||
|
|
|
@ -299,7 +299,7 @@ class AWSExporter(Exporter):
|
||||||
title="Machines are accessible using passwords supplied by the user during the Monkey's configuration.",
|
title="Machines are accessible using passwords supplied by the user during the Monkey's configuration.",
|
||||||
description="Change {0}'s password to a complex one-use password that is not shared with other computers on the "
|
description="Change {0}'s password to a complex one-use password that is not shared with other computers on the "
|
||||||
"network.",
|
"network.",
|
||||||
recommendation="The machine machine ({ip_address}) is vulnerable to a WMI attack. The Monkey authenticated over "
|
recommendation="The machine {machine} ({ip_address}) is vulnerable to a WMI attack. The Monkey authenticated over "
|
||||||
"the WMI protocol with user {username} and its password.".format(
|
"the WMI protocol with user {username} and its password.".format(
|
||||||
machine=issue['machine'],
|
machine=issue['machine'],
|
||||||
ip_address=issue['ip_address'],
|
ip_address=issue['ip_address'],
|
||||||
|
@ -316,7 +316,7 @@ class AWSExporter(Exporter):
|
||||||
title="Machines are accessible using passwords supplied by the user during the Monkey's configuration.",
|
title="Machines are accessible using passwords supplied by the user during the Monkey's configuration.",
|
||||||
description="Change {0}'s password to a complex one-use password that is not shared with other computers on the "
|
description="Change {0}'s password to a complex one-use password that is not shared with other computers on the "
|
||||||
"network.".format(issue['username']),
|
"network.".format(issue['username']),
|
||||||
recommendation="The machine machine ({ip_address}) is vulnerable to a WMI attack. The Monkey used a "
|
recommendation="The machine {machine} ({ip_address}) is vulnerable to a WMI attack. The Monkey used a "
|
||||||
"pass-the-hash attack over WMI protocol with user {username}".format(
|
"pass-the-hash attack over WMI protocol with user {username}".format(
|
||||||
machine=issue['machine'],
|
machine=issue['machine'],
|
||||||
ip_address=issue['ip_address'],
|
ip_address=issue['ip_address'],
|
||||||
|
|
|
@ -4,7 +4,6 @@ import dateutil
|
||||||
|
|
||||||
from monkey_island.cc.encryptor import encryptor
|
from monkey_island.cc.encryptor import encryptor
|
||||||
from monkey_island.cc.models import Monkey
|
from monkey_island.cc.models import Monkey
|
||||||
from monkey_island.cc.models.edge import Edge
|
|
||||||
from monkey_island.cc.services.edge.displayed_edge import EdgeService
|
from monkey_island.cc.services.edge.displayed_edge import EdgeService
|
||||||
from monkey_island.cc.services.node import NodeService
|
from monkey_island.cc.services.node import NodeService
|
||||||
from monkey_island.cc.services.telemetry.processing.utils import \
|
from monkey_island.cc.services.telemetry.processing.utils import \
|
||||||
|
|
|
@ -7,7 +7,7 @@ for more details.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from Crypto.Hash import SHA3_512
|
from Crypto.Hash import SHA3_512 # noqa: DUO133
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue