[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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
┌──(root💀kali)-[/home/kali/H■■n■/■■■ls]
└─# sudo apt update && sudo apt install -y docker.io
Get:1 http://mirror.keiminem.com/kali kali-rolling InRelease [34.0 kB]
Get:2 http://mirror.keiminem.com/kali kali-rolling/main amd64 Packages [21.9 MB]
Get:3 http://mirror.keiminem.com/kali kali-rolling/main amd64 Contents (deb) [53.9 MB]
Get:4 http://mirror.keiminem.com/kali kali-rolling/contrib amd64 Packages [104 kB]
Get:5 http://mirror.keiminem.com/kali kali-rolling/contrib amd64 Contents (deb) [171 kB]
Get:6 http://mirror.keiminem.com/kali kali-rolling/non-free amd64 Packages [170 kB]
Get:7 http://mirror.keiminem.com/kali kali-rolling/non-free amd64 Contents (deb) [878 kB]
Get:8 http://mirror.keiminem.com/kali kali-rolling/non-free-firmware amd64 Packages [17.3 kB]
Get:9 http://mirror.keiminem.com/kali kali-rolling/non-free-firmware amd64 Contents (deb) [44.4 kB]
Fetched 77.2 MB in 22s (3,567 kB/s)
178 packages can be upgraded. Run 'apt list --upgradable' to see them.
The following packages were automatically installed and are no longer required:
chromium-sandbox libfmt10 libopenjph0.28
gcc-15-base libfyaml0 libsimdutf33
gnome-accessibility-themes libgcc-15-dev libstdc++-15-dev
gnome-themes-extra libgumbo3 libstemmer0d
libaccountsservice0 libhdf4-0 libunibreak7
libappstream5 libmupdf27.0 libxmlb2
libavfilter11 libntfs-3g90 python3-unicodedata2
libflashrom1 libobjc-15-dev
Use 'sudo apt autoremove' to remove them.

Installing:
docker.io

Installing dependencies:
containerd libintl-xs-perl python3-protobuf
criu libmodule-find-perl python3-pycriu
docker-buildx libproc-processtable-perl runc
docker-cli libsort-naturally-perl tini-static
libcompel1 libterm-readkey-perl
libintl-perl needrestart

Suggested packages:
containernetworking-plugins debootstrap xfsprogs
docker-doc rinse zfs-fuse
btrfs-progs rootlesskit | zfsutils-linux

Summary:
Upgrading: 0, Installing: 17, Removing: 0, Not Upgrading: 178
Download size: 80.1 MB
Space needed: 338 MB / 60.1 GB available

Get:1 http://http.kali.org/kali kali-rolling/main amd64 runc amd64 1.3.6+ds1-1 [6,708 kB]
Get:6 http://http.kali.org/kali kali-rolling/main amd64 docker-cli amd64 28.5.2+dfsg4-5 [8,260 kB]
Get:7 http://http.kali.org/kali kali-rolling/main amd64 tini-static amd64 0.19.0-6+b3 [280 kB]
...<omission>...
Get:13 http://mirror.krfoss.org/kali kali-rolling/main amd64 libsort-naturally-perl all 1.03-4 [13.1 kB]
Get:16 http://mirror.zzunipark.com/kali kali-rolling/main amd64 python3-protobuf amd64 3.21.12-17 [156 kB]
Get:4 https://mirror5.krfoss.org/kali kali-rolling/main amd64 criu amd64 4.2.1-1 [557 kB]
Get:10 http://http.kali.org/kali kali-rolling/main amd64 libintl-xs-perl amd64 1.37-1+b1 [15.2 kB]
Fetched 80.1 MB in 14s (5,777 kB/s)
Preconfiguring packages ...
Selecting previously unselected package runc.
(Reading database… 486585 files and directories currently installed.)
Preparing to unpack …/00-runc_1.3.6+ds1-1_amd64.deb…
Unpacking runc (1.3.6+ds1-1)…
Selecting previously unselected package containerd.
Preparing to unpack …/01-containerd_2.1.9+ds1-5_amd64.deb…
...<omission>...
Setting up python3-pycriu (4.2.1-1)…
Setting up docker.io (28.5.2+dfsg4-5)…
Creating group 'docker' with GID 963.
update-rc.d: We have no instructions for the docker init script.
update-rc.d: It looks like a non-network service, we enable it.
Created symlink '/etc/systemd/system/multi-user.target.wants/docker.service' → '/usr/lib/systemd/system/docker.service'.
Created symlink '/etc/systemd/system/sockets.target.wants/docker.socket' → '/usr/lib/systemd/system/docker.socket'.
Setting up libintl-xs-perl (1.37-1+b1)…
Processing triggers for libc-bin (2.43-7)…
Processing triggers for man-db (2.13.1-1)…
Processing triggers for kali-menu (2026.3.4)…

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
2
sudo usermod -aG docker $USER
newgrp docker

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:3000 in your browser and create an administrator account.

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.

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

run llama3.1:8b```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
```ollama run deepseek-r1:7b``` # Most recommended

[3]. Popular models (?)<br>
```ollama run gemma3:12b```<br>
```ollama run qwen2.5:14b```<br>
```ollama run phi4```<br>
```ollama run mistral:7b```<br>
```ollama run deepseek-r1:8b```<br>

[4]. Korean-specialized model<br>
```ollama run EEVE-Korean-Instruct-10.8B```

[5]. Japanese-specialized model (Japanese-to-English translation) <br>
```ollama pull 7shi/gemma-2-jpn-translate:2b-instruct-q8_0``` <br>
```ollama run 7shi/gemma-2-jpn-translate:2b-instruct-q8_0``` <br>

[5-1]. Japanese-specialized model [Coding] <br>
A classic model for coding<br>
Model: ```qwen2.5-coder(0.5B ~ 32B)``` <br>
Highlights:
- Supports many programming languages.<br>
It is good at code completion, refactoring, and test generation. <br>
- Without a GPU, use 3B or smaller; with a GPU, 7B–14B is a practical range for laptops.
<br>

```ollama pull qwen2.5-coder:3b```<br>
```ollama run qwen2.5-coder:3b```

[6-1]. Tips to Improve Speed on Low-Spec CPUs
- Allocate swap memory: If physical RAM is 8 GB or less, <br>
make sure the Linux host has at least 4 GB of active swap space.<br>
Check with ```free -h```. This helps prevent the container from being killed<br>
during temporary memory spikes.<br>

- Optional less-restrictive helper model: If ```qwen2.5-coder:3b``` <br>
refuses to generate a particular attack payload, you can add the lightweight 3B model<br>
```mannix/llama3.2-3b-abliterated``` as a secondary model instead of dolphin-mistral,<br>
which is described here as less restrictive.<br>
It should run comfortably even in an 8 GB environment.<br>

If you share your Linux host CPU core count and<br>
distribution (Kali, Ubuntu, etc.),<br>
I can also provide optimized thread settings (num_thread) or a shell function<br>
to automate scanning tools that you can add to ```~/.bashrc```,<br>
including a one-line setup.<br>
</details>
<!-- End of collapsed section --> <br>

Other notes:
<!-- Start of collapsed section -->
<details>
<summary>👉 Click to expand </summary>

#### Call the API (OpenAI-compatible format)
```bash
# Basic Generate API
$ - curl http://localhost:11434/api/generate \
-H "Content-Type: application/json" \
-d '{ "model": "llama3.1:8b", "prompt": "Hi!", "stream": false }'

# OpenAI-compatible Chat API
$ - curl http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{ "model": "llama3.1:8b",
"messages": [{"role":"user","content":"Hello"}] }'

What to Check If It Does Not Run

Windows

  • Install with administrator privileges
  • Check whether Ollama is running in the background
  • Test ollama --version in 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

  1. Select a model: Open localhost:3000 and choose a model from the selector at the top.

    (e.g., qwen2.5:3b), then start chatting.
  2. 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.
  3. Stop and restart containers: You can stop them when not in use to free up resources.
1
2
docker stop open-webui ollama   # Stop
docker start ollama open-webui # Start again

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 the subprocess module under Workspace > Tools

    to register a Python function that runs only a limited set of Kali Linux commands

    (e.g., nmap, whois, and dig).

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,

    install shell-gpt and 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.

  1. Stop the download or run if it is still in progress.

      ● Press Ctrl + C in the terminal to stop it.

  2. Remove the installed model (ollama rm)

1
docker exec -it ollama ollama rm qwen2.5:3b
  1. 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
2
3
4
5
6
7
8
9
10
11
12
13
14
# 1. Sign in to Docker Hub
docker login

# 2. Copy Ollama volume data into the container and create an image (including models)
docker exec ollama cp -r /root/.ollama /ollama_backup
docker commit ollama your-docker-id/my-ollama:latest

# 3. Copy Open WebUI volume data into the container and create an image (including accounts/prompts)
docker exec open-webui cp -r /app/backend/data /webui_backup
docker commit open-webui your-docker-id/my-open-webui:latest

# 4. Push to your Docker Hub account
docker push your-docker-id/my-ollama:latest
docker push your-docker-id/my-open-webui:latest

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
2
3
4
5
# 1. Run Ollama (automatically restore backed-up models)
docker run -d -p 11434:11434 --name ollama --restart always luna0x03/my-ollama:latest bash -c "cp -rn /ollama_backup/* /root/.ollama/ && ollama serve"

# 2. Run Open WebUI and connect it to Ollama (automatically restore backed-up settings)
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"

(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
2
3
4
5
6
ollama list         # List installed models
ollama pull llama3 # Download a model
ollama run llama3 # Run a model
ollama rm llama3 # Remove a model
ollama ps # Check running models
ollama show llama3 # Show model details

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