Prompting the Red Team: How to Run an AI-Assisted Security Audit of a Web App in 2026
Most teams discover their vulnerabilities the same way: after a customer reports a strange error, or worse, after a breach. A full manual pentest is expensive and happens once a year. But LLMs have quietly become a serious second pair of eyes for developers and security engineers — not a replacement for a real red team, but a fast, cheap first pass that catches the embarrassing stuff before it reaches production.
The catch: generic prompts like «find vulnerabilities in this code» produce generic, hallucinated answers. A useful AI security review needs the right context, the right framework (OWASP Top 10), and a healthy distrust of the output. Below are practical, copy-paste-ready prompts for secure code review, dependency auditing, log analysis, and attack modeling — with real examples and honest caveats about where the model will fail you.
1. The OWASP Top 10 Triage Prompt
When to use: first pass over a new codebase or a pull request touching auth, input handling, or database code.
You are a senior application security engineer. Review the code below
against the OWASP Top 10 (2021). For each category, state whether it
applies, cite the exact line or function, and rate severity
(Critical/High/Medium/Low). Do not invent issues — if you see nothing,
say «no finding». Output a Markdown table.
Code:
Example output for a Flask route using request.args directly in cursor.execute(): the model flags A03 Injection (High), cites the line, and suggests parameterized queries. It is fast, but you must verify each finding — see the caveats below.
2. SQL Injection Deep-Dive
When to use: any query built with string concatenation or f-strings.
Analyze this code for SQL injection (OWASP A03). For each vulnerable
query: (1) show the attack payload a user could send, (2) explain the
impact, (3) rewrite it using parameterized queries for this DB driver.
Assume PostgreSQL and psycopg2.
Real example: f"SELECT * FROM users WHERE id = {user_id}" — the model returns the payload 1 OR 1=1-- and the safe rewrite cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,)).
3. XSS and Output Encoding Review
When to use: templates, frontend rendering, rich-text fields.
Review this template/component for XSS (OWASP A03). Identify every
place user input reaches the DOM. For each: is it escaped? Is it a
trusted context? Suggest the correct escaping for HTML, attribute,
and JS contexts. Flag any use of innerHTML, dangerouslySetInnerHTML,
or v-html.
4. Dependency & Supply-Chain Audit
When to use: before releases, and after any npm audit / pip-audit run.
Here is my package.json (or requirements.txt) and the output of
`npm audit --json`. Summarize: which CVEs are Critical/High, which
packages are direct vs transitive, and which upgrades are safe vs
breaking. Prioritize by exploitability in a web context.
Paste real audit output — the model is good at triage, not at knowing CVEs it was not trained on. Always cross-check against the NVD (nvd.nist.gov).
5. Log Analysis for Attack Patterns
When to use: suspicious traffic, incident triage.
You are a SOC analyst. Here are 200 lines of nginx access logs.
Identify: scanning behavior, injection attempts (SQLi/XSS/path
traversal), brute-force patterns, and anomalous user agents.
Group by source IP and give a one-line verdict per cluster.
6. Threat Modeling (STRIDE)
When to use: design review, before writing code.
Act as a threat modeler. Here is my architecture (components, data
flows, trust boundaries). Apply STRIDE. For each threat: describe the
attack, the asset at risk, and a concrete mitigation. Output a table.
7. The Red Team Prompt — Attack Simulation
When to use: pre-pentest rehearsal, security training.
You are a red team operator with written authorization to test this
staging app. Given this feature description and API surface, list the
5 most likely attack chains a real attacker would try, ordered by
likelihood. For each: the steps, the payloads, and what a defender
would see in logs.
8. Secure Code Review for Auth & Sessions
When to use: login, JWT, password reset, role checks.
Audit this auth code for: broken access control (A01), weak session
management, JWT pitfalls (alg=none, missing expiry), and IDOR.
For each finding, show the exploit request and the fix.
9. Secrets & Config Leakage Scan
When to use: before every commit to a public repo.
Scan this diff for hardcoded secrets, API keys, tokens, and
credentials. Also flag insecure config: debug=True, permissive CORS
(*), missing security headers. Suggest a fix and a .gitignore entry.
10. The «Explain Like a Pentester» Prompt
When to use: onboarding juniors, writing security docs.
Explain this vulnerability to a junior developer in plain language:
what it is, how an attacker exploits it step by step, why it matters,
and how to prevent it. Use a concrete example, no jargon without a
definition.
Where AI Fails: The Honest Caveats
| Task | LLM does well | LLM fails / needs a human |
|---|---|---|
| Pattern spotting | SQLi, XSS, hardcoded secrets | Business-logic flaws |
| Triage | CVE prioritization | Zero-day reasoning |
| Speed | Seconds per file | Deep chained exploits |
| Accuracy | Common patterns | Hallucinated CVEs, false positives |
Three rules: (1) Never paste real secrets or production data into a public LLM — use a self-hosted model or redact first. (2) Verify every CVE against NVD; models invent plausible-sounding IDs. (3) AI does not replace a manual pentest — it shrinks the surface a human then confirms. Use it as a fast first pass, not a sign-off.
Putting It Together
Run prompts 1–3 on every PR touching input handling, prompt 4 before releases, and prompts 6–8 during design and auth work. Keep the outputs in your repo as a security changelog. If you want to build this habit systematically — from OWASP Top 10 to DevSecOps workflows — explore the security and AI tracks on asibiont.com and turn these prompts into a repeatable process, not a one-off experiment.
Comments