new: Automatic reporting via API

Related to #678
pull/679/head
Raphaël Vinot 2023-04-28 17:19:49 +02:00
parent c80f1b1bd7
commit 6a9bcc0050
3 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import asyncio import asyncio
import json
import logging import logging
import logging.config import logging.config
import signal import signal
@ -93,6 +94,12 @@ class AsyncCapture(AbstractManager):
cookies=entries.get('cookies') # type: ignore 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() lazy_cleanup = self.lookyloo.redis.pipeline()
if queue and self.lookyloo.redis.zscore('queues', queue): if queue and self.lookyloo.redis.zscore('queues', queue):
lazy_cleanup.zincrby('queues', -1, queue) lazy_cleanup.zincrby('queues', -1, queue)

View File

@ -666,7 +666,7 @@ class Lookyloo():
result.append(self.takedown_details(rendered_hostnode)) result.append(self.takedown_details(rendered_hostnode))
return result 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''' '''Send an email notification regarding a specific capture'''
if not get_config('generic', 'enable_mail_notification'): if not get_config('generic', 'enable_mail_notification'):
return return
@ -702,7 +702,7 @@ class Lookyloo():
uuid=capture_uuid, uuid=capture_uuid,
initial_url=initial_url, initial_url=initial_url,
redirects=redirects, redirects=redirects,
comment=comment, comment=comment if comment else '',
sender=msg['From'].addresses[0].display_name, sender=msg['From'].addresses[0].display_name,
) )
msg.set_content(body) msg.set_content(body)

View File

@ -355,6 +355,11 @@ class CaptureCookies(Resource):
# Just text # 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', { submit_fields_post = api.model('SubmitFieldsPost', {
'url': fields.Url(description="The URL to capture"), 'url': fields.Url(description="The URL to capture"),
'document': fields.String(description="A base64 encoded document, it can be anything a browser can display."), '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=''), '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'), '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=''), '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.")
}) })