diff --git a/bin/packages/config.cfg.sample b/bin/packages/config.cfg.sample index ec51e715..ae015d8e 100644 --- a/bin/packages/config.cfg.sample +++ b/bin/packages/config.cfg.sample @@ -162,6 +162,11 @@ host = localhost port = 6382 db = 7 +[ARDB_Statistics] +host = localhost +port = 6382 +db = 8 + [Url] cc_critical = DE diff --git a/var/www/modules/Flask_config.py b/var/www/modules/Flask_config.py index 3996b14c..80ef9f18 100644 --- a/var/www/modules/Flask_config.py +++ b/var/www/modules/Flask_config.py @@ -90,6 +90,12 @@ r_serv_db = redis.StrictRedis( db=cfg.getint("ARDB_DB", "db"), decode_responses=True) +r_serv_statistics = redis.StrictRedis( + host=cfg.get("ARDB_Statistics", "host"), + port=cfg.getint("ARDB_Statistics", "port"), + db=cfg.getint("ARDB_Statistics", "db"), + decode_responses=True) + sys.path.append('../../configs/keys') # MISP # diff --git a/var/www/modules/Tags/Flask_Tags.py b/var/www/modules/Tags/Flask_Tags.py index 31877d70..be85ee92 100644 --- a/var/www/modules/Tags/Flask_Tags.py +++ b/var/www/modules/Tags/Flask_Tags.py @@ -9,6 +9,7 @@ from flask import Flask, render_template, jsonify, request, Blueprint, redirect, import json from datetime import datetime +import ssdeep import Paste @@ -22,6 +23,7 @@ app = Flask_config.app cfg = Flask_config.cfg r_serv_tags = Flask_config.r_serv_tags r_serv_metadata = Flask_config.r_serv_metadata +r_serv_statistics = Flask_config.r_serv_statistics max_preview_char = Flask_config.max_preview_char max_preview_modal = Flask_config.max_preview_modal bootstrap_label = Flask_config.bootstrap_label @@ -297,6 +299,26 @@ def confirm_tag(): return 'incompatible tag' +@Tags.route("/Tags/tag_validation") +def tag_validation(): + + path = request.args.get('paste') + tag = request.args.get('tag') + status = request.args.get('status') + + if (status == 'fp' or status == 'tp') and r_serv_tags.sismember('list_tags', tag): + + tag_hash = ssdeep.hash(tag) + r_serv_statistics.hset(tag_hash, status, path) + if status == 'tp': + r_serv_statistics.hdel(tag_hash, 'fp') + else: + r_serv_statistics.hdel(tag_hash, 'tp') + + return redirect(url_for('showsavedpastes.showsavedpaste', paste=path)) + else: + return 'input error' + @Tags.route("/Tags/addTags") def addTags(): diff --git a/var/www/modules/showpaste/Flask_showpaste.py b/var/www/modules/showpaste/Flask_showpaste.py index 9a718305..0112b3ec 100644 --- a/var/www/modules/showpaste/Flask_showpaste.py +++ b/var/www/modules/showpaste/Flask_showpaste.py @@ -9,6 +9,7 @@ import json import flask from flask import Flask, render_template, jsonify, request, Blueprint, make_response import difflib +import ssdeep import Paste @@ -20,6 +21,7 @@ cfg = Flask_config.cfg r_serv_pasteName = Flask_config.r_serv_pasteName r_serv_metadata = Flask_config.r_serv_metadata r_serv_tags = Flask_config.r_serv_tags +r_serv_statistics = Flask_config.r_serv_statistics max_preview_char = Flask_config.max_preview_char max_preview_modal = Flask_config.max_preview_modal DiffMaxLineLength = Flask_config.DiffMaxLineLength @@ -112,9 +114,21 @@ def showpaste(content_range): for tag in l_tags: if(tag[9:28] == 'automatic-detection'): - list_tags.append( (tag, True) ) + automatic = True else: - list_tags.append( (tag, False) ) + automatic = False + + tag_hash = ssdeep.hash(tag) + if r_serv_statistics.hexists(tag_hash, 'tp'): + tag_status_tp = True + else: + tag_status_tp = False + if r_serv_statistics.hexists(tag_hash, 'fp'): + tag_status_fp = True + else: + tag_status_fp = False + + list_tags.append( (tag, automatic, tag_status_tp, tag_status_fp) ) if Flask_config.pymisp is False: misp = False diff --git a/var/www/modules/showpaste/templates/show_saved_paste.html b/var/www/modules/showpaste/templates/show_saved_paste.html index 8209ba4b..1340f471 100644 --- a/var/www/modules/showpaste/templates/show_saved_paste.html +++ b/var/www/modules/showpaste/templates/show_saved_paste.html @@ -122,6 +122,28 @@ {{ tag[0] }}