new: first try to add an url in the hostnode to dl the file if there is one to be downloaded

pull/492/head
Arhamyss 2022-08-09 18:23:11 +02:00
parent 137c05648b
commit 5a77044530
5 changed files with 162 additions and 1292 deletions

View File

@ -490,6 +490,10 @@ class Lookyloo():
'''Get rendered HTML''' '''Get rendered HTML'''
return self._get_raw(capture_uuid, 'html', all_html) return self._get_raw(capture_uuid, 'html', all_html)
def get_data(self, capture_uuid: str, /) -> Tuple[str, BytesIO]:
'''Get the data'''
return self._get_raw(capture_uuid, 'data.filename', False).getvalue().decode(), self._get_raw(capture_uuid, 'data', False)
def get_cookies(self, capture_uuid: str, /, all_cookies: bool=False) -> BytesIO: def get_cookies(self, capture_uuid: str, /, all_cookies: bool=False) -> BytesIO:
'''Get the cookie(s)''' '''Get the cookie(s)'''
return self._get_raw(capture_uuid, 'cookies.json', all_cookies) return self._get_raw(capture_uuid, 'cookies.json', all_cookies)
@ -890,6 +894,17 @@ class Lookyloo():
'url_object': url, 'url_object': url,
} }
if url.empty_response:
if ct.root_hartree.rendered_node == url:
# check if a file is available
filename, data = self.lookyloo.get_data(self.uuid)
if filename:
# we have a file to download
url.add_feature('has_dl_file', True)
if not url.empty_response: if not url.empty_response:
# Index lookup # Index lookup
# %%% Full body %%% # %%% Full body %%%

1421
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -67,6 +67,7 @@ har2tree = "^1.13.2"
playwrightcapture = "^1.13.4" playwrightcapture = "^1.13.4"
passivetotal = "^2.5.9" passivetotal = "^2.5.9"
werkzeug = "2.1.2" werkzeug = "2.1.2"
filetype = "^1.1.0"
[tool.poetry.extras] [tool.poetry.extras]
misp = ['python-magic', 'pydeep2'] misp = ['python-magic', 'pydeep2']

View File

@ -6,6 +6,7 @@ import json
import logging import logging
import os import os
import time import time
import filetype
from datetime import date, datetime, timedelta, timezone from datetime import date, datetime, timedelta, timezone
from io import BytesIO, StringIO from io import BytesIO, StringIO
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
@ -482,6 +483,17 @@ def image(tree_uuid: str):
return send_file(to_return, mimetype='image/png', return send_file(to_return, mimetype='image/png',
as_attachment=True, attachment_filename='image.png') as_attachment=True, attachment_filename='image.png')
@app.route('/tree/<string:tree_uuid>/data', methods=['GET'])
def data(tree_uuid: str):
filename, data = lookyloo.get_data(tree_uuid)
if len(filename) == 0:
if filetype.guess_mime(data.getvalue()) is None:
mime = 'application/octet-stream'
else:
mime = filetype.guess_mime(data.getvalue())
return send_file(data, mimetype= mime,
as_attachment=True, attachment_filename=filename)
@app.route('/tree/<string:tree_uuid>/thumbnail/', defaults={'width': 64}, methods=['GET']) @app.route('/tree/<string:tree_uuid>/thumbnail/', defaults={'width': 64}, methods=['GET'])
@app.route('/tree/<string:tree_uuid>/thumbnail/<int:width>', methods=['GET']) @app.route('/tree/<string:tree_uuid>/thumbnail/<int:width>', methods=['GET'])

View File

@ -181,6 +181,11 @@
</p> </p>
{{ popup_icons(keys_response, url['url_object'], tree_uuid) }} {{ popup_icons(keys_response, url['url_object'], tree_uuid) }}
{% if url['url_object'].has_dl_file %}
<a href="{{ url_for('get_data', tree_uuid=tree_uuid }}">
Download file
</a>
{% if url['url_object'].rendered_html %} {% if url['url_object'].rendered_html %}
<a href="{{ url_for('urlnode_rendered_content', tree_uuid=tree_uuid, node_uuid=url['url_object'].uuid) }}"> <a href="{{ url_for('urlnode_rendered_content', tree_uuid=tree_uuid, node_uuid=url['url_object'].uuid) }}">
Download rendered HTML page Download rendered HTML page