Merge pull request #30 from withshubh/deepfix

Autofixes made using DeepSource
This commit is contained in:
Shubhendra Singh Chauhan 2020-12-04 23:47:49 +05:30 committed by GitHub
commit 69b7e700dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 24 additions and 16 deletions

14
.deepsource.toml Normal file
View File

@ -0,0 +1,14 @@
version = 1
test_patterns = ["**/**_test.py"]
[[analyzers]]
name = "python"
enabled = true
dependency_file_paths = [
"monkey/monkey_island/requirements.txt",
"monkey/infection_monkey/requirements.txt"
]
[analyzers.meta]
runtime_version = "3.x.x"

View File

@ -228,7 +228,6 @@ class ShellShockExploiter(HostExploiter):
Checks if which urls exist
:return: Sequence of URLs to try and attack
"""
import requests
attack_path = 'http://'
if is_https:
attack_path = 'https://'

View File

@ -56,7 +56,7 @@ class WebRCE(HostExploiter):
Method that creates a dictionary of configuration values for exploit
:return: configuration dict
"""
exploit_config = dict()
exploit_config = {}
# dropper: If true monkey will use dropper parameter that will detach monkey's process and try to copy
# it's file to the default destination path.

View File

@ -113,7 +113,7 @@ class NetworkScanner(object):
:return: Victim or None if victim isn't alive
"""
LOG.debug("Scanning target address: %r", victim)
if any([scanner.is_host_alive(victim) for scanner in self.scanners]):
if any(scanner.is_host_alive(victim) for scanner in self.scanners):
LOG.debug("Found potential target_ip: %r", victim)
return victim
else:

View File

@ -139,7 +139,7 @@ def check_tcp_ports(ip, ports, timeout=DEFAULT_TIMEOUT, get_banner=False):
timeout = int(round(timeout)) # clamp to integer, to avoid checking input
sockets_to_try = possible_ports[:]
connected_ports_sockets = []
while (timeout >= 0) and len(sockets_to_try):
while (timeout >= 0) and sockets_to_try:
sock_objects = [s[1] for s in sockets_to_try]
_, writeable_sockets, _ = select.select(sock_objects, sock_objects, sock_objects, 0)

View File

@ -67,8 +67,8 @@ def _get_windows_cred(pypykatz_cred: PypykatzCredential):
def _hash_to_string(hash_: Any):
if type(hash_) == str:
if type(hash_) is str:
return hash_
if type(hash_) == bytes:
if type(hash_) is bytes:
return binascii.hexlify(bytearray(hash_)).decode()
raise Exception(f"Can't convert hash_ to string, unsupported hash_ type {type(hash_)}")

View File

@ -1,5 +1,3 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import \
TestPlugin # noqa: F401
class SomeDummyPlugin:

View File

@ -87,20 +87,18 @@ class Monkey(flask_restful.Resource):
parent = monkey_json.get('parent')
parent_to_add = (monkey_json.get('guid'), None) # default values in case of manual run
if parent and parent != monkey_json.get('guid'): # current parent is known
exploit_telem = [x for x in
mongo.db.telemetry.find({'telem_category': {'$eq': 'exploit'},
exploit_telem = list(mongo.db.telemetry.find({'telem_category': {'$eq': 'exploit'},
'data.result': {'$eq': True},
'data.machine.ip_addr': {'$in': monkey_json['ip_addresses']},
'monkey_guid': {'$eq': parent}})]
'monkey_guid': {'$eq': parent}}))
if 1 == len(exploit_telem):
parent_to_add = (exploit_telem[0].get('monkey_guid'), exploit_telem[0].get('data').get('exploiter'))
else:
parent_to_add = (parent, None)
elif (not parent or parent == monkey_json.get('guid')) and 'ip_addresses' in monkey_json:
exploit_telem = [x for x in
mongo.db.telemetry.find({'telem_category': {'$eq': 'exploit'},
exploit_telem = list(mongo.db.telemetry.find({'telem_category': {'$eq': 'exploit'},
'data.result': {'$eq': True},
'data.machine.ip_addr': {'$in': monkey_json['ip_addresses']}})]
'data.machine.ip_addr': {'$in': monkey_json['ip_addresses']}}))
if 1 == len(exploit_telem):
parent_to_add = (exploit_telem[0].get('monkey_guid'), exploit_telem[0].get('data').get('exploiter'))

View File

@ -63,7 +63,7 @@ class DisplayedEdgeService:
@staticmethod
def services_to_displayed_services(services, for_report=False):
if for_report:
return [x for x in services]
return list(services)
else:
return [x + ": " + (services[x]['name'] if 'name' in services[x] else 'unknown') for x in services]

View File

@ -1,6 +1,5 @@
from monkey_island.cc.database import mongo
from monkey_island.cc.models import Monkey
from monkey_island.cc.services.edge.edge import EdgeService
from monkey_island.cc.services.node import NodeService
from monkey_island.cc.services.telemetry.processing.utils import \
get_edge_by_scan_or_exploit_telemetry