Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /mcp /zen-agents /server.py
| """ | |
| Zen-Agents MCP Server – 11 spezialisierte Agenten als MCP-Tools. | |
| Ermöglicht Hermes/openCode: | |
| - Einzelne Agenten ausführen (recon, exploit, analysis, ...) | |
| - Workflows orchestrieren (k-audit) | |
| - Agent-Status abfragen | |
| """ | |
| import asyncio | |
| import json | |
| import os | |
| from typing import Any | |
| from mcp.server.fastmcp import FastMCP | |
| from agents.agent_coordinator_v3 import AgentCoordinator, create_agent, WorkflowPhase | |
| from agents.react_agent import ReActAgent | |
| from agents.guardrails import RISK_SAFE, RISK_NORMAL, RISK_ELEVATED, RISK_AGGRESSIVE | |
| mcp = FastMCP( | |
| "zen-agents", | |
| instructions="11 spezialisierte Pentest-Agenten: Recon, Exploit, Analysis, Report, RedTeam, Social, Network, Cloud, ICS, Mobile, Crypto.", | |
| ) | |
| coordinator = AgentCoordinator() | |
| _active_agents: dict[str, ReActAgent] = {} | |
| RISK_MAP = { | |
| "SAFE": RISK_SAFE, | |
| "NORMAL": RISK_NORMAL, | |
| "ELEVATED": RISK_ELEVATED, | |
| "AGGRESSIVE": RISK_AGGRESSIVE, | |
| } | |
| AGENT_DESCRIPTIONS = { | |
| "recon": "Reconnaissance – OSINT, Subdomain-Enumeration, Port-Scans", | |
| "exploit": "Exploitation – Automatische Exploit-Auswahl, Sandbox-Execution", | |
| "analysis": "Analysis – False-Positive-Erkennung, CVSS/EPSS-Scoring", | |
| "report": "Reporting – PDF/HTML/DOCX-Report-Generierung", | |
| "redteam": "Red Team – Full-scope adversarial simulation", | |
| "social": "Social Engineering – Phishing-Simulation, OSINT", | |
| "network": "Network – Netzwerk-Infrastruktur-Tests", | |
| "cloud": "Cloud – AWS/Azure/GCP Security Assessment", | |
| "ics": "ICS/SCADA – Industrial Systems Security", | |
| "mobile": "Mobile – iOS/Android Security", | |
| "crypto": "Crypto – Cryptographic Analysis", | |
| } | |
| def agent_list() -> str: | |
| """List all available specialized agents.""" | |
| return json.dumps( | |
| { | |
| "agents": [{"id": aid, "description": desc} for aid, desc in AGENT_DESCRIPTIONS.items()], | |
| "count": len(AGENT_DESCRIPTIONS), | |
| } | |
| ) | |
| def agent_run( | |
| agent_type: str = "recon", | |
| target: str = "", | |
| task: str = "", | |
| risk_level: str = "NORMAL", | |
| ) -> str: | |
| """Run a single specialized agent on a target. | |
| Args: | |
| agent_type: Agent type (recon, exploit, analysis, report, redteam, social, network, cloud, ics, mobile, crypto) | |
| target: Target domain/IP | |
| task: Custom task description (optional) | |
| risk_level: Risk level (SAFE, NORMAL, ELEVATED, AGGRESSIVE) | |
| """ | |
| if agent_type not in AGENT_DESCRIPTIONS: | |
| return json.dumps( | |
| {"status": "error", "error": f"Unknown agent: {agent_type}. Use agent_list to see available agents."} | |
| ) | |
| risk = RISK_MAP.get(risk_level.upper(), RISK_NORMAL) | |
| agent = create_agent(f"{agent_type}_agent", risk_level=risk) | |
| full_task = task or f"Run {agent_type} analysis on {target}" | |
| try: | |
| result = asyncio.run(agent.run(full_task)) | |
| return json.dumps({"status": "ok", "agent": agent_type, "target": target, "result": result}) | |
| except Exception as e: | |
| return json.dumps({"status": "error", "agent": agent_type, "error": str(e)}) | |
| def workflow_create( | |
| target: str = "", | |
| phases: str = "recon,scan,exploit,report", | |
| risk_level: str = "NORMAL", | |
| ) -> str: | |
| """Create and execute a multi-agent workflow. | |
| Args: | |
| target: Target domain/IP to audit | |
| phases: Comma-separated phases (recon, scan, exploit, report, audit, social, network, mobile, redteam, ics, cloud, crypto) | |
| risk_level: Risk level (SAFE, NORMAL, ELEVATED, AGGRESSIVE) | |
| """ | |
| if not target: | |
| return json.dumps({"status": "error", "error": "target is required"}) | |
| phase_list = [p.strip() for p in phases.split(",")] | |
| risk = RISK_MAP.get(risk_level.upper(), RISK_NORMAL) | |
| coord = AgentCoordinator(risk_level=risk) | |
| workflow = coord.create_workflow(target=target, phases=phase_list) | |
| try: | |
| result = asyncio.run(coord.execute_workflow(workflow)) | |
| return json.dumps({"status": "ok", "workflow_id": workflow.workflow_id, "result": result}) | |
| except Exception as e: | |
| return json.dumps({"status": "error", "workflow_id": workflow.workflow_id, "error": str(e)}) | |
| def workflow_status( | |
| workflow_id: str = "", | |
| ) -> str: | |
| """Get workflow execution status. | |
| Args: | |
| workflow_id: Workflow ID from workflow_create | |
| """ | |
| if not workflow_id: | |
| return json.dumps({"status": "ok", "workflows": coordinator.list_workflows()}) | |
| wf = coordinator.get_workflow(workflow_id) | |
| if wf: | |
| return json.dumps({"status": "ok", "workflow": wf}) | |
| return json.dumps({"status": "error", "error": f"Workflow {workflow_id} not found"}) | |
| def agent_state() -> str: | |
| """Get global agent system state (active agents, workflows).""" | |
| return json.dumps(coordinator.get_state()) | |
| def full_audit( | |
| target: str = "", | |
| phases: str = "recon,scan,exploit,report", | |
| output_dir: str = "", | |
| force: bool = False, | |
| ) -> str: | |
| """Run a complete security audit workflow (k-audit equivalent). | |
| Args: | |
| target: Target domain/IP | |
| phases: Comma-separated phases | |
| output_dir: Directory to save results | |
| force: Bypass guardrails | |
| """ | |
| if not target: | |
| return json.dumps({"status": "error", "error": "target is required"}) | |
| risk = RISK_AGGRESSIVE if force else RISK_NORMAL | |
| coord = AgentCoordinator(risk_level=risk) | |
| phase_list = [p.strip() for p in phases.split(",")] | |
| workflow = coord.create_workflow(target=target, phases=phase_list) | |
| try: | |
| result = asyncio.run(coord.execute_workflow(workflow)) | |
| report = {"status": "ok", "workflow_id": workflow.workflow_id, "target": target, "result": result} | |
| if output_dir: | |
| import os | |
| os.makedirs(output_dir, exist_ok=True) | |
| path = os.path.join(output_dir, f"audit-{workflow.workflow_id}.json") | |
| with open(path, "w") as f: | |
| json.dump(report, f, indent=2) | |
| return json.dumps(report) | |
| except Exception as e: | |
| return json.dumps({"status": "error", "error": str(e)}) | |
| def main(): | |
| mcp.run() | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 6.2 kB
- Xet hash:
- 0ffbaaceb05dc7eb7040fe74b6d5991e9d6ed07e316290911cd5322e13c5bcab
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.