説明なし

case_assets_routes.py 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.datamgmt.case.case_assets_db import get_analysis_status_list
  23. from app.datamgmt.case.case_assets_db import get_asset
  24. from app.datamgmt.case.case_assets_db import get_assets_types
  25. from app.datamgmt.case.case_assets_db import get_case_assets_comments_count
  26. from app.datamgmt.case.case_assets_db import get_compromise_status_list
  27. from app.datamgmt.case.case_assets_db import get_linked_iocs_id_from_asset
  28. from app.datamgmt.case.case_db import get_case
  29. from app.datamgmt.case.case_iocs_db import get_iocs
  30. from app.datamgmt.manage.manage_attribute_db import get_default_custom_attributes
  31. from app.forms import AssetBasicForm
  32. from app.forms import ModalAddCaseAssetForm
  33. from app.models.authorization import CaseAccessLevel
  34. from app.blueprints.access_controls import ac_case_requires
  35. from app.blueprints.responses import response_error
  36. case_assets_blueprint = Blueprint('case_assets',
  37. __name__,
  38. template_folder='templates')
  39. @case_assets_blueprint.route('/case/assets', methods=['GET'])
  40. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  41. def case_assets(caseid, url_redir):
  42. """
  43. Returns the page of case assets, with the list of available assets types.
  44. :return: The HTML page of case assets
  45. """
  46. if url_redir:
  47. return redirect(url_for('case_assets.case_assets', cid=caseid, redirect=True))
  48. form = ModalAddCaseAssetForm()
  49. # Get asset types from database
  50. form.asset_id.choices = get_assets_types()
  51. # Retrieve the assets linked to the investigation
  52. case = get_case(caseid)
  53. return render_template("case_assets.html", case=case, form=form)
  54. @case_assets_blueprint.route('/case/assets/add/modal', methods=['GET'])
  55. @ac_case_requires(CaseAccessLevel.full_access)
  56. def add_asset_modal(caseid, url_redir):
  57. if url_redir:
  58. return redirect(url_for('case_assets.case_assets', cid=caseid, redirect=True))
  59. form = AssetBasicForm()
  60. form.asset_type_id.choices = get_assets_types()
  61. form.analysis_status_id.choices = get_analysis_status_list()
  62. form.asset_compromise_status_id.choices = get_compromise_status_list()
  63. # Get IoCs from the case
  64. ioc = get_iocs(caseid)
  65. attributes = get_default_custom_attributes('asset')
  66. return render_template("modal_add_case_multi_asset.html", form=form, asset=None, ioc=ioc, attributes=attributes)
  67. @case_assets_blueprint.route('/case/assets/<int:cur_id>/modal', methods=['GET'])
  68. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  69. def asset_view_modal(cur_id, caseid, url_redir):
  70. if url_redir:
  71. return redirect(url_for('case_assets.case_assets', cid=caseid, redirect=True))
  72. # Get IoCs from the case
  73. case_iocs = get_iocs(caseid)
  74. # Get IoCs already linked to the asset
  75. asset_iocs = get_linked_iocs_id_from_asset(cur_id)
  76. ioc_prefill = [row for row in asset_iocs]
  77. # Build the form
  78. form = AssetBasicForm()
  79. asset = get_asset(cur_id)
  80. form.asset_name.render_kw = {'value': asset.asset_name}
  81. form.asset_description.data = asset.asset_description
  82. form.asset_info.data = asset.asset_info
  83. form.asset_ip.render_kw = {'value': asset.asset_ip}
  84. form.asset_domain.render_kw = {'value': asset.asset_domain}
  85. form.asset_compromise_status_id.choices = get_compromise_status_list()
  86. form.asset_type_id.choices = get_assets_types()
  87. form.analysis_status_id.choices = get_analysis_status_list()
  88. form.asset_tags.render_kw = {'value': asset.asset_tags}
  89. comments_map = get_case_assets_comments_count([cur_id])
  90. return render_template("modal_add_case_asset.html", form=form, asset=asset, map={}, ioc=case_iocs,
  91. ioc_prefill=ioc_prefill, attributes=asset.custom_attributes, comments_map=comments_map)
  92. @case_assets_blueprint.route('/case/assets/<int:cur_id>/comments/modal', methods=['GET'])
  93. @ac_case_requires(CaseAccessLevel.read_only, CaseAccessLevel.full_access)
  94. def case_comment_asset_modal(cur_id, caseid, url_redir):
  95. if url_redir:
  96. return redirect(url_for('case_task.case_task', cid=caseid, redirect=True))
  97. asset = get_asset(cur_id)
  98. if not asset:
  99. return response_error('Invalid asset ID')
  100. return render_template("modal_conversation.html", element_id=cur_id, element_type='assets',
  101. title=asset.asset_name)