80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
# File: src/config.py
|
|
"""Configuration settings for the reconnaissance tool."""
|
|
|
|
import os
|
|
import logging
|
|
from dataclasses import dataclass
|
|
from typing import List, Optional
|
|
|
|
@dataclass
|
|
class Config:
|
|
"""Configuration class for the reconnaissance tool."""
|
|
|
|
# DNS servers to query
|
|
DNS_SERVERS: List[str] = None
|
|
|
|
# API keys
|
|
shodan_key: Optional[str] = None
|
|
virustotal_key: Optional[str] = None
|
|
|
|
# Rate limiting (requests per second)
|
|
# DNS servers are generally quite robust, increased from 10 to 50/s
|
|
DNS_RATE_LIMIT: float = 50.0
|
|
CRT_SH_RATE_LIMIT: float = 2.0
|
|
SHODAN_RATE_LIMIT: float = 0.5 # Shodan is more restrictive
|
|
VIRUSTOTAL_RATE_LIMIT: float = 0.25 # VirusTotal is very restrictive
|
|
|
|
# Recursive depth
|
|
max_depth: int = 2
|
|
|
|
# Timeouts
|
|
DNS_TIMEOUT: int = 5
|
|
HTTP_TIMEOUT: int = 20
|
|
|
|
# Logging level
|
|
log_level: str = "INFO"
|
|
|
|
def __post_init__(self):
|
|
if self.DNS_SERVERS is None:
|
|
# Use multiple reliable DNS servers
|
|
self.DNS_SERVERS = [
|
|
'1.1.1.1', # Cloudflare
|
|
'8.8.8.8', # Google
|
|
'9.9.9.9' # Quad9
|
|
]
|
|
|
|
@classmethod
|
|
def from_args(cls, shodan_key: Optional[str] = None,
|
|
virustotal_key: Optional[str] = None,
|
|
max_depth: int = 2,
|
|
log_level: str = "INFO") -> 'Config':
|
|
"""Create config from command line arguments."""
|
|
return cls(
|
|
shodan_key=shodan_key,
|
|
virustotal_key=virustotal_key,
|
|
max_depth=max_depth,
|
|
log_level=log_level.upper()
|
|
)
|
|
|
|
def setup_logging(self, cli_mode: bool = True):
|
|
"""Set up logging configuration."""
|
|
log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
|
|
if cli_mode:
|
|
# For CLI, use a more readable format
|
|
log_format = '%(asctime)s [%(levelname)s] %(message)s'
|
|
|
|
logging.basicConfig(
|
|
level=getattr(logging, self.log_level, logging.INFO),
|
|
format=log_format,
|
|
datefmt='%H:%M:%S'
|
|
)
|
|
|
|
# Set specific loggers
|
|
logging.getLogger('urllib3').setLevel(logging.WARNING) # Reduce HTTP noise
|
|
logging.getLogger('requests').setLevel(logging.WARNING) # Reduce HTTP noise
|
|
|
|
if self.log_level == "DEBUG":
|
|
logging.getLogger(__name__.split('.')[0]).setLevel(logging.DEBUG)
|
|
|
|
return logging.getLogger(__name__) |