Keine Beschreibung

case_ioc_routes.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # IRIS Source Code
  2. # Copyright (C) 2021 - Airbus CyberSecurity (SAS) - DFIR-IRIS Team
  3. # ir@cyberactionlab.net - contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from flask import Blueprint
  19. from flask import redirect
  20. from flask import render_template
  21. from flask import url_for
  22. from app.business.iocs import iocs_get
  23. from app.business.errors import ObjectNotFoundError
  24. from app.datamgmt.case.case_assets_db import get_assets_types
  25. from app.datamgmt.case.case_db import get_case
  26. from app.datamgmt.case.case_iocs_db import get_case_iocs_comments_count
  27. from app.datamgmt.case.case_iocs_db import get_ioc_types_list
  28. from app.datamgmt.case.case_iocs_db import get_tlps
  29. from app.datamgmt.manage.manage_attribute_db import get_default_custom_attributes
  30. from app.forms import ModalAddCaseAssetForm
  31. from app.forms import ModalAddCaseIOCForm
  32. from app.models.authorization import CaseAccessLevel
  33. from app.models.models import Ioc
  34. from app.blueprints.access_controls import ac_case_requires
  35. from app.blueprints.responses import response_error
  36. case_ioc_blueprint = Blueprint(
  37. 'case_ioc',
  38. __name__,
  39. template_folder='templates'
  40. )
  41. @case_ioc_blueprint.route('/case/ioc', methods=['GET'])
  42. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  43. def case_ioc(caseid, url_redir):
  44. if url_redir:
  45. return redirect(url_for('case_ioc.case_ioc', cid=caseid, redirect=True))
  46. form = ModalAddCaseAssetForm()
  47. form.asset_id.choices = get_assets_types()
  48. # Retrieve the assets linked to the investigation
  49. case = get_case(caseid)
  50. return render_template("case_ioc.html", case=case, form=form)
  51. @case_ioc_blueprint.route('/case/ioc/add/modal', methods=['GET'])
  52. @ac_case_requires(CaseAccessLevel.full_access)
  53. def case_add_ioc_modal(caseid, url_redir):
  54. if url_redir:
  55. return redirect(url_for('case_assets.case_assets', cid=caseid, redirect=True))
  56. form = ModalAddCaseIOCForm()
  57. form.ioc_type_id.choices = [(row['type_id'], row['type_name']) for row in get_ioc_types_list()]
  58. form.ioc_tlp_id.choices = get_tlps()
  59. attributes = get_default_custom_attributes('ioc')
  60. return render_template("modal_add_case_ioc.html", form=form, ioc=Ioc(), attributes=attributes)
  61. @case_ioc_blueprint.route('/case/ioc/<int:cur_id>/modal', methods=['GET'])
  62. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  63. def case_view_ioc_modal(cur_id, caseid, url_redir):
  64. if url_redir:
  65. return redirect(url_for('case_assets.case_assets', cid=caseid, redirect=True))
  66. form = ModalAddCaseIOCForm()
  67. try:
  68. ioc = iocs_get(cur_id)
  69. form.ioc_type_id.choices = [(row['type_id'], row['type_name']) for row in get_ioc_types_list()]
  70. form.ioc_tlp_id.choices = get_tlps()
  71. # Render the IOC
  72. form.ioc_tags.render_kw = {'value': ioc.ioc_tags}
  73. form.ioc_description.data = ioc.ioc_description
  74. form.ioc_value.data = ioc.ioc_value
  75. comments_map = get_case_iocs_comments_count([cur_id])
  76. return render_template('modal_add_case_ioc.html', form=form, ioc=ioc, attributes=ioc.custom_attributes,
  77. comments_map=comments_map)
  78. except ObjectNotFoundError:
  79. return response_error('Invalid IOC ID for this case')
  80. @case_ioc_blueprint.route('/case/ioc/<int:cur_id>/comments/modal', methods=['GET'])
  81. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  82. def case_comment_ioc_modal(cur_id, caseid, url_redir):
  83. if url_redir:
  84. return redirect(url_for('case_ioc.case_ioc', cid=caseid, redirect=True))
  85. try:
  86. ioc = iocs_get(cur_id)
  87. return render_template('modal_conversation.html', element_id=cur_id, element_type='ioc', title=ioc.ioc_value)
  88. except ObjectNotFoundError:
  89. return response_error('Invalid ioc ID')