n8n Workflows
Seven workflows in config/n8n/workflows/, all imported by playbook 04.6:
- Automated Domain & IP Reputation Guard — the main pipeline. Runs every minute and analyses one observable — a domain and the IP it resolved to — per run, as long as the VirusTotal budget allows it (see VirusTotal Budget).
- Deep Recon — runs hourly (at :20) after the verdict: domain age, certificate history and the web page of high-scored domains, then an AI re-assessment. See Deep Recon.
- Blocklist Candidates and Blocklist Publish — daily (03:20 and 05:20): own Pi-hole blocklists for malicious, tracking and telemetry domains, published to sentinel-blocklists. See Own Blocklists.
- API Usage Monitor — hourly (at :05): VirusTotal's own usage counter and the daily usage e-mail. See API Usage.
- Sandbox Scan — every 2 minutes: abuse.ch and urlscan.io checks of what the browser sandbox saw. See Sandbox Scan.
- Failure Guard — the Error Workflow of all the others: stops a workflow after
failure_guard_thresholdfailed runs in a row and sends one e-mail. See Failure Guard.
An earlier version is published in the n8n library: Score DNS Threats with VirusTotal, Abuse.ch, HashiCorp Vault, and Gemini.
Flow
flowchart TD
A[Load AI configuration] --> B[Pick observable if budget allows<br>claim_next_observable]
B --> C[VirusTotal: IP]
C --> S[Shodan InternetDB: IP]
S --> D{detections ≥<br>vt_gate_min_malicious?}
D -- no --> E[Rule score] --> F[Clean verdict<br>no AI, no email]
D -- yes --> G[ThreatFox: IP<br>URLhaus: domain<br>urlscan.io search: domain]
G --> H[Rule score 1–5]
H --> I[AI agent<br>Gemini + historical_verdicts]
I --> J[Parse and clamp score]
J --> K[Store verdict, audit, raw CTI]
F --> K
K --> L[Vector memory]
K --> M{score ≥ email_min_score?}
M -- yes --> N[Email alert]
K --> O{auto-block conditions?}
O -- yes --> P[Pi-hole denylist + block log] Steps
- Load configuration — one query reads all
ai_settings, the threat scale and the active prompt. Every threshold below comes from there and is edited in the AI Config UI. - Pick observable —
claim_next_observable()returns the next row ofv_pending_observables, or nothing when the VirusTotal budget is used up. Private IPs, allow-listed domains and pairs analysed in the lastcache_ttl_daysare already filtered out. - VirusTotal — VirusTotal checks the IP; the HTTP status goes into
api_call_logright away. A failed lookup (quota, auth, server error) is never scored as clean: the run fails and the observable is retried later. The request is not retried inside the run, so one claim is exactly one VirusTotal call. - Shodan and the gate — every IP is also looked up in Shodan InternetDB (switch
shodan_internetdb_enabled): open ports, software, known CVEs, tags and the hostnames Shodan saw on the IP. Free, no API key, no quota; weekly snapshot, non-commercial use only. It is context for the AI agent and the e-mail and does not change the rule score. Belowvt_gate_min_maliciousdetections the observable is then scored by rules only and stored as clean: no further API calls, no AI tokens, no email. - Enrich — ThreatFox (by IP), URLhaus (by domain) and two urlscan.io searches (switch
urlscan_search_enabled, scans younger thanurlscan_search_days): earlier scans of the domain's page (title, HTTP status, TLS issuer and certificate age, urlscan's verdict) and other sites urlscan saw on the same IP (malicious ones first). All are supporting sources; urlscan.io is only searched, nothing is submitted, and nothing here changes the rule score. - Rule score —
compute_threat_score()in PostgreSQL turns the results into a score 1–5 with a step-by-step trace. - AI agent — reviews the evidence and the rule score (details below).
- Store — raw responses, verdict, audit record and the embedding for vector memory.
- Act — email and Pi-hole auto-block (details below).
VirusTotal Budget
The public API allows 4 requests per minute and 500 per day; the daily quota resets at 00:00 UTC. The workflow runs every minute, and claim_next_observable() decides whether this run may call VirusTotal. Used is the higher of two counters: VirusTotal calls in api_call_log today (every caller), and VirusTotal's own counter for the key, read hourly by API Usage Monitor. The second one also sees calls this stack never logged — the dev environment and manual tests use the same key.
| Setting | Default | Meaning |
|---|---|---|
vt_daily_limit | 500 | Calls per day. At the limit the workflow stops until the reset. |
vt_per_minute_limit | 4 | Calls in the last 60 seconds. Matters when runs overlap or the schedule runs more often than once a minute. |
vt_reserve_per_hour | 5 | Calls kept back per hour left until the reset, for traffic that arrives later. 0 = spend the budget as soon as there is work. |
A backlog is therefore cleared at up to 60 observables per hour instead of being spread over the day, while the reserve keeps calls for the evening and night. Every claim is a row in api_call_log (outcome claimed, then the HTTP status); the same row stops two overlapping runs from taking the same observable. If a run fails before storing a verdict (e.g. VirusTotal returns 429), the pair is picked up again after 15 minutes.
The live lookups of the AI Config UI simulator go through the same budget (api_claim()): a lookup is refused while the per-minute limit or the reserve is reached. To clear a backlog faster than 60 per hour, set the Schedule Trigger to run every 15–20 seconds; the per-minute limit still holds.
API Usage
Every outgoing request is a row in cyber_sentinel_ai.api_call_log: provider, caller, endpoint, time, HTTP status and outcome (ok, no_data, rate_limited, error, or claimed when the run stopped before the result). The workflows log in one Log API calls node at the end of a run; VirusTotal is logged right after its call. The table is partitioned by month and kept 3 months, like dns_queries.
| Caller | Providers |
|---|---|
main | VirusTotal, Shodan, abuse.ch (ThreatFox, URLhaus), urlscan.io search, Gemini (one row per AI Agent run) |
deep_recon | RDAP, crt.sh, urlscan.io (search, scan, every poll of the result, DOM), Gemini |
blocklist_candidates | Gemini (one row per batch) |
simulator | VirusTotal, abuse.ch |
monitor | VirusTotal quota (virustotal_quota — free, does not count against the quota) |
API Usage Monitor runs every hour at :05: it stores VirusTotal's counter in api_provider_quota and sends one e-mail per provider and UTC day when its usage crosses api_alert_threshold_pct (80 %) of its daily limit (vt_daily_limit, api_daily_limit_<provider>; 0 = no limit). Only VirusTotal is stopped by its budget — the other providers are counted and alerted. The AI Config UI shows everything on the API usage page: today per provider and caller, per hour, the last 30 days, rate limits and errors.
Failure Guard
Every workflow above has Failure Guard as its Error Workflow (workflow settings). n8n starts it after each failed run. It reads the last failure_guard_threshold + 1 runs of that workflow through the n8n API:
- the last
failure_guard_threshold(10) runs all failed → the workflow is deactivated and one e-mail goes out with the failed node, the error and the time of the first failure; - a run still in flight after the stop finds that alert in
workflow_failure_alertsand sends nothing; a successful run starts the count again.
It needs no Vault: it uses the n8n credentials Postgres account, SMTP account and n8n API (Failure Guard) directly, and reads sender and recipient from cyber_sentinel_ai.ops_settings, which playbook 04.3 writes from vault_n8n_user / vault_n8n_alert_to. So it also works when Vault is sealed — the case that stopped the pipeline unnoticed for three days in November 2026. Every alert is stored in workflow_failure_alerts. After fixing the cause, activate the workflow again in n8n.
n8n starts an Error Workflow only while it is active, and every import (04.6) deactivates it. Playbook 06.3 therefore activates Failure Guard and issues its API key (scopes workflow:read, workflow:list, workflow:deactivate, execution:read, execution:list; the old key is deleted) — run it after every 04.6. 00_main.yml does.
Rule Score
| Step | Rule |
|---|---|
| 1 | VirusTotal detections → CLEAN / LOW / MEDIUM / HIGH (vt_low_max, vt_medium_max); trusted infrastructure with ≤ vt_big_player_noise_max detections is CLEAN |
| 2 | ThreatFox → CLEAN (not listed), MEDIUM (listed), HIGH (listed and seen in the last tf_active_days) |
| 3 | Combine: active ThreatFox IOC with a malware family or ≥ tf_active_vt_min detections → 5; any HIGH or hits in both → 4; MEDIUM → 3; LOW → 2; else 1 |
| 4 | URLhaus: +1 when the base is ≥ 3 and the domain has online malicious URLs |
| 5 | Trusted infrastructure without a ThreatFox malware family is capped at 2 |
AI Agent
| Model | Gemini 3.1 Flash Lite, temperature 0.2 |
| Prompt | Active version from prompt_templates; threat scale and ai_max_deviation injected at run time. Version 1.2 (inactive draft) also describes the urlscan.io and Shodan evidence — activate it in the AI Config UI |
| Input | Observable, VirusTotal / ThreatFox / URLhaus / urlscan.io / Shodan evidence, rule score with its trace |
| Tool | historical_verdicts — similarity search over past verdicts in pgvector, called once |
| Output | Structured JSON: label, English summary, primary evidence, supporting context, Polish analysis, proposed score, reason for any deviation, cited past verdicts |
The agent explains the rule score and may change it only for a reason visible in the evidence. The workflow then enforces the limits itself:
- the final score stays within
ai_max_deviationof the rule score, whatever the model proposes; - if the agent fails or returns invalid output, the rule score is stored with
ai_status = failed— nothing is lost; - cited past verdicts are kept only if they exist;
- evidence from the internet is treated as data; the prompt forbids following instructions found in it.
Every verdict is recorded in verdict_audit: rule score, final score, deviation reason, model and prompt version. Successful verdicts are embedded and added to verdict_vectors, so the next analysis can find them.
Actions
Email — sent when the AI analysed the observable and the final score is ≥ email_min_score. Colour follows severity; all values are HTML-escaped. The urlscan.io block shows earlier scans of the page, the TLS certificate issuer and age, and other sites on the same IP; the Shodan block shows open ports, the hostnames on the IP and the software. Known CVEs stay in the data for the AI agent but are not e-mailed — InternetDB derives them from software versions, so they are noisy.
Pi-hole auto-block — the domain is added to Pi-hole's exact denylist when all of these hold:
pihole_block_enabled = 1,- VirusTotal answered and detections ≥
pihole_block_min_vt_malicious, - the IP is not trusted infrastructure.
The workflow logs in with a Pi-hole application password, adds the domain with a comment, logs out and writes the result (blocked, already_blocked or error) to pihole_block_log. To unblock, remove the domain in Pi-hole.
Deep Recon
Runs hourly at minute 20. For verdicts with a final score ≥ recon_min_score (from the last recon_lookback_days) it collects what the main workflow does not, and lets an AI analyst re-assess the verdict. Verdicts are never changed automatically.
flowchart TD
A[Load settings + recon prompt] --> B{recon_enabled and<br>daily scan limit left?}
B -- yes --> C[Claim one verdict<br>v_pending_recon → deep_recon 'running']
C --> R[RDAP: registration date, registrar]
R --> T[crt.sh: certificate history]
T --> D{urlscan.io scan of the domain<br>younger than recon_reuse_days?}
D -- yes --> F[Get scan result]
D -- no --> E[Submit unlisted / private scan] --> W[Wait 30 s] --> F
F --> G{ready?}
G -- running --> P[Wait 10 s, poll again] --> F
G -- yes --> H[Page DOM → text, forms, password fields]
E -. refused / DNS error .-> N[No page: domain context only]
G -. failed / timeout .-> N
H --> I[Recon analyst: Gemini, no tools,<br>structured output, score limit]
N --> I
I --> J[deep_recon 'done' + raw payloads]
J --> K{proposed score ≠ verdict?}
K -- yes --> M[E-mail] - Queue —
v_pending_recon. A verdict is claimed with arunningrow before any external call, so a failing domain is never retried in a loop. A domain with a recent recon is skipped, so several verdicts of one domain lead to one recon. Re-queue from the AI Config UI (Deep recon page). - Domain — RDAP (
rdap.org, no key) is asked for two candidates, the last three and the last two labels of the domain; the longest one the registry knows is the registered domain (shop.firma.com.pl→firma.com.pl). Some TLDs have no RDAP: then the domain age is unknown. For subdomains of platforms on the allow-list exclusions (github.io,ngrok.io, …) the registration describes the platform, which the analyst is told. - Certificates — crt.sh (Certificate Transparency, no key): number of certificates, first and latest, issuers, names. crt.sh is often slow; a failure is recorded and the run goes on.
- Page — the page's TLS certificates (subject, issuer, validity) and the domains it loads resources from are extracted from the scan; the other sites on the same IP come from the verdict. urlscan.io scan reused when younger than
recon_reuse_days, otherwise submitted (unlisted, or private withrecon_private_scans). At mostrecon_daily_limitnew scans per day; urlscan.io free plan: 1000 unlisted or 50 private per day. Without a page (no key, refused, domain gone, timeout) the analyst still runs on the domain context. - Recon analyst — prompt from
recon_prompt_templates(versioned, edited in the AI Config UI;[[THREAT_SCALE]]and[[MAX_DEVIATION]]resolved at run time). Input: the verdict as stored, RDAP, crt.sh and page facts with up to 6000 characters of page text. Output: page type, impersonated brand, credential harvesting, confirms / contradicts / inconclusive, confidence, proposed score with reason, indicators, English summary, Polish analysis. The workflow keeps the proposed score withinrecon_max_deviationof the verdict, whatever the model says; a failed or invalid answer still saves the facts withai_status = failed. - Untrusted page — the page is attacker-controlled. Its text is passed only as data, comments and scripts are stripped, URLs are defanged, the model has no tools, and e-mail links point only to urlscan.io.
- Result —
deep_recon, one row per verdict. Raw RDAP and urlscan.io payloads go tothreat_data_rawand are linked to the verdict's indicator. When the proposed score differs (score_changed) andrecon_email_enabled = 1, an e-mail shows both scores, the reason, the page and the domain history.
Own Blocklists
Domains that get through Pi-hole but should not — malicious ones the main workflow blocked or the browser sandbox confirmed, telemetry and tracking — are published as plain domain lists to the public repository lukaszFD/sentinel-blocklists. Pi-hole pulls them as adlists. The database is the source of truth; the files are generated from it.
flowchart TD
Q[dns_queries] --> P{name matches a pattern,<br>queried ≥ blocklist_min_queries}
P --> AI[Blocklist Candidates: Gemini in batches<br>telemetry / tracking / ads / functional / unknown]
AI --> C[blocklist_entries 'candidate']
C --> UI[AI Config UI: approve / reject]
B[pihole_block_log] --> M[malicious, approved,<br>expires after blocklist_malicious_ttl_days]
SB[sandbox hits<br>v_blocklist_hits] --> M
UI --> R[blocklist_render: 3 files]
M --> R
R --> D{equal to main?}
D -- no --> PR[one commit on n8n/daily-update,<br>open or update the pull request]
PR --> MG[manual merge] --> PH[Pi-hole gravity update] - Lists —
lists/malicious.txt,lists/tracking.txt,lists/telemetry.txt: one domain per line, exact match, no IPs. Each file starts with a header (title, description, entry count) rendered byblocklist_render(); the malicious list's description names both sources, pipeline and browser sandbox. - Candidates — domains with a public IPv4 answer in the last
blocklist_lookback_days, queried at leastblocklist_min_queriestimes, whose name contains an active pattern (blocklist_name_patterns), not classified yet and not on any list. At mostblocklist_ai_daily_limitper day,blocklist_ai_batch_sizeper request. No VirusTotal calls. Answers about domains that were not in the batch are dropped. - Review — telemetry and tracking at or above
blocklist_ai_min_confidencewait for approval on the Blocklists page; an e-mail announces them. Rejected domains are kept and never proposed again. - Malicious — every Pi-hole auto-block is copied as approved; a new block extends the expiry. A rejected malicious domain stays rejected.
- Sandbox hits — a host, URL or payload hash with a CTI hit in the browser sandbox puts its full host (FQDN, not the registered domain) on the malicious list as approved, source
sandbox, expiry from the latest hit. Allow-listed hosts (Tranco top N, manual), IP literals and shared platforms themselves (storage.googleapis.com) never; a host already listed by another source is left as is. It reaches the pull request on the next daily run. - Protection — a domain covered by a manual allow-list entry is never published. Tranco entries and trusted infrastructure do not protect: telemetry usually sits on popular vendor domains.
- Publish — the branch
n8n/daily-updateis rebuilt frommainevery run with the full generated files, so one pull request always shows the whole difference. A pull request left open after the lists became equal tomainagain is closed. The merge stays manual: a ruleset onmainrequires a pull request.blocklist_publish_enabled = 0(default) is a dry run — compared and logged only. Every run is logged inblocklist_publish_log; a new or updated pull request and errors are e-mailed.
Sandbox Scan
Checks the observables of the browser sandbox — hosts, IPs, URLs and payload hashes that sandbox_log_processor stored in cyber_sentinel_sandbox.
flowchart LR
C[claim_checks<br>sandbox_scan_batch_size] --> P[Plan requests]
P --> H[CTI request<br>one HTTP node, 300 ms apart]
H --> E[Evaluate results]
E --> L[Log API calls] --> S[record_checks]
S --> M{new hits?} -- yes --> X[E-mail]
S --> U{page without<br>earlier urlscan scan?} -- yes --> V[private scan] --> S2[record_checks: submitted] | Observable | Lookups |
|---|---|
| host, IP | ThreatFox search_ioc, URLhaus host |
| URL | URLhaus url; top-level pages also urlscan.io (search, else a private scan) |
| SHA-256 | MalwareBazaar get_info, ThreatFox search_hash |
- Allow-listed hosts and their URLs never reach the queue; downloaded payloads always do.
- A private scan is fetched by a later run (after a minute); after 15 minutes without a result it is marked failed. At most
sandbox_urlscan_daily_limitprivate scans per UTC day. - Every request is logged in
api_call_logwith callersandbox(providersabusech,urlscan). - An observable is checked once; seen again after
sandbox_recheck_days, it is checked again. - One e-mail per run for the observables that became a hit (
sandbox_alert_enabled).
Secrets
The workflows read secrets from HashiCorp Vault at run time:
| Vault path | Used for |
|---|---|
cyber-sentinel/credentials/postgres/app_manager | PostgreSQL |
cyber-sentinel/api-keys/virustotal | VirusTotal |
cyber-sentinel/api-keys/abuse/api-key | ThreatFox, URLhaus, MalwareBazaar (Sandbox Scan) |
cyber-sentinel/api-keys/gemini/home-network-guardian | Gemini |
cyber-sentinel/credentials/gmail | Email: SMTP login and alert recipient (to) |
cyber-sentinel/credentials/pihole-api | Pi-hole API |
cyber-sentinel/api-keys/urlscanio/api-key | urlscan.io search (main, Sandbox Scan), page scans (Deep Recon) and private scans (Sandbox Scan) |
cyber-sentinel/api-keys/github/blocklists | GitHub fine-grained token for sentinel-blocklists: Contents and Pull requests read/write (Blocklist Publish) |
The n8n credentials needed by the AI and database nodes (Vault token, PostgreSQL, Gemini, SMTP) are created with fixed IDs by playbook 06.2, and the n8n API key of Failure Guard by playbook 06.3, so the imported workflows work without manual setup.