A handwritten 1765 ship's logbook open to ruled columns of dates, winds and remarks, with the article title about writing Zeek scripts with an LLM
Cover based on a photo by John Byron, via Wikimedia Commons, Public domain

You can write a Zeek script with an LLM in seconds, and the draft will usually look right: a module line, a redef enum Notice::Type, an event handler, a NOTICE call. Then Zeek refuses to load it. Models guess event signatures from memory, drop arguments, and forget the declarations the logging framework needs. Some mistakes are quieter: a script that loads cleanly can still write nothing at all if Zeek never sees the traffic you think it sees. An LLM Zeek detection script is a draft until Zeek has parsed it and produced the log lines you expected from a pcap you own.

This guide runs that loop on one small detection: a client that racks up HTTP 404s, the shape of a content scanner walking a web server you run. Every error and every log line below came from Zeek 9.0.1, the current LTS release on zeek.org, installed from the project's openSUSE Build Service packages for Debian 13, reading a pcap we generated on one box. We rechecked the event signatures, BIFs and framework calls against the Zeek 9.0.1 documentation on November 23, 2026. The drafts were written for this guide to reproduce mistakes models commonly make in Zeek scripts; they are not a captured model transcript, and no model was called in the lab. Zeek's output is the evidence, not the model's.

Defensive and authorized work only. Write scripts for networks you own or are hired to monitor, and replay only lab traffic or captures you are cleared to handle. Strip addresses, hostnames, cookies and tokens before anything goes into a prompt.

If you write signatures rather than scripts, see Suricata rules with an LLM; Zeek is event-driven code that keeps state and writes logs, which fails in different ways. The same draft-then-validate loop covers Sigma and YARA rules, Falco rules and osquery queries.

Why write Zeek scripts with an LLM

Zeek turns traffic into events (http_request, http_reply, dns_request and hundreds more), and scripts react to those events. A useful detection script usually needs four pieces: the right event handler with the exact signature, some state (a table with an expiry), a log stream for your own records, and a call into the Notice framework when a threshold is crossed.

That is a lot of boilerplate, and models are good at boilerplate. They are much less reliable on the details Zeek checks strictly: which arguments an event takes in your version, which identifiers must be declared in an export block, and which framework call needs which record type. Those are exactly the places an AI Zeek notice script breaks.

How to test an LLM-written Zeek script

Ask two questions, in order:

  1. Does it parse? zeek -a script.zeek stops after parsing (-a|--parse-only in zeek --help). A bad script prints an error in ... line with a file and line number, and Zeek exits 1.
  2. Does it log the right thing, and only that? Replay a pcap with -r and read the logs it writes into the current directory. zeek-cut pulls named columns out of Zeek's tab-separated logs.
# 1. Does it parse?
zeek -a lab404.zeek

# 2. What does it log?
zeek -C -r lab-http.pcap lab404.zeek
zeek-cut note msg src < notice.log

-C (--no-checksums) is there on purpose. We come back to why in Step 6.

Diagram of the loop to write a Zeek script with an LLM: the model drafts a script, zeek -a rejects a wrong http_reply event signature and an undeclared Log::ID, zeek -C -r replays a lab pcap, and only a script that writes the expected notice.log and lab404.log is kept
Parse the draft, replay the lab capture, and check both logs against the expected results. Image: RedRouter, Original

Step 1: Build a lab pcap you own

Decide what should and shouldn't fire before you ask the model for anything. We served a static directory with Python's http.server on 127.0.0.1:8080, captured the loopback interface with tcpdump, and sent 18 requests with curl from two loopback source addresses:

ClientRequestsShould it raise a notice?
127.0.0.2 ("browser")/, /robots.txt, /favicon.ico (one 404)No
127.0.0.3 ("scanner", user agent lab-scanner/0.1)15 paths that don't exist, such as /.git/config, /.env, /wp-login.phpYes, once

A baseline run with no custom script confirmed what Zeek sees in http.log: three requests from 127.0.0.2 (200, 200, 404) and fifteen 404s from 127.0.0.3. The threshold for this lab is 10 404s from one client.

Step 2: Give the model the version and the event

A prompt that works:

Write one Zeek 9.0 script. Module Lab404. Count HTTP 404 responses per client address in a table that expires entries 5 minutes after creation. Write every 404 to a custom log named lab404 with ts, uid, client, uri and the running count. When one client reaches 10, raise a notice of type Lab404::HTTP_404_Burst with $identifier set to the client address. Use the http_reply event with its full signature from the Zeek 9.0 docs. Return the script only.

Naming the version and asking for "the full signature from the docs" removes one class of errors. It does not remove the need to check, as the next step shows.

Step 3: A wrong event signature

A typical first draft:

# Draft 1 (LLM-style): flag a client that racks up HTTP 404s.
@load base/frameworks/notice

module Lab404;

export {
	redef enum Notice::Type += { HTTP_404_Burst };
	const threshold = 10 &redef;
}

global hits: table[addr] of count &default=0 &create_expire=5min;

event http_reply(c: connection, code: count, reason: string)
	{
	if ( code != 404 )
		return;

	local src = c$id$orig_h;
	hits[src] += 1;

	if ( hits[src] == threshold )
		NOTICE([$note=HTTP_404_Burst,
		        $msg=fmt("%s got %d HTTP 404s", src, hits[src]),
		        $conn=c,
		        $identifier=cat(src)]);
	}

Zeek 9.0.1 refuses it before reading a single packet:

error in d1-wrong-signature.zeek, line 13 and /opt/zeek/share/zeek/base/bif/plugins/Zeek_HTTP.events.bif.zeek, line 48: use of undeclared alternate prototype (event(c:connection, code:count, reason:string) and http_reply)

The HTTP events reference gives the real signature: http_reply is event (c: connection, version: string, code: count, reason: string). The draft dropped version. The error wording points at a Zeek feature: the types reference says "multiple alternate event prototype declarations are allowed, but the alternates must be some subset of the first, canonical prototype". The model's three-argument handler is a subset, but nobody declared it as an alternate, so Zeek rejects it. Copy the signature from the docs for your version; don't trust the model's memory of it.

The same applies to http_request, which in 9.0 takes (c: connection, method: string, original_URI: string, unescaped_URI: string, version: string). We checked: a three-argument http_request(c, method, original_URI) handler fails zeek -a with the same "undeclared alternate prototype" error.

Step 4: A missing Log::ID

The second draft fixes the signature and adds the custom log the prompt asked for:

# Draft 2 (LLM-style): signature fixed, custom log added.
@load base/frameworks/notice
@load base/protocols/http

module Lab404;

export {
	redef enum Notice::Type += { HTTP_404_Burst };
	const threshold = 10 &redef;

	type Info: record {
		ts:     time   &log;
		uid:    string &log;
		client: addr   &log;
		uri:    string &log &optional;
		hits:   count  &log;
	};
}

global hits: table[addr] of count &default=0 &create_expire=5min;

event zeek_init()
	{
	Log::create_stream(Lab404::LOG, [$columns=Info, $path="lab404"]);
	}

event http_reply(c: connection, version: string, code: count, reason: string)
	{
	if ( code != 404 )
		return;

	local src = c$id$orig_h;
	hits[src] += 1;

	Log::write(Lab404::LOG, [$ts=network_time(), $uid=c$uid, $client=src,
	                         $uri=c$http$uri, $hits=hits[src]]);

	if ( hits[src] == threshold )
		NOTICE([$note=HTTP_404_Burst,
		        $msg=fmt("%s got %d HTTP 404s", src, hits[src]),
		        $conn=c,
		        $identifier=cat(src)]);
	}

It fails on a different line:

error in d2-missing-log-id.zeek, line 24: unknown identifier Lab404::LOG, at or near "Lab404::LOG"

Log::create_stream takes a Log::ID, and each stream needs its own value added to that enum. The logging framework docs do this with redef enum Log::ID += { LOG }; inside the module's export block. The draft referenced Lab404::LOG without ever declaring it. When you send a draft back for a fix, paste the exact error in line; it names the file, the line and the identifier, which is more than a model gets from "it doesn't work".

Step 5: The fixed AI Zeek notice script

This version parses (zeek -a exits 0) and is the one we kept:

# lab404.zeek: notice + custom log for HTTP 404 bursts from one client.
# Lab traffic only. Tested with: zeek -C -r lab-http.pcap lab404.zeek
@load base/frameworks/notice
@load base/protocols/http

module Lab404;

export {
	redef enum Log::ID += { LOG };
	redef enum Notice::Type += { HTTP_404_Burst };

	## 404s from one client before we raise a notice.
	const threshold = 10 &redef;

	type Info: record {
		ts:     time   &log;
		uid:    string &log;
		client: addr   &log;
		uri:    string &log &optional;
		hits:   count  &log;
	};
}

# Per-client 404 counter; entries expire 5 minutes after creation.
global hits: table[addr] of count &default=0 &create_expire=5min;

event zeek_init()
	{
	Log::create_stream(Lab404::LOG, [$columns=Info, $path="lab404"]);
	}

event http_reply(c: connection, version: string, code: count, reason: string)
	{
	if ( code != 404 )
		return;

	local src = c$id$orig_h;
	hits[src] += 1;

	local rec = Info($ts=network_time(), $uid=c$uid, $client=src, $hits=hits[src]);
	if ( c?$http && c$http?$uri )
		rec$uri = c$http$uri;
	Log::write(Lab404::LOG, rec);

	if ( hits[src] == threshold )
		NOTICE([$note=HTTP_404_Burst,
		        $msg=fmt("%s got %d HTTP 404s within 5 minutes", src, hits[src]),
		        $conn=c,
		        $identifier=cat(src)]);
	}

What each piece is, checked against the docs:

  • http_reply with the full four-argument signature from the HTTP events reference.
  • &default=0 and &create_expire=5min are documented table attributes. A client's count drops when its entry expires five minutes after it was created.
  • Log::create_stream and Log::write from the logging framework, with $path="lab404" setting the file name.
  • NOTICE with a Notice::Info record. The Notice framework docs use the same $identifier=cat(...) pattern so repeat notices for one host are suppressed.
  • network_time, fmt and cat are real BIFs in 9.0. c$http$uri comes from the HTTP::Info record the base HTTP script fills in; the script checks it exists before reading it.

Replaying the lab pcap with zeek -C -r lab-http.pcap lab404.zeek exits 0 and writes notice.log and lab404.log next to the usual conn.log, http.log and files.log. The notice:

$ zeek-cut note msg src suppress_for < notice.log
Lab404::HTTP_404_Burst	127.0.0.3 got 10 HTTP 404s within 5 minutes	127.0.0.3	3600.000000

One notice, for the scanner, at the tenth 404. The browser's single /favicon.ico 404 was logged but did not reach the threshold. The equality check raises a notice only when the count reaches 10. Zeek also suppresses repeat notices with the same identifier for one hour, the default reported as 3600 seconds in suppress_for. The custom log:

$ zeek-cut ts uid client uri hits < lab404.log
1795466203.598909	CcsQw5amO3rCnFPv2	127.0.0.2	/favicon.ico	1
1795466203.605200	Crxj072wcxFH76IACl	127.0.0.3	/admin/	1
1795466203.611619	CnOBiw3FWL7u0LZlpl	127.0.0.3	/.git/config	2
1795466203.635690	CGgcK73sMy0dHf8Yu9	127.0.0.3	/.env	3
1795466203.641992	CYVdzW2pRcBEwNSrka	127.0.0.3	/wp-login.php	4
1795466203.647495	CbA3T43QCROxK9AJ75	127.0.0.3	/phpmyadmin/	5
1795466203.658223	CnbxCM3G9cxB2IwQpg	127.0.0.3	/backup.zip	6
1795466203.665388	C0koAo3T7PMIxtlau3	127.0.0.3	/config.php	7
1795466203.674176	CVrigh1J5yJGkOhmae	127.0.0.3	/server-status	8
1795466203.679768	CkXI072Pa9t1aqZMgb	127.0.0.3	/admin.php	9
1795466203.686432	CxqVKG1PmD8XDcdOM2	127.0.0.3	/login.php	10
1795466203.693088	Cul2aO1bNZKw6b9NSe	127.0.0.3	/.aws/credentials	11
1795466203.698570	C2w5501FxJRWz8qFnb	127.0.0.3	/api/v1/users	12
1795466203.705287	Cn3JCA2qxZlOWpqo2a	127.0.0.3	/debug/	13
1795466203.712129	CoUblv22FWQlVwhuv3	127.0.0.3	/old/	14
1795466203.718406	CVh8bO2Ghz5v15Lo46	127.0.0.3	/test.php	15

That is the whole point of the replay: the counts, the client split and the notice all match what the pcap table in Step 1 said should happen. We also ran the same script with the threshold raised on the command line (zeek -C -r lab-http.pcap lab404.zeek Lab404::threshold=20). It exited 0, wrote lab404.log, and wrote no notice.log, as expected for 15 404s.

Step 6: The quiet failure, no -C and no logs

Run the fixed script without -C on the same loopback capture and Zeek still exits 0. It writes conn.log, weird.log, reporter.log and packet_filter.log, and no http.log, lab404.log or notice.log. The reason is printed on stderr and kept in reporter.log:

1795466203.718667 warning in /opt/zeek/share/zeek/base/misc/find-checksum-offloading.zeek, line 54: Your trace file likely has invalid TCP checksums, most likely from NIC checksum offloading.  By default, packets with invalid checksums are discarded by Zeek unless using the -C command-line option or toggling the 'ignore_checksums' variable.  Alternatively, disable checksum offloading by the network adapter to ensure Zeek analyzes the actual checksums that are transmitted.

weird.log shows bad_TCP_checksum for the first connection from each client. Loopback and many NIC captures carry checksums the kernel never filled in, so Zeek drops the packets and your script never sees an HTTP reply. A model reviewing your script cannot spot this, because nothing is wrong with the script. The Zeek FAQ covers the same checksum issue. Use -C (or redef ignore_checksums = T;) for lab pcaps, and fix offloading on a live sensor instead of hiding it.

Common mistakes in LLM Zeek detection scripts

  • Event signatures from memory. Missing or reordered arguments fail with "use of undeclared alternate prototype". Copy signatures from the docs for your Zeek version.
  • Undeclared enums. Lab404::LOG and new notice types must be added with redef enum Log::ID += { LOG }; and redef enum Notice::Type += { ... }; in export.
  • Invented events and BIFs. If you can't find it on docs.zeek.org, it doesn't exist in your build. zeek -a will tell you, usually with "unknown identifier".
  • Unchecked optional fields. Reading c$http$uri without c?$http && c$http?$uri works until the one connection where it isn't set. Then Zeek raises an expression error (field value missing) instead of writing your record.
  • No suppression. Without $identifier, a noisy client can raise a notice on every event. Set it, and choose $suppress_for if the one-hour default doesn't fit.
  • Unbounded state. A table with no expiry attribute grows for as long as Zeek runs. Use &create_expire, &read_expire or &write_expire. For production thresholds across many keys, the SumStats framework is the built-in alternative.
  • Trusting a clean exit. Exit 0 with no notice.log is a result, not a pass. Check the logs against what the pcap should produce.

What to send the model

  • Send: your Zeek version, the detection goal in plain words, the exact event signature from the docs, the full error in line from zeek -a, and the zeek-cut columns that came out wrong.
  • Scrub: real IP addresses, hostnames, URIs with tokens, cookies and anything that identifies your users. Replay the pattern in a lab, as we did, and send that.
  • Don't send: production pcaps or full http.log files. The model doesn't need them to fix a handler.
  • Check retention. On RedRouter, zero data retention is an opt-in setting, off by default. The data handling docs explain what is stored and how to turn it on, and what RedRouter keeps covers the defaults in plain terms.

Automating the parse loop

zeek -a exits non-zero on a parse error, so the load-and-retry step is easy to script. This sketch asks a model for a script, parses it, and sends any error in lines back until it parses. It uses the OpenAI Python SDK with RedRouter's https://redrouter.org/v1 base URL from the quickstart. We did not run it against the API for this post; the Zeek half is the same command shown above.

import os, subprocess
from openai import OpenAI

client = OpenAI(base_url="https://redrouter.org/v1", api_key=os.environ["REDROUTER_API_KEY"])
messages = [{"role": "user", "content": open("prompt.txt").read()}]

for attempt in range(4):
    reply = client.chat.completions.create(model="glm-5.3-flash-red", messages=messages)
    script = reply.choices[0].message.content.strip().removeprefix("```zeek").strip("`").strip()
    open("draft.zeek", "w").write(script + "\n")
    test = subprocess.run(["zeek", "-a", "draft.zeek"], capture_output=True, text=True)
    if test.returncode == 0:
        print("Parses. Now replay your lab pcap with zeek -C -r and read the logs.")
        break
    errors = "\n".join(l for l in (test.stdout + test.stderr).splitlines() if "error" in l)
    messages += [{"role": "assistant", "content": script},
                 {"role": "user", "content": "zeek -a failed:\n" + errors + "\nReturn the fixed script only."}]

Stop the automation at "it parses". Whether the notice fires on the right client is a judgment against your pcap, so keep a person on Steps 5 and 6.

Choosing a model for Zeek scripts

Use any model that follows a "script only" instruction and can hold a few rounds of errors. On RedRouter, GLM 5.3 Flash Red (glm-5.3-flash-red) is $0.25 per 1M input tokens, $0.13 per 1M cached input tokens and $1.00 per 1M output tokens. red-cyber-1 (Beta), the featured model for authorized penetration testing and red-team work, is $0.28 / $0.13 / $1.10 per 1M tokens. The models docs list a 1,048,576-token context window for both and current rates for every model; plans are on /pricing.

Detection prompts describe attacks precisely: scanner paths, credential files, exploit strings. RedRouter is built for that kind of authorized security work.

FAQ

Can I write a Zeek script with an LLM?

Yes, as a first draft. In our lab, a draft with a wrong http_reply signature and a second with an undeclared Log::ID both failed to parse before a third version loaded and produced the expected notice.log. Each Zeek error named the file, line and identifier to fix.

How do I test an AI Zeek notice script?

Parse it with zeek -a script.zeek, then replay a pcap you own with zeek -C -r lab.pcap script.zeek and read notice.log and your custom log with zeek-cut. The pcap should contain traffic that must raise the notice and traffic that must not.

What does "use of undeclared alternate prototype" mean?

Your event handler's arguments don't match the event's canonical signature, and no alternate prototype with those arguments was declared. Copy the signature from the event's page on docs.zeek.org for your version.

Why did Zeek write no notice.log when the script loaded fine?

Check reporter.log. On our loopback capture, Zeek discarded packets with bad TCP checksums, so no HTTP events fired. Add -C for lab pcaps.

Is LLM Zeek detection good enough for production?

Only after the same validation you'd give hand-written code: parse, replay known-good and known-bad traffic, review state and suppression, then deploy. The model saves typing; the pcap decides.

Is it safe to paste Zeek logs into an LLM?

Not raw production logs unless your terms allow it. Send scrubbed columns and lab replays. On RedRouter, zero data retention is opt-in and off by default; see the data handling docs.

Sources