Skip to content

Commit

Permalink
chg: [correlation graph] select correlation depth
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed May 26, 2023
1 parent b4f1a43 commit 5d4b718
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
23 changes: 19 additions & 4 deletions var/www/blueprints/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ def sanitise_nb_max_nodes(nb_max_nodes):
nb_max_nodes = 300
return nb_max_nodes

def sanitise_level(level):
try:
level = int(level)
if level < 0:
level = 2
except (TypeError, ValueError):
level = 2
return level

# ============= ROUTES ==============
@correlation.route('/correlation/show', methods=['GET', 'POST'])
@login_required
Expand All @@ -67,6 +76,7 @@ def show_correlation():
mode = 'inter'
else:
mode = 'union'
level = sanitise_level(request.form.get('level'))

## get all selected correlations
filter_types = []
Expand Down Expand Up @@ -104,7 +114,7 @@ def show_correlation():

# redirect to keep history and bookmark
return redirect(url_for('correlation.show_correlation', type=object_type, subtype=subtype, id=obj_id, mode=mode,
max_nodes=max_nodes, filter=filter_types))
max_nodes=max_nodes, level=level, filter=filter_types))

# request.method == 'GET'
else:
Expand All @@ -113,6 +123,7 @@ def show_correlation():
obj_id = request.args.get('id')
max_nodes = sanitise_nb_max_nodes(request.args.get('max_nodes'))
mode = sanitise_graph_mode(request.args.get('mode'))
level = sanitise_level(request.args.get('level'))

related_btc = bool(request.args.get('related_btc', False))

Expand All @@ -125,7 +136,7 @@ def show_correlation():
else:
dict_object = {"object_type": obj_type,
"correlation_id": obj_id,
"max_nodes": max_nodes, "mode": mode,
"max_nodes": max_nodes, "mode": mode, "level": level,
"filter": filter_types, "filter_str": ",".join(filter_types),
"metadata": ail_objects.get_object_meta(obj_type, subtype, obj_id,
options={'tags'}, flask_context=True),
Expand Down Expand Up @@ -175,10 +186,11 @@ def graph_node_json():
subtype = request.args.get('subtype')
obj_type = request.args.get('type')
max_nodes = sanitise_nb_max_nodes(request.args.get('max_nodes'))
level = sanitise_level(request.args.get('level'))

filter_types = ail_objects.sanitize_objs_types(request.args.get('filter', '').split(','))

json_graph = ail_objects.get_correlations_graph_node(obj_type, subtype, obj_id, filter_types=filter_types, max_nodes=max_nodes, level=2, flask_context=True)
json_graph = ail_objects.get_correlations_graph_node(obj_type, subtype, obj_id, filter_types=filter_types, max_nodes=max_nodes, level=level, flask_context=True)
#json_graph = Correlate_object.get_graph_node_object_correlation(obj_type, obj_id, 'union', correlation_names, correlation_objects, requested_correl_type=subtype, max_nodes=max_nodes)
return jsonify(json_graph)

Expand All @@ -204,6 +216,7 @@ def correlation_tags_add():
subtype = request.form.get('tag_subtype', '')
obj_type = request.form.get('tag_obj_type')
nb_max = sanitise_nb_max_nodes(request.form.get('tag_nb_max'))
level = sanitise_level(request.form.get('tag_level'))
filter_types = ail_objects.sanitize_objs_types(request.form.get('tag_filter', '').split(','))

if not ail_objects.exists_obj(obj_type, subtype, obj_id):
Expand Down Expand Up @@ -232,8 +245,10 @@ def correlation_tags_add():
tags = []

if tags:
ail_objects.obj_correlations_objs_add_tags(obj_type, subtype, obj_id, tags, filter_types=filter_types, lvl=2, nb_max=nb_max)
ail_objects.obj_correlations_objs_add_tags(obj_type, subtype, obj_id, tags, filter_types=filter_types,
lvl=level + 1, nb_max=nb_max)

return redirect(url_for('correlation.show_correlation',
type=obj_type, subtype=subtype, id=obj_id,
level=level,
filter=",".join(filter_types)))
24 changes: 17 additions & 7 deletions var/www/templates/correlation/show_correlation.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,23 @@
</div>

</li>
{# <li class="list-group-item text-left">#}
{# <div class="d-flex mt-1">#}
{# Union&nbsp;&nbsp;#}
{# <div class="custom-control custom-switch">#}
{# <input class="custom-control-input" type="checkbox" name="mode" value="True" id="mode" {%if dict_object["mode"]=="inter"%}checked{%endif%}>#}
{# <label class="custom-control-label" for="mode">Intersection</label>#}
{# </div>#}
{# </div>#}
{# </li>#}
<li class="list-group-item text-left">
<div class="d-flex mt-1">
Union&nbsp;&nbsp;
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" name="mode" value="True" id="mode" {%if dict_object["mode"]=="inter"%}checked{%endif%}>
<label class="custom-control-label" for="mode">Intersection</label>
</div>

<div class="form-group">
<label for="max_nb_nodes_in">Correlation Depth:</label>
<input class="form-control" type="number" value="{{dict_object["level"]}}" min="0" id="level" name="level">
</div>


</li>
<li class="list-group-item text-left">

Expand Down Expand Up @@ -316,6 +325,7 @@ <h4><i class="fas fa-tags"></i> Tags All Objects</h4>
<input type="hidden" id="tag_obj_type" name="tag_obj_type" value="{{ dict_object["object_type"] }}">
<input type="hidden" id="tag_subtype" name="tag_subtype" value="{{ dict_object["metadata"]["type_id"] }}">
<input type="hidden" id="tag_obj_id" name="tag_obj_id" value="{{ dict_object["correlation_id"] }}">
<input type="hidden" id="tag_level" name="tag_level" value="{{dict_object["level"]}}">
<input type="hidden" id="tag_nb_max" name="tag_nb_max" value="{{dict_object["max_nodes"]}}">
<input type="hidden" id="filter" name="tag_filter" value="{{dict_object["filter_str"]}}">
{% include 'tags/block_tags_selector.html' %}
Expand All @@ -336,7 +346,7 @@ <h4><i class="fas fa-tags"></i> Tags All Objects</h4>
$(document).ready(function(){
$("#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"] }}&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 %}");
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 %}");
{% if dict_object["object_type"] in ["cryptocurrency", "pgp", "username"] %}
all_graph.line_chart = create_line_chart('graph_line', "{{ url_for('objects_subtypes.objects_cve_graphline_json') }}?type={{ dict_object["object_type"] }}&subtype={{dict_object["metadata"]["type_id"]}}&id={{dict_object["correlation_id"]}}");
{% elif dict_object["object_type"] == "decoded" %}
Expand Down

0 comments on commit 5d4b718

Please sign in to comment.