Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py import order travis #727

Merged
merged 4 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install:
# Python
- pip freeze
- pip install -r monkey/monkey_island/requirements.txt # for unit tests
- pip install flake8 pytest dlint # for next stages
- pip install flake8 pytest dlint flake8-import-order # for next stages
- pip install coverage # for code coverage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to replace this with isort too

- pip install -r monkey/infection_monkey/requirements.txt # for unit tests
- pip install pipdeptree
Expand Down
9 changes: 5 additions & 4 deletions monkey/common/cloud/aws/aws_instance.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import json
import logging
import re
import urllib.request
import urllib.error
import logging

__author__ = 'itay.mizeretz'
import urllib.request

from common.cloud.environment_names import Environment
from common.cloud.instance import CloudInstance

__author__ = 'itay.mizeretz'


AWS_INSTANCE_METADATA_LOCAL_IP_ADDRESS = "169.254.169.254"
AWS_LATEST_METADATA_URI_PREFIX = 'http://{0}/latest/'.format(AWS_INSTANCE_METADATA_LOCAL_IP_ADDRESS)
ACCOUNT_ID_KEY = "accountId"
Expand Down
4 changes: 2 additions & 2 deletions monkey/common/cloud/aws/aws_service_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from unittest import TestCase
from .aws_service import filter_instance_data_from_aws_response

import json
from .aws_service import filter_instance_data_from_aws_response

__author__ = 'shay.nehmad'

Expand Down
1 change: 1 addition & 0 deletions monkey/common/cloud/azure/azure_instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging

import requests

from common.cloud.environment_names import Environment
Expand Down
1 change: 1 addition & 0 deletions monkey/common/cloud/gcp/gcp_instance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging

import requests

from common.cloud.environment_names import Environment
Expand Down
2 changes: 1 addition & 1 deletion monkey/common/cmd/cmd_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import logging
import time
from abc import abstractmethod

from common.cmd.cmd import Cmd
Expand Down
5 changes: 2 additions & 3 deletions monkey/common/network/network_range.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import ipaddress
import logging
import random
import socket
import struct
from abc import ABCMeta, abstractmethod

import ipaddress
import logging

__author__ = 'itamar'

LOG = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions monkey/common/utils/mongo_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

if sys.platform == 'win32':
import win32com
import wmi
Expand Down
7 changes: 4 additions & 3 deletions monkey/infection_monkey/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

import infection_monkey.monkeyfs as monkeyfs
import infection_monkey.tunnel as tunnel
from infection_monkey.config import WormConfiguration, GUID
from infection_monkey.network.info import local_ips, check_internet_access
from infection_monkey.config import GUID, WormConfiguration
from infection_monkey.network.info import check_internet_access, local_ips
from infection_monkey.transport.http import HTTPConnectProxy
from infection_monkey.transport.tcp import TcpProxy
from infection_monkey.utils.exceptions.planned_shutdown_exception import \
PlannedShutdownException

__author__ = 'hoffer'

from infection_monkey.utils.exceptions.planned_shutdown_exception import PlannedShutdownException

requests.packages.urllib3.disable_warnings()

Expand Down
13 changes: 8 additions & 5 deletions monkey/infection_monkey/dropper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import ctypes
import filecmp
import logging
import os
import pprint
Expand All @@ -9,13 +10,15 @@
import time
from ctypes import c_char_p

import filecmp
from common.utils.attack_utils import ScanStatus, UsageEnum
from infection_monkey.config import WormConfiguration
from infection_monkey.exploit.tools.helpers import build_monkey_commandline_explicitly
from infection_monkey.model import MONKEY_CMDLINE_WINDOWS, MONKEY_CMDLINE_LINUX, GENERAL_CMDLINE_LINUX
from infection_monkey.system_info import SystemInfoCollector, OperatingSystem
from infection_monkey.exploit.tools.helpers import \
build_monkey_commandline_explicitly
from infection_monkey.model import (GENERAL_CMDLINE_LINUX,
MONKEY_CMDLINE_LINUX,
MONKEY_CMDLINE_WINDOWS)
from infection_monkey.system_info import OperatingSystem, SystemInfoCollector
from infection_monkey.telemetry.attack.t1106_telem import T1106Telem
from common.utils.attack_utils import ScanStatus, UsageEnum

if "win32" == sys.platform:
from win32process import DETACHED_PROCESS
Expand Down
7 changes: 3 additions & 4 deletions monkey/infection_monkey/exploit/HostExploiter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from abc import abstractmethod

from infection_monkey.config import WormConfiguration
from common.utils.exploit_enum import ExploitType
from datetime import datetime

from infection_monkey.utils.plugins.plugin import Plugin
import infection_monkey.exploit
from common.utils.exploit_enum import ExploitType
from infection_monkey.config import WormConfiguration
from infection_monkey.utils.plugins.plugin import Plugin

__author__ = 'itamar'

Expand Down
14 changes: 8 additions & 6 deletions monkey/infection_monkey/exploit/elasticgroovy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

import json
import logging
import re

import requests

from common.data.network_consts import ES_SERVICE
from common.utils.attack_utils import BITS_UPLOAD_STRING, ScanStatus
from infection_monkey.exploit.web_rce import WebRCE
from infection_monkey.model import WGET_HTTP_UPLOAD, BITSADMIN_CMDLINE_HTTP, CHECK_COMMAND, ID_STRING, CMD_PREFIX, \
DOWNLOAD_TIMEOUT
from infection_monkey.model import (BITSADMIN_CMDLINE_HTTP, CHECK_COMMAND,
CMD_PREFIX, DOWNLOAD_TIMEOUT, ID_STRING,
WGET_HTTP_UPLOAD)
from infection_monkey.network.elasticfinger import ES_PORT
from common.data.network_consts import ES_SERVICE
from infection_monkey.telemetry.attack.t1197_telem import T1197Telem
from common.utils.attack_utils import ScanStatus, BITS_UPLOAD_STRING

import re

__author__ = 'danielg, VakarisZ'

Expand Down
16 changes: 10 additions & 6 deletions monkey/infection_monkey/exploit/hadoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
Implementation is based on code from https://github.com/vulhub/vulhub/tree/master/hadoop/unauthorized-yarn
"""

import requests
import json
import random
import string
import logging
import posixpath
import random
import string

from infection_monkey.exploit.web_rce import WebRCE
import requests

from infection_monkey.exploit.tools.helpers import (build_monkey_commandline,
get_monkey_depth)
from infection_monkey.exploit.tools.http_tools import HTTPTools
from infection_monkey.exploit.tools.helpers import build_monkey_commandline, get_monkey_depth
from infection_monkey.model import MONKEY_ARG, ID_STRING, HADOOP_WINDOWS_COMMAND, HADOOP_LINUX_COMMAND
from infection_monkey.exploit.web_rce import WebRCE
from infection_monkey.model import (HADOOP_LINUX_COMMAND,
HADOOP_WINDOWS_COMMAND, ID_STRING,
MONKEY_ARG)

__author__ = 'VakarisZ'

Expand Down
9 changes: 6 additions & 3 deletions monkey/infection_monkey/exploit/mssqlexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

import pymssql

from common.utils.exceptions import (ExploitingVulnerableMachineError,
FailedExploitationError)
from common.utils.exploit_enum import ExploitType
from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import (build_monkey_commandline,
get_monkey_depth,
get_monkey_dest_path)
from infection_monkey.exploit.tools.http_tools import MonkeyHTTPServer
from infection_monkey.exploit.tools.helpers import get_monkey_dest_path, build_monkey_commandline, get_monkey_depth
from infection_monkey.model import DROPPER_ARG
from infection_monkey.exploit.tools.payload_parsing import LimitedSizePayload
from common.utils.exceptions import ExploitingVulnerableMachineError, FailedExploitationError
from infection_monkey.model import DROPPER_ARG

LOG = logging.getLogger(__name__)

Expand Down
20 changes: 13 additions & 7 deletions monkey/infection_monkey/exploit/sambacry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
import impacket.smbconnection
from impacket.nmb import NetBIOSError
from impacket.nt_errors import STATUS_SUCCESS
from impacket.smb import FILE_OPEN, SMB_DIALECT, SMB, SMBCommand, SMBNtCreateAndX_Parameters, SMBNtCreateAndX_Data, \
FILE_READ_DATA, FILE_SHARE_READ, FILE_NON_DIRECTORY_FILE, FILE_WRITE_DATA, FILE_DIRECTORY_FILE
from impacket.smb import SessionError
from impacket.smb3structs import SMB2_IL_IMPERSONATION, SMB2_CREATE, SMB2_FLAGS_DFS_OPERATIONS, SMB2Create, \
SMB2Packet, SMB2Create_Response, SMB2_OPLOCK_LEVEL_NONE
from impacket.smb import (FILE_DIRECTORY_FILE, FILE_NON_DIRECTORY_FILE,
FILE_OPEN, FILE_READ_DATA, FILE_SHARE_READ,
FILE_WRITE_DATA, SMB, SMB_DIALECT, SessionError,
SMBCommand, SMBNtCreateAndX_Data,
SMBNtCreateAndX_Parameters)
from impacket.smb3structs import (SMB2_CREATE, SMB2_FLAGS_DFS_OPERATIONS,
SMB2_IL_IMPERSONATION,
SMB2_OPLOCK_LEVEL_NONE, SMB2Create,
SMB2Create_Response, SMB2Packet)
from impacket.smbconnection import SMBConnection

import infection_monkey.monkeyfs as monkeyfs
from common.utils.attack_utils import ScanStatus
from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import (build_monkey_commandline,
get_monkey_depth,
get_target_monkey_by_os)
from infection_monkey.model import DROPPER_ARG
from infection_monkey.network.smbfinger import SMB_SERVICE
from infection_monkey.exploit.tools.helpers import build_monkey_commandline, get_target_monkey_by_os, get_monkey_depth
from infection_monkey.network.tools import get_interface_to_target
from infection_monkey.pyinstaller_utils import get_binary_file_path
from common.utils.attack_utils import ScanStatus
from infection_monkey.telemetry.attack.t1105_telem import T1105Telem

__author__ = 'itay.mizeretz'
Expand Down
6 changes: 4 additions & 2 deletions monkey/infection_monkey/exploit/shellshock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

from common.utils.attack_utils import ScanStatus
from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import get_target_monkey, get_monkey_depth, build_monkey_commandline
from infection_monkey.model import DROPPER_ARG
from infection_monkey.exploit.shellshock_resources import CGI_FILES
from infection_monkey.exploit.tools.helpers import (build_monkey_commandline,
get_monkey_depth,
get_target_monkey)
from infection_monkey.exploit.tools.http_tools import HTTPTools
from infection_monkey.model import DROPPER_ARG
from infection_monkey.telemetry.attack.t1222_telem import T1222Telem

__author__ = 'danielg'
Expand Down
14 changes: 9 additions & 5 deletions monkey/infection_monkey/exploit/smbexec.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from logging import getLogger

from impacket.dcerpc.v5 import transport, scmr
from impacket.dcerpc.v5 import scmr, transport
from impacket.smbconnection import SMB_DIALECT

from common.utils.attack_utils import ScanStatus, UsageEnum
from common.utils.exploit_enum import ExploitType
from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import get_target_monkey, get_monkey_depth, build_monkey_commandline
from infection_monkey.exploit.tools.helpers import (build_monkey_commandline,
get_monkey_depth,
get_target_monkey)
from infection_monkey.exploit.tools.smb_tools import SmbTools
from infection_monkey.model import MONKEY_CMDLINE_DETACHED_WINDOWS, DROPPER_CMDLINE_DETACHED_WINDOWS, VictimHost
from infection_monkey.model import (DROPPER_CMDLINE_DETACHED_WINDOWS,
MONKEY_CMDLINE_DETACHED_WINDOWS,
VictimHost)
from infection_monkey.network.smbfinger import SMBFinger
from infection_monkey.network.tools import check_tcp_port
from common.utils.exploit_enum import ExploitType
from infection_monkey.telemetry.attack.t1035_telem import T1035Telem
from common.utils.attack_utils import ScanStatus, UsageEnum

LOG = getLogger(__name__)

Expand Down
13 changes: 8 additions & 5 deletions monkey/infection_monkey/exploit/sshexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import paramiko

import infection_monkey.monkeyfs as monkeyfs
from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import get_target_monkey, get_monkey_depth, build_monkey_commandline
from infection_monkey.model import MONKEY_ARG
from infection_monkey.network.tools import check_tcp_port, get_interface_to_target
from common.utils.attack_utils import ScanStatus
from common.utils.exceptions import FailedExploitationError
from common.utils.exploit_enum import ExploitType
from common.utils.attack_utils import ScanStatus
from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import (build_monkey_commandline,
get_monkey_depth,
get_target_monkey)
from infection_monkey.model import MONKEY_ARG
from infection_monkey.network.tools import (check_tcp_port,
get_interface_to_target)
from infection_monkey.telemetry.attack.t1105_telem import T1105Telem
from infection_monkey.telemetry.attack.t1222_telem import T1222Telem

Expand Down
3 changes: 2 additions & 1 deletion monkey/infection_monkey/exploit/tools/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ def try_get_target_monkey(host):


def get_target_monkey(host):
from infection_monkey.control import ControlClient
import platform
import sys

from infection_monkey.control import ControlClient

if host.monkey_exe:
return host.monkey_exe

Expand Down
4 changes: 2 additions & 2 deletions monkey/infection_monkey/exploit/tools/http_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import urllib.request
from threading import Lock

from infection_monkey.exploit.tools.helpers import try_get_target_monkey
from infection_monkey.model import DOWNLOAD_TIMEOUT
from infection_monkey.network.firewall import app as firewall
from infection_monkey.network.info import get_free_tcp_port
from infection_monkey.transport import HTTPServer, LockedHTTPServer
from infection_monkey.exploit.tools.helpers import try_get_target_monkey
from infection_monkey.network.tools import get_interface_to_target
from infection_monkey.transport import HTTPServer, LockedHTTPServer

__author__ = 'itamar'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest import TestCase
from .payload_parsing import Payload, LimitedSizePayload

from .payload_parsing import LimitedSizePayload, Payload


class TestPayload(TestCase):
Expand Down
8 changes: 4 additions & 4 deletions monkey/infection_monkey/exploit/tools/smb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import ntpath
import pprint

from impacket.dcerpc.v5 import transport, srvs
from impacket.dcerpc.v5 import srvs, transport
from impacket.smb3structs import SMB2_DIALECT_002, SMB2_DIALECT_21
from impacket.smbconnection import SMBConnection, SMB_DIALECT
from impacket.smbconnection import SMB_DIALECT, SMBConnection

import infection_monkey.config
import infection_monkey.monkeyfs as monkeyfs
from common.utils.attack_utils import ScanStatus
from infection_monkey.telemetry.attack.t1105_telem import T1105Telem
from infection_monkey.network.tools import get_interface_to_target
from infection_monkey.config import Configuration
from infection_monkey.network.tools import get_interface_to_target
from infection_monkey.telemetry.attack.t1105_telem import T1105Telem

__author__ = 'itamar'

Expand Down
3 changes: 2 additions & 1 deletion monkey/infection_monkey/exploit/tools/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from infection_monkey.exploit.tools.helpers import build_monkey_commandline_explicitly
from infection_monkey.exploit.tools.helpers import \
build_monkey_commandline_explicitly


class TestHelpers(unittest.TestCase):
Expand Down
10 changes: 6 additions & 4 deletions monkey/infection_monkey/exploit/vsftpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

import socket
import time
from logging import getLogger

from common.utils.attack_utils import ScanStatus
from infection_monkey.exploit.HostExploiter import HostExploiter
from infection_monkey.exploit.tools.helpers import get_target_monkey, build_monkey_commandline, get_monkey_depth
from infection_monkey.exploit.tools.helpers import (build_monkey_commandline,
get_monkey_depth,
get_target_monkey)
from infection_monkey.exploit.tools.http_tools import HTTPTools
from infection_monkey.model import MONKEY_ARG, CHMOD_MONKEY, RUN_MONKEY, WGET_HTTP_UPLOAD, DOWNLOAD_TIMEOUT
from logging import getLogger

from infection_monkey.model import (CHMOD_MONKEY, DOWNLOAD_TIMEOUT, MONKEY_ARG,
RUN_MONKEY, WGET_HTTP_UPLOAD)
from infection_monkey.telemetry.attack.t1222_telem import T1222Telem

LOG = getLogger(__name__)
Expand Down
Loading