chg: Add logging to debug why some files are not downloadable

pull/961/head
Raphaël Vinot 2024-10-16 15:25:12 +02:00
parent d1ca709ed9
commit 12e9430443
2 changed files with 8 additions and 1 deletions

View File

@ -1118,12 +1118,15 @@ class Lookyloo():
url = self.get_urlnode_from_tree(tree_uuid, urlnode_uuid)
except IndexError:
# unable to find the uuid, the cache is probably in a weird state.
self.logger.info(f'Unable to find node "{urlnode_uuid}" in "{tree_uuid}"')
return None
except NoValidHarFile as e:
# something went poorly when rebuilding the tree (probably a recursive error)
self.logger.warning(e)
return None
if url.empty_response:
self.logger.info(f'The response for node "{urlnode_uuid}" in "{tree_uuid}" is empty.')
return None
if not h or h == url.body_hash:
# we want the body
@ -1131,11 +1134,13 @@ class Lookyloo():
# We want an embedded ressource
if h not in url.resources_hashes:
self.logger.info(f'Unable to find "{h}" in capture "{tree_uuid}" - node "{urlnode_uuid}".')
return None
for mimetype, blobs in url.embedded_ressources.items():
for ressource_h, blob in blobs:
if ressource_h == h:
return 'embedded_ressource.bin', BytesIO(blob.getvalue()), mimetype
self.logger.info(f'Unable to find "{h}" in capture "{tree_uuid}" - node "{urlnode_uuid}", but in a weird way.')
return None
def __misp_add_vt_to_URLObject(self, obj: MISPObject) -> MISPObject | None:

View File

@ -1542,14 +1542,16 @@ def recapture(tree_uuid: str) -> str | Response | WerkzeugResponse:
@app.route('/ressource_by_hash/<string:sha512>', methods=['GET'])
@file_response # type: ignore[misc]
def ressource_by_hash(sha512: str) -> Response:
content_fallback = f'Unable to find "{sha512}"'
if uuids := get_indexing(flask_login.current_user).get_hash_uuids(sha512):
# got UUIDs for this hash
capture_uuid, urlnode_uuid = uuids
content_fallback += f' in capture "{capture_uuid}" and node "{urlnode_uuid}"'
if ressource := lookyloo.get_ressource(capture_uuid, urlnode_uuid, sha512):
filename, body, mimetype = ressource
return send_file(body, as_attachment=True, download_name=filename)
return send_file(BytesIO(f'Unable to find {sha512}'.encode()), as_attachment=True, download_name='Unknown_Hash.txt')
return send_file(BytesIO(content_fallback.encode()), as_attachment=True, download_name='Unknown_Hash.txt')
# ################## Submit existing capture ##################