Skip to main content

Security testing toolkit for LLM-based systems

Project description

LLM Pentest

CI PyPI Python License: MIT OWASP

Security testing toolkit for LLM-based systems — chatbots, RAG pipelines, and AI agents.

Tests for prompt injection, data exfiltration, tool abuse, and jailbreaking.

Install

pip install -e .

Quick Start

# Interactive setup
llm-pentest init

# Or use a built-in profile
llm-pentest scan --profile openai

# Or provide a config file
cp examples/target.yaml my-target.yaml
llm-pentest scan -c my-target.yaml

Usage

# List payloads and chains
llm-pentest payloads

# Scan specific category
llm-pentest scan -c target.yaml --category prompt_injection

# Scan single payload
llm-pentest scan -c target.yaml --payload pi-001

# Parallel scanning (5 concurrent requests)
llm-pentest scan -c target.yaml -n 5

# Only fail CI on high/critical findings
llm-pentest scan -c target.yaml --fail-on high

# Use a profile instead of config file
llm-pentest scan --profile openai --model gpt-4o

# HTML report
llm-pentest scan -c target.yaml --format html -o report.html

# SARIF report (GitHub Code Scanning compatible)
llm-pentest scan -c target.yaml --format sarif -o report.sarif

# Baseline comparison
llm-pentest scan -c target.yaml -o baseline.json
# ... fix vulnerabilities ...
llm-pentest scan -c target.yaml -o current.json --baseline baseline.json

# Standalone diff
llm-pentest diff -b baseline.json --current current.json

# Custom detection hooks
llm-pentest scan -c target.yaml --hooks my_hooks.py

# LLM-as-judge for better detection accuracy
llm-pentest scan -c target.yaml --judge-endpoint https://api.openai.com/v1/chat/completions --judge-key $OPENAI_API_KEY

# Dry run (no requests sent)
llm-pentest scan -c target.yaml --dry-run

Target Profiles

Built-in profiles for common providers (llm-pentest profiles):

Profile Endpoint Default Model
openai api.openai.com gpt-4o-mini
anthropic api.anthropic.com claude-sonnet-4-20250514
ollama localhost:11434 llama3

Attack Categories

Category Payloads OWASP Description
prompt_injection pi-001 to pi-009 LLM01 System prompt extraction, instruction override, encoding bypass, indirect injection
data_exfiltration de-001 to de-005 LLM06 RAG context leak, credential extraction, PII harvesting
tool_abuse ta-001 to ta-004 LLM07, LLM08 Unauthorized tool use, parameter injection, CoT hijacking, DoS
jailbreak jb-001 to jb-004 LLM01 Role-play, hypothetical framing, token smuggling, persona splitting

Attack Chains

Chains compose multiple payloads into multi-step attack sequences:

- id: chain-001
  name: "Jailbreak then Extract Credentials"
  steps:
    - payload_id: jb-001
      prompt_index: 0
    - payload_id: de-002
      prompt_index: 0

Custom Payloads

Drop YAML files into payloads/ or pass --payloads-dir:

- id: custom-001
  name: "My Custom Attack"
  category: prompt_injection
  severity: high
  owasp: ["LLM01"]
  prompts:
    - "Your attack prompt here"
  detection:
    - pattern: "expected response pattern"
      confidence: 0.8

Custom Detection Hooks

Write Python functions for domain-specific detection:

# my_hooks.py — any function named detect_* is auto-registered
def detect_internal_data(payload, prompt, response):
    if "internal-project-name" in response.lower():
        return "Leaked internal project name"
    return None
llm-pentest scan -c target.yaml --hooks my_hooks.py

CI/CD Integration

# Fail only on high/critical findings
llm-pentest scan -c target.yaml --fail-on high || echo "Vulnerabilities found!"

# SARIF for GitHub Code Scanning
llm-pentest scan -c target.yaml --format sarif -o results.sarif

# Baseline regression check
llm-pentest scan -c target.yaml --baseline previous.json --fail-on high

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_pentest-0.1.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_pentest-0.1.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file llm_pentest-0.1.0.tar.gz.

File metadata

  • Download URL: llm_pentest-0.1.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llm_pentest-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b0798c732600509046ba7b89ce2c0c7e1535af6c8f613b348353acbc4909887
MD5 d1f8ccbde3e03ad0b3d757f037b8820b
BLAKE2b-256 1055cb0dfbfef945959013588f34883fedb0b8f562b786a2ef5f1bb520b3c8ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_pentest-0.1.0.tar.gz:

Publisher: publish.yml on jcazako/llm-pentest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_pentest-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llm_pentest-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llm_pentest-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afdbbe532641cbed33898087468e091b4d8e4b3f64f90449c72a33353308f072
MD5 fdbfab577d378de4034e25337e5e5fdb
BLAKE2b-256 beefd938d8be970a873cebe3e484ccd742f0df04986fb05007b84999bcb8e017

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_pentest-0.1.0-py3-none-any.whl:

Publisher: publish.yml on jcazako/llm-pentest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page