Skip to content

Commit

Permalink
chg: [correlation graph] show message if max_nodes reached + fix cook…
Browse files Browse the repository at this point in the history
…ie-name sparkline
  • Loading branch information
Terrtia committed Jun 20, 2023
1 parent 501d10b commit 4567c9d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
15 changes: 10 additions & 5 deletions bin/lib/correlations_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,22 @@ def delete_obj_correlations(obj_type, subtype, obj_id):
def get_obj_str_id(obj_type, subtype, obj_id):
if subtype is None:
subtype = ''
return f'{obj_type};{subtype};{obj_id}'
return f'{obj_type}:{subtype}:{obj_id}'

def get_correlations_graph_nodes_links(obj_type, subtype, obj_id, filter_types=[], max_nodes=300, level=1, flask_context=False):
links = set()
nodes = set()
meta = {'complete': True, 'objs': set()}

obj_str_id = get_obj_str_id(obj_type, subtype, obj_id)

_get_correlations_graph_node(links, nodes, obj_type, subtype, obj_id, level, max_nodes, filter_types=filter_types, previous_str_obj='')
return obj_str_id, nodes, links
_get_correlations_graph_node(links, nodes, meta, obj_type, subtype, obj_id, level, max_nodes, filter_types=filter_types, previous_str_obj='')
return obj_str_id, nodes, links, meta


def _get_correlations_graph_node(links, nodes, obj_type, subtype, obj_id, level, max_nodes, filter_types=[], previous_str_obj=''):
def _get_correlations_graph_node(links, nodes, meta, obj_type, subtype, obj_id, level, max_nodes, filter_types=[], previous_str_obj=''):
obj_str_id = get_obj_str_id(obj_type, subtype, obj_id)
meta['objs'].add(obj_str_id)
nodes.add(obj_str_id)

obj_correlations = get_correlations(obj_type, subtype, obj_id, filter_types=filter_types)
Expand All @@ -189,15 +191,18 @@ def _get_correlations_graph_node(links, nodes, obj_type, subtype, obj_id, level,
for str_obj in obj_correlations[correl_type]:
subtype2, obj2_id = str_obj.split(':', 1)
obj2_str_id = get_obj_str_id(correl_type, subtype2, obj2_id)
meta['objs'].add(obj2_str_id)

if obj2_str_id == previous_str_obj:
continue

if len(nodes) > max_nodes != 0:
meta['complete'] = False
break
nodes.add(obj2_str_id)
links.add((obj_str_id, obj2_str_id))

if level > 0:
next_level = level - 1
_get_correlations_graph_node(links, nodes, correl_type, subtype2, obj2_id, next_level, max_nodes, filter_types=filter_types, previous_str_obj=obj_str_id)
_get_correlations_graph_node(links, nodes, meta, correl_type, subtype2, obj2_id, next_level, max_nodes, filter_types=filter_types, previous_str_obj=obj_str_id)

18 changes: 10 additions & 8 deletions bin/lib/objects/ail_objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
# -*-coding:UTF-8 -*

import os
import sys

Expand Down Expand Up @@ -169,7 +168,7 @@ def get_object_card_meta(obj_type, subtype, id, related_btc=False):
obj = get_object(obj_type, subtype, id)
meta = obj.get_meta()
meta['icon'] = obj.get_svg_icon()
if subtype or obj_type == 'cve' or obj_type == 'title' or obj_type == 'favicon':
if subtype or obj_type == 'cookie-name' or obj_type == 'cve' or obj_type == 'title' or obj_type == 'favicon':
meta['sparkline'] = obj.get_sparkline()
if obj_type == 'cve':
meta['cve_search'] = obj.get_cve_search()
Expand Down Expand Up @@ -396,7 +395,7 @@ def create_correlation_graph_links(links_set):
def create_correlation_graph_nodes(nodes_set, obj_str_id, flask_context=True):
graph_nodes_list = []
for node_id in nodes_set:
obj_type, subtype, obj_id = node_id.split(';', 2)
obj_type, subtype, obj_id = node_id.split(':', 2)
dict_node = {'id': node_id}
dict_node['style'] = get_object_svg(obj_type, subtype, obj_id)

Expand All @@ -418,12 +417,15 @@ def create_correlation_graph_nodes(nodes_set, obj_str_id, flask_context=True):

def get_correlations_graph_node(obj_type, subtype, obj_id, filter_types=[], max_nodes=300, level=1,
flask_context=False):
obj_str_id, nodes, links = correlations_engine.get_correlations_graph_nodes_links(obj_type, subtype, obj_id,
filter_types=filter_types,
max_nodes=max_nodes, level=level,
flask_context=flask_context)
obj_str_id, nodes, links, meta = correlations_engine.get_correlations_graph_nodes_links(obj_type, subtype, obj_id,
filter_types=filter_types,
max_nodes=max_nodes, level=level,
flask_context=flask_context)
# print(meta)
meta['objs'] = list(meta['objs'])
return {"nodes": create_correlation_graph_nodes(nodes, obj_str_id, flask_context=flask_context),
"links": create_correlation_graph_links(links)}
"links": create_correlation_graph_links(links),
"meta": meta}


# --- CORRELATION --- #
Expand Down
2 changes: 1 addition & 1 deletion var/www/blueprints/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def show_correlation():
@login_read_only
def get_description():
object_id = request.args.get('object_id')
object_id = object_id.split(';')
object_id = object_id.split(':')
# unpack object_id # # TODO: put me in lib
if len(object_id) == 3:
object_type = object_id[0]
Expand Down
10 changes: 10 additions & 0 deletions var/www/templates/correlation/show_correlation.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
<i class="fas fa-sync"></i>&nbsp;Resize Graph
</button>
</span>
<div id="incomplete_graph" class="text-danger mt-3">
<i class="fas fa-exclamation-triangle"></i>&nbsp;Graph Incomplete, Max Nodes Reached.
</div>
</div>
<div class="card-body graph_panel">
<div id="graph_loading" class="ml-3 mt-3">
Expand Down Expand Up @@ -350,6 +353,7 @@ <h4><i class="fas fa-tags"></i> Tags All Objects</h4>

var all_graph = {};
$(document).ready(function(){
$("#incomplete_graph").hide();
$("#page-Decoded").addClass("active");

all_graph.node_graph = create_graph("{{ url_for('correlation.graph_node_json') }}?id={{ dict_object["correlation_id"] }}&type={{ dict_object["object_type"] }}&mode={{ dict_object["mode"] }}&level={{ dict_object["level"] }}&filter={{ dict_object["filter_str"] }}&max_nodes={{dict_object["max_nodes"]}}{% if 'type_id' in dict_object["metadata"] %}&subtype={{ dict_object["metadata"]["type_id"] }}{% endif %}");
Expand Down Expand Up @@ -526,6 +530,12 @@ <h4><i class="fas fa-tags"></i> Tags All Objects</h4>
// Loading ...
$("#graph_loading").remove();

if (!data.meta.complete){
$("#incomplete_graph").show();
}



})
.catch(function(error) {
$("#graph_loading").remove()
Expand Down
4 changes: 2 additions & 2 deletions var/www/templates/investigations/investigations.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>

<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
Expand Down

0 comments on commit 4567c9d

Please sign in to comment.