AI Red Teaming Lab 4: AI-Powered OSINT, Phishing Operations & Network Recon — a technical write-up
Lab 4 builds AI-augmented offensive automation in n8n: four chat-driven workflows that combine LLM calls (Groq) with OSINT APIs (SerpAPI, Hunter.io) and remote Nmap scanning over SSH. No native n8n AI-agent nodes are used — every "agent" is a raw HTTP request to Groq's OpenAI-compatible endpoint with a carefully engineered system prompt. The prompt engineering is the lab content.
Attack path (how the steps chain)
- Start from a name — the OSINT workflow turns "Jane Doe from Acme" into LinkedIn/social profiles, org email addresses, and the company's email pattern (SerpAPI + Hunter.io).
- Weaponize the OSINT — the phishing workflow feeds the same collected data to a "seasoned social engineer" persona, producing a copy-paste-ready spear-phish personalized with the target's role and colleagues.
- Map the infrastructure in parallel — the Nmap-over-SSH workflow scans the target and the LLM turns raw ports into a vulnerability assessment with an explicit attack-path analysis and risk scoring.
- Fuse everything behind one chat — the capstone router classifies intent (SCAN / OSINT / GITHUB) in a single word and dispatches the right chain, including commit-email harvesting from GitHub metadata.
- The real-world chain this mirrors: recon (OSINT + scan) → weaponization (phish) → delivery → initial access — the front half of every intrusion, automated end-to-end.
1. Setup (common to all exercises)
docker volume create n8n_data
docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
# open http://localhost:5678, create owner account
# Workflows → Import from File → each exercise JSON
Keys needed: Groq (console.groq.com), SerpAPI, Hunter.io.
The shipped JSONs contain hardcoded lab keys inline in HTTP node URLs/headers — replace them with your own
(worth fixing properly: use n8n Credentials, rotate exposed keys).
For Ex 3/4 create an SSH Password credential for a host with nmap (a Kali VM is ideal)
and select it on the Nmap nodes — the shipped credential IDs are placeholders.
Finally, toggle each workflow to Active so the chat webhook responds.
2. Exercise 1 — AI OSINT pipeline
Flow: Chat Trigger → Parse Target Input (JS: strips command verbs, extracts name + company via
"X from Y" regex, guesses company.com domain) → three parallel collectors → aggregate → Groq report.
- LinkedIn Search (SerpAPI): Google-dork
site:linkedin.com <name> <company>. - Social Media Search (SerpAPI): twitter/facebook/instagram dorks.
- Hunter.io: domain-search → org emails, names, positions, and the email pattern.
- Aggregate OSINT Data: try/catch per source so one failing API doesn't kill the run.
- AI OSINT Report (
llama-3.3-70b-versatile): "Red Team OSINT specialist" prompt — raw clickable URLs, list EVERY discovered email (never guess), state the pattern, produce Executive Summary / Target Footprint / Emails / Suggested Attack Vectors.
Input: osint on Sundar Pichai from Google · Output: a formatted report with profile URLs, org email list + pattern, and social-engineering attack vectors.
3. Exercise 2 — OSINT → targeted phishing
Same collection half, but the LLM is prompted as a "seasoned social engineer": write ONE highly
targeted phishing email with a compelling subject, using psychological triggers (urgency, authority, curiosity),
no introductory text. A Merge node (mergeByPosition) joins the three sources, and the output is
wrapped in a "Targeted Phishing Payload Generated" block with an authorized-use watermark.
Expected: a copy-paste-ready spear-phish personalized with the target's role, company context,
and colleagues discovered via OSINT.
4. Exercise 3 — AI-analyzed Nmap scan
Linear pipeline: Chat → Parse Target (IPv4 regex → domain → last token) → SSH node running
nmap -Pn -sV -T4 <target> on the remote host → Prepare AI Body → Groq
(llama-3.1-8b-instant, temp 0.2) with an elite-pentester system prompt demanding an exact skeleton:
Executive Summary, Open Ports table, per-port Vulnerability Assessment (Risk / Attack Surface / MITRE ATT&CK /
CVEs / Remediation), Attack Path Analysis, Risk Score Matrix (X/10), Top-5 Actions.
Input: scan scanme.nmap.org · Output: a structured pentest-style report. Lab quirk: the parsed scanType ("verbose") is never used downstream — a workflow limitation, not your error.
5. Exercise 4 — All-in-One agentic router (~30 nodes)
The capstone: an LLM acts as an intent router. A cheap classification call
(llama-3.3-70b-versatile) answers exactly one word — SCAN, OSINT, or
GITHUB — and a Switch node dispatches:
- SCAN branch: robust target parser; normal (
nmap -sV -sC -oX -) vs aggressive (sudo nmap -sV -O -A -T4 -p- -oX -) over SSH; XML parsed to JSON; script output surfaced fortcpwrappedports; Groq analysis with "do not hallucinate" rules. - OSINT branch: multi-stage fusion — employee LinkedIn search, company social search, Hunter.io, then chained LLM stages: per-source analysis → company profile → intelligence aggregator (fusion engine: dedupe, entity extraction, confidence scoring) → unified Red Team assessment.
- GITHUB branch: username extraction → repo listing → per-repo README fetch + commit history → commit-email harvesting (filters noreply addresses — a real OSINT technique for leaking personal emails from git metadata) → conversational AI analysis.
Inputs: aggressive scan example.com · research Jane Doe from Acme · analyze github torvalds.
6. Key insights
- Model choices are deliberate: 70B for routing/report writing, 8B for fast scan/GitHub summarization; temperatures 0.2–0.3 on analysis to reduce hallucination.
- Nmap-over-SSH decouples the scanner from n8n — the Docker container never needs nmap installed.
-oX -XML-to-stdout + n8n's XML node makes results machine-parseable before the LLM sees them (Ex 4), vs raw text in Ex 3.- Anti-hallucination prompt rules in Ex 4 ("Not found in provided data", "no exploitation steps") are production-grade patterns worth reusing.
7. Troubleshooting
- Chat not responding → workflow not Active; use the Chat Trigger's hosted URL.
- 401/403 → replace the shared hardcoded keys in every HTTP node (search the canvas for groq/serpapi/hunter).
- SSH fails → create your own SSH credential and select it on the Nmap nodes; verify nmap + sudo on the target host.
- Hunter returns nothing → the domain is guessed as
<company>.com; type the real domain. - Router misclassification → the Switch uses
containsmatching; use clear keywords ("scan", "github", "research"). - GitHub rate limits → unauthenticated API is 60 req/hr; add a token header for repo-heavy users.