Introducing a new way to review your PRs.

Read the announcement

greydgl / pentestgpt

Automated Penetration Testing Agentic Framework Powered by Large Language Models

View on GitHub

13 documents · Updated Nov 16, 2026

docs / legacy-cli-and-orchestration

Legacy CLI and Interactive Pentest Orchestration

Overview

The legacy PentestGPT entry point is pentestgpt_legacy/main.py. It builds the pentestgpt-legacy CLI around three modes: interactive operation, --list-models, and --smoke-test. --version reads pentestgpt_legacy/_version.py, while pentestgpt_legacy/__init__.py exposes the same package version. The supported-model listing is rendered from pentestgpt_legacy.llm.registry.models_by_provider() and marks providers configured according to pentestgpt_legacy.config.configured_providers().

Configuration for the CLI is split intentionally. pentestgpt_legacy/config.py is the app-level bridge used by the CLI: it imports provider settings from pentestgpt_legacy/…/config.py and selects default reasoning and parsing models by scanning DEFAULT_REASONING_PREFERENCE and DEFAULT_PARSING_PREFERENCE from pentestgpt_legacy/…/registry.py for the first model whose provider is configured. The underlying settings object in pentestgpt_legacy/…/config.py reads .env and environment variables for provider keys such as OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY, DEEPSEEK_API_KEY, GROK_API_KEY/XAI_API_KEY, QWEN_API_KEY/DASHSCOPE_API_KEY, and KIMI_API_KEY/MOONSHOT_API_KEY. main.py also supports --base-url, which writes a provider-specific *_BASE_URL environment override for the selected reasoning, parsing, and generation models before constructing any LLM clients.

Interactive mode in pentestgpt_legacy/main.py calls run_interactive(), resolves the reasoning and parsing models from CLI flags or defaults, lazily imports pentestgpt_legacy/…/pentest_gpt.py, constructs pentestGPT, and calls session.main(). The orchestrator in utils/pentest_gpt.py is the classic human-in-the-loop flow: three independent LLMClient sessions cooperate as reasoning, generation, and parsing agents. pentestGPT.__init__() creates log output under the CLI --log-dir, constructs clients via pentestgpt_legacy.llm.factory.get_client(), defaults the generation model to the reasoning model, computes a parsing chunk window from the reasoning model context window, and initializes in-memory transcript state.

The three LLM sessions are initialized in pentestGPT.initialize() using prompt strings from pentestgpt_legacy/…/prompt_class.py: generation_session_init, reasoning_session_init, and input_parsing_init. LLMClient in pentestgpt_legacy/…/client.py gives the legacy core the expected synchronous send_new_message() and send_message() API while preserving per-conversation history internally and bridging to async provider calls. After session initialization, _feed_init_prompts() asks the user for the one-line test description, sends it to the reasoning agent with PentestGPTPrompt.task_description to construct the initial Penetration Testing Tree (PTT), then sends that reasoning output to the generation agent with todo_to_command to expand the initial task guidance.

The main REPL is pentestGPT.input_handler() in pentestgpt_legacy/…/pentest_gpt.py. User command completion and validation come from pentestgpt_legacy/…/task_handler.py: main_task_entry() accepts only next, more, todo, discuss, google, help, or quit, and local_task_entry() accepts only discuss, brainstorm, help, google, or continue. Multiline free-text input and radio selection are handled by pentestgpt_legacy/…/prompt_select.py, where Shift+Right accepts multiline prompts.

The main commands drive different parts of the orchestration flow:

  • next asks the user to classify pasted input as tool, user-comments, web, or default, summarizes it through input_parsing_handler(), then sends the parsed summary to reasoning_handler(). The reasoning handler updates the PTT with process_results and immediately asks the reasoning session to select the next favorable task with process_results_task_selection.
  • more requires a previous reasoning response. It sends that response to the generation session, then sends local_task_init to switch into a local sub-task loop where local_input_handler() can discuss or brainstorm details with the generation agent until continue is entered.
  • todo asks the reasoning agent to revise/select tasks using ask_todo, then sends the resulting reasoning response to the generation agent with todo_to_command for concrete instructions.
  • discuss collects user text and sends it through reasoning_handler() with the discussion prompt prefix so the PTT can be updated as part of the response.
  • google is a placeholder in both main and local loops; utils/pentest_gpt.py logs and prints a fixed “still under development” message rather than calling an external search service.
  • quit returns False to break the main loop.

Input summarization is centralized in pentestGPT.input_parsing_handler(). It prepends source-specific instructions from postfix_options, normalizes pasted content onto one line, wraps it at 8,000 characters, and sends each chunk to the parsing LLM session. The summarized output is logged in the input_parsing transcript and is what the reasoning agent sees for long tool/web/user input. reasoning_handler() also re-routes oversized text through input_parsing_handler() when it exceeds parsing_char_window, so callers that bypass next still get summarization before updating the PTT.

State is mostly in memory during the run. pentestGPT.history records timestamped user, PentestGPT, reasoning, parsing, generation, and exception entries. On exit from pentestGPT.main(), the history is written as JSON to <log_dir>/pentestGPT_log_<timestamp>.txt; then save_session() asks for a session name and writes {"task_log": ..., "history": ...} under test_history/ in the current working directory. There is no server-side conversation resume: utils/pentest_gpt.py explicitly relies on the LLMClient objects to hold conversation state for the current process.

Connectivity tooling is also rooted in this area. pentestgpt_legacy/smoke_test.py powers pentestgpt-legacy --smoke-test by selecting registry models, building a client with get_client(), making one real provider call asking for OK, and returning a non-zero exit code if any attempted model fails. Models whose providers lack credentials are skipped, not failed. pentestgpt_legacy/test_connection.py is a lighter wrapper that probes the first non-legacy model for each configured provider via the same _probe() function.

Coupling

Risks

  • pentestgpt_legacy/…/pentest_gpt.py writes session files with open(..., "w") in save_session() and in the final log write without specifying an encoding or using atomic writes. If the process is interrupted during exit, the JSON transcript in logs/ or test_history/ can be partially written and unusable.
  • pentestgpt_legacy/…/pentest_gpt.py treats the fixed Google placeholder as a successful command response. If callers or tests later expect real web-search results from the google command in either the main or local loop, the orchestration will continue with “still under development” text rather than retrieved content.