From 0ee36e484f75698f8604afa826249036db0a5de3 Mon Sep 17 00:00:00 2001 From: Terrtia Date: Tue, 19 Jun 2018 11:31:30 +0200 Subject: [PATCH] fix hive connection + submitted dir creation --- .gitignore | 3 + var/www/modules/Flask_config.py | 19 +++++-- .../modules/PasteSubmit/Flask_PasteSubmit.py | 24 +++++++- .../templates/edit_tag_export.html | 55 ++++++++++++------- var/www/update_thirdparty.sh | 6 ++ 5 files changed, 78 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 4a266743..e74906ae 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ BASE64 DATA_ARDB indexdir/ logs/ +old/ # Webstuff var/www/static/ @@ -26,9 +27,11 @@ var/www/static/ !var/www/static/js/plot-graph.js !var/www/static/js/trendingchart.js var/www/templates/header.html +var/www/submitted # Local config bin/packages/config.cfg +configs/keys # installed files nltk_data/ diff --git a/var/www/modules/Flask_config.py b/var/www/modules/Flask_config.py index b377cbc5..afccb9df 100644 --- a/var/www/modules/Flask_config.py +++ b/var/www/modules/Flask_config.py @@ -93,8 +93,8 @@ r_serv_db = redis.StrictRedis( sys.path.append('../../configs/keys') # MISP # -from pymisp import PyMISP try: + from pymisp import PyMISP from mispKEYS import misp_url, misp_key, misp_verifycert pymisp = PyMISP(misp_url, misp_key, misp_verifycert) misp_event_url = misp_url + '/events/view/' @@ -104,23 +104,30 @@ except: pymisp = False misp_event_url = '#' # The Hive # -from thehive4py.api import TheHiveApi -import thehive4py.exceptions try: - from theHiveKEYS import the_hive_url, the_hive_key + from thehive4py.api import TheHiveApi + import thehive4py.exceptions + from theHiveKEYS import the_hive_url, the_hive_key, the_hive_verifycert if the_hive_url == '': HiveApi = False hive_case_url = '#' print('The HIVE not connected') else: - HiveApi = TheHiveApi(the_hive_url, the_hive_key) + HiveApi = TheHiveApi(the_hive_url, the_hive_key, cert=the_hive_verifycert) hive_case_url = the_hive_url+'/index.html#/case/id_here/details' - print('The Hive connected') + #HiveApi.do_patch(the_hive_url) except: print('The HIVE not connected') HiveApi = False hive_case_url = '#' +try: + HiveApi.get_alert(0) + print('The Hive connected') +except thehive4py.exceptions.AlertException: + HiveApi = False + print('The Hive not connected') + # VARIABLES # max_preview_char = int(cfg.get("Flask", "max_preview_char")) # Maximum number of character to display in the tooltip max_preview_modal = int(cfg.get("Flask", "max_preview_modal")) # Maximum number of character to display in the modal diff --git a/var/www/modules/PasteSubmit/Flask_PasteSubmit.py b/var/www/modules/PasteSubmit/Flask_PasteSubmit.py index 6ae9e891..28d3550f 100644 --- a/var/www/modules/PasteSubmit/Flask_PasteSubmit.py +++ b/var/www/modules/PasteSubmit/Flask_PasteSubmit.py @@ -23,8 +23,16 @@ import Paste from pytaxonomies import Taxonomies from pymispgalaxies import Galaxies, Clusters -from pymisp.mispevent import MISPObject -from thehive4py.models import Case, CaseTask, CustomFieldHelper, CaseObservable +try: + from pymisp.mispevent import MISPObject + flag_misp = True +except: + flag_misp = False +try: + from thehive4py.models import Case, CaseTask, CustomFieldHelper, CaseObservable + flag_hive = True +except: + flag_hive = False # ============ VARIABLES ============ import Flask_config @@ -37,8 +45,12 @@ r_serv_db = Flask_config.r_serv_db r_serv_log_submit = Flask_config.r_serv_log_submit pymisp = Flask_config.pymisp +if pymisp is False: + flag_misp = False HiveApi = Flask_config.HiveApi +if HiveApi is False: + flag_hive = False PasteSubmit = Blueprint('PasteSubmit', __name__, template_folder='templates') @@ -308,6 +320,10 @@ def submit(): # clean file name UUID = clean_filename(paste_name)''' + # create submitted dir + if not os.path.exists(UPLOAD_FOLDER): + os.makedirs(UPLOAD_FOLDER) + if not '.' in file.filename: full_path = os.path.join(UPLOAD_FOLDER, UUID) else: @@ -518,7 +534,9 @@ def edit_tag_export(): status_misp=status_misp, status_hive=status_hive, nb_tags_whitelist_misp=nb_tags_whitelist_misp, - nb_tags_whitelist_hive=nb_tags_whitelist_hive) + nb_tags_whitelist_hive=nb_tags_whitelist_hive, + flag_misp=flag_misp, + flag_hive=flag_hive) @PasteSubmit.route("/PasteSubmit/tag_export_edited", methods=['POST']) def tag_export_edited(): diff --git a/var/www/modules/PasteSubmit/templates/edit_tag_export.html b/var/www/modules/PasteSubmit/templates/edit_tag_export.html index 17cba8be..01822042 100644 --- a/var/www/modules/PasteSubmit/templates/edit_tag_export.html +++ b/var/www/modules/PasteSubmit/templates/edit_tag_export.html @@ -71,16 +71,24 @@
- {% if misp_active %} - - Disable Event Creation - - {% endif %} - {% if not misp_active %} - - Enable Event Creation - - {% endif %} + {% if flag_misp %} + {% if misp_active %} + + Disable Event Creation + + {% endif %} + {% if not misp_active %} + + Enable Event Creation + + {% endif %} + {% endif %} + + {% if not flag_misp %} + + {% endif %} @@ -101,16 +109,23 @@ - {% if hive_active %} - - Disable Alert Creation - - {% endif %} - {% if not hive_active %} - - Enable Alert Creation - - {% endif %} + {% if flag_hive %} + {% if hive_active %} + + Disable Alert Creation + + {% endif %} + {% if not hive_active %} + + Enable Alert Creation + + {% endif %} + {% endif %} + {% if not flag_hive %} + + {% endif %} diff --git a/var/www/update_thirdparty.sh b/var/www/update_thirdparty.sh index 676529b3..9084b99d 100755 --- a/var/www/update_thirdparty.sh +++ b/var/www/update_thirdparty.sh @@ -70,3 +70,9 @@ source ./../../AILENV/bin/activate #Update MISP Taxonomies and Galaxies python3 -m pip install git+https://github.com/MISP/PyTaxonomies python3 -m pip install git+https://github.com/MISP/PyMISPGalaxies + +#Update PyMISP +python3 -m pip install git+https://github.com/MISP/PyMISP + +#Update the Hive +python3 -m pip install git+https://github.com/TheHive-Project/TheHive4py