From 40ca3ed9bc20b02cd49c4704279b386e7123e305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 20 Feb 2024 01:13:20 +0100 Subject: [PATCH] new: easy way to find other captures with same favicon --- lookyloo/indexing.py | 3 ++ website/web/__init__.py | 20 +++++++++ website/web/templates/tree.html | 28 +++++++++++++ website/web/templates/tree_favicons.html | 53 ++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 website/web/templates/tree_favicons.html diff --git a/lookyloo/indexing.py b/lookyloo/indexing.py index 59a02399..252915a4 100644 --- a/lookyloo/indexing.py +++ b/lookyloo/indexing.py @@ -339,6 +339,9 @@ def get_captures_hostname(self, hostname: str) -> set[str]: def favicons(self) -> list[tuple[str, float]]: return self.redis.zrevrange('favicons', 0, 200, withscores=True) + def favicon_frequency(self, favicon_sha512: str) -> float | None: + return self.redis.zscore('favicons', favicon_sha512) + def favicon_number_captures(self, favicon_sha512: str) -> int: return self.redis.scard(f'favicons|{favicon_sha512}|captures') diff --git a/website/web/__init__.py b/website/web/__init__.py index 8dda2eca..8a68554e 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -5,6 +5,7 @@ import base64 import calendar import functools +import hashlib import http import json import logging @@ -833,6 +834,25 @@ def mark_as_legitimate(tree_uuid: str) -> Response: return jsonify({'message': 'Legitimate entry added.'}) +@app.route('/tree//favicons', methods=['GET']) +def tree_favicons(tree_uuid: str) -> str: + favicons = [] + favicons_zip = lookyloo.get_potential_favicons(tree_uuid, all_favicons=True, for_datauri=False) + with ZipFile(favicons_zip, 'r') as myzip: + for name in myzip.namelist(): + if not name.endswith('.ico'): + continue + favicon = myzip.read(name) + if not favicon: + continue + favicon_sha512 = hashlib.sha512(favicon).hexdigest() + frequency = lookyloo.indexing.favicon_frequency(favicon_sha512) + number_captures = lookyloo.indexing.favicon_number_captures(favicon_sha512) + b64_favicon = base64.b64encode(favicon).decode() + favicons.append((favicon_sha512, frequency, number_captures, b64_favicon)) + return render_template('tree_favicons.html', tree_uuid=tree_uuid, favicons=favicons) + + @app.route('/tree//body_hashes', methods=['GET']) def tree_body_hashes(tree_uuid: str) -> str: body_hashes = lookyloo.get_all_body_hashes(tree_uuid) diff --git a/website/web/templates/tree.html b/website/web/templates/tree.html index 83a40068..4cfe590f 100644 --- a/website/web/templates/tree.html +++ b/website/web/templates/tree.html @@ -84,6 +84,13 @@ }); + + +{% if from_popup %} + +{% endif %} + + + + + + + + + + + {% for favicon_sha512, freq, number_captures, b64_favicon in favicons %} + + + + + + {% endfor %} + +
FaviconFrequencyNumber of captures
+ + + + {{ freq }}{{ number_captures }}