forked from p15670423/monkey
Variable names and const location fixes
This commit is contained in:
parent
cd3835a42e
commit
4b0ea4aed7
|
@ -304,7 +304,7 @@ class ControlClient(object):
|
|||
try:
|
||||
target_addr, target_port = my_proxy.split(':', 1)
|
||||
target_port = int(target_port)
|
||||
except:
|
||||
except ValueError:
|
||||
return None
|
||||
else:
|
||||
proxy_class = HTTPConnectProxy
|
||||
|
|
|
@ -26,6 +26,7 @@ else:
|
|||
try:
|
||||
WindowsError
|
||||
except NameError:
|
||||
# noinspection PyShadowingBuiltins
|
||||
WindowsError = IOError
|
||||
|
||||
__author__ = 'itamar'
|
||||
|
@ -103,14 +104,14 @@ class MonkeyDrops(object):
|
|||
dropper_date_reference_path = WormConfiguration.dropper_date_reference_path_linux
|
||||
try:
|
||||
ref_stat = os.stat(dropper_date_reference_path)
|
||||
except OSError as exc:
|
||||
except OSError:
|
||||
LOG.warning("Cannot set reference date using '%s', file not found",
|
||||
dropper_date_reference_path)
|
||||
else:
|
||||
try:
|
||||
os.utime(self._config['destination_path'],
|
||||
(ref_stat.st_atime, ref_stat.st_mtime))
|
||||
except:
|
||||
except OSError:
|
||||
LOG.warning("Cannot set reference date to destination file")
|
||||
|
||||
monkey_options =\
|
||||
|
|
|
@ -25,7 +25,7 @@ class FirewallApp(object):
|
|||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
def __exit__(self, exc_type, value, traceback):
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
|
@ -49,9 +49,9 @@ class WinAdvFirewall(FirewallApp):
|
|||
except:
|
||||
return None
|
||||
|
||||
def add_firewall_rule(self, name="Firewall", dir="in", action="allow", program=sys.executable, **kwargs):
|
||||
def add_firewall_rule(self, name="Firewall", direction="in", action="allow", program=sys.executable, **kwargs):
|
||||
netsh_args = {'name': name,
|
||||
'dir': dir,
|
||||
'dir': direction,
|
||||
'action': action,
|
||||
'program': program}
|
||||
netsh_args.update(kwargs)
|
||||
|
|
|
@ -16,6 +16,11 @@ from infection_monkey.utils.environment import is_windows_os
|
|||
|
||||
# Timeout for monkey connections
|
||||
TIMEOUT = 15
|
||||
LOOPBACK_NAME = b"lo"
|
||||
SIOCGIFADDR = 0x8915 # get PA address
|
||||
SIOCGIFNETMASK = 0x891b # get network PA mask
|
||||
RTF_UP = 0x0001 # Route usable
|
||||
RTF_REJECT = 0x0200
|
||||
|
||||
|
||||
def get_host_subnets():
|
||||
|
@ -62,12 +67,6 @@ else:
|
|||
|
||||
|
||||
def get_routes(): # based on scapy implementation for route parsing
|
||||
LOOPBACK_NAME = b"lo"
|
||||
SIOCGIFADDR = 0x8915 # get PA address
|
||||
SIOCGIFNETMASK = 0x891b # get network PA mask
|
||||
RTF_UP = 0x0001 # Route usable
|
||||
RTF_REJECT = 0x0200
|
||||
|
||||
try:
|
||||
f = open("/proc/net/route", "r")
|
||||
except IOError:
|
||||
|
|
|
@ -64,7 +64,6 @@ class FileServHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
|
|||
if self.path != '/' + urllib.parse.quote(os.path.basename(self.filename)):
|
||||
self.send_error(500, "")
|
||||
return None, 0, 0
|
||||
f = None
|
||||
try:
|
||||
f = monkeyfs.open(self.filename, 'rb')
|
||||
except IOError:
|
||||
|
@ -100,10 +99,10 @@ class FileServHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
|
|||
self.end_headers()
|
||||
return f, start_range, end_range
|
||||
|
||||
def log_message(self, format, *args):
|
||||
def log_message(self, format_string, *args):
|
||||
LOG.debug("FileServHTTPRequestHandler: %s - - [%s] %s" % (self.address_string(),
|
||||
self.log_date_time_string(),
|
||||
format % args))
|
||||
format_string % args))
|
||||
|
||||
|
||||
class HTTPConnectProxyHandler(http.server.BaseHTTPRequestHandler):
|
||||
|
@ -117,7 +116,6 @@ class HTTPConnectProxyHandler(http.server.BaseHTTPRequestHandler):
|
|||
def do_CONNECT(self):
|
||||
# just provide a tunnel, transfer the data with no modification
|
||||
req = self
|
||||
reqbody = None
|
||||
req.path = "https://%s/" % req.path.replace(':443', '')
|
||||
|
||||
u = urlsplit(req.path)
|
||||
|
@ -148,9 +146,9 @@ class HTTPConnectProxyHandler(http.server.BaseHTTPRequestHandler):
|
|||
update_last_serve_time()
|
||||
conn.close()
|
||||
|
||||
def log_message(self, format, *args):
|
||||
def log_message(self, format_string, *args):
|
||||
LOG.debug("HTTPConnectProxyHandler: %s - [%s] %s" %
|
||||
(self.address_string(), self.log_date_time_string(), format % args))
|
||||
(self.address_string(), self.log_date_time_string(), format_string % args))
|
||||
|
||||
|
||||
class HTTPServer(threading.Thread):
|
||||
|
|
|
@ -34,8 +34,8 @@ def load_server_configuration_from_file():
|
|||
|
||||
|
||||
def load_env_from_file():
|
||||
config_json = load_server_configuration_from_file()
|
||||
return config_json['server_config']
|
||||
loaded_config_json = load_server_configuration_from_file()
|
||||
return loaded_config_json['server_config']
|
||||
|
||||
|
||||
try:
|
||||
|
|
|
@ -132,7 +132,7 @@ def is_monkey(object_id):
|
|||
try:
|
||||
_ = Monkey.get_single_monkey_by_id(object_id)
|
||||
return True
|
||||
except:
|
||||
except MonkeyNotFoundError:
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ class ConfigService:
|
|||
if should_encrypt:
|
||||
try:
|
||||
ConfigService.encrypt_config(config_json)
|
||||
except KeyError as e:
|
||||
except KeyError:
|
||||
logger.error('Bad configuration file was submitted.')
|
||||
return False
|
||||
mongo.db.config.update({'name': 'newconfig'}, {"$set": config_json}, upsert=True)
|
||||
|
@ -154,9 +154,9 @@ class ConfigService:
|
|||
@staticmethod
|
||||
def init_default_config():
|
||||
if ConfigService.default_config is None:
|
||||
defaultValidatingDraft4Validator = ConfigService._extend_config_with_default(Draft4Validator)
|
||||
default_validating_draft4_validator = ConfigService._extend_config_with_default(Draft4Validator)
|
||||
config = {}
|
||||
defaultValidatingDraft4Validator(SCHEMA).validate(config)
|
||||
default_validating_draft4_validator(SCHEMA).validate(config)
|
||||
ConfigService.default_config = config
|
||||
|
||||
@staticmethod
|
||||
|
@ -207,15 +207,15 @@ class ConfigService:
|
|||
# Do it only for root.
|
||||
if instance != {}:
|
||||
return
|
||||
for property, subschema in list(properties.items()):
|
||||
for property1, subschema1 in list(properties.items()):
|
||||
main_dict = {}
|
||||
for property2, subschema2 in list(subschema["properties"].items()):
|
||||
for property2, subschema2 in list(subschema1["properties"].items()):
|
||||
sub_dict = {}
|
||||
for property3, subschema3 in list(subschema2["properties"].items()):
|
||||
if "default" in subschema3:
|
||||
sub_dict[property3] = subschema3["default"]
|
||||
main_dict[property2] = sub_dict
|
||||
instance.setdefault(property, main_dict)
|
||||
instance.setdefault(property1, main_dict)
|
||||
|
||||
for error in validate_properties(validator, properties, instance, schema):
|
||||
yield error
|
||||
|
|
|
@ -141,7 +141,7 @@ class EdgeService:
|
|||
|
||||
@staticmethod
|
||||
def get_edge_label(edge):
|
||||
NodeService = monkey_island.cc.services.node.NodeService
|
||||
node_service = monkey_island.cc.services.node.NodeService
|
||||
from_id = edge["from"]
|
||||
to_id = edge["to"]
|
||||
|
||||
|
@ -153,9 +153,9 @@ class EdgeService:
|
|||
if is_monkey(to_id):
|
||||
to_label = get_monkey_label_by_id(to_id)
|
||||
else:
|
||||
to_label = NodeService.get_node_label(NodeService.get_node_by_id(to_id))
|
||||
to_label = node_service.get_node_label(node_service.get_node_by_id(to_id))
|
||||
|
||||
RIGHT_ARROW = "\u2192"
|
||||
return "%s %s %s" % (from_label, RIGHT_ARROW, to_label)
|
||||
|
||||
|
||||
RIGHT_ARROW = "\u2192"
|
||||
|
|
|
@ -56,9 +56,9 @@ class NodeService:
|
|||
accessible_from_nodes.append(from_node_label)
|
||||
accessible_from_nodes_hostnames.append(from_node_hostname)
|
||||
|
||||
for exploit in edge["exploits"]:
|
||||
exploit["origin"] = from_node_label
|
||||
exploits.append(exploit)
|
||||
for edge_exploit in edge["exploits"]:
|
||||
edge_exploit["origin"] = from_node_label
|
||||
exploits.append(edge_exploit)
|
||||
|
||||
exploits = sorted(exploits, key=lambda exploit: exploit['timestamp'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue