From 068c92d5a453880f73c8e649c9d8b589a7a88e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 27 Oct 2020 01:42:00 +0100 Subject: [PATCH] new: API to query hostnames --- lookyloo/lookyloo.py | 14 ++++++++++++-- website/web/__init__.py | 11 +++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 03e72703..ca51899a 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -704,7 +704,7 @@ class Lookyloo(): to_return[capture_uuid]['urlnodes'][urlnode.uuid]['hash'] = urlnode.body_hash return to_return - def get_hostname_occurrences(self, hostname: str): + def get_hostname_occurrences(self, hostname: str, with_urls_occurrences: bool=False): capture_uuids = self.indexing.get_captures_hostname(hostname) to_return: Dict[str, Dict] = {cuuid: {} for cuuid in capture_uuids} for capture_uuid in capture_uuids: @@ -716,7 +716,17 @@ class Lookyloo(): if not ct: raise MissingUUID(f'Unable to find {capture_dir}') to_return[capture_uuid]['start_timestamp'] = ct.root_hartree.start_time.isoformat() - to_return[capture_uuid]['hostnodes'] = [hn.uuid for hn in ct.root_hartree.hostname_tree.search_node(name=hostname)] + to_return[capture_uuid]['hostnodes'] = [] + for hostnode in ct.root_hartree.hostname_tree.search_nodes(name=hostname): + to_return[capture_uuid]['hostnodes'].append(hostnode.uuid) + if with_urls_occurrences: + to_return[capture_uuid]['urlnodes'] = {} + for urlnode in hostnode.urls: + to_return[capture_uuid]['urlnodes'][urlnode.uuid] = {'start_time': urlnode.start_time.isoformat(), + 'url': urlnode.name, + 'hostnode_uuid': urlnode.hostnode_uuid} + if hasattr(urlnode, 'body_hash'): + to_return[capture_uuid]['urlnodes'][urlnode.uuid]['hash'] = urlnode.body_hash return to_return def get_cookie_name_investigator(self, cookie_name: str): diff --git a/website/web/__init__.py b/website/web/__init__.py index 7a54c5cf..d1da9e4b 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -615,5 +615,12 @@ def json_hash_info(h: str): @app.route('/json/url_info', methods=['POST']) def json_url_info(): to_query = request.get_json(force=True) - occrrences = lookyloo.get_url_occurrences(to_query['url']) - return jsonify(occrrences) + occurrences = lookyloo.get_url_occurrences(**to_query) + return jsonify(occurrences) + + +@app.route('/json/hostname_info', methods=['POST']) +def json_hostname_info(): + to_query = request.get_json(force=True) + occurrences = lookyloo.get_hostname_occurrences(**to_query) + return jsonify(occurrences)