From 6a9bcc0050677577dab1926c2e61910c60724aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 28 Apr 2023 17:19:49 +0200 Subject: [PATCH] new: Automatic reporting via API Related to #678 --- bin/async_capture.py | 7 +++++++ lookyloo/lookyloo.py | 4 ++-- website/web/genericapi.py | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bin/async_capture.py b/bin/async_capture.py index da50512..8cfb92c 100755 --- a/bin/async_capture.py +++ b/bin/async_capture.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import asyncio +import json import logging import logging.config import signal @@ -93,6 +94,12 @@ class AsyncCapture(AbstractManager): cookies=entries.get('cookies') # type: ignore ) + if ('auto_report' in to_capture): + settings = json.loads(to_capture['auto_report']) + if settings.get('email'): + self.lookyloo.send_mail(uuid, email=settings['email'], + comment=settings.get('comment')) + lazy_cleanup = self.lookyloo.redis.pipeline() if queue and self.lookyloo.redis.zscore('queues', queue): lazy_cleanup.zincrby('queues', -1, queue) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 125c82f..3b20727 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -666,7 +666,7 @@ class Lookyloo(): result.append(self.takedown_details(rendered_hostnode)) return result - def send_mail(self, capture_uuid: str, /, email: str='', comment: str='') -> None: + def send_mail(self, capture_uuid: str, /, email: str='', comment: Optional[str]=None) -> None: '''Send an email notification regarding a specific capture''' if not get_config('generic', 'enable_mail_notification'): return @@ -702,7 +702,7 @@ class Lookyloo(): uuid=capture_uuid, initial_url=initial_url, redirects=redirects, - comment=comment, + comment=comment if comment else '', sender=msg['From'].addresses[0].display_name, ) msg.set_content(body) diff --git a/website/web/genericapi.py b/website/web/genericapi.py index 528e282..e3da23d 100644 --- a/website/web/genericapi.py +++ b/website/web/genericapi.py @@ -355,6 +355,11 @@ class CaptureCookies(Resource): # Just text +auto_report_model = api.model('AutoReportModel', { + 'email': fields.String(description="Email of the reporter, used by the analyst to get in touch."), + 'comment': fields.String(description="Description of the URL, will be given to the analyst.") +}) + submit_fields_post = api.model('SubmitFieldsPost', { 'url': fields.Url(description="The URL to capture"), 'document': fields.String(description="A base64 encoded document, it can be anything a browser can display."), @@ -366,7 +371,8 @@ submit_fields_post = api.model('SubmitFieldsPost', { 'referer': fields.String(description="Referer to pass to the capture", example=''), 'headers': fields.String(description="Headers to pass to the capture", example='Accept-Language: en-US;q=0.5, fr-FR;q=0.4'), 'proxy': fields.Url(description="Proxy to use for the capture. Format: [scheme]://[username]:[password]@[hostname]:[port]", example=''), - 'cookies': fields.String(description="JSON export of a list of cookies as exported from an other capture", example='') + 'cookies': fields.String(description="JSON export of a list of cookies as exported from an other capture", example=''), + 'auto_report': fields.Nested(auto_report_model, description="The settings for the automatic reporting.") })