lookyloo/lookyloo/modules/pandora.py

50 lines
1.7 KiB
Python
Raw Normal View History

2022-08-23 17:55:19 +02:00
#!/usr/bin/env python3
2024-01-12 17:15:41 +01:00
from __future__ import annotations
2022-08-23 17:55:19 +02:00
from io import BytesIO
2024-01-12 17:15:41 +01:00
from typing import Dict, Any
2022-08-23 17:55:19 +02:00
2024-01-12 17:15:41 +01:00
from pypandora import PyPandora # type: ignore[attr-defined]
2022-08-23 17:55:19 +02:00
from ..default import ConfigError
2022-08-23 17:55:19 +02:00
from ..helpers import get_useragent_for_requests
from .abstractmodule import AbstractModule
2022-08-23 17:55:19 +02:00
class Pandora(AbstractModule):
2022-08-23 17:55:19 +02:00
def module_init(self) -> bool:
if not self.config.get('url'):
self.logger.info('No URL in config.')
return False
2022-08-24 13:28:37 +02:00
self.client = PyPandora(root_url=self.config['url'], useragent=get_useragent_for_requests())
2022-08-23 17:55:19 +02:00
if not self.client.is_up:
self.logger.warning('Not up.')
return False
2022-08-23 17:55:19 +02:00
self.allow_auto_trigger = bool(self.config.get('allow_auto_trigger', False))
2022-08-23 17:55:19 +02:00
return True
2022-08-23 17:55:19 +02:00
2024-01-12 17:15:41 +01:00
def capture_default_trigger(self, file_in_memory: BytesIO, filename: str, /, auto_trigger: bool=False) -> dict[str, str]:
2022-08-23 17:55:19 +02:00
'''Automatically submit the file if the landing URL is a file instead of a webpage'''
if not self.available:
return {'error': 'Module not available'}
if auto_trigger and not self.allow_auto_trigger:
# NOTE: if auto_trigger is true, it means the request comes from the
# auto trigger feature (disabled by default)
return {'error': 'Auto trigger not allowed on module'}
self.submit_file(file_in_memory, filename)
return {'success': 'Module triggered'}
2024-01-12 17:15:41 +01:00
def submit_file(self, file_in_memory: BytesIO, filename: str) -> dict[str, Any]:
2022-08-23 17:55:19 +02:00
'''Submit a file to Pandora'''
if not self.available:
raise ConfigError('Pandora not available, probably not able to reach the server.')
return self.client.submit(file_in_memory, filename, seed_expire=0)