fix hive connection + submitted dir creation

This commit is contained in:
Terrtia 2018-06-19 11:31:30 +02:00
parent 86c2cfa04b
commit 0ee36e484f
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
5 changed files with 78 additions and 29 deletions

3
.gitignore vendored
View file

@ -17,6 +17,7 @@ BASE64
DATA_ARDB DATA_ARDB
indexdir/ indexdir/
logs/ logs/
old/
# Webstuff # Webstuff
var/www/static/ var/www/static/
@ -26,9 +27,11 @@ var/www/static/
!var/www/static/js/plot-graph.js !var/www/static/js/plot-graph.js
!var/www/static/js/trendingchart.js !var/www/static/js/trendingchart.js
var/www/templates/header.html var/www/templates/header.html
var/www/submitted
# Local config # Local config
bin/packages/config.cfg bin/packages/config.cfg
configs/keys
# installed files # installed files
nltk_data/ nltk_data/

View file

@ -93,8 +93,8 @@ r_serv_db = redis.StrictRedis(
sys.path.append('../../configs/keys') sys.path.append('../../configs/keys')
# MISP # # MISP #
from pymisp import PyMISP
try: try:
from pymisp import PyMISP
from mispKEYS import misp_url, misp_key, misp_verifycert from mispKEYS import misp_url, misp_key, misp_verifycert
pymisp = PyMISP(misp_url, misp_key, misp_verifycert) pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
misp_event_url = misp_url + '/events/view/' misp_event_url = misp_url + '/events/view/'
@ -104,23 +104,30 @@ except:
pymisp = False pymisp = False
misp_event_url = '#' misp_event_url = '#'
# The Hive # # The Hive #
try:
from thehive4py.api import TheHiveApi from thehive4py.api import TheHiveApi
import thehive4py.exceptions import thehive4py.exceptions
try: from theHiveKEYS import the_hive_url, the_hive_key, the_hive_verifycert
from theHiveKEYS import the_hive_url, the_hive_key
if the_hive_url == '': if the_hive_url == '':
HiveApi = False HiveApi = False
hive_case_url = '#' hive_case_url = '#'
print('The HIVE not connected') print('The HIVE not connected')
else: 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' hive_case_url = the_hive_url+'/index.html#/case/id_here/details'
print('The Hive connected') #HiveApi.do_patch(the_hive_url)
except: except:
print('The HIVE not connected') print('The HIVE not connected')
HiveApi = False HiveApi = False
hive_case_url = '#' hive_case_url = '#'
try:
HiveApi.get_alert(0)
print('The Hive connected')
except thehive4py.exceptions.AlertException:
HiveApi = False
print('The Hive not connected')
# VARIABLES # # VARIABLES #
max_preview_char = int(cfg.get("Flask", "max_preview_char")) # Maximum number of character to display in the tooltip 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 max_preview_modal = int(cfg.get("Flask", "max_preview_modal")) # Maximum number of character to display in the modal

View file

@ -23,8 +23,16 @@ import Paste
from pytaxonomies import Taxonomies from pytaxonomies import Taxonomies
from pymispgalaxies import Galaxies, Clusters from pymispgalaxies import Galaxies, Clusters
try:
from pymisp.mispevent import MISPObject from pymisp.mispevent import MISPObject
flag_misp = True
except:
flag_misp = False
try:
from thehive4py.models import Case, CaseTask, CustomFieldHelper, CaseObservable from thehive4py.models import Case, CaseTask, CustomFieldHelper, CaseObservable
flag_hive = True
except:
flag_hive = False
# ============ VARIABLES ============ # ============ VARIABLES ============
import Flask_config 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 r_serv_log_submit = Flask_config.r_serv_log_submit
pymisp = Flask_config.pymisp pymisp = Flask_config.pymisp
if pymisp is False:
flag_misp = False
HiveApi = Flask_config.HiveApi HiveApi = Flask_config.HiveApi
if HiveApi is False:
flag_hive = False
PasteSubmit = Blueprint('PasteSubmit', __name__, template_folder='templates') PasteSubmit = Blueprint('PasteSubmit', __name__, template_folder='templates')
@ -308,6 +320,10 @@ def submit():
# clean file name # clean file name
UUID = clean_filename(paste_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: if not '.' in file.filename:
full_path = os.path.join(UPLOAD_FOLDER, UUID) full_path = os.path.join(UPLOAD_FOLDER, UUID)
else: else:
@ -518,7 +534,9 @@ def edit_tag_export():
status_misp=status_misp, status_misp=status_misp,
status_hive=status_hive, status_hive=status_hive,
nb_tags_whitelist_misp=nb_tags_whitelist_misp, 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']) @PasteSubmit.route("/PasteSubmit/tag_export_edited", methods=['POST'])
def tag_export_edited(): def tag_export_edited():

View file

@ -71,6 +71,7 @@
</div> </div>
<br> <br>
{% if flag_misp %}
{% if misp_active %} {% if misp_active %}
<a href="{{ url_for('PasteSubmit.disable_misp_auto_event') }}" class="btn btn-danger pull-right"> <a href="{{ url_for('PasteSubmit.disable_misp_auto_event') }}" class="btn btn-danger pull-right">
<i class="fa fa-times fa"></i> Disable Event Creation <i class="fa fa-times fa"></i> Disable Event Creation
@ -81,6 +82,13 @@
<i class="fa fa-check-square-o fa"></i> Enable Event Creation <i class="fa fa-check-square-o fa"></i> Enable Event Creation
</a> </a>
{% endif %} {% endif %}
{% endif %}
{% if not flag_misp %}
<button class="btn btn-danger pull-right disabled">
<i class="fa fa-times fa"></i> MISP is not connected
</button>
{% endif %}
</div> </div>
</div> </div>
</div> </div>
@ -101,6 +109,7 @@
<img id="misp-logo" src="{{url_for('static', filename='image/thehive-logo.png') }}" width="500"> <img id="misp-logo" src="{{url_for('static', filename='image/thehive-logo.png') }}" width="500">
</div> </div>
{% if flag_hive %}
{% if hive_active %} {% if hive_active %}
<a href="{{ url_for('PasteSubmit.disable_hive_auto_alert') }}" class="btn btn-danger pull-right"> <a href="{{ url_for('PasteSubmit.disable_hive_auto_alert') }}" class="btn btn-danger pull-right">
<i class="fa fa-times fa"></i> Disable Alert Creation <i class="fa fa-times fa"></i> Disable Alert Creation
@ -111,6 +120,12 @@
<i class="fa fa-check-square-o fa"></i> Enable Alert Creation <i class="fa fa-check-square-o fa"></i> Enable Alert Creation
</a> </a>
{% endif %} {% endif %}
{% endif %}
{% if not flag_hive %}
<button class="btn btn-danger pull-right disabled">
<i class="fa fa-times fa"></i> The Hive is not connected
</button>
{% endif %}
</div> </div>
</div> </div>
</div> </div>

View file

@ -70,3 +70,9 @@ source ./../../AILENV/bin/activate
#Update MISP Taxonomies and Galaxies #Update MISP Taxonomies and Galaxies
python3 -m pip install git+https://github.com/MISP/PyTaxonomies python3 -m pip install git+https://github.com/MISP/PyTaxonomies
python3 -m pip install git+https://github.com/MISP/PyMISPGalaxies 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