mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-20 23:57:11 -04:00
[PR #148] [CLOSED] Feat: enhance AI guidance workflow for pentesting support #191
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/148
Author: @Priyanka-2725
Created: 2/26/2026
Status: ❌ Closed
Base:
master← Head:docs/better-ai-pentesting-guides📝 Commits (1)
cc6deccFeat: enhance AI guidance workflow for pentesting support📊 Changes
5 files changed (+103 additions, -106 deletions)
View changed files
📝
backend/cmd/ftester/worker/executor.go(+8 -1)📝
backend/pkg/templates/prompts/adviser.tmpl(+1 -0)📝
backend/pkg/templates/prompts/pentester.tmpl(+73 -0)📝
backend/pkg/templates/prompts/searcher.tmpl(+21 -0)➖
backend/pkg/tools/testdata/sploitus_result_nginx.json(+0 -105)📄 Description
Description of the Change
Problem
Two separate issues were addressed in this PR:
1. Silent error handling in
ftestertool executor (Bug)In
backend/cmd/ftester/worker/executor.go,GetToolcalledGetFlowPrimaryContainerwith an optimisticif err == nilguard. When the container lookup failed, no error was surfaced —containerIDremained0andcontainerLIDremained"".NewTerminalTool/NewFileToolwere then constructed with these invalid identifiers. Later, whenExecCommandcalleddockerClient.IsContainerRunning(ctx, ""), the Docker API produced cryptic errors such as"container is not running"or"failed to inspect container"that gave no indication of the actual root cause.2. AI agents lack authoritative pentest methodology references (Enhancement)
The
pentester,searcher, andadviseragents had no explicit guidance to consult well-known, structured penetration testing knowledge bases. This led to agents spending excessive time on trial-and-error enumeration instead of following proven methodologies available in community references like HackTricks and PentestBook.Solution
1. Fail-fast container error handling
GetToolnow checks whether the requested tool actually requires a container (TerminalToolNameorFileToolName). For those tools,GetFlowPrimaryContaineris called and any error is immediately returned with a clear, contextual message:Tools that do not require a container (browser, search engines, memory, etc.) skip the DB call entirely, removing an unnecessary round-trip on every tool creation for those cases.
2. Integrated pentest knowledge base references into agent prompts
Three prompt templates were updated:
pentester.tmpl: Added a## PENTESTING KNOWLEDGE RESOURCESsection directly before the execution context block. It defines two prioritised resources (HackTricks at priority 1, PentestBook at priority 2), provides<when_to_use>guidance for each, catalogs 13 deep-link URLs covering all major attack surfaces (network services, web, Linux/Windows privesc, Active Directory, cloud, Docker, Kubernetes, phishing, exfiltration, tunneling), and defines a<reference_workflow>that integrates the external references with the existing internal guide store (search_guide/store_guide).searcher.tmpl: Added a<pentesting_knowledge_refs>block inside the<search_tools>matrix at priority 2 (equal to memory tools, above general search engines), directing the searcher agent to browse HackTricks and PentestBook before reaching for Google or DuckDuckGo on any security-related query.adviser.tmpl: Added a bullet to the "Emphasize Technical Precision" section instructing the adviser to cite specific HackTricks or PentestBook sections in security recommendations, so downstream pentester/searcher agents can act on them directly.Closes #
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps — Bug Fix (
executor.go)docker compose upagainst a flow that has no primary container provisioned (e.g., container was manually deleted from DB).ftester, invoke a task that triggersTerminalToolNameorFileToolNameviaGetTool."container is not running"with no indication of which flow is affected."failed to get primary container for flow <id>: <db error>".BrowserToolName,GoogleToolName) continue to work normally even when no container is available.Test Steps — Enhancement (Prompt templates)
https://book.hacktricks.wiki/en/network-services-pentesting/index.html(or the specific service page) before attempting manual enumeration.https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/index.htmlas a first-priority source.go test ./pkg/templates/... -v— all template integrity tests must pass (no undeclared or unused template variables introduced).Test Results
{{.Var}}tokens introduced insearcher.tmploradviser.tmpl; the two variables used in the newpentester.tmplsection —SearchGuideToolNameandStoreGuideToolName— were already declared and used in the existing template).Security Considerations
Bug fix: The change enforces fail-fast behavior — rather than silently passing empty container identifiers to the Docker API (which could produce ambiguous side effects), the system now rejects the operation cleanly. This reduces the risk of an agent incorrectly believing it has executed commands when it has not.
Prompt enhancement: The referenced resources (HackTricks, PentestBook) are public, read-only knowledge bases. The agents browse them using the existing
browsertool under the same authorization model as any other URL. No new permissions, credentials, or network policies are required. URLs are hardcoded static strings — no user-controlled input is passed to the references.Performance Impact
Bug fix: For
TerminalToolNameandFileToolName, behavior is unchanged (one DB call, same as before). For all other tool names, the DB call is eliminated entirely — a minor improvement since previously everyGetToolcall made an unnecessaryGetFlowPrimaryContainerround-trip regardless of the tool type.Prompt enhancement: Adds static text to three system prompts (~2–3 KB combined). This increases token count per agent invocation by a negligible amount. The operational benefit — agents immediately resolving technique questions from authoritative structured sources instead of iterating through trial-and-error — is expected to reduce total tool call count and task completion time.
Documentation Updates
Deployment Notes
No environment variable changes, database migrations, or configuration file updates required. Both changes are purely in-process (Go source code and Go template files). A standard
docker compose build && docker compose upis sufficient to deploy.Checklist
Code Quality
go fmtandgo vet(for Go code)npm run lint(for TypeScript/JavaScript code)Security
Compatibility
Documentation
Additional Notes
On the bug fix pattern: The original
if err == nil { use result }idiom is an anti-pattern when the success of the resource retrieval is a precondition for correct downstream behavior. All other callers ofGetFlowPrimaryContainerin the codebase (tools.go,tester.go,flow.go,assistant.go) already follow the correctif err != nil { return err }pattern. This change bringsexecutor.gointo conformance with the rest of the codebase.On the knowledge base references: The URLs provided have been verified against the current published structure of both sites (as of 2026-02-24). Both sites are actively maintained. The
<reference_workflow>step that instructs agents to useaction: "links"beforeaction: "markdown"is intentional — it allows agents to adapt to any future URL structure changes by discovering current sub-page navigation dynamically rather than hard-failing on a stale deep link.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.