chg: [UI MISP import]show error +imported uuid/global_id

This commit is contained in:
Terrtia 2020-02-18 13:47:47 +01:00
parent 1b861f55ee
commit b0dde78c2e
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
9 changed files with 107 additions and 18 deletions

View file

@ -207,19 +207,30 @@ def create_obj_relationships(map_uuid_global_id, misp_obj):
Correlate_object.create_obj_relationship(obj_meta_src['type'], obj_meta_src['id'], obj_meta_target['type'], obj_meta_target['id'], Correlate_object.create_obj_relationship(obj_meta_src['type'], obj_meta_src['id'], obj_meta_target['type'], obj_meta_target['id'],
obj1_subtype=obj_meta_src['subtype'], obj2_subtype=obj_meta_target['subtype']) obj1_subtype=obj_meta_src['subtype'], obj2_subtype=obj_meta_target['subtype'])
def create_map_all_obj_uuid_golbal_id(map_uuid_global_id):
for obj_uuid in map_uuid_global_id:
create_map_objuuid_golbal_id(obj_uuid, map_uuid_global_id[obj_uuid])
def create_map_objuuid_golbal_id(obj_uuid, global_id):
print(obj_uuid)
print(global_id)
def import_objs_from_file(filepath): def import_objs_from_file(filepath):
event_to_import = MISPEvent()
event_to_import.load_file(filepath)
map_uuid_global_id = {} map_uuid_global_id = {}
event_to_import = MISPEvent()
try:
event_to_import.load_file(filepath)
except:
return map_uuid_global_id
for misp_obj in event_to_import.objects: for misp_obj in event_to_import.objects:
get_misp_import_fct(map_uuid_global_id, misp_obj) get_misp_import_fct(map_uuid_global_id, misp_obj)
for misp_obj in event_to_import.objects: for misp_obj in event_to_import.objects:
create_obj_relationships(map_uuid_global_id, misp_obj) create_obj_relationships(map_uuid_global_id, misp_obj)
#print(map_uuid_global_id)
create_map_all_obj_uuid_golbal_id(map_uuid_global_id)
return map_uuid_global_id return map_uuid_global_id

View file

@ -383,6 +383,19 @@ def get_obj_global_id(obj_type, obj_id, obj_sub_type=None):
return '{}:{}'.format(obj_type, obj_id) return '{}:{}'.format(obj_type, obj_id)
def get_global_id_from_id(global_id):
obj_meta = {}
global_id = global_id.split(':', 3)
if len(global_id) > 2:
obj_meta['type'] = global_id[0]
obj_meta['subtype'] = global_id[1]
obj_meta['id'] = global_id[2]
else:
obj_meta['type'] = global_id[0]
obj_meta['subtype'] = None
obj_meta['id'] = global_id[1]
return obj_meta
# used by UI # used by UI
def get_obj_str_type_subtype(obj_type, obj_subtype): def get_obj_str_type_subtype(obj_type, obj_subtype):
if obj_subtype: if obj_subtype:

View file

@ -324,7 +324,7 @@ def save_decoded_file_content(sha1_string, file_content, date_from, date_to=None
filepath = get_decoded_filepath(sha1_string, mimetype=mimetype) filepath = get_decoded_filepath(sha1_string, mimetype=mimetype)
if os.path.isfile(filepath): if os.path.isfile(filepath):
print('File already exist') #print('File already exist')
return False return False
# create dir # create dir

View file

@ -167,7 +167,7 @@ def get_screenshot_file_content(sha256_string):
def save_screenshot_file(sha256_string, io_content): def save_screenshot_file(sha256_string, io_content):
filepath = get_screenshot_filepath(sha256_string) filepath = get_screenshot_filepath(sha256_string)
if os.path.isfile(filepath): if os.path.isfile(filepath):
print('File already exist') #print('File already exist')
return False return False
# # TODO: check if is IO file # # TODO: check if is IO file
with open(filepath, 'wb') as f: with open(filepath, 'wb') as f:
@ -183,7 +183,6 @@ def delete_screenshot_file(obj_id):
return True return True
def create_screenshot(obj_id, obj_meta, io_content): def create_screenshot(obj_id, obj_meta, io_content):
print(obj_id)
# # TODO: check if sha256 # # TODO: check if sha256
res = save_screenshot_file(obj_id, io_content) res = save_screenshot_file(obj_id, io_content)
if res: if res:

View file

@ -348,7 +348,7 @@ def get_raw_content(item_id):
def save_raw_content(item_id, io_content): def save_raw_content(item_id, io_content):
filepath = get_item_filename(item_id) filepath = get_item_filename(item_id)
if os.path.isfile(filepath): if os.path.isfile(filepath):
print('File already exist') #print('File already exist')
return False return False
# # TODO: check if is IO file # # TODO: check if is IO file
with open(filepath, 'wb') as f: with open(filepath, 'wb') as f:

View file

@ -45,13 +45,13 @@ import_export = Blueprint('import_export', __name__, template_folder=os.path.joi
@login_required @login_required
@login_analyst @login_analyst
def import_object(): def import_object():
tags = request.args.get('tags') return render_template("import_object.html")
return render_template("import_object.html", bootstrap_label=bootstrap_label)
@import_export.route("/import_export/import_file", methods=['POST']) @import_export.route("/import_export/import_file", methods=['POST'])
@login_required @login_required
@login_analyst @login_analyst
def import_object_file(): def import_object_file():
error = None
is_file = False is_file = False
if 'file' in request.files: if 'file' in request.files:
@ -60,20 +60,29 @@ def import_object_file():
if file.filename: if file.filename:
is_file = True is_file = True
all_imported_obj = []
if is_file: if is_file:
filename = MispImport.sanitize_import_file_path(file.filename) filename = MispImport.sanitize_import_file_path(file.filename)
file.save(filename) file.save(filename)
map_uuid_global_id = MispImport.import_objs_from_file(filename) map_uuid_global_id = MispImport.import_objs_from_file(filename)
os.remove(filename) os.remove(filename)
for obj_uuid in map_uuid_global_id:
dict_obj = Correlate_object.get_global_id_from_id(map_uuid_global_id[obj_uuid])
dict_obj['uuid'] = obj_uuid
dict_obj['url'] = Correlate_object.get_item_url(dict_obj['type'], dict_obj['id'], correlation_type=dict_obj['subtype'])
dict_obj['node'] = Correlate_object.get_correlation_node_icon(dict_obj['type'], correlation_type=dict_obj['subtype'], value=dict_obj['id'])
all_imported_obj.append(dict_obj)
return render_template("import_object.html", bootstrap_label=bootstrap_label) if not all_imported_obj:
error = "error: Empty or invalid JSON file"
return render_template("import_object.html", all_imported_obj=all_imported_obj, error=error)
@import_export.route('/import_export/export') @import_export.route('/import_export/export')
@login_required @login_required
@login_analyst @login_analyst
def export_object(): def export_object():
object_type = request.args.get('object_type') return render_template("export_object.html")
return render_template("export_object.html", bootstrap_label=bootstrap_label)
@import_export.route("/import_export/export_file", methods=['POST']) @import_export.route("/import_export/export_file", methods=['POST'])
@login_required @login_required

View file

@ -20,7 +20,7 @@
<option value="cryptocurrency;monero" {%if obj_type=="cryptocurrency;monero"%}selected{%endif%}>Cryptocurrency - Monero</option> <option value="cryptocurrency;monero" {%if obj_type=="cryptocurrency;monero"%}selected{%endif%}>Cryptocurrency - Monero</option>
<option value="cryptocurrency;zcash" {%if obj_type=="cryptocurrency;zcash"%}selected{%endif%}>Cryptocurrency - Zcash</option> <option value="cryptocurrency;zcash" {%if obj_type=="cryptocurrency;zcash"%}selected{%endif%}>Cryptocurrency - Zcash</option>
</select> </select>
<input type="text" class="form-control col-8 {%if obj_error%}is-invalid{%endif%}" name="{{input_uuid}}" value="{{obj_id}}"> <input type="text" class="form-control col-8 {%if obj_error%}is-invalid{%else%}is-valid{%endif%}" name="{{input_uuid}}" value="{{obj_id}}">
<input class="form-control col-1" type="number" min="0" name="{{input_uuid}}" {%if obj_lvl%}value="{{obj_lvl}}"{%else%}value="0"{%endif%}> <input class="form-control col-1" type="number" min="0" name="{{input_uuid}}" {%if obj_lvl%}value="{{obj_lvl}}"{%else%}value="0"{%endif%}>
<span class="btn btn-danger input-group-addon delete-field col-1"><i class="fas fa-trash-alt"></i></span> <span class="btn btn-danger input-group-addon delete-field col-1"><i class="fas fa-trash-alt"></i></span>
<div class="invalid-feedback"> <div class="invalid-feedback">

View file

@ -14,9 +14,7 @@
<!-- JS --> <!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script> <script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/helper.js')}}"></script> <script src="{{ url_for('static', filename='js/helper.js')}}"></script>
<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script> <script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
<script language="javascript" src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
</head> </head>
<body> <body>

View file

@ -10,13 +10,14 @@
<!-- Core CSS --> <!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
<!-- JS --> <!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script> <script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/helper.js')}}"></script> <script src="{{ url_for('static', filename='js/helper.js')}}"></script>
<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script> <script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
<script language="javascript" src="{{ url_for('static', filename='js/d3.min.js') }}"></script> <script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
</head> </head>
<body> <body>
@ -48,10 +49,64 @@
</form> </form>
{% if error %}
<div class="text-center text-danger">
<b>{{error}}</b>
</div>
{% endif %}
</div> </div>
</div> </div>
{% if all_imported_obj %}
<div class="card mb-3 mt-1">
<div class="card-header text-white bg-dark">
<h5 class="card-title">
<img src="{{ url_for('static', filename='image/ail-icon.png')}}" alt="AIL" style="width:100px;"> Objects Imported <span class="badge badge-primary">{{all_imported_obj|length}}</span></h5>
</div>
<div class="card-body">
<table class="table table-bordered table-hover" id="myTable_">
<thead class="thead-dark">
<tr>
<th>Object UUID</th>
<th></th>
<th>Object Type</th>
<th>Object ID</th>
</tr>
</thead>
<tbody>
{% for dict_obj in all_imported_obj %}
<tr>
<td class="pb-0">{{ dict_obj['uuid'] }}</td>
<td class="pb-0">
<div class="my-1">
<svg height="26" width="26">
<g class="nodes">
<circle cx="13" cy="13" r="13" fill="{{ dict_obj['node']['node_color'] }}"></circle>
<text x="13" y="13" text-anchor="middle" dominant-baseline="central" class="graph_node_icon {{ dict_obj['node']['icon_class'] }}" font-size="16px">{{ dict_obj['node']['icon_text'] }}</text>
</g>
</svg>
</div>
</td>
<td class="pb-0">{{ dict_obj['type'] }}</td>
<td class="pb-0">
<a target="_blank" href="{{ dict_obj['url'] }}">
{{ dict_obj['id'] }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include 'correlation/legend_graph_correlation.html' %}
</div>
</div>
{% endif %}
</div> </div>
</div> </div>
@ -59,6 +114,10 @@
$(document).ready(function(){ $(document).ready(function(){
$("#page-Decoded").addClass("active"); $("#page-Decoded").addClass("active");
$("#nav_misp_import").addClass("active"); $("#nav_misp_import").addClass("active");
{% if all_imported_obj %}
$('#myTable_').DataTable({ "lengthMenu": [ 5, 10, 25, 50, 100 ], "pageLength": 10, "order": [[ 2, "asc" ]] });
{% endif %}
}); });
function toggle_sidebar(){ function toggle_sidebar(){