Cyber Security

Setting Up a Home Cybersecurity Learning Lab: An AI-Assisted Study Guide

Learning Lab: An AI-Assisted Study Guide

Last year I watched a student do something I've seen a hundred times before: he installed an AI pentesting tool on his main laptop, pointed it at a random internet IP address "just to see what happens," and almost got his entire family's network blocked by the ISP within an hour. He wasn't malicious. He was just curious — and completely unconstrained. This article exists so you never have to learn that lesson the hard way.

If you want to learn AI-assisted penetration testing — and specifically PentestGPT, the most popular open-source AI penetration testing tool in the world — the single most important decision you will make is not which model to use. It's where you let the tool operate. A properly built educational lab turns a potentially dangerous AI into a patient, harmless teacher. Here's exactly how to build one, step by step.

Why an Isolated Lab Is the Whole Point

PentestGPT is a co-pilot, not an autopilot. It plans engagements, generates payloads, suggests next steps, and remembers what you taught it. That makes it an extraordinary teacher — and an equally dangerous toy when aimed at the wrong target. A single misconfigured network interface, one forgotten port forward, and your "educational tool" is probing your router, your roommate's laptop, or someone else's production server.

The solution isn't willpower. It's architecture. If the tool physically cannot reach anything except disposable virtual machines on an isolated virtual network, then the question of "should I attack this?" never even comes up. The lab does the discipline for you. That's the design philosophy behind everything below.

What You Need Before You Start

  • A computer with at least 16 GB of RAM (8 GB per VM, and you'll run two VMs). A decent CPU helps too — the AI does its thinking in the cloud, but the VMs do real work locally.
  • 60–80 GB of free disk space for two virtual machines and snapshots.
  • VirtualBox (free) or VMware Workstation Player (also free for personal use).
  • An API key from one of these providers: OpenAI (GPT-4 recommended), Google Gemini, or DeepSeek. PentestGPT now supports all three backends.
  • A little patience. The install itself takes ten minutes. The learning takes as long as you want it to.

Step 1: Create the Attacker Machine (Kali Linux)

Kali is the standard penetration testing distribution, and PentestGPT is designed to work alongside its tools. Download the official Kali ISO from the Kali website and create a new VM in VirtualBox:

  • Memory: 8 GB (4 GB is the minimum, but the tool runs alongside Nmap, SQLMap, and a browser — give it room).
  • Disk: 40 GB virtual disk, dynamically allocated.
  • Processors: 2–4 cores.
  • Install with the default options. Use a strong user password — yes, even in a lab. You're building habits, not shortcuts.

Once Kali boots, take a snapshot. You'll thank yourself later when an experiment breaks something and you restore in five seconds instead of debugging for an hour.

Step 2: Create the Target Machine (Your Victim)

You need something to practice against. These are the standard, legal, made-for-learning targets:

  • Metasploitable 2 or 3 — a deliberately vulnerable Ubuntu machine packed with exploitable services. It's the classic first victim.
  • DVWA (Damn Vulnerable Web Application) — runs inside your target VM and gives you web-specific practice: SQL injection, XSS, command injection, and more.
  • VulnHub boxes — downloadable vulnerable VMs of varying difficulty. Great for levelling up once you finish the basics.

Give the target VM 4 GB of RAM and a 20 GB disk. Then install it, boot it, and take a clean snapshot immediately. From this moment on, the target is disposable — that's what makes it a lab and not a liability.

Step 3: Wire the Network (The Most Important Step)

Here is where most people get into trouble. In VirtualBox, each VM has a network mode, and the default is usually NAT, which gives the VM outbound internet access. For this lab, you want Host-Only Adapter on both machines. Here's why:

  • Host-only creates a private virtual network that only your VMs can see. Nothing on your real home network is reachable from inside it, and nothing inside it can reach the rest of your network.
  • Bridged mode puts the VM directly on your real network like a physical device — never use this for the lab.
  • NAT hides the VM behind your host, which sounds safe, but it can still reach the internet and your router. Not what we want for the target, and not ideal for the attacker either.

Apply Host-Only Adapter to both VMs. If you want internet access inside the attacker VM to reach the API providers, you can add a second NAT adapter to Kali — but think carefully before doing the same for the target. A target with no internet at all is a target that cannot leak anything anywhere. Then boot both machines and confirm they can ping each other on the host-only network (something like 192.168.56.x). Write down the target's IP — you'll feed it to PentestGPT next.

Step 4: Install PentestGPT on Kali

Open a terminal on the Kali VM. You need Python 3.10 or newer, which Kali ships with by default. Then:

pip3 install git+https://github.com/GreyDGL/PentestGPT

Next, configure your AI backend. Choose the provider with the API key you have:

# Option A: OpenAI (best quality, recommended)
export OPENAI_API_KEY='your_key_here'

# Option B: Google Gemini
export GOOGLE_API_KEY='your_key_here'

# Option C: DeepSeek (cheapest)
export DEEPSEEK_API_KEY='your_key_here'

Now verify the connection. This command runs a short test conversation with the model and confirms your key works:

pentestgpt-connection

Two practical notes from real-world usage: expect to pay a small amount per session if you use GPT-4 — it's worth it, because reasoning quality is exactly what you're learning from. And if you use DeepSeek, you may need to edit the model name in pentestgpt/test_connection.py to deepseek-chat; it's a known quirk.

Step 5: Start Your First AI-Led Engagement

With Kali on the host-only network and the target booted, launch PentestGPT:

pentestgpt

You'll get an interactive session. Tell it the target IP — your Metasploitable machine on the isolated network — and let it start planning. The default flow is beautiful for learning:

  • The tool plans an overall strategy before touching anything.
  • It proposes a next step and asks for your confirmation before executing.
  • It works through plugins like Nmap, Nikto, and SQLMap, explaining what it's doing along the way.
  • When you correct it — for example, telling it the real service version after you test it yourself — it fine-tunes its approach mid-engagement.

Don't rush the exploitation part. The real lesson is the thinking: watch how it enumerates, how it forms hypotheses, and how it chooses the cheapest path to a foothold. That's the hacker-mindset training that makes this tool worth running.

Step 6: Do It Once With a Local Model (Optional But Valuable)

After you've spent a few sessions on a paid API, install Ollama on the Kali VM and run a local model like Llama 3 instead. PentestGPT supports local backends, and the drop in reasoning quality is an education in itself. You'll see exactly why model quality matters, you'll watch the AI make the kind of mistakes a beginner makes, and you'll learn to spot them the moment they appear. Best of all, it costs nothing, so you can experiment as much as you want. The contrast between the two backends teaches more about both AI and pentesting than either one alone.

The Five Rules of an Educational Lab

Print these out. Tape them next to the monitor. Ignore them only if you want to learn the expensive way:

  • Rule 1 — The target list is a wall, not a guideline. Only VMs you created and snapshotted in this lab count as targets. Everything else is off-limits, full stop.
  • Rule 2 — No real IPs, ever. Not your router. Not your own laptop. Not a "friend's website." If it isn't a machine you built, it doesn't exist for this lab.
  • Rule 3 — Keep the lab disposable. When the target gets rooted or bricked — and it will — restore the snapshot. Don't fix it. The repetition is the training.
  • Rule 4 — Log everything. PentestGPT saves conversation history. Review it after each session. Asking "why did the AI choose that payload?" after the fact is where the real learning happens.
  • Rule 5 — Treat failure as the syllabus. When an exploit fails, ask why before trying the next one. A lab that never fails teaches you nothing.

Troubleshooting: The Four Problems Everyone Hits

PentestGPT can't connect to the API

Re-run pentestgpt-connection and check that the environment variable is set in the same terminal session where you launch the tool. Also confirm you have a payment method linked to the provider account — GPT-4 access requires it, even for small usage.

The VMs can't ping each other

Verify both are using Host-Only Adapter with the same adapter name in VirtualBox settings. If they still can't see each other, check Kali's firewall (sudo ufw status) and remember that some vulnerable targets ship with firewalls disabled — that's fine, the attacker Kali is the one that needs to reach out.

DeepSeek returns a model error

The known fix: open pentestgpt/test_connection.py and change the model name to deepseek-chat, then re-run the connection test.

The target got completely destroyed

That's not a bug — that's the lab working as intended. Restore the snapshot you took in Step 2 and start again. The second run is always faster than the first, and that speed-up is the skill you're building.

Frequently Asked Questions

Is PentestGPT free to use?

The tool itself is completely free and open source. The AI model behind it isn't. Free-tier models work but produce noticeably weaker reasoning, so for learning purposes a paid GPT-4 API key — which costs pennies per short session — is the recommended setup. A local model via Ollama is the free alternative, with the quality trade-off described above.

Do I need to know how to hack before using PentestGPT?

No — but you need to know how to be careful. Absolute beginners can learn the methodology directly from the tool, which explains its reasoning as it goes. What you must understand first is the lab architecture: what your target is, what your scope is, and why nothing outside the VMs exists for this tool.

Can this lab prepare me for certifications?

Yes. The workflow PentestGPT demonstrates — planning, enumeration, hypothesis testing, exploitation, and reflection — mirrors the methodology behind the OSCP and similar certifications. Treat it as a thinking coach, not a shortcut, and it will accelerate your preparation considerably.

How long does the whole setup take?

About an hour the first time, including downloads. The VM installs are the slow part. The actual PentestGPT installation takes less than ten minutes once Kali is booted.

Why VirtualBox instead of a cloud server?

Two reasons. First, a local lab guarantees isolation — your targets are physically separated from the internet, which is something no cloud account can promise as cleanly. Second, snapshots: restoring a broken target takes five seconds locally. In the cloud, you're rebuilding from a template every time. For learning, local is simply better.

Final Thoughts: The Lab Is the Teacher

Here's the thing nobody tells you about building an educational AI lab: the artificial intelligence is not the interesting part. The interesting part is you. The lab exists to give you thousands of cheap, safe repetitions of the one skill that matters in this field — the ability to look at a system, form a hypothesis about how it could be broken, and test it methodically without ever leaving your scope.

Built the way I've described, your lab makes safety automatic. The network is isolated, the targets are disposable, and the AI becomes what it should be: a tireless mentor that walks you through every decision while you practice making them yourself. Take the hour to build it properly. Then take the next hundred hours using it. That's how real skills are built — one snapshot, one session, one hypothesis at a time.

Danial Dababneh

Danial Dababneh

Developer with 26 years of experience in programming and 18 years in the hospitality industry.