greydgl--pentestgpt
b9869307d0
* fix: 🐛 minor typo and build process * feat: 🎸 [WIP] Pentest mode * feat: 🎸 code abstraction * feat: modernize legacy PentestGPT with native multi-LLM support (#469) Rebuild the classic USENIX-2024 interactive PentestGPT (reasoning / generation / parsing sessions + Pentesting Task Tree + REPL) as a standalone `pentestgpt_legacy` package on a native per-provider LLM layer that supports the latest 2026 models. - llm/: BaseProvider + OpenAI-compatible / Anthropic / Gemini connectors, a web-verified model registry (OpenAI, Anthropic, Gemini, DeepSeek, xAI, Qwen, Moonshot, local Ollama), a factory, and an LLMClient bridging async providers to the core's synchronous send_new_message/send_message session API. - CLI `pentestgpt-legacy`: --list-models and --smoke-test (live per-model round-trip matrix), plus --reasoning-model / --parsing-model / --base-url. - Tests: 25 unit tests (mocked, no network). Live smoke test verified 22/22 models with a configured key respond. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> * fix(backend): address review on ClaudeCodeBackend subprocess handling - _build_env: pop ANTHROPIC_API_KEY instead of setting it to "", so an empty value can't shadow the CLI's own auth fallback (e.g. subscription login). - _kill_process: reap the force-killed process with os.waitpid(.., WNOHANG) instead of calling the proc.wait() coroutine without awaiting it (removes the "coroutine was never awaited" warning). - query/_drain_stderr: drain subprocess stderr in a background task so its pipe buffer can't fill and deadlock the child. Also reformats backend.py, fixing the failing Lint (ruff format) check. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(docker-test): assert uv instead of Poetry in container health check The project migrated from Poetry to uv (the Dockerfile installs uv to /home/pentester/.local/bin, which is on PATH), so test_poetry_installed failed with exit 127. Replace it with test_uv_installed checking `uv --version`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
52 行
1.6 KiB
Python
52 行
1.6 KiB
Python
"""Per-provider connectivity check.
|
|
|
|
A lightweight wrapper over the smoke test that probes the first current-tier
|
|
model of each configured provider — handy for quickly confirming your keys work
|
|
before starting a session. For full coverage use ``pentestgpt-legacy --smoke-test``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
|
|
from pentestgpt_legacy.config import configured_providers
|
|
from pentestgpt_legacy.llm.registry import ALL_SPECS, PROVIDERS
|
|
from pentestgpt_legacy.smoke_test import PASS, _probe
|
|
|
|
|
|
def _flagship_per_provider() -> list:
|
|
ready = set(configured_providers())
|
|
chosen = []
|
|
seen: set[str] = set()
|
|
for spec in ALL_SPECS:
|
|
if spec.provider in ready and spec.provider not in seen and not spec.legacy:
|
|
chosen.append(spec)
|
|
seen.add(spec.provider)
|
|
return chosen
|
|
|
|
|
|
async def _run() -> bool:
|
|
specs = _flagship_per_provider()
|
|
if not specs:
|
|
print("No providers configured. Set an API key in your environment or .env file.")
|
|
return False
|
|
|
|
print("\n=== PentestGPT connectivity test ===\n")
|
|
all_ok = True
|
|
for spec in specs:
|
|
status, detail = await _probe(spec)
|
|
mark = "✓" if status == PASS else "✗"
|
|
print(f" {mark} {PROVIDERS[spec.provider].label:<16} {spec.id:<28} {detail}")
|
|
all_ok = all_ok and status == PASS
|
|
print()
|
|
return all_ok
|
|
|
|
|
|
def test_connection() -> bool:
|
|
"""Synchronous entry point; returns True if all configured providers connect."""
|
|
return asyncio.run(_run())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(0 if test_connection() else 1)
|