AI pentesting guides / Free, open-source and AI pentesting

Step-by-step setup

Ollama pentesting: a step-by-step setup for a local AI pentester

Ollama pentesting means using Ollama to serve an open-weight model on your own machine and pointing an AI pentesting harness at it, so the agent's reasoning runs locally with no API key and no per-token cost. With Pentest-Swarm, the whole setup is a model pull and one command.

This page is a practical walkthrough: which models work, the Ollama settings that matter, a first run against a safe lab, and how to diagnose the usual problems. If you want the broader case for local models first, see the local LLM pentesting guide.

Step 1: install Ollama and pull a tool-calling model

Install Ollama from ollama.com, then pull a model that supports tools. On the Ollama library, filter by the 'tools' capability; models without it cannot emit the structured tool calls an agent needs and will simply chat about what they would do. Start with the largest tool-capable model that runs at a comfortable speed on your hardware, then compare a smaller one later.

Step 2: give the model enough context

Pentesting runs are long: tool output, HTTP responses and the agent's own notes accumulate quickly. Ollama's default context window is often smaller than a model's maximum, and when it overflows the model loses track of earlier findings. Ollama documents the OLLAMA_CONTEXT_LENGTH environment variable for raising it when you start the server (for example OLLAMA_CONTEXT_LENGTH=32768 ollama serve). Larger contexts need more memory, so raise it in steps.

Step 3: run against a lab first

  • Make sure Docker is running; the bundled labs start in containers and are torn down afterwards.
  • Run pentestswarm scan --lab --lab-target crapi --provider ollama --swarm --tui.
  • Watch the TUI or the dashboard on localhost:7777 to see which agents act and what they find.
  • Repeat with --lab-target vampi and --lab-target dvga to see REST and GraphQL behaviour.
  • Note what the model found and missed; that is your baseline before testing anything real.

Troubleshooting common problems

  • The agent describes commands instead of running them: the model lacks native tool calling. Switch models.
  • Runs stall or repeat the same step: context is overflowing or the model is too small. Raise the context length or try a larger model.
  • Very slow steps: the model is partly running on CPU. Use a smaller quantisation or a smaller model.
  • Connection refused: make sure ollama serve is running and reachable from where Pentest-Swarm runs, especially inside Docker.
With Pentest-Swarm

Pentest-Swarm with Ollama

Pentest-Swarm lists Ollama as a first-class provider: no key, no cloud, and no spend cap needed because the cost is zero. Every agent in the swarm inherits the one provider setting.

  • Install the CLI: npm install -g @armurai/pentestswarm (or Homebrew, go install, Docker).
  • Use the launcher: pentestswarm run, then choose Ollama as the provider.
  • Or script it: pentestswarm scan staging.example.com --scope staging.example.com --provider ollama --swarm --safe-mode.
  • Per-agent model overrides live in config.yaml if you want a different local model for a specific role.
  • Turn on --verify (beta) so out-of-band, differential and timing oracles confirm findings independently of the model.

Where it falls short

An Ollama-served model is usually weaker than a frontier cloud model, so a local run may miss findings that a Claude-driven run would catch, especially multi-step chains. The concurrent swarm scheduler is alpha; if a local run behaves erratically, try the stable sequential runner by omitting --swarm. Ollama does not help with targets Pentest-Swarm does not cover, such as mobile apps or thick clients.

Questions

Which Ollama model is best for pentesting?

There is no fixed answer because new open models appear constantly. Use one tagged with tool support, give it a large context, and compare candidates on the same practice lab.

Do I need an API key with Ollama?

No. Pentest-Swarm needs no key for Ollama or LM Studio, and no model traffic leaves your machine.

Can Ollama run on a different machine from Pentest-Swarm?

Yes, as long as the Ollama server is reachable over the network. Keep that link private, because it carries details of your target.

Sources

  1. Ollama models with tool support
  2. Ollama tool calling docs
  3. Ollama FAQ: context length