Penetration testing

Garak for Beginners: Test an LLM for Security Weaknesses

garak is an open-source scanner for large language models. It sends a battery of test prompts, called probes, and checks whether the model fails, for example by following injected instructions. It is a good first tool for AI security testing. Test only models and applications you own or have written permission to test. Read prompt injection explained first.

Install

  • python3 -m venv garak-env && source garak-env/bin/activate
  • python3 -m pip install garak
  • python3 -m garak --list_probes shows the probes available in your version.

Run a Small Scan

Start with a small local model so nothing leaves your machine. The Hugging Face gpt2 model is tiny and good for learning the workflow, even though its results say little about modern models:

  • python3 -m garak --model_type huggingface --model_name gpt2 --probes promptinject

The first run downloads the model, so it can take a few minutes. Hosted models need an API key you own and a different --model_type; see the garak documentation, and watch the cost.

Read the Results

garak prints a summary per probe and detector and tells you where the full report is saved. A failure means the model did the unwanted thing for some of the prompts. Open the report and read the actual prompts and replies, because the pass rate alone does not tell you the impact.

What a Scanner Cannot Do

  • It tests the model, not your whole application, its permissions or its data.
  • It cannot tell you what a successful injection would be able to do in your product.
  • Manual testing of the application around the model is still needed; see AI red teaming for beginners.

Where It Fits

AI security testing is the subject of EC-Council's COASP; see the COASP exam guide. The web and API base that AI applications sit on is taught in our Application Security course.

Sources and Further Reading

Want to start with the web and API testing base first? Book free trial classes. Contact us or call +91 86868 92922.

Start Your Cyber Security Career

Talk to a counselor, choose the right course for your goals, and get the fee, syllabus and next batch dates in writing.

Book Free Trial Classes

By submitting, you agree that Hacking Trainer Academy may contact you about courses by phone, WhatsApp or email. See our privacy notice and refund policy.

WhatsApp