Add initial UI support for Webhook in tracker

This commit is contained in:
TonyJabbour 2021-09-28 20:31:19 +02:00
parent b3b30616b2
commit 06a886732c
5 changed files with 227 additions and 192 deletions

View file

@ -106,6 +106,9 @@ def get_tracker_tags(tracker_uuid):
def get_tracker_mails(tracker_uuid): def get_tracker_mails(tracker_uuid):
return list(r_serv_tracker.smembers('tracker:mail:{}'.format(tracker_uuid))) return list(r_serv_tracker.smembers('tracker:mail:{}'.format(tracker_uuid)))
def get_tracker_webhook(tracker_uuid):
return r_serv_tracker.hget('tracker:{}'.format(tracker_uuid), 'webhook')
def get_tracker_uuid_sources(tracker_uuid): def get_tracker_uuid_sources(tracker_uuid):
return list(r_serv_tracker.smembers(f'tracker:sources:{tracker_uuid}')) return list(r_serv_tracker.smembers(f'tracker:sources:{tracker_uuid}'))
@ -129,7 +132,7 @@ def get_tracker_last_seen(tracker_uuid):
else: else:
return None return None
def get_tracker_metedata(tracker_uuid, user_id=False, description=False, level=False, tags=False, mails=False, sources=True, sparkline=False): def get_tracker_metedata(tracker_uuid, user_id=False, description=False, level=False, tags=False, mails=False, sources=True, sparkline=False, webhook=False):
dict_uuid = {} dict_uuid = {}
dict_uuid['tracker'] = get_tracker_by_uuid(tracker_uuid) dict_uuid['tracker'] = get_tracker_by_uuid(tracker_uuid)
dict_uuid['type'] = get_tracker_type(tracker_uuid) dict_uuid['type'] = get_tracker_type(tracker_uuid)
@ -149,6 +152,8 @@ def get_tracker_metedata(tracker_uuid, user_id=False, description=False, level=F
dict_uuid['tags'] = get_tracker_tags(tracker_uuid) dict_uuid['tags'] = get_tracker_tags(tracker_uuid)
if sparkline: if sparkline:
dict_uuid['sparkline'] = get_tracker_sparkline(tracker_uuid) dict_uuid['sparkline'] = get_tracker_sparkline(tracker_uuid)
if webhook:
dict_uuid['webhook'] = get_tracker_webhook(tracker_uuid)
dict_uuid['uuid'] = tracker_uuid dict_uuid['uuid'] = tracker_uuid
return dict_uuid return dict_uuid

View file

@ -96,6 +96,7 @@ def add_tracked_menu():
tracker_type = request.form.get("tracker_type") tracker_type = request.form.get("tracker_type")
nb_words = request.form.get("nb_word", 1) nb_words = request.form.get("nb_word", 1)
description = request.form.get("description", '') description = request.form.get("description", '')
webhook = request.form.get("webhook", '')
level = request.form.get("level", 0) level = request.form.get("level", 0)
tags = request.form.get("tags", []) tags = request.form.get("tags", [])
mails = request.form.get("mails", []) mails = request.form.get("mails", [])
@ -125,7 +126,7 @@ def add_tracked_menu():
input_dict = {"tracker": tracker, "type": tracker_type, "nb_words": nb_words, input_dict = {"tracker": tracker, "type": tracker_type, "nb_words": nb_words,
"tags": tags, "mails": mails, "sources": sources, "tags": tags, "mails": mails, "sources": sources,
"level": level, "description": description} "level": level, "description": description, "webhook": webhook}
user_id = current_user.get_id() user_id = current_user.get_id()
# edit tracker # edit tracker
if tracker_uuid: if tracker_uuid:
@ -155,7 +156,7 @@ def edit_tracked_menu():
if res: # invalid access if res: # invalid access
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1] return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
dict_tracker = Tracker.get_tracker_metedata(tracker_uuid, user_id=True, level=True, description=True, tags=True, mails=True, sources=True) dict_tracker = Tracker.get_tracker_metedata(tracker_uuid, user_id=True, level=True, description=True, tags=True, mails=True, sources=True, webhook=True)
dict_tracker['tags'] = ' '.join(dict_tracker['tags']) dict_tracker['tags'] = ' '.join(dict_tracker['tags'])
dict_tracker['mails'] = ' '.join(dict_tracker['mails']) dict_tracker['mails'] = ' '.join(dict_tracker['mails'])
@ -202,7 +203,7 @@ def show_tracker():
if date_to: if date_to:
date_to = date_to.replace('-', '') date_to = date_to.replace('-', '')
tracker_metadata = Tracker.get_tracker_metedata(tracker_uuid, user_id=True, level=True, description=True, tags=True, mails=True, sources=True, sparkline=True) tracker_metadata = Tracker.get_tracker_metedata(tracker_uuid, user_id=True, level=True, description=True, tags=True, mails=True, sources=True, sparkline=True, webhook=True)
if tracker_metadata['type'] == 'yara': if tracker_metadata['type'] == 'yara':
yara_rule_content = Tracker.get_yara_rule_content(tracker_metadata['tracker']) yara_rule_content = Tracker.get_yara_rule_content(tracker_metadata['tracker'])

View file

@ -43,7 +43,7 @@
<div class="row"> <div class="row">
<div class="col-12 col-xl-9"> <div class="col-12 col-xl-9">
<div class="input-group mb-2 mr-sm-2"> <div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend"> <div class="input-group-prepend"-->
<div class="input-group-text bg-danger text-white"><i class="fas fa-tag"></i></div> <div class="input-group-text bg-danger text-white"><i class="fas fa-tag"></i></div>
</div> </div>
<input id="tags" name="tags" class="form-control" placeholder="Tags (optional, space separated)" type="text" {%if dict_tracker%}{%if dict_tracker['tags']%}value="{{dict_tracker['tags']}}"{%endif%}{%endif%}> <input id="tags" name="tags" class="form-control" placeholder="Tags (optional, space separated)" type="text" {%if dict_tracker%}{%if dict_tracker['tags']%}value="{{dict_tracker['tags']}}"{%endif%}{%endif%}>
@ -53,6 +53,12 @@
<div class="input-group-text bg-secondary text-white"><i class="fas fa-at"></i></div> <div class="input-group-text bg-secondary text-white"><i class="fas fa-at"></i></div>
</div> </div>
<input id="mails" name="mails" class="form-control" placeholder="E-Mails Notification (optional, space separated)" type="text" {%if dict_tracker%}{%if dict_tracker['mails']%}value="{{dict_tracker['mails']}}"{%endif%}{%endif%}> <input id="mails" name="mails" class="form-control" placeholder="E-Mails Notification (optional, space separated)" type="text" {%if dict_tracker%}{%if dict_tracker['mails']%}value="{{dict_tracker['mails']}}"{%endif%}{%endif%}>
</div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-secondary text-white"><i class="fas fa-at"></i></div>
</div>
<input id="webhook" name="webhook" class="form-control" placeholder="Webhook URL" type="text" {%if dict_tracker%}{%if dict_tracker['webhook']%}value="{{dict_tracker['webhook']}}"{%endif%}{%endif%}>
</div> </div>
<div class="input-group mb-2 mr-sm-2"> <div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend"> <div class="input-group-prepend">

View file

@ -74,6 +74,7 @@
<th>Created by</th> <th>Created by</th>
<th>First seen</th> <th>First seen</th>
<th>Last seen</th> <th>Last seen</th>
<th>Webhook URL</th>
<th>Tags <span class="btn-link btn-interaction mouse_pointer" title="Edit Tags List" onclick="edit_tags();"><i class="fas fa-pencil-alt" style="color:Red;"></i></span></th> <th>Tags <span class="btn-link btn-interaction mouse_pointer" title="Edit Tags List" onclick="edit_tags();"><i class="fas fa-pencil-alt" style="color:Red;"></i></span></th>
<th>Email <span class="btn-link btn-interaction mouse_pointer" title="Edit Email List" onclick="edit_mails();"><i class="fas fa-pencil-alt" style="color:Red;"></i></span></th> <th>Email <span class="btn-link btn-interaction mouse_pointer" title="Edit Email List" onclick="edit_mails();"><i class="fas fa-pencil-alt" style="color:Red;"></i></span></th>
</tr> </tr>
@ -95,6 +96,11 @@
{{ tracker_metadata['last_seen'][0:4] }}/{{ tracker_metadata['last_seen'][4:6] }}/{{ tracker_metadata['last_seen'][6:8] }} {{ tracker_metadata['last_seen'][0:4] }}/{{ tracker_metadata['last_seen'][4:6] }}/{{ tracker_metadata['last_seen'][6:8] }}
{% endif %} {% endif %}
</td> </td>
<td>
{% if tracker_metadata['wehook'] %}
{{ tracker_metadata['wehook'] }}
{% endif %}
</td>
<td> <td>
{% for tag in tracker_metadata['tags'] %} {% for tag in tracker_metadata['tags'] %}
<a href="{{ url_for('tags_ui.get_obj_by_tags') }}?object_type=item&ltags={{ tag }}"> <a href="{{ url_for('tags_ui.get_obj_by_tags') }}?object_type=item&ltags={{ tag }}">

View file

@ -13,21 +13,23 @@
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script> <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/bootstrap4.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.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/dataTables.bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/d3.min.js') }}"></script> <script src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/d3/sparklines.js')}}"></script> <script src="{{ url_for('static', filename='js/d3/sparklines.js') }}"></script>
<style> <style>
.btn-link { .btn-link {
color: #000000 color: #000000
} }
.mouse_pointer{
.mouse_pointer {
cursor: pointer; cursor: pointer;
} }
.lb-md { .lb-md {
font-size: 16px; font-size: 16px;
} }
@ -35,9 +37,9 @@
</head> </head>
<body> <body>
{% include 'nav_bar.html' %} {% include 'nav_bar.html' %}
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
{% include 'hunter/menu_sidebar.html' %} {% include 'hunter/menu_sidebar.html' %}
@ -46,7 +48,7 @@
<div class="card my-3"> <div class="card my-3">
<div class="card-header"> <div class="card-header">
<h5 class="card-title">Your {{filter_type}} Trackers</h5> <h5 class="card-title">Your {{ filter_type }} Trackers</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<table id="table_user_trackers" class="table table-striped table-bordered"> <table id="table_user_trackers" class="table table-striped table-bordered">
@ -56,6 +58,7 @@
<th>Tracker</th> <th>Tracker</th>
<th>First seen</th> <th>First seen</th>
<th>Last seen</th> <th>Last seen</th>
<th>Webhook URL</th>
<th>Email notification</th> <th>Email notification</th>
<th>sparkline</th> <th>sparkline</th>
</tr> </tr>
@ -63,15 +66,15 @@
<tbody style="font-size: 15px;"> <tbody style="font-size: 15px;">
{% for dict_uuid in user_term %} {% for dict_uuid in user_term %}
<tr> <tr>
<td>{{dict_uuid['type']}}</td> <td>{{ dict_uuid['type'] }}</td>
<td> <td>
<span> <span>
<a target="_blank" href="{{ url_for('hunter.show_tracker') }}?uuid={{ dict_uuid['uuid'] }}"> <a target="_blank" href="{{ url_for('hunter.show_tracker') }}?uuid={{ dict_uuid['uuid'] }}">
{% if dict_uuid['term']%} {% if dict_uuid['term'] %}
{% if dict_uuid['term']|length > 256 %} {% if dict_uuid['term']|length > 256 %}
{{ dict_uuid['term'][0:256]}}... {{ dict_uuid['term'][0:256] }}...
{% else %} {% else %}
{{ dict_uuid['term']}} {{ dict_uuid['term'] }}
{% endif %} {% endif %}
{% endif %} {% endif %}
</a> </a>
@ -86,12 +89,19 @@
</td> </td>
<td> <td>
{% if dict_uuid['first_seen'] %} {% if dict_uuid['first_seen'] %}
{{dict_uuid['first_seen'][0:4]}}/{{dict_uuid['first_seen'][4:6]}}/{{dict_uuid['first_seen'][6:8]}} {{ dict_uuid['first_seen'][0:4] }}/{{ dict_uuid['first_seen'][4:6] }}/
{{ dict_uuid['first_seen'][6:8] }}
{% endif %} {% endif %}
</td> </td>
<td> <td>
{% if dict_uuid['last_seen'] %} {% if dict_uuid['last_seen'] %}
{{dict_uuid['last_seen'][0:4]}}/{{dict_uuid['last_seen'][4:6]}}/{{dict_uuid['last_seen'][6:8]}} {{ dict_uuid['last_seen'][0:4] }}/{{ dict_uuid['last_seen'][4:6] }}/
{{ dict_uuid['last_seen'][6:8] }}
{% endif %}
</td>
<td>
{% if dict_uuid['webhook'] %}
{{ dict_uuid['webhook'] }}
{% endif %} {% endif %}
</td> </td>
<td> <td>
@ -109,7 +119,7 @@
<div class="card my-3"> <div class="card my-3">
<div class="card-header"> <div class="card-header">
<h5 class="card-title">Global {{filter_type}} Trackers</h5> <h5 class="card-title">Global {{ filter_type }} Trackers</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<table id="table_global_trackers" class="table table-striped table-bordered"> <table id="table_global_trackers" class="table table-striped table-bordered">
@ -119,6 +129,7 @@
<th>Tracker</th> <th>Tracker</th>
<th>First seen</th> <th>First seen</th>
<th>Last seen</th> <th>Last seen</th>
<th>Webhook URL</th>
<th>Email notification</th> <th>Email notification</th>
<th>sparkline</th> <th>sparkline</th>
</tr> </tr>
@ -126,15 +137,15 @@
<tbody style="font-size: 15px;"> <tbody style="font-size: 15px;">
{% for dict_uuid in global_term %} {% for dict_uuid in global_term %}
<tr> <tr>
<td>{{dict_uuid['type']}}</td> <td>{{ dict_uuid['type'] }}</td>
<td> <td>
<span> <span>
<a target="_blank" href="{{ url_for('hunter.show_tracker') }}?uuid={{ dict_uuid['uuid'] }}"> <a target="_blank" href="{{ url_for('hunter.show_tracker') }}?uuid={{ dict_uuid['uuid'] }}">
{% if dict_uuid['term']%} {% if dict_uuid['term'] %}
{% if dict_uuid['term']|length > 256 %} {% if dict_uuid['term']|length > 256 %}
{{ dict_uuid['term'][0:256]}}... {{ dict_uuid['term'][0:256] }}...
{% else %} {% else %}
{{ dict_uuid['term']}} {{ dict_uuid['term'] }}
{% endif %} {% endif %}
{% endif %} {% endif %}
</a> </a>
@ -149,12 +160,19 @@
</td> </td>
<td> <td>
{% if dict_uuid['first_seen'] %} {% if dict_uuid['first_seen'] %}
{{dict_uuid['first_seen'][0:4]}}/{{dict_uuid['first_seen'][4:6]}}/{{dict_uuid['first_seen'][6:8]}} {{ dict_uuid['first_seen'][0:4] }}/{{ dict_uuid['first_seen'][4:6] }}/
{{ dict_uuid['first_seen'][6:8] }}
{% endif %} {% endif %}
</td> </td>
<td> <td>
{% if dict_uuid['last_seen'] %} {% if dict_uuid['last_seen'] %}
{{dict_uuid['last_seen'][0:4]}}/{{dict_uuid['last_seen'][4:6]}}/{{dict_uuid['last_seen'][6:8]}} {{ dict_uuid['last_seen'][0:4] }}/{{ dict_uuid['last_seen'][4:6] }}/
{{ dict_uuid['last_seen'][6:8] }}
{% endif %}
</td>
<td>
{% if dict_uuid['webhook'] %}
{{ dict_uuid['webhook'] }}
{% endif %} {% endif %}
</td> </td>
<td> <td>
@ -171,18 +189,17 @@
</div> </div>
<a class="btn btn-info my-4" href="{{ url_for('hunter.add_tracked_menu') }}">
<a class="btn btn-info my-4" href="{{url_for('hunter.add_tracked_menu')}}">
<i class="fas fa-plus-circle ml-auto"></i> <i class="fas fa-plus-circle ml-auto"></i>
Create New Tracker Create New Tracker
</a> </a>
</div> </div>
</div> </div>
</div> </div>
<script> <script>
$(document).ready(function(){ $(document).ready(function () {
$("#page-Tracker").addClass("active"); $("#page-Tracker").addClass("active");
$("#nav_tracker_{{filter_type}}").addClass("active"); $("#nav_tracker_{{filter_type}}").addClass("active");
@ -196,30 +213,30 @@ $(document).ready(function(){
$('#table_user_trackers').DataTable({ $('#table_user_trackers').DataTable({
"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]], "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
"iDisplayLength": 10, "iDisplayLength": 10,
"order": [[ 0, "desc" ]] "order": [[0, "desc"]]
}); });
$('#table_global_trackers').DataTable({ $('#table_global_trackers').DataTable({
"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]], "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
"iDisplayLength": 10, "iDisplayLength": 10,
"order": [[ 0, "desc" ]] "order": [[0, "desc"]]
}); });
}); });
function toggle_sidebar(){ function toggle_sidebar() {
if($('#nav_menu').is(':visible')){ if ($('#nav_menu').is(':visible')) {
$('#nav_menu').hide(); $('#nav_menu').hide();
$('#side_menu').removeClass('border-right') $('#side_menu').removeClass('border-right')
$('#side_menu').removeClass('col-lg-2') $('#side_menu').removeClass('col-lg-2')
$('#core_content').removeClass('col-lg-10') $('#core_content').removeClass('col-lg-10')
}else{ } else {
$('#nav_menu').show(); $('#nav_menu').show();
$('#side_menu').addClass('border-right') $('#side_menu').addClass('border-right')
$('#side_menu').addClass('col-lg-2') $('#side_menu').addClass('col-lg-2')
$('#core_content').addClass('col-lg-10') $('#core_content').addClass('col-lg-10')
} }
} }
</script> </script>
</body> </body>