"""Tool Manager for Bug Bounty Hunter MCP"""
import os
import json
from typing import Dict, List, Optional
from pathlib import Path
class ToolManager:
"""Manages security tool configurations and execution"""
def __init__(self, config_path: Optional[str] = None):
"""
Initialize Tool Manager
Args:
config_path: Path to config.json file
"""
self.config_path = config_path or os.path.join(
Path(__file__).parent.parent.parent,
'config.json'
)
self.config = self.load_config()
def load_config(self) -> Dict:
"""
Load configuration from file
Returns:
Configuration dictionary
"""
if os.path.exists(self.config_path):
with open(self.config_path, 'r') as f:
return json.load(f)
return {}
def get_tool_config(self, category: str, tool: str) -> Dict:
"""
Get configuration for specific tool
Args:
category: Tool category (recon, fuzzing, vuln_scan, etc.)
tool: Tool name
Returns:
Tool configuration dictionary
"""
return self.config.get(category, {}).get(tool, {})
def get_wordlist_path(self, wordlist_type: str) -> str:
"""
Get path to wordlist
Args:
wordlist_type: Type of wordlist (subdomain, directory, parameter, etc.)
Returns:
Path to wordlist file
"""
wordlist_dir = os.getenv('WORDLIST_DIR', '/usr/share/wordlists')
wordlist_map = {
'common': os.path.join(wordlist_dir, 'dirb/common.txt'),
'medium': os.path.join(wordlist_dir, 'dirbuster/directory-list-2.3-medium.txt'),
'large': os.path.join(wordlist_dir, 'dirbuster/directory-list-2.3-big.txt'),
'subdomain': os.path.join(wordlist_dir, 'subdomains-top1million-5000.txt'),
'parameters': os.path.join(wordlist_dir, 'parameters.txt'),
'vhosts': os.path.join(wordlist_dir, 'vhosts.txt'),
}
return wordlist_map.get(wordlist_type, wordlist_map['common'])
def get_nuclei_templates(self, template_category: str = "all") -> List[str]:
"""
Get Nuclei template paths
Args:
template_category: Template category (cves, exposures, etc.)
Returns:
List of template paths
"""
nuclei_templates = os.getenv('NUCLEI_TEMPLATES', '/root/nuclei-templates')
if template_category == "all":
return [nuclei_templates]
template_map = {
'cves': os.path.join(nuclei_templates, 'cves'),
'exposures': os.path.join(nuclei_templates, 'exposures'),
'misconfigurations': os.path.join(nuclei_templates, 'misconfigurations'),
'vulnerabilities': os.path.join(nuclei_templates, 'vulnerabilities'),
'default-logins': os.path.join(nuclei_templates, 'default-logins'),
'takeovers': os.path.join(nuclei_templates, 'takeovers'),
}
return [template_map.get(template_category, nuclei_templates)]
def build_command(
self,
tool: str,
args: Dict,
flags: List[str] = []
) -> str:
"""
Build command line for tool execution
Args:
tool: Tool name
args: Arguments dictionary
flags: Additional flags
Returns:
Command string
"""
cmd_parts = [tool]
# Add arguments
for key, value in args.items():
if value is None:
continue
# Handle different argument formats
if isinstance(value, bool) and value:
cmd_parts.append(f"-{key}")
elif isinstance(value, list):
for item in value:
cmd_parts.append(f"-{key} {item}")
else:
cmd_parts.append(f"-{key} {value}")
# Add flags
cmd_parts.extend(flags)
return ' '.join(cmd_parts)