Show minimal info on services.
Make optimization for machine label on report
This commit is contained in:
parent
8ed439e24e
commit
80914716b7
|
@ -11,22 +11,22 @@ class EdgeService:
|
|||
pass
|
||||
|
||||
@staticmethod
|
||||
def get_displayed_edge_by_id(edge_id):
|
||||
def get_displayed_edge_by_id(edge_id, for_report=False):
|
||||
edge = mongo.db.edge.find({"_id": ObjectId(edge_id)})[0]
|
||||
return EdgeService.edge_to_displayed_edge(edge)
|
||||
return EdgeService.edge_to_displayed_edge(edge, for_report)
|
||||
|
||||
@staticmethod
|
||||
def get_displayed_edges_by_to(to):
|
||||
def get_displayed_edges_by_to(to, for_report=False):
|
||||
edges = mongo.db.edge.find({"to": ObjectId(to)})
|
||||
return [EdgeService.edge_to_displayed_edge(edge) for edge in edges]
|
||||
return [EdgeService.edge_to_displayed_edge(edge, for_report) for edge in edges]
|
||||
|
||||
@staticmethod
|
||||
def edge_to_displayed_edge(edge):
|
||||
def edge_to_displayed_edge(edge, for_report=False):
|
||||
services = []
|
||||
os = {}
|
||||
|
||||
if len(edge["scans"]) > 0:
|
||||
services = EdgeService.services_to_displayed_services(edge["scans"][-1]["data"]["services"])
|
||||
services = EdgeService.services_to_displayed_services(edge["scans"][-1]["data"]["services"], for_report)
|
||||
os = edge["scans"][-1]["data"]["os"]
|
||||
|
||||
displayed_edge = EdgeService.edge_to_net_edge(edge)
|
||||
|
@ -104,8 +104,11 @@ class EdgeService:
|
|||
return edges
|
||||
|
||||
@staticmethod
|
||||
def services_to_displayed_services(services):
|
||||
return [x + ": " + (services[x]['name'] if services[x].has_key('name') else 'unknown') for x in services]
|
||||
def services_to_displayed_services(services, for_report=False):
|
||||
if for_report:
|
||||
return [x for x in services]
|
||||
else:
|
||||
return [x + ": " + (services[x]['name'] if 'name' in services[x] else 'unknown') for x in services]
|
||||
|
||||
@staticmethod
|
||||
def edge_to_net_edge(edge):
|
||||
|
|
|
@ -12,11 +12,11 @@ class NodeService:
|
|||
pass
|
||||
|
||||
@staticmethod
|
||||
def get_displayed_node_by_id(node_id):
|
||||
def get_displayed_node_by_id(node_id, for_report=False):
|
||||
if ObjectId(node_id) == NodeService.get_monkey_island_pseudo_id():
|
||||
return NodeService.get_monkey_island_node()
|
||||
|
||||
edges = EdgeService.get_displayed_edges_by_to(node_id)
|
||||
edges = EdgeService.get_displayed_edges_by_to(node_id, for_report)
|
||||
accessible_from_nodes = []
|
||||
exploits = []
|
||||
|
||||
|
@ -29,14 +29,14 @@ class NodeService:
|
|||
return new_node
|
||||
|
||||
# node is infected
|
||||
new_node = NodeService.monkey_to_net_node(monkey)
|
||||
new_node = NodeService.monkey_to_net_node(monkey, for_report)
|
||||
for key in monkey:
|
||||
if key not in ['_id', 'modifytime', 'parent', 'dead', 'description']:
|
||||
new_node[key] = monkey[key]
|
||||
|
||||
else:
|
||||
# node is uninfected
|
||||
new_node = NodeService.node_to_net_node(node)
|
||||
new_node = NodeService.node_to_net_node(node, for_report)
|
||||
new_node["ip_addresses"] = node["ip_addresses"]
|
||||
|
||||
for edge in edges:
|
||||
|
@ -119,22 +119,24 @@ class NodeService:
|
|||
return "%s_%s" % (node_type, node_os)
|
||||
|
||||
@staticmethod
|
||||
def monkey_to_net_node(monkey):
|
||||
def monkey_to_net_node(monkey, for_report=False):
|
||||
label = monkey['hostname'] if for_report else NodeService.get_monkey_label(monkey)
|
||||
return \
|
||||
{
|
||||
"id": monkey["_id"],
|
||||
"label": NodeService.get_monkey_label(monkey),
|
||||
"label": label,
|
||||
"group": NodeService.get_monkey_group(monkey),
|
||||
"os": NodeService.get_monkey_os(monkey),
|
||||
"dead": monkey["dead"],
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def node_to_net_node(node):
|
||||
def node_to_net_node(node, for_report=False):
|
||||
label = node['os']['version'] if for_report else NodeService.get_node_label(node)
|
||||
return \
|
||||
{
|
||||
"id": node["_id"],
|
||||
"label": NodeService.get_node_label(node),
|
||||
"label": label,
|
||||
"group": NodeService.get_node_group(node),
|
||||
"os": NodeService.get_node_os(node)
|
||||
}
|
||||
|
|
|
@ -76,17 +76,16 @@ class ReportService:
|
|||
@staticmethod
|
||||
def get_scanned():
|
||||
nodes = \
|
||||
[NodeService.get_displayed_node_by_id(node['_id']) for node in mongo.db.node.find({}, {'_id': 1})] \
|
||||
+ [NodeService.get_displayed_node_by_id(monkey['_id']) for monkey in mongo.db.monkey.find({}, {'_id': 1})]
|
||||
[NodeService.get_displayed_node_by_id(node['_id'], True) for node in mongo.db.node.find({}, {'_id': 1})] \
|
||||
+ [NodeService.get_displayed_node_by_id(monkey['_id'], True) for monkey in mongo.db.monkey.find({}, {'_id': 1})]
|
||||
nodes = [
|
||||
{
|
||||
'label':
|
||||
node['hostname'] if 'hostname' in node else NodeService.get_node_by_id(node['id'])['os']['version'],
|
||||
'label': node['label'],
|
||||
'ip_addresses': node['ip_addresses'],
|
||||
'accessible_from_nodes':
|
||||
(x['hostname'] for x in
|
||||
(NodeService.get_displayed_node_by_id(edge['from'])
|
||||
for edge in EdgeService.get_displayed_edges_by_to(node['id']))),
|
||||
(NodeService.get_displayed_node_by_id(edge['from'], True)
|
||||
for edge in EdgeService.get_displayed_edges_by_to(node['id'], True))),
|
||||
'services': node['services']
|
||||
}
|
||||
for node in nodes]
|
||||
|
@ -96,14 +95,14 @@ class ReportService:
|
|||
@staticmethod
|
||||
def get_exploited():
|
||||
exploited = \
|
||||
[NodeService.get_displayed_node_by_id(monkey['_id']) for monkey in mongo.db.monkey.find({}, {'_id': 1})
|
||||
[NodeService.get_displayed_node_by_id(monkey['_id'], True) for monkey in mongo.db.monkey.find({}, {'_id': 1})
|
||||
if not NodeService.get_monkey_manual_run(NodeService.get_monkey_by_id(monkey['_id']))] \
|
||||
+ [NodeService.get_displayed_node_by_id(node['_id'])
|
||||
+ [NodeService.get_displayed_node_by_id(node['_id'], True)
|
||||
for node in mongo.db.node.find({'exploited': True}, {'_id': 1})]
|
||||
|
||||
exploited = [
|
||||
{
|
||||
'label': NodeService.get_node_hostname(NodeService.get_node_or_monkey_by_id(monkey['id'])),
|
||||
'label': monkey['label'],
|
||||
'ip_addresses': monkey['ip_addresses'],
|
||||
'exploits': list(set(
|
||||
[ReportService.EXPLOIT_DISPLAY_DICT[exploit['exploiter']] for exploit in monkey['exploits'] if
|
||||
|
|
Loading…
Reference in New Issue