[Kali Linux] Building a Local LLM Agent for Pentesting

This post has been substantially revised (?)
Building A Local LLM Agent For Pentesting
This time, we will set up a local LLM to save time during penetration testing practice and
bug hunting through bug bounty programs.
We will use a tool that is still popular (?)
and build a local LLM.
This guide targets a low-spec, CPU-only environment without a GPU, where possible.
The setup is as follows.
1. Update the Package List and Install Docker
1 | sudo apt update && sudo apt install -y docker.io |
The installation is successful when you see output similar to the following.
👉 Click to expand
1 | ┌──(root💀kali)-[/home/kali/H■■n■/■■■ls] |
2. Start Docker and Enable It at Boot
1 | sudo systemctl enable --now docker |
3. Add the Current User to the Docker Group (to Run Docker Without sudo)
1 | sudo usermod -aG docker $USER |
4. Run the Ollama and Open WebUI Containers
This section shows how to run and connect both services.
As above, the instructions assume a low-spec, CPU-only environment without a GPU.
① Run Ollama
1 | docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama |
(If you have an NVIDIA GPU, add the --gpus=all option.)
② Run Open WebUI (Automatically Connected to Ollama)
1 | docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backen |
- Open
localhost:3000in your browser and create an administrator account.
5. Install Lightweight Models Recommended for Low-Spec Systems
For systems with 8 GB of RAM or CPU-only systems, 1B–3B (1–3 billion parameters)
quantized models of this size are a good fit.
Choose one of the commands below to install a model from the terminal.
| Model | Approx. Size | RAM | Features and Recommended Use | Install Command |
|---|---|---|---|---|
| Gemma 2(2B) | 1.6 GB | 4 GB+ | Google lightweight model | docker exec -it ollama ollama run gemma2:2b |
| Llama 3.2 (3B) | 2.0 GB | 6 GB+ | Meta lightweight model | docker exec -it ollama ollama run llama3.2:3b |
| Qwen 2.5 (3B) | 1.9 GB | 6 GB+ | Alibaba model; strong multilingual and coding capabilities |
docker exec -it ollama ollama run qwen2.5:3b |
| Qwen 2.5 (1.5B) | 1.0 GB | Under 4 GB | For very low-spec systems; very fast responses |
docker exec -it ollama ollama run qwen2.5:1.5b |
(For security and hacking assistance on Kali Linux, qwen2.5:3b is recommended for its coding capabilities.)
5-1. 💡 Faster, Lighter Alternative Models
If a 3B model feels too demanding or downloads too slowly,
try one half its size, such as 1.5B or 1B.
● Qwen 2.5 Coder 1.5B (about 1 GB, recommended for coding and hacking assistance):
1 | docker exec -it ollama ollama run qwen2.5-coder:1.5b |
● Llama 3.2 1B (about 1.3 GB, ultra-lightweight):
1 | docker exec -it ollama ollama run llama3.2:1b |
Other potentially useful models:
👉 Click to expand
[1]. [Recommended] Download a model for low-spec systems ollama run qwen2.5-coder:3b
[2]. Download and run a model in one step
1 | ```ollama run deepseek-r1:7b``` # Most recommended |
What to Check If It Does Not Run
Windows
- Install with administrator privileges
- Check whether Ollama is running in the background
- Test
ollama --versionin PowerShell
Linux
Check the service status
sudo systemctl status ollama
Change the port if it is already in use
OLLAMA_HOST=0.0.0.0:11435 ollama serve
6. Use Models in Open WebUI and Optimization Tips
- Select a model: Open
localhost:3000and choose a model from the selector at the top.
(e.g.,qwen2.5:3b), then start chatting. - Allocate virtual memory (swap): If Kali Linux is running in a VM,
the container may be terminated if it runs out of RAM. It is safer to allocate at least 4 GB
of swap space. - Stop and restart containers: You can stop them when not in use to free up resources.
1 | docker stop open-webui ollama # Stop |
7. Connect an Agent That Runs Terminal Commands (Optional)
To have the AI do more than answer questions, such as run an Nmap scan
or analyze its results, connect it to MCP (Model Context Protocol)
or Open Interpreter. Keep in mind that
these tools may be demanding on low-spec systems.
- Lightweight approach (use Open WebUI Python tools):
In Open WebUI, use thesubprocessmodule underWorkspace > Tools
to register a Python function that runs only a limited set of Kali Linux commands
(e.g.,nmap,whois, anddig).
Then you can ask in chat, for example, “Scan the ports on 192.■■■.1.■0 and analyze vulnerabilities.”
- Dedicated CLI agents (PentestGPT / ShellGPT):
If you want a lightweight agent that runs directly in the terminal instead of Open WebUI,
installshell-gptand connect it to the local Ollama API (localhost:11434).
This uses far fewer resources.
8. If You Do Not Like an Installed Model
Here is how to remove a model you no longer want to use.
Stop the download or run if it is still in progress.
● PressCtrl + Cin the terminal to stop it.Remove the installed model (
ollama rm)
1 | docker exec -it ollama ollama rm qwen2.5:3b |
- Confirm that it was removed and disk space was freed
1 | docker exec -it ollama ollama list |
(If qwen2.5:3b does not appear in the list, it has been removed.)
(If you force-stop a download and are concerned that temporary files still take up space
even though the model does not appear in the list, try running docker restart ollama.
This may clear temporary files.)
9. If You Have a Docker Hub Account
If you have a personal Docker Hub account, you can back up your containers
to your account as follows.
Step 1: Push the Current Containers to Your Docker Account (Backup)
In the commands below, replace your-docker-id with your Docker Hub
username, then run the commands in order.
1 | # 1. Sign in to Docker Hub |
Step 2: Later, Connect and Run Both Services at Once Using Your Images
On another PC or a fresh Kali Linux installation, restore your backed-up models and settings
and run both services with the following commands.
1 | # 1. Run Ollama (automatically restore backed-up models) |
(Optional) Combine Both Commands on One Line with (&&)
To run both commands in sequence with a single terminal entry, use the command below.
1 | docker run -d -p 11434:11434 --name ollama --restart always luna0x03/my-ollama:latest bash -c "cp -rn /ollama_backup/* /root/.ollama/ && ollama serve" && docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway --name open-webui --restart always luna0x03/my-open-webui:latest bash -c "cp -rn /webui_backup/* /app/backend/data/ && bash start.sh" |
Appendix
👉 Click to expand
🔧Common Ollama Commands
Here are some frequently used Ollama commands.
1 | ollama list # List installed models |
Docker Commands
Here are some frequently used Docker commands as well.
0. Sign In
1. Basic Sign-In (Interactive)
• docker login: Sign in to your personal account on a remote registry
- Username: Enter your Docker Hub username (recommended over your email address)
- Password: Enter your password or Personal Access Token (PAT)
(For security, typed characters will not appear; press Enter when done.)
2. Sign In with a Specified Username
• docker login -u <docker_username>
3. Sign In to a Private Registry (AWS ECR, GitHub, etc.)
To sign in to a remote registry other than Docker Hub, append its server address.
• docker login <registry_address>
Notes and Sign Out
• If you use two-factor authentication (2FA), use a token from the Docker Hub website
(Account Settings > Personal access tokens) instead of your account password.
Enter the access token in the password field.
• docker logout: Sign out
1. Manage Images
• docker pull <image:tag> : Download an image from a remote registry
• docker images (or docker image ls): List local images
• docker build -t <image:tag> <path> : Build an image from a Dockerfile
• docker rmi <image_id_or_name> : Remove an image
2. Run and Manage Containers
• docker run -d --name <name> -p <host_port>:<container_port> -v <volume/path> :<container_path> -e TZ=Asia/Seoul <image> :
Create and run a container in the background
• docker ps : List running containers
• docker ps -a : List all containers, including stopped ones
• docker stop <container_name_or_id> : Stop a container
• docker start <container_name_or_id> : Start a stopped container
• docker restart <container_name_or_id> : Restart a container
• docker rm <container_name_or_id> : Remove a stopped container (add -f to force removal)
3. Access, Logs, and Debugging
• docker exec -it <container_name_or_id> /bin/sh (or /bin/bash) : Open a shell in a running container
• docker logs -f <container_name_or_id> : Follow container logs in real time
• docker inspect <container_name_or_id> : View detailed container configuration and network information
4. Cleanup and Other
• docker system df : Check Docker disk usage
• docker system prune : Remove unused containers, networks, and dangling images