Island: Add notes/explanations/thoughs in the services

This commit is contained in:
vakarisz 2022-05-18 13:03:24 +03:00
parent 6438afbcd5
commit e0b4037270
3 changed files with 36 additions and 15 deletions

View File

@ -21,6 +21,8 @@ class NetEdgeService:
def _get_standard_net_edges():
return [DisplayedEdgeService.edge_to_net_edge(x) for x in EdgeService.get_all_edges()]
# If we save the island machine as a standard machine, we won't need these
# methods
@staticmethod
def _get_uninfected_island_net_edges():
edges = []

View File

@ -80,6 +80,11 @@ class NodeService:
domain_name = " (" + node["domain_name"] + ")"
return node["os"]["version"] + " : " + node["ip_addresses"][0] + domain_name
# A lot of methods like these duplicate between monkey and node.
# That's a result of poor entity model, because both nodes and monkeys
# store the same information. It's best to extract the machine specific data
# to "Machine" entity (like IP's and os) and agent specific data to "Agent" (like alive,
# parent, etc)
@staticmethod
def get_monkey_os(monkey):
os = "unknown"
@ -221,6 +226,11 @@ class NodeService:
def get_monkey_by_id(monkey_id):
return mongo.db.monkey.find_one({"_id": ObjectId(monkey_id)})
# GUID is generated from uuid.getnode() and represents machine it was ran on
# All monkeys that ran on the same machine will have the same GUID, but
# we can just store the monkeys on the same machine document/have one to many relationship
# GUID could be stored on machine to uniquely identify the same machine even after the
# ip, domain name or other changes. Not entirely sure it's necessary
@staticmethod
def get_monkey_by_guid(monkey_guid):
return mongo.db.monkey.find_one({"guid": monkey_guid})
@ -237,6 +247,8 @@ class NodeService:
def get_node_by_id(node_id):
return mongo.db.node.find_one({"_id": ObjectId(node_id)})
# This is only used to determine if report is the latest or if we need to
# generate a new one. This info should end up in Simulation entity instead.
@staticmethod
def update_monkey_modify_time(monkey_id):
mongo.db.monkey.update(
@ -259,6 +271,8 @@ class NodeService:
{"guid": monkey["guid"]}, {"$set": {"command_control_channel": info}}, upsert=False
)
# TODO this returns a mock island agent
# It's better to just initialize the island machine on reset I think
@staticmethod
def get_monkey_island_monkey():
ip_addresses = local_ip_addresses()

View File

@ -57,6 +57,7 @@ class ReportService:
def initialize(cls, aws_service: AWSService):
cls._aws_service = aws_service
# This should pull from Simulation entity
@staticmethod
def get_first_monkey_time():
return (
@ -88,6 +89,7 @@ class ReportService:
return st
# This shoud be replaced by a query to edges and get tunnel edges?
@staticmethod
def get_tunnels():
return [
@ -103,6 +105,7 @@ class ReportService:
for tunnel in mongo.db.monkey.find({"tunnel": {"$exists": True}}, {"tunnel": 1})
]
# This should be replaced by machine query for "scanned" status
@staticmethod
def get_scanned():
formatted_nodes = []
@ -110,6 +113,8 @@ class ReportService:
nodes = ReportService.get_all_displayed_nodes()
for node in nodes:
# This information should be evident from the map, not sure a table/list is a good way
# to display it anyways
nodes_that_can_access_current_node = node["accessible_from_nodes_hostnames"]
formatted_nodes.append(
{