From 12e943044301183871e6ddd7585aba661a944d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 16 Oct 2024 15:25:12 +0200 Subject: [PATCH] chg: Add logging to debug why some files are not downloadable --- lookyloo/lookyloo.py | 5 +++++ website/web/__init__.py | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 7cb71910..c3601de2 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -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: diff --git a/website/web/__init__.py b/website/web/__init__.py index 3d687a13..d7601abe 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -1542,14 +1542,16 @@ def recapture(tree_uuid: str) -> str | Response | WerkzeugResponse: @app.route('/ressource_by_hash/', 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 ##################