Skip to content

Commit 4ee8e05

Browse files
committed
chg: [show tracker] filter result by object type
1 parent 76369d7 commit 4ee8e05

File tree

4 files changed

+131
-63
lines changed

4 files changed

+131
-63
lines changed

bin/lib/Tracker.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,22 @@ def get_objs(self):
390390
def get_nb_objs_by_date(self, date):
391391
return r_tracker.scard(f'tracker:objs:{self.uuid}:{date}')
392392

393-
def get_objs_by_date(self, date):
394-
return r_tracker.smembers(f'tracker:objs:{self.uuid}:{date}')
393+
def get_objs_by_date(self, date, obj_types=[]):
394+
objs = r_tracker.smembers(f'tracker:objs:{self.uuid}:{date}')
395+
if obj_types:
396+
l_objs = set()
397+
for obj in objs:
398+
obj_type = obj.split(':', 1)[0]
399+
if obj_type in obj_types:
400+
l_objs.add(obj)
401+
return l_objs
402+
else:
403+
return objs
395404

396-
def get_objs_by_daterange(self, date_from, date_to):
405+
def get_objs_by_daterange(self, date_from, date_to, obj_types):
397406
objs = set()
398407
for date in Date.get_daterange(date_from, date_to):
399-
objs |= self.get_objs_by_date(date)
408+
objs |= self.get_objs_by_date(date, obj_types=obj_types)
400409
return objs
401410

402411
def get_obj_dates(self, obj_type, subtype, obj_id):

var/www/blueprints/hunters.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,34 @@ def tracked_menu_admin():
153153
bootstrap_label=bootstrap_label)
154154

155155

156-
@hunters.route("/tracker/show")
156+
@hunters.route("/tracker/show", methods=['GET', 'POST'])
157157
@login_required
158158
@login_read_only
159159
def show_tracker():
160160
user_id = current_user.get_user_id()
161161
user_org = current_user.get_org()
162162
user_role = current_user.get_role()
163-
tracker_uuid = request.args.get('uuid', None)
163+
filter_obj_types = []
164+
165+
if request.method == 'POST':
166+
tracker_uuid = request.form.get('tracker_uuid', None)
167+
date_from = request.form.get('date_from')
168+
date_to = request.form.get('date_to')
169+
for obj_type in Tracker.get_objects_tracked():
170+
new_filter = request.form.get(f'{obj_type}_obj')
171+
if new_filter:
172+
filter_obj_types.append(obj_type)
173+
if sorted(filter_obj_types) == Tracker.get_objects_tracked():
174+
filter_obj_types = []
175+
else:
176+
tracker_uuid = request.args.get('uuid', None)
177+
date_from = request.args.get('date_from')
178+
date_to = request.args.get('date_to')
179+
164180
res = Tracker.api_check_tracker_acl(tracker_uuid, user_org, user_id, user_role, 'view')
165181
if res: # invalid access
166182
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
167183

168-
date_from = request.args.get('date_from')
169-
date_to = request.args.get('date_to')
170-
171184
if date_from:
172185
date_from = date_from.replace('-', '')
173186
if date_to:
@@ -190,7 +203,7 @@ def show_tracker():
190203

191204
if date_from:
192205
date_from, date_to = Date.sanitise_daterange(date_from, date_to)
193-
objs = tracker.get_objs_by_daterange(date_from, date_to)
206+
objs = tracker.get_objs_by_daterange(date_from, date_to, filter_obj_types)
194207
meta['objs'] = ail_objects.get_objects_meta(objs, options={'last_full_date'}, flask_context=True)
195208
else:
196209
date_from = ''
@@ -204,9 +217,10 @@ def show_tracker():
204217
meta['filters'] = json.dumps(meta['filters'], indent=4)
205218

206219
return render_template("tracker_show.html", meta=meta,
207-
rule_content=yara_rule_content,
208-
typo_squatting=typo_squatting,
209-
bootstrap_label=bootstrap_label)
220+
rule_content=yara_rule_content,
221+
typo_squatting=typo_squatting,
222+
filter_obj_types=filter_obj_types,
223+
bootstrap_label=bootstrap_label)
210224

211225
def parse_add_edit_request(request_form):
212226
to_track = request_form.get("tracker")

var/www/templates/hunter/tracker_show.html

+70-27
Original file line numberDiff line numberDiff line change
@@ -223,40 +223,83 @@ <h5 class="mb-0">Yara Rule:</h5>
223223
</p>
224224
{% endif %}
225225

226-
<div class="card mb-5 mt-1">
227-
<div class="card-body">
228-
229-
<div class="row mb-3">
230-
<div class="col-md-6">
231-
<div class="input-group" id="date-range-from">
232-
<div class="input-group-prepend"><span class="input-group-text"><i
233-
class="far fa-calendar-alt" aria-hidden="true"></i></span></div>
234-
<input class="form-control" id="date-range-from-input" placeholder="yyyy-mm-dd"
235-
name="date_from" autocomplete="off"
236-
{% if meta['date_from'] %}value="{{ meta['date_from'][0:4] }}-{{ meta['date_from'][4:6] }}-{{ meta['date_from'][6:8] }}"
237-
{% elif meta['first_seen'] %}value="{{ meta['first_seen'][0:4] }}-{{ meta['first_seen'][4:6] }}-{{ meta['first_seen'][6:8] }}"
238-
{% endif %}>
226+
<form action="{{ url_for('hunters.show_tracker') }}" method='post'>
227+
<input id="tracker_uuid" name="tracker_uuid" class="form-control" type="text" value="{{ meta['uuid'] }}" hidden>
228+
229+
<div class="card mb-5 mt-1">
230+
<div class="card-body">
231+
232+
<div class="row mb-3">
233+
<div class="col-md-6">
234+
<div class="input-group" id="date-range-from">
235+
<div class="input-group-prepend"><span class="input-group-text"><i
236+
class="far fa-calendar-alt" aria-hidden="true"></i></span></div>
237+
<input class="form-control" id="date-range-from-input" placeholder="yyyy-mm-dd"
238+
name="date_from" autocomplete="off"
239+
{% if meta['date_from'] %}value="{{ meta['date_from'][0:4] }}-{{ meta['date_from'][4:6] }}-{{ meta['date_from'][6:8] }}"
240+
{% elif meta['first_seen'] %}value="{{ meta['first_seen'][0:4] }}-{{ meta['first_seen'][4:6] }}-{{ meta['first_seen'][6:8] }}"
241+
{% endif %}>
242+
</div>
243+
</div>
244+
<div class="col-md-6">
245+
<div class="input-group" id="date-range-to">
246+
<div class="input-group-prepend"><span class="input-group-text"><i
247+
class="far fa-calendar-alt" aria-hidden="true"></i></span></div>
248+
<input class="form-control" id="date-range-to-input" placeholder="yyyy-mm-dd"
249+
name="date_to" autocomplete="off"
250+
{% if meta['date_to'] %}value="{{ meta['date_to'][0:4] }}-{{ meta['date_to'][4:6] }}-{{ meta['date_to'][6:8] }}"
251+
{% elif meta['last_seen'] %}value="{{ meta['last_seen'][0:4] }}-{{ meta['last_seen'][4:6] }}-{{ meta['last_seen'][6:8] }}"
252+
{% endif %}>
253+
</div>
239254
</div>
240255
</div>
241-
<div class="col-md-6">
242-
<div class="input-group" id="date-range-to">
243-
<div class="input-group-prepend"><span class="input-group-text"><i
244-
class="far fa-calendar-alt" aria-hidden="true"></i></span></div>
245-
<input class="form-control" id="date-range-to-input" placeholder="yyyy-mm-dd"
246-
name="date_to" autocomplete="off"
247-
{% if meta['date_to'] %}value="{{ meta['date_to'][0:4] }}-{{ meta['date_to'][4:6] }}-{{ meta['date_to'][6:8] }}"
248-
{% elif meta['last_seen'] %}value="{{ meta['last_seen'][0:4] }}-{{ meta['last_seen'][4:6] }}-{{ meta['last_seen'][6:8] }}"
249-
{% endif %}>
256+
<h5>Filter Objects:</h5>
257+
<div class="row">
258+
<div class="col-lg-6">
259+
<div class="custom-control custom-switch mt-1">
260+
<input class="custom-control-input" type="checkbox" name="decoded_obj" id="decoded_obj" {% if 'decoded' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
261+
<label class="custom-control-label" for="decoded_obj"><i class="fas fa-lock-open"></i>&nbsp;Decoded <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="Content that has been decoded from an encoded format, such as base64"></i></label>
262+
</div>
263+
<div class="custom-control custom-switch mt-1">
264+
<input class="custom-control-input" type="checkbox" name="item_obj" id="item_obj" {% if 'item' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
265+
<label class="custom-control-label" for="item_obj"><i class="fas fa-file"></i>&nbsp;Item <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="Text that has been processed by AIL. It can include various types of extracted information"></i></label>
266+
</div>
267+
<div class="custom-control custom-switch mt-1">
268+
<input class="custom-control-input" type="checkbox" name="pgp_obj" id="pgp_obj" {% if 'pgp' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
269+
<label class="custom-control-label" for="pgp_obj"><i class="fas fa-key"></i>&nbsp;PGP <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="PGP key/block metadata"></i></label>
270+
</div>
271+
<div class="custom-control custom-switch mt-1">
272+
<input class="custom-control-input" type="checkbox" name="title_obj" id="title_obj" {% if 'title' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
273+
<label class="custom-control-label" for="title_obj"><i class="fas fa-heading"></i>&nbsp;Title <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="Title that has been extracted from a HTML page"></i></label>
274+
</div>
275+
</div>
276+
<div class="col-lg-6">
277+
<div class="custom-control custom-switch mt-1">
278+
<input class="custom-control-input" type="checkbox" name="message_obj" id="message_obj" {% if 'message' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
279+
<label class="custom-control-label" for="message_obj"><i class="fas fa-comment-dots"></i>&nbsp;Message <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="Messages from Chats"></i></label>
280+
</div>
281+
<div class="custom-control custom-switch mt-1">
282+
<input class="custom-control-input" type="checkbox" name="ocr_obj" id="ocr_obj" {% if 'ocr' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
283+
<label class="custom-control-label" for="ocr_obj"><i class="fas fa-expand"></i>&nbsp;OCR <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="Text extracted from Images"></i></label>
284+
</div>
285+
<div class="custom-control custom-switch mt-1">
286+
<input class="custom-control-input" type="checkbox" name="barcode_obj" id="barcode_obj" {% if 'barcode' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
287+
<label class="custom-control-label" for="barcode_obj"><i class="fas fa-barcode"></i>&nbsp;Barcode <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="Qcodes Extracted from Images ans Screenshots"></i></label>
288+
</div>
289+
<div class="custom-control custom-switch mt-1">
290+
<input class="custom-control-input" type="checkbox" name="qrcode_obj" id="qrcode_obj" {% if 'qrcode' in filter_obj_types or filter_obj_types|length == 0 %}checked=""{% endif %}>
291+
<label class="custom-control-label" for="qrcode_obj"><i class="fas fa-qrcode"></i>&nbsp;Qrcode <i class="fas fa-info-circle text-info" data-toggle="tooltip" data-placement="right" title="Qcodes Extracted from Images ans Screenshots"></i></label>
292+
</div>
250293
</div>
251294
</div>
252-
</div>
253295

254-
<button class="btn btn-info" type="button" id="button-search-tags" onclick="getItems();">
255-
<i class="fas fa-search"></i> Tracked Objects
256-
</button>
296+
<button class="btn btn-info mt-2">
297+
<i class="fas fa-search"></i> Tracked Objects
298+
</button>
257299

300+
</div>
258301
</div>
259-
</div>
302+
</form>
260303

261304
</div>
262305
</div>

var/www/templates/settings/menu_sidebar.html

+25-23
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,31 @@ <h5 class="d-flex text-muted w-100" id="nav_server">
1717
</a>
1818
</li>
1919
</ul>
20-
<h5 class="d-flex text-muted w-100" id="nav_sync">
21-
<span>AIL SYNC</span>
22-
</h5>
23-
<ul class="nav flex-md-column flex-row navbar-nav justify-content-between w-100"> <!--nav-pills-->
24-
<li class="nav-item">
25-
<a class="nav-link" href="{{url_for('ail_2_ail_sync.ail_2_ail_dashboard')}}" id="nav_ail_sync">
26-
<img src="{{ url_for('static', filename='image/ail.png')}}" alt="AIL servers" style="width:25px;">
27-
<span>AIL SYNC</span>
28-
</a>
29-
</li>
30-
<li class="nav-item">
31-
<a class="nav-link" href="{{url_for('ail_2_ail_sync.ail_servers')}}" id="nav_ail_servers">
32-
<i class="fas fa-server"></i>
33-
<span>Servers</span>
34-
</a>
35-
</li>
36-
<li class="nav-item">
37-
<a class="nav-link" href="{{url_for('ail_2_ail_sync.sync_queues')}}" id="navsync_queues">
38-
<i class="fas fa-stream"></i>
39-
<span>Sync queues</span>
40-
</a>
41-
</li>
42-
</ul>
20+
{% if acl_admin %}
21+
<h5 class="d-flex text-muted w-100" id="nav_sync">
22+
<span>AIL SYNC</span>
23+
</h5>
24+
<ul class="nav flex-md-column flex-row navbar-nav justify-content-between w-100"> <!--nav-pills-->
25+
<li class="nav-item">
26+
<a class="nav-link" href="{{url_for('ail_2_ail_sync.ail_2_ail_dashboard')}}" id="nav_ail_sync">
27+
<img src="{{ url_for('static', filename='image/ail.png')}}" alt="AIL servers" style="width:25px;">
28+
<span>AIL SYNC</span>
29+
</a>
30+
</li>
31+
<li class="nav-item">
32+
<a class="nav-link" href="{{url_for('ail_2_ail_sync.ail_servers')}}" id="nav_ail_servers">
33+
<i class="fas fa-server"></i>
34+
<span>Servers</span>
35+
</a>
36+
</li>
37+
<li class="nav-item">
38+
<a class="nav-link" href="{{url_for('ail_2_ail_sync.sync_queues')}}" id="navsync_queues">
39+
<i class="fas fa-stream"></i>
40+
<span>Sync queues</span>
41+
</a>
42+
</li>
43+
</ul>
44+
{% endif %}
4345
<h5 class="d-flex text-muted w-100" id="nav_settings">
4446
<span>Settings</span>
4547
</h5>

0 commit comments

Comments
 (0)