zen-ai-pentest 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. agents/__init__.py +28 -0
  2. agents/agent_base.py +239 -0
  3. agents/agent_orchestrator.py +346 -0
  4. agents/analysis_agent.py +225 -0
  5. agents/cli.py +258 -0
  6. agents/exploit_agent.py +224 -0
  7. agents/integration.py +211 -0
  8. agents/post_scan_agent.py +937 -0
  9. agents/react_agent.py +384 -0
  10. agents/react_agent_enhanced.py +616 -0
  11. agents/react_agent_vm.py +298 -0
  12. agents/research_agent.py +176 -0
  13. api/__init__.py +11 -0
  14. api/auth.py +123 -0
  15. api/main.py +1027 -0
  16. api/schemas.py +357 -0
  17. api/websocket.py +97 -0
  18. autonomous/__init__.py +122 -0
  19. autonomous/agent.py +253 -0
  20. autonomous/agent_loop.py +1370 -0
  21. autonomous/exploit_validator.py +1537 -0
  22. autonomous/memory.py +448 -0
  23. autonomous/react.py +339 -0
  24. autonomous/tool_executor.py +488 -0
  25. backends/__init__.py +16 -0
  26. backends/chatgpt_direct.py +133 -0
  27. backends/claude_direct.py +130 -0
  28. backends/duckduckgo.py +138 -0
  29. backends/openrouter.py +120 -0
  30. benchmarks/__init__.py +149 -0
  31. benchmarks/benchmark_engine.py +904 -0
  32. benchmarks/ci_benchmark.py +785 -0
  33. benchmarks/comparison.py +729 -0
  34. benchmarks/metrics.py +553 -0
  35. benchmarks/run_benchmarks.py +809 -0
  36. ci_cd/__init__.py +2 -0
  37. core/__init__.py +17 -0
  38. core/async_pool.py +282 -0
  39. core/asyncio_fix.py +222 -0
  40. core/cache.py +472 -0
  41. core/container.py +277 -0
  42. core/database.py +114 -0
  43. core/input_validator.py +353 -0
  44. core/models.py +288 -0
  45. core/orchestrator.py +611 -0
  46. core/plugin_manager.py +571 -0
  47. core/rate_limiter.py +405 -0
  48. core/secure_config.py +328 -0
  49. core/shield_integration.py +296 -0
  50. modules/__init__.py +46 -0
  51. modules/cve_database.py +362 -0
  52. modules/exploit_assist.py +330 -0
  53. modules/nuclei_integration.py +480 -0
  54. modules/osint.py +604 -0
  55. modules/protonvpn.py +554 -0
  56. modules/recon.py +165 -0
  57. modules/sql_injection_db.py +826 -0
  58. modules/tool_orchestrator.py +498 -0
  59. modules/vuln_scanner.py +292 -0
  60. modules/wordlist_generator.py +566 -0
  61. risk_engine/__init__.py +99 -0
  62. risk_engine/business_impact.py +267 -0
  63. risk_engine/business_impact_calculator.py +563 -0
  64. risk_engine/cvss.py +156 -0
  65. risk_engine/epss.py +190 -0
  66. risk_engine/example_usage.py +294 -0
  67. risk_engine/false_positive_engine.py +1073 -0
  68. risk_engine/scorer.py +304 -0
  69. web_ui/backend/main.py +471 -0
  70. zen_ai_pentest-2.0.0.dist-info/METADATA +795 -0
  71. zen_ai_pentest-2.0.0.dist-info/RECORD +75 -0
  72. zen_ai_pentest-2.0.0.dist-info/WHEEL +5 -0
  73. zen_ai_pentest-2.0.0.dist-info/entry_points.txt +2 -0
  74. zen_ai_pentest-2.0.0.dist-info/licenses/LICENSE +21 -0
  75. zen_ai_pentest-2.0.0.dist-info/top_level.txt +10 -0
@@ -0,0 +1,224 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Exploit Agent - Specializes in developing exploits and payloads
4
+ Part of the Multi-Agent Collaboration System
5
+ Author: SHAdd0WTAka
6
+ """
7
+
8
+ import asyncio
9
+ import logging
10
+ from typing import Any, Dict, List
11
+
12
+ from modules.sql_injection_db import (DBType, SQLInjectionDatabase,
13
+ SQLITechnique)
14
+
15
+ from .agent_base import AgentMessage, AgentRole, BaseAgent
16
+
17
+ logger = logging.getLogger("ZenAI.Agents")
18
+
19
+
20
+ class ExploitAgent(BaseAgent):
21
+ """
22
+ Exploit Agent - Generates exploits, payloads, and attack code
23
+ Works with Research and Analysis agents for context
24
+ """
25
+
26
+ def __init__(self, name: str, orchestrator=None, zen_orchestrator=None):
27
+ super().__init__(name, AgentRole.EXPLOIT, orchestrator)
28
+ self.zen_orchestrator = zen_orchestrator
29
+ self.sqli_db = SQLInjectionDatabase()
30
+ self.payload_cache = {}
31
+
32
+ # Register handlers
33
+ self.register_handler("exploit_request", self._handle_exploit_request)
34
+ self.register_handler("findings", self._handle_findings)
35
+ self.register_handler("analysis_result", self._handle_analysis_result)
36
+
37
+ async def _handle_exploit_request(self, msg: AgentMessage):
38
+ """Handle requests for exploit development"""
39
+ vuln_type = msg.context.get("vulnerability_type", "")
40
+ target_info = msg.context.get("target_info", {})
41
+
42
+ logger.info(
43
+ f"[ExploitAgent:{self.name}] Received exploit request for {vuln_type}"
44
+ )
45
+
46
+ # Generate exploit
47
+ exploit = await self._develop_exploit(vuln_type, target_info)
48
+
49
+ # Send back to requester
50
+ await self.send_message(
51
+ content=f"Exploit developed for {vuln_type}",
52
+ recipient=msg.sender,
53
+ msg_type="exploit_ready",
54
+ context={
55
+ "exploit": exploit,
56
+ "vulnerability": vuln_type,
57
+ "author": self.name,
58
+ },
59
+ )
60
+
61
+ # Also share with all for coordination
62
+ if exploit.get("severity") in ["critical", "high"]:
63
+ await self.send_message(
64
+ content=f"High-severity exploit available: {vuln_type}",
65
+ recipient="all",
66
+ msg_type="exploit_notification",
67
+ priority=3,
68
+ context={"exploit_summary": exploit.get("summary", "")},
69
+ )
70
+
71
+ async def _handle_findings(self, msg: AgentMessage):
72
+ """Process findings to identify exploitable vulnerabilities"""
73
+ findings = msg.context.get("findings", [])
74
+
75
+ exploitable = []
76
+ for finding in findings:
77
+ if finding.get("type") == "cve":
78
+ cve_data = finding.get("data", {})
79
+ severity = getattr(cve_data, "severity", "Unknown")
80
+ if severity in ["Critical", "High"]:
81
+ exploitable.append(finding)
82
+
83
+ if exploitable:
84
+ logger.info(
85
+ f"[ExploitAgent:{self.name}] Found {len(exploitable)} exploitable vulnerabilities"
86
+ )
87
+
88
+ # Request analysis of these for exploit development
89
+ await self.send_message(
90
+ content=f"Requesting analysis of {len(exploitable)} exploitable CVEs",
91
+ recipient="role:analyst",
92
+ msg_type="analysis_request",
93
+ context={"data": exploitable, "analysis_type": "attack_path"},
94
+ )
95
+
96
+ async def _handle_analysis_result(self, msg: AgentMessage):
97
+ """Handle analysis results to develop targeted exploits"""
98
+ analysis = msg.context.get("analysis", {})
99
+
100
+ # If analysis identified attack paths, develop exploits for them
101
+ if "paths" in analysis:
102
+ for path in analysis.get("paths", []):
103
+ # Develop exploit for each stage
104
+ pass
105
+
106
+ async def _develop_exploit(self, vuln_type: str, target_info: Dict) -> Dict:
107
+ """Develop an exploit for the given vulnerability"""
108
+ exploit = {
109
+ "vulnerability": vuln_type,
110
+ "target": target_info.get("target", "unknown"),
111
+ "severity": "medium",
112
+ "payloads": [],
113
+ "techniques": [],
114
+ "mitigation": "",
115
+ "detection": "",
116
+ "summary": "",
117
+ }
118
+
119
+ # Use SQL injection database if relevant
120
+ if "sql" in vuln_type.lower() or "injection" in vuln_type.lower():
121
+ db_type_str = target_info.get("db_type", "mysql")
122
+ try:
123
+ db_type = DBType(db_type_str)
124
+ payloads = self.sqli_db.get_payloads(
125
+ db_type=db_type, technique=SQLITechnique.UNION_BASED
126
+ )
127
+
128
+ exploit["payloads"] = [
129
+ {"name": p.name, "payload": p.payload} for p in payloads[:3]
130
+ ]
131
+ exploit["severity"] = "critical"
132
+
133
+ except ValueError:
134
+ pass
135
+
136
+ # Use LLM for complex exploit development
137
+ if self.zen_orchestrator:
138
+ prompt = f"""
139
+ Develop a proof-of-concept exploit for:
140
+ Vulnerability: {vuln_type}
141
+ Target: {target_info}
142
+
143
+ Provide:
144
+ 1. Exploit technique overview
145
+ 2. Step-by-step exploitation
146
+ 3. Sample payload (safe for testing)
147
+ 4. Detection methods
148
+ 5. Mitigation recommendations
149
+
150
+ FOR AUTHORIZED TESTING ONLY.
151
+ """
152
+
153
+ response = await self.zen_orchestrator.process(prompt)
154
+
155
+ exploit["techniques"] = response.content.split("\n")
156
+ exploit["summary"] = response.content[:200]
157
+
158
+ return exploit
159
+
160
+ async def generate_payload(self, payload_type: str, encoding: str = "raw") -> str:
161
+ """Generate a specific payload"""
162
+ if payload_type == "reverse_shell":
163
+ # Generate reverse shell payload
164
+ if self.zen_orchestrator:
165
+ prompt = """
166
+ Generate a bash reverse shell payload for testing.
167
+ Target: Linux
168
+ Safe for authorized testing only.
169
+ """
170
+ response = await self.zen_orchestrator.process(prompt)
171
+ return response.content
172
+
173
+ elif payload_type == "sqli":
174
+ # Get from SQL injection database
175
+ payloads = self.sqli_db.get_payloads(DBType.MYSQL)
176
+ if payloads:
177
+ return payloads[0].payload
178
+
179
+ return "# Payload generation failed"
180
+
181
+ async def collaborate_on_exploit(self, target_vuln: str, participants: List[str]):
182
+ """Collaborate with other agents on complex exploit development"""
183
+ # Request research from ResearchAgent
184
+ await self.send_message(
185
+ content=f"Need research on {target_vuln} for exploit development",
186
+ recipient="role:researcher",
187
+ msg_type="request_info",
188
+ requires_response=True,
189
+ context={"info_type": "exploit_vectors", "target": target_vuln},
190
+ )
191
+
192
+ # Request analysis from AnalysisAgent
193
+ await self.send_message(
194
+ content=f"Requesting attack path analysis for {target_vuln}",
195
+ recipient="role:analyst",
196
+ msg_type="analysis_request",
197
+ requires_response=True,
198
+ context={"analysis_type": "attack_path", "target": target_vuln},
199
+ )
200
+
201
+ async def execute_task(self, task: Dict) -> Dict:
202
+ """Execute exploit development task"""
203
+ task_type = task.get("type", "")
204
+ context = task.get("context", {})
205
+
206
+ logger.info(f"[ExploitAgent:{self.name}] Executing task: {task_type}")
207
+
208
+ if task_type == "exploit_development":
209
+ vuln = context.get("vulnerability", {})
210
+ exploit = await self._develop_exploit(
211
+ vuln.get("name", "unknown"), vuln.get("target_info", {})
212
+ )
213
+
214
+ # Share with coordinator
215
+ await self.send_message(
216
+ content="Exploit development complete",
217
+ recipient="role:coordinator",
218
+ msg_type="exploit_complete",
219
+ context={"exploit": exploit},
220
+ )
221
+
222
+ return {"status": "complete", "exploit": exploit, "agent": self.name}
223
+
224
+ return {"status": "unknown_task"}
agents/integration.py ADDED
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Integration Module - Connect Multi-Agent System to Zen AI Pentest
4
+ Provides easy interface for pentesters to use agent collaboration
5
+ Author: SHAdd0WTAka
6
+ """
7
+
8
+ import asyncio
9
+ import logging
10
+ from typing import Any, Dict, List, Optional
11
+
12
+ from .agent_orchestrator import AgentOrchestrator
13
+ from .analysis_agent import AnalysisAgent
14
+ from .exploit_agent import ExploitAgent
15
+ from .research_agent import ResearchAgent
16
+
17
+ logger = logging.getLogger("ZenAI.Agents")
18
+
19
+
20
+ class AgentSystemIntegration:
21
+ """
22
+ High-level interface for using the multi-agent system
23
+ Pentesters can use this to coordinate agent research and analysis
24
+ """
25
+
26
+ def __init__(self, zen_orchestrator=None):
27
+ self.agent_orchestrator = AgentOrchestrator(zen_orchestrator)
28
+ self.zen_orchestrator = zen_orchestrator
29
+ self.initialized = False
30
+
31
+ async def initialize(self):
32
+ """Initialize the agent system with default agents"""
33
+ if self.initialized:
34
+ return
35
+
36
+ logger.info("[AgentIntegration] Initializing multi-agent system...")
37
+
38
+ # Create default agents
39
+ research_agent = ResearchAgent(
40
+ name="ResearchBot-Alpha",
41
+ orchestrator=self.agent_orchestrator,
42
+ zen_orchestrator=self.zen_orchestrator,
43
+ )
44
+
45
+ analysis_agent = AnalysisAgent(
46
+ name="AnalysisBot-Beta",
47
+ orchestrator=self.agent_orchestrator,
48
+ zen_orchestrator=self.zen_orchestrator,
49
+ )
50
+
51
+ exploit_agent = ExploitAgent(
52
+ name="ExploitBot-Gamma",
53
+ orchestrator=self.agent_orchestrator,
54
+ zen_orchestrator=self.zen_orchestrator,
55
+ )
56
+
57
+ # Register agents
58
+ self.agent_orchestrator.register_agent(research_agent)
59
+ self.agent_orchestrator.register_agent(analysis_agent)
60
+ self.agent_orchestrator.register_agent(exploit_agent)
61
+
62
+ # Start all agents
63
+ await self.agent_orchestrator.start_all()
64
+
65
+ self.initialized = True
66
+ logger.info("[AgentIntegration] Multi-agent system initialized with 3 agents")
67
+
68
+ async def conduct_research(self, topic: str, pentest_context: Dict) -> str:
69
+ """
70
+ Start coordinated research on a topic
71
+ Agents will work together and share findings
72
+ """
73
+ if not self.initialized:
74
+ await self.initialize()
75
+
76
+ thread_id = await self.agent_orchestrator.start_research_coordination(
77
+ topic=topic, pentest_context=pentest_context
78
+ )
79
+
80
+ logger.info(f"[AgentIntegration] Research started: {thread_id}")
81
+
82
+ # Wait a bit for agents to work
83
+ await asyncio.sleep(2)
84
+
85
+ return thread_id
86
+
87
+ async def analyze_target(self, target: str, findings: List[Dict]) -> Dict:
88
+ """
89
+ Have agents analyze a target collaboratively
90
+ """
91
+ if not self.initialized:
92
+ await self.initialize()
93
+
94
+ logger.info(f"[AgentIntegration] Starting collaborative analysis of {target}")
95
+
96
+ # Coordinate agents for vulnerability analysis
97
+ results = await self.agent_orchestrator.coordinate_agents(
98
+ task_type="vulnerability_analysis",
99
+ context={"target": target, "findings": findings},
100
+ )
101
+
102
+ return results
103
+
104
+ async def develop_exploits(self, vulnerabilities: List[Dict]) -> List[Dict]:
105
+ """
106
+ Have ExploitAgent develop exploits for vulnerabilities
107
+ """
108
+ if not self.initialized:
109
+ await self.initialize()
110
+
111
+ exploits = []
112
+
113
+ for vuln in vulnerabilities:
114
+ # Send exploit request to ExploitAgent
115
+ await self.agent_orchestrator.agents[
116
+ list(self.agent_orchestrator.agents.keys())[2] # ExploitAgent
117
+ ].receive_message(
118
+ type(
119
+ "Msg",
120
+ (),
121
+ {
122
+ "sender": "user",
123
+ "recipient": "ExploitBot-Gamma",
124
+ "msg_type": "exploit_request",
125
+ "context": {
126
+ "vulnerability_type": vuln.get("name"),
127
+ "target_info": vuln.get("target_info", {}),
128
+ },
129
+ },
130
+ )()
131
+ )
132
+
133
+ return exploits
134
+
135
+ async def facilitate_discussion(self, topic: str, rounds: int = 3) -> List[str]:
136
+ """
137
+ Have agents discuss a topic and share insights
138
+ Similar to Clawed/Moltbot conversations
139
+ """
140
+ if not self.initialized:
141
+ await self.initialize()
142
+
143
+ agent_ids = list(self.agent_orchestrator.agents.keys())
144
+
145
+ conversation = await self.agent_orchestrator.facilitate_conversation(
146
+ topic=topic, participants=agent_ids, rounds=rounds
147
+ )
148
+
149
+ # Extract conversation content
150
+ messages = [msg.content for msg in conversation]
151
+
152
+ return messages
153
+
154
+ def get_system_status(self) -> Dict:
155
+ """Get status of the multi-agent system"""
156
+ if not self.initialized:
157
+ return {"status": "not_initialized"}
158
+
159
+ return self.agent_orchestrator.get_system_status()
160
+
161
+ async def share_context(self, key: str, value: Any):
162
+ """Share context with all agents"""
163
+ if self.initialized:
164
+ await self.agent_orchestrator.update_shared_context(
165
+ key=key, value=value, source_agent_id="user"
166
+ )
167
+
168
+ async def shutdown(self):
169
+ """Shutdown the agent system gracefully"""
170
+ if self.initialized:
171
+ await self.agent_orchestrator.stop_all()
172
+ self.initialized = False
173
+ logger.info("[AgentIntegration] Agent system shutdown complete")
174
+
175
+
176
+ # Convenience functions for direct use
177
+
178
+
179
+ async def start_collaborative_research(
180
+ topic: str, zen_orchestrator=None
181
+ ) -> AgentSystemIntegration:
182
+ """
183
+ Quick-start function to begin collaborative research
184
+
185
+ Usage:
186
+ integration = await start_collaborative_research("WordPress vulnerabilities")
187
+ # Let agents work...
188
+ status = integration.get_system_status()
189
+ """
190
+ integration = AgentSystemIntegration(zen_orchestrator)
191
+ await integration.initialize()
192
+ await integration.conduct_research(
193
+ topic=topic, pentest_context={"target_type": "web", "scope": "full"}
194
+ )
195
+ return integration
196
+
197
+
198
+ async def multi_agent_analysis(
199
+ target: str, findings: List[Dict], zen_orchestrator=None
200
+ ) -> Dict:
201
+ """
202
+ One-shot function for multi-agent analysis
203
+
204
+ Usage:
205
+ results = await multi_agent_analysis("example.com", nmap_findings)
206
+ print(results["shared_findings"])
207
+ """
208
+ integration = AgentSystemIntegration(zen_orchestrator)
209
+ results = await integration.analyze_target(target, findings)
210
+ await integration.shutdown()
211
+ return results