aiptx 2.0.2__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.

Potentially problematic release.


This version of aiptx might be problematic. Click here for more details.

Files changed (165) hide show
  1. aipt_v2/__init__.py +110 -0
  2. aipt_v2/__main__.py +24 -0
  3. aipt_v2/agents/AIPTxAgent/__init__.py +10 -0
  4. aipt_v2/agents/AIPTxAgent/aiptx_agent.py +211 -0
  5. aipt_v2/agents/__init__.py +24 -0
  6. aipt_v2/agents/base.py +520 -0
  7. aipt_v2/agents/ptt.py +406 -0
  8. aipt_v2/agents/state.py +168 -0
  9. aipt_v2/app.py +960 -0
  10. aipt_v2/browser/__init__.py +31 -0
  11. aipt_v2/browser/automation.py +458 -0
  12. aipt_v2/browser/crawler.py +453 -0
  13. aipt_v2/cli.py +321 -0
  14. aipt_v2/compliance/__init__.py +71 -0
  15. aipt_v2/compliance/compliance_report.py +449 -0
  16. aipt_v2/compliance/framework_mapper.py +424 -0
  17. aipt_v2/compliance/nist_mapping.py +345 -0
  18. aipt_v2/compliance/owasp_mapping.py +330 -0
  19. aipt_v2/compliance/pci_mapping.py +297 -0
  20. aipt_v2/config.py +288 -0
  21. aipt_v2/core/__init__.py +43 -0
  22. aipt_v2/core/agent.py +630 -0
  23. aipt_v2/core/llm.py +395 -0
  24. aipt_v2/core/memory.py +305 -0
  25. aipt_v2/core/ptt.py +329 -0
  26. aipt_v2/database/__init__.py +14 -0
  27. aipt_v2/database/models.py +232 -0
  28. aipt_v2/database/repository.py +384 -0
  29. aipt_v2/docker/__init__.py +23 -0
  30. aipt_v2/docker/builder.py +260 -0
  31. aipt_v2/docker/manager.py +222 -0
  32. aipt_v2/docker/sandbox.py +371 -0
  33. aipt_v2/evasion/__init__.py +58 -0
  34. aipt_v2/evasion/request_obfuscator.py +272 -0
  35. aipt_v2/evasion/tls_fingerprint.py +285 -0
  36. aipt_v2/evasion/ua_rotator.py +301 -0
  37. aipt_v2/evasion/waf_bypass.py +439 -0
  38. aipt_v2/execution/__init__.py +23 -0
  39. aipt_v2/execution/executor.py +302 -0
  40. aipt_v2/execution/parser.py +544 -0
  41. aipt_v2/execution/terminal.py +337 -0
  42. aipt_v2/health.py +437 -0
  43. aipt_v2/intelligence/__init__.py +85 -0
  44. aipt_v2/intelligence/auth.py +520 -0
  45. aipt_v2/intelligence/chaining.py +775 -0
  46. aipt_v2/intelligence/cve_aipt.py +334 -0
  47. aipt_v2/intelligence/cve_info.py +1111 -0
  48. aipt_v2/intelligence/rag.py +239 -0
  49. aipt_v2/intelligence/scope.py +442 -0
  50. aipt_v2/intelligence/searchers/__init__.py +5 -0
  51. aipt_v2/intelligence/searchers/exploitdb_searcher.py +523 -0
  52. aipt_v2/intelligence/searchers/github_searcher.py +467 -0
  53. aipt_v2/intelligence/searchers/google_searcher.py +281 -0
  54. aipt_v2/intelligence/tools.json +443 -0
  55. aipt_v2/intelligence/triage.py +670 -0
  56. aipt_v2/interface/__init__.py +5 -0
  57. aipt_v2/interface/cli.py +230 -0
  58. aipt_v2/interface/main.py +501 -0
  59. aipt_v2/interface/tui.py +1276 -0
  60. aipt_v2/interface/utils.py +583 -0
  61. aipt_v2/llm/__init__.py +39 -0
  62. aipt_v2/llm/config.py +26 -0
  63. aipt_v2/llm/llm.py +514 -0
  64. aipt_v2/llm/memory.py +214 -0
  65. aipt_v2/llm/request_queue.py +89 -0
  66. aipt_v2/llm/utils.py +89 -0
  67. aipt_v2/models/__init__.py +15 -0
  68. aipt_v2/models/findings.py +295 -0
  69. aipt_v2/models/phase_result.py +224 -0
  70. aipt_v2/models/scan_config.py +207 -0
  71. aipt_v2/monitoring/grafana/dashboards/aipt-dashboard.json +355 -0
  72. aipt_v2/monitoring/grafana/dashboards/default.yml +17 -0
  73. aipt_v2/monitoring/grafana/datasources/prometheus.yml +17 -0
  74. aipt_v2/monitoring/prometheus.yml +60 -0
  75. aipt_v2/orchestration/__init__.py +52 -0
  76. aipt_v2/orchestration/pipeline.py +398 -0
  77. aipt_v2/orchestration/progress.py +300 -0
  78. aipt_v2/orchestration/scheduler.py +296 -0
  79. aipt_v2/orchestrator.py +2284 -0
  80. aipt_v2/payloads/__init__.py +27 -0
  81. aipt_v2/payloads/cmdi.py +150 -0
  82. aipt_v2/payloads/sqli.py +263 -0
  83. aipt_v2/payloads/ssrf.py +204 -0
  84. aipt_v2/payloads/templates.py +222 -0
  85. aipt_v2/payloads/traversal.py +166 -0
  86. aipt_v2/payloads/xss.py +204 -0
  87. aipt_v2/prompts/__init__.py +60 -0
  88. aipt_v2/proxy/__init__.py +29 -0
  89. aipt_v2/proxy/history.py +352 -0
  90. aipt_v2/proxy/interceptor.py +452 -0
  91. aipt_v2/recon/__init__.py +44 -0
  92. aipt_v2/recon/dns.py +241 -0
  93. aipt_v2/recon/osint.py +367 -0
  94. aipt_v2/recon/subdomain.py +372 -0
  95. aipt_v2/recon/tech_detect.py +311 -0
  96. aipt_v2/reports/__init__.py +17 -0
  97. aipt_v2/reports/generator.py +313 -0
  98. aipt_v2/reports/html_report.py +378 -0
  99. aipt_v2/runtime/__init__.py +44 -0
  100. aipt_v2/runtime/base.py +30 -0
  101. aipt_v2/runtime/docker.py +401 -0
  102. aipt_v2/runtime/local.py +346 -0
  103. aipt_v2/runtime/tool_server.py +205 -0
  104. aipt_v2/scanners/__init__.py +28 -0
  105. aipt_v2/scanners/base.py +273 -0
  106. aipt_v2/scanners/nikto.py +244 -0
  107. aipt_v2/scanners/nmap.py +402 -0
  108. aipt_v2/scanners/nuclei.py +273 -0
  109. aipt_v2/scanners/web.py +454 -0
  110. aipt_v2/scripts/security_audit.py +366 -0
  111. aipt_v2/telemetry/__init__.py +7 -0
  112. aipt_v2/telemetry/tracer.py +347 -0
  113. aipt_v2/terminal/__init__.py +28 -0
  114. aipt_v2/terminal/executor.py +400 -0
  115. aipt_v2/terminal/sandbox.py +350 -0
  116. aipt_v2/tools/__init__.py +44 -0
  117. aipt_v2/tools/active_directory/__init__.py +78 -0
  118. aipt_v2/tools/active_directory/ad_config.py +238 -0
  119. aipt_v2/tools/active_directory/bloodhound_wrapper.py +447 -0
  120. aipt_v2/tools/active_directory/kerberos_attacks.py +430 -0
  121. aipt_v2/tools/active_directory/ldap_enum.py +533 -0
  122. aipt_v2/tools/active_directory/smb_attacks.py +505 -0
  123. aipt_v2/tools/agents_graph/__init__.py +19 -0
  124. aipt_v2/tools/agents_graph/agents_graph_actions.py +69 -0
  125. aipt_v2/tools/api_security/__init__.py +76 -0
  126. aipt_v2/tools/api_security/api_discovery.py +608 -0
  127. aipt_v2/tools/api_security/graphql_scanner.py +622 -0
  128. aipt_v2/tools/api_security/jwt_analyzer.py +577 -0
  129. aipt_v2/tools/api_security/openapi_fuzzer.py +761 -0
  130. aipt_v2/tools/browser/__init__.py +5 -0
  131. aipt_v2/tools/browser/browser_actions.py +238 -0
  132. aipt_v2/tools/browser/browser_instance.py +535 -0
  133. aipt_v2/tools/browser/tab_manager.py +344 -0
  134. aipt_v2/tools/cloud/__init__.py +70 -0
  135. aipt_v2/tools/cloud/cloud_config.py +273 -0
  136. aipt_v2/tools/cloud/cloud_scanner.py +639 -0
  137. aipt_v2/tools/cloud/prowler_tool.py +571 -0
  138. aipt_v2/tools/cloud/scoutsuite_tool.py +359 -0
  139. aipt_v2/tools/executor.py +307 -0
  140. aipt_v2/tools/parser.py +408 -0
  141. aipt_v2/tools/proxy/__init__.py +5 -0
  142. aipt_v2/tools/proxy/proxy_actions.py +103 -0
  143. aipt_v2/tools/proxy/proxy_manager.py +789 -0
  144. aipt_v2/tools/registry.py +196 -0
  145. aipt_v2/tools/scanners/__init__.py +343 -0
  146. aipt_v2/tools/scanners/acunetix_tool.py +712 -0
  147. aipt_v2/tools/scanners/burp_tool.py +631 -0
  148. aipt_v2/tools/scanners/config.py +156 -0
  149. aipt_v2/tools/scanners/nessus_tool.py +588 -0
  150. aipt_v2/tools/scanners/zap_tool.py +612 -0
  151. aipt_v2/tools/terminal/__init__.py +5 -0
  152. aipt_v2/tools/terminal/terminal_actions.py +37 -0
  153. aipt_v2/tools/terminal/terminal_manager.py +153 -0
  154. aipt_v2/tools/terminal/terminal_session.py +449 -0
  155. aipt_v2/tools/tool_processing.py +108 -0
  156. aipt_v2/utils/__init__.py +17 -0
  157. aipt_v2/utils/logging.py +201 -0
  158. aipt_v2/utils/model_manager.py +187 -0
  159. aipt_v2/utils/searchers/__init__.py +269 -0
  160. aiptx-2.0.2.dist-info/METADATA +324 -0
  161. aiptx-2.0.2.dist-info/RECORD +165 -0
  162. aiptx-2.0.2.dist-info/WHEEL +5 -0
  163. aiptx-2.0.2.dist-info/entry_points.txt +7 -0
  164. aiptx-2.0.2.dist-info/licenses/LICENSE +21 -0
  165. aiptx-2.0.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,501 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ AIPTx Agent Interface
4
+ """
5
+
6
+ import argparse
7
+ import asyncio
8
+ import logging
9
+ import os
10
+ import shutil
11
+ import sys
12
+ from pathlib import Path
13
+ from typing import Any
14
+
15
+ import litellm
16
+ from docker.errors import DockerException
17
+ from rich.console import Console
18
+ from rich.panel import Panel
19
+ from rich.text import Text
20
+
21
+ from aipt_v2.interface.cli import run_cli
22
+ from aipt_v2.interface.tui import run_tui
23
+ from aipt_v2.interface.utils import (
24
+ assign_workspace_subdirs,
25
+ build_final_stats_text,
26
+ check_docker_connection,
27
+ clone_repository,
28
+ collect_local_sources,
29
+ generate_run_name,
30
+ image_exists,
31
+ infer_target_type,
32
+ process_pull_line,
33
+ validate_llm_response,
34
+ )
35
+ from aipt_v2.runtime.docker_runtime import AIPT_IMAGE
36
+ from aipt_v2.telemetry.tracer import get_global_tracer
37
+
38
+
39
+ logging.getLogger().setLevel(logging.ERROR)
40
+
41
+
42
+ def validate_environment() -> None: # noqa: PLR0912, PLR0915
43
+ console = Console()
44
+ missing_required_vars = []
45
+ missing_optional_vars = []
46
+
47
+ if not os.getenv("AIPT_LLM"):
48
+ missing_required_vars.append("AIPT_LLM")
49
+
50
+ has_base_url = any(
51
+ [
52
+ os.getenv("LLM_API_BASE"),
53
+ os.getenv("OPENAI_API_BASE"),
54
+ os.getenv("LITELLM_BASE_URL"),
55
+ os.getenv("OLLAMA_API_BASE"),
56
+ ]
57
+ )
58
+
59
+ if not os.getenv("LLM_API_KEY"):
60
+ if not has_base_url:
61
+ missing_required_vars.append("LLM_API_KEY")
62
+ else:
63
+ missing_optional_vars.append("LLM_API_KEY")
64
+
65
+ if not has_base_url:
66
+ missing_optional_vars.append("LLM_API_BASE")
67
+
68
+ if not os.getenv("PERPLEXITY_API_KEY"):
69
+ missing_optional_vars.append("PERPLEXITY_API_KEY")
70
+
71
+ if missing_required_vars:
72
+ error_text = Text()
73
+ error_text.append("❌ ", style="bold red")
74
+ error_text.append("MISSING REQUIRED ENVIRONMENT VARIABLES", style="bold red")
75
+ error_text.append("\n\n", style="white")
76
+
77
+ for var in missing_required_vars:
78
+ error_text.append(f"• {var}", style="bold yellow")
79
+ error_text.append(" is not set\n", style="white")
80
+
81
+ if missing_optional_vars:
82
+ error_text.append("\nOptional environment variables:\n", style="dim white")
83
+ for var in missing_optional_vars:
84
+ error_text.append(f"• {var}", style="dim yellow")
85
+ error_text.append(" is not set\n", style="dim white")
86
+
87
+ error_text.append("\nRequired environment variables:\n", style="white")
88
+ for var in missing_required_vars:
89
+ if var == "AIPT_LLM":
90
+ error_text.append("• ", style="white")
91
+ error_text.append("AIPT_LLM", style="bold cyan")
92
+ error_text.append(
93
+ " - Model name to use with litellm (e.g., 'openai/gpt-5')\n",
94
+ style="white",
95
+ )
96
+ elif var == "LLM_API_KEY":
97
+ error_text.append("• ", style="white")
98
+ error_text.append("LLM_API_KEY", style="bold cyan")
99
+ error_text.append(
100
+ " - API key for the LLM provider (required for cloud providers)\n",
101
+ style="white",
102
+ )
103
+
104
+ if missing_optional_vars:
105
+ error_text.append("\nOptional environment variables:\n", style="white")
106
+ for var in missing_optional_vars:
107
+ if var == "LLM_API_KEY":
108
+ error_text.append("• ", style="white")
109
+ error_text.append("LLM_API_KEY", style="bold cyan")
110
+ error_text.append(" - API key for the LLM provider\n", style="white")
111
+ elif var == "LLM_API_BASE":
112
+ error_text.append("• ", style="white")
113
+ error_text.append("LLM_API_BASE", style="bold cyan")
114
+ error_text.append(
115
+ " - Custom API base URL if using local models (e.g., Ollama, LMStudio)\n",
116
+ style="white",
117
+ )
118
+ elif var == "PERPLEXITY_API_KEY":
119
+ error_text.append("• ", style="white")
120
+ error_text.append("PERPLEXITY_API_KEY", style="bold cyan")
121
+ error_text.append(
122
+ " - API key for Perplexity AI web search (enables real-time research)\n",
123
+ style="white",
124
+ )
125
+
126
+ error_text.append("\nExample setup:\n", style="white")
127
+ error_text.append("export AIPT_LLM='openai/gpt-5'\n", style="dim white")
128
+
129
+ if "LLM_API_KEY" in missing_required_vars:
130
+ error_text.append("export LLM_API_KEY='your-api-key-here'\n", style="dim white")
131
+
132
+ if missing_optional_vars:
133
+ for var in missing_optional_vars:
134
+ if var == "LLM_API_KEY":
135
+ error_text.append(
136
+ "export LLM_API_KEY='your-api-key-here' # optional with local models\n",
137
+ style="dim white",
138
+ )
139
+ elif var == "LLM_API_BASE":
140
+ error_text.append(
141
+ "export LLM_API_BASE='http://localhost:11434' "
142
+ "# needed for local models only\n",
143
+ style="dim white",
144
+ )
145
+ elif var == "PERPLEXITY_API_KEY":
146
+ error_text.append(
147
+ "export PERPLEXITY_API_KEY='your-perplexity-key-here'\n", style="dim white"
148
+ )
149
+
150
+ panel = Panel(
151
+ error_text,
152
+ title="[bold red]🛡️ AIPT CONFIGURATION ERROR",
153
+ title_align="center",
154
+ border_style="red",
155
+ padding=(1, 2),
156
+ )
157
+
158
+ console.print("\n")
159
+ console.print(panel)
160
+ console.print()
161
+ sys.exit(1)
162
+
163
+
164
+ def check_docker_installed() -> None:
165
+ if shutil.which("docker") is None:
166
+ console = Console()
167
+ error_text = Text()
168
+ error_text.append("❌ ", style="bold red")
169
+ error_text.append("DOCKER NOT INSTALLED", style="bold red")
170
+ error_text.append("\n\n", style="white")
171
+ error_text.append("The 'docker' CLI was not found in your PATH.\n", style="white")
172
+ error_text.append(
173
+ "Please install Docker and ensure the 'docker' command is available.\n\n", style="white"
174
+ )
175
+
176
+ panel = Panel(
177
+ error_text,
178
+ title="[bold red]🛡️ AIPT STARTUP ERROR",
179
+ title_align="center",
180
+ border_style="red",
181
+ padding=(1, 2),
182
+ )
183
+ console.print("\n", panel, "\n")
184
+ sys.exit(1)
185
+
186
+
187
+ async def warm_up_llm() -> None:
188
+ console = Console()
189
+
190
+ try:
191
+ model_name = os.getenv("AIPT_LLM", "openai/gpt-5")
192
+ api_key = os.getenv("LLM_API_KEY")
193
+ api_base = (
194
+ os.getenv("LLM_API_BASE")
195
+ or os.getenv("OPENAI_API_BASE")
196
+ or os.getenv("LITELLM_BASE_URL")
197
+ or os.getenv("OLLAMA_API_BASE")
198
+ )
199
+
200
+ test_messages = [
201
+ {"role": "system", "content": "You are a helpful assistant."},
202
+ {"role": "user", "content": "Reply with just 'OK'."},
203
+ ]
204
+
205
+ llm_timeout = int(os.getenv("LLM_TIMEOUT", "600"))
206
+
207
+ completion_kwargs: dict[str, Any] = {
208
+ "model": model_name,
209
+ "messages": test_messages,
210
+ "timeout": llm_timeout,
211
+ }
212
+ if api_key:
213
+ completion_kwargs["api_key"] = api_key
214
+ if api_base:
215
+ completion_kwargs["api_base"] = api_base
216
+
217
+ response = litellm.completion(**completion_kwargs)
218
+
219
+ validate_llm_response(response)
220
+
221
+ except Exception as e: # noqa: BLE001
222
+ error_text = Text()
223
+ error_text.append("❌ ", style="bold red")
224
+ error_text.append("LLM CONNECTION FAILED", style="bold red")
225
+ error_text.append("\n\n", style="white")
226
+ error_text.append("Could not establish connection to the language model.\n", style="white")
227
+ error_text.append("Please check your configuration and try again.\n", style="white")
228
+ error_text.append(f"\nError: {e}", style="dim white")
229
+
230
+ panel = Panel(
231
+ error_text,
232
+ title="[bold red]🛡️ AIPT STARTUP ERROR",
233
+ title_align="center",
234
+ border_style="red",
235
+ padding=(1, 2),
236
+ )
237
+
238
+ console.print("\n")
239
+ console.print(panel)
240
+ console.print()
241
+ sys.exit(1)
242
+
243
+
244
+ def parse_arguments() -> argparse.Namespace:
245
+ parser = argparse.ArgumentParser(
246
+ description="AIPTx Multi-Agent Cybersecurity Penetration Testing Tool",
247
+ formatter_class=argparse.RawDescriptionHelpFormatter,
248
+ epilog="""
249
+ Examples:
250
+ # Web application penetration test
251
+ aipt --target https://example.com
252
+
253
+ # GitHub repository analysis
254
+ aipt --target https://github.com/user/repo
255
+ aipt --target git@github.com:user/repo.git
256
+
257
+ # Local code analysis
258
+ aipt --target ./my-project
259
+
260
+ # Domain penetration test
261
+ aipt --target example.com
262
+
263
+ # IP address penetration test
264
+ aipt --target 192.168.1.42
265
+
266
+ # Multiple targets (e.g., white-box testing with source and deployed app)
267
+ aipt --target https://github.com/user/repo --target https://example.com
268
+ aipt --target ./my-project --target https://staging.example.com --target https://prod.example.com
269
+
270
+ # Custom instructions (inline)
271
+ aipt --target example.com --instruction "Focus on authentication vulnerabilities"
272
+
273
+ # Custom instructions (from file)
274
+ aipt --target example.com --instruction ./instructions.txt
275
+ aipt --target https://app.com --instruction /path/to/detailed_instructions.md
276
+ """,
277
+ )
278
+
279
+ parser.add_argument(
280
+ "-t",
281
+ "--target",
282
+ type=str,
283
+ required=True,
284
+ action="append",
285
+ help="Target to test (URL, repository, local directory path, domain name, or IP address). "
286
+ "Can be specified multiple times for multi-target scans.",
287
+ )
288
+ parser.add_argument(
289
+ "--instruction",
290
+ type=str,
291
+ help="Custom instructions for the penetration test. This can be "
292
+ "specific vulnerability types to focus on (e.g., 'Focus on IDOR and XSS'), "
293
+ "testing approaches (e.g., 'Perform thorough authentication testing'), "
294
+ "test credentials (e.g., 'Use the following credentials to access the app: "
295
+ "admin:password123'), "
296
+ "or areas of interest (e.g., 'Check login API endpoint for security issues'). "
297
+ "You can also provide a path to a file containing detailed instructions "
298
+ "(e.g., '--instruction ./instructions.txt').",
299
+ )
300
+
301
+ parser.add_argument(
302
+ "--run-name",
303
+ type=str,
304
+ help="Custom name for this penetration test run",
305
+ )
306
+
307
+ parser.add_argument(
308
+ "-n",
309
+ "--non-interactive",
310
+ action="store_true",
311
+ help=(
312
+ "Run in non-interactive mode (no TUI, exits on completion). "
313
+ "Default is interactive mode with TUI."
314
+ ),
315
+ )
316
+
317
+ args = parser.parse_args()
318
+
319
+ if args.instruction:
320
+ instruction_path = Path(args.instruction)
321
+ if instruction_path.exists() and instruction_path.is_file():
322
+ try:
323
+ with instruction_path.open(encoding="utf-8") as f:
324
+ args.instruction = f.read().strip()
325
+ if not args.instruction:
326
+ parser.error(f"Instruction file '{instruction_path}' is empty")
327
+ except Exception as e: # noqa: BLE001
328
+ parser.error(f"Failed to read instruction file '{instruction_path}': {e}")
329
+
330
+ args.targets_info = []
331
+ for target in args.target:
332
+ try:
333
+ target_type, target_dict = infer_target_type(target)
334
+
335
+ if target_type == "local_code":
336
+ display_target = target_dict.get("target_path", target)
337
+ else:
338
+ display_target = target
339
+
340
+ args.targets_info.append(
341
+ {"type": target_type, "details": target_dict, "original": display_target}
342
+ )
343
+ except ValueError:
344
+ parser.error(f"Invalid target '{target}'")
345
+
346
+ assign_workspace_subdirs(args.targets_info)
347
+
348
+ return args
349
+
350
+
351
+ def display_completion_message(args: argparse.Namespace, results_path: Path) -> None:
352
+ console = Console()
353
+ tracer = get_global_tracer()
354
+
355
+ scan_completed = False
356
+ if tracer and tracer.scan_results:
357
+ scan_completed = tracer.scan_results.get("scan_completed", False)
358
+
359
+ has_vulnerabilities = tracer and len(tracer.vulnerability_reports) > 0
360
+
361
+ completion_text = Text()
362
+ if scan_completed:
363
+ completion_text.append("🦉 ", style="bold white")
364
+ completion_text.append("AGENT FINISHED", style="bold green")
365
+ completion_text.append(" • ", style="dim white")
366
+ completion_text.append("Penetration test completed", style="white")
367
+ else:
368
+ completion_text.append("🦉 ", style="bold white")
369
+ completion_text.append("SESSION ENDED", style="bold yellow")
370
+ completion_text.append(" • ", style="dim white")
371
+ completion_text.append("Penetration test interrupted by user", style="white")
372
+
373
+ stats_text = build_final_stats_text(tracer)
374
+
375
+ target_text = Text()
376
+ if len(args.targets_info) == 1:
377
+ target_text.append("🎯 Target: ", style="bold cyan")
378
+ target_text.append(args.targets_info[0]["original"], style="bold white")
379
+ else:
380
+ target_text.append("🎯 Targets: ", style="bold cyan")
381
+ target_text.append(f"{len(args.targets_info)} targets\n", style="bold white")
382
+ for i, target_info in enumerate(args.targets_info):
383
+ target_text.append(" • ", style="dim white")
384
+ target_text.append(target_info["original"], style="white")
385
+ if i < len(args.targets_info) - 1:
386
+ target_text.append("\n")
387
+
388
+ panel_parts = [completion_text, "\n\n", target_text]
389
+
390
+ if stats_text.plain:
391
+ panel_parts.extend(["\n", stats_text])
392
+
393
+ if scan_completed or has_vulnerabilities:
394
+ results_text = Text()
395
+ results_text.append("📊 Results Saved To: ", style="bold cyan")
396
+ results_text.append(str(results_path), style="bold yellow")
397
+ panel_parts.extend(["\n\n", results_text])
398
+
399
+ panel_content = Text.assemble(*panel_parts)
400
+
401
+ border_style = "green" if scan_completed else "yellow"
402
+
403
+ panel = Panel(
404
+ panel_content,
405
+ title="[bold green]🛡️ AIPT PENETRATION TESTING AGENT",
406
+ title_align="center",
407
+ border_style=border_style,
408
+ padding=(1, 2),
409
+ )
410
+
411
+ console.print("\n")
412
+ console.print(panel)
413
+ console.print()
414
+
415
+
416
+ def pull_docker_image() -> None:
417
+ console = Console()
418
+ client = check_docker_connection()
419
+
420
+ if image_exists(client, AIPT_IMAGE):
421
+ return
422
+
423
+ console.print()
424
+ console.print(f"[bold cyan]🐳 Pulling Docker image:[/] {AIPT_IMAGE}")
425
+ console.print("[dim yellow]This only happens on first run and may take a few minutes...[/]")
426
+ console.print()
427
+
428
+ with console.status("[bold cyan]Downloading image layers...", spinner="dots") as status:
429
+ try:
430
+ layers_info: dict[str, str] = {}
431
+ last_update = ""
432
+
433
+ for line in client.api.pull(AIPT_IMAGE, stream=True, decode=True):
434
+ last_update = process_pull_line(line, layers_info, status, last_update)
435
+
436
+ except DockerException as e:
437
+ console.print()
438
+ error_text = Text()
439
+ error_text.append("❌ ", style="bold red")
440
+ error_text.append("FAILED TO PULL IMAGE", style="bold red")
441
+ error_text.append("\n\n", style="white")
442
+ error_text.append(f"Could not download: {AIPT_IMAGE}\n", style="white")
443
+ error_text.append(str(e), style="dim red")
444
+
445
+ panel = Panel(
446
+ error_text,
447
+ title="[bold red]🛡️ DOCKER PULL ERROR",
448
+ title_align="center",
449
+ border_style="red",
450
+ padding=(1, 2),
451
+ )
452
+ console.print(panel, "\n")
453
+ sys.exit(1)
454
+
455
+ success_text = Text()
456
+ success_text.append("✅ ", style="bold green")
457
+ success_text.append("Successfully pulled Docker image", style="green")
458
+ console.print(success_text)
459
+ console.print()
460
+
461
+
462
+ def main() -> None:
463
+ if sys.platform == "win32":
464
+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
465
+
466
+ args = parse_arguments()
467
+
468
+ check_docker_installed()
469
+ pull_docker_image()
470
+
471
+ validate_environment()
472
+ asyncio.run(warm_up_llm())
473
+
474
+ if not args.run_name:
475
+ args.run_name = generate_run_name(args.targets_info)
476
+
477
+ for target_info in args.targets_info:
478
+ if target_info["type"] == "repository":
479
+ repo_url = target_info["details"]["target_repo"]
480
+ dest_name = target_info["details"].get("workspace_subdir")
481
+ cloned_path = clone_repository(repo_url, args.run_name, dest_name)
482
+ target_info["details"]["cloned_repo_path"] = cloned_path
483
+
484
+ args.local_sources = collect_local_sources(args.targets_info)
485
+
486
+ if args.non_interactive:
487
+ asyncio.run(run_cli(args))
488
+ else:
489
+ asyncio.run(run_tui(args))
490
+
491
+ results_path = Path("aipt_runs") / args.run_name
492
+ display_completion_message(args, results_path)
493
+
494
+ if args.non_interactive:
495
+ tracer = get_global_tracer()
496
+ if tracer and tracer.vulnerability_reports:
497
+ sys.exit(2)
498
+
499
+
500
+ if __name__ == "__main__":
501
+ main()