Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 076e890

Browse files
committed
Merge remote-tracking branch 'origin/topic/awelzel/move-tracing-events-to-scripting'
* origin/topic/awelzel/move-tracing-events-to-scripting: Move tracing-events into ./scripting
2 parents 4143b0b + 02a26df commit 076e890

File tree

3 files changed

+88
-86
lines changed

3 files changed

+88
-86
lines changed

quickstart.rst

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -372,92 +372,6 @@ on the command line:
372372
mkdir output_directory ; zeek -r mypackets.trace Log::default_logdir=output_directory
373373
374374
375-
Tracing Events
376-
--------------
377-
378-
Zeek provides a mechanism for recording the events that occur during
379-
an execution run (on live traffic, or from a pcap) in a manner that you
380-
can then later replay to get the same effect but without the traffic source.
381-
You can also edit the recording to introduce differences between the original,
382-
such as introducing corner-cases to aid in testing, or anonymizing sensitive
383-
information.
384-
385-
You create a trace using:
386-
387-
.. code-block:: console
388-
389-
zeek --event-trace=mytrace.zeek <traffic-option> <other-options> <scripts...>
390-
391-
or, equivalently:
392-
393-
.. code-block:: console
394-
395-
zeek -E mytrace.zeek <traffic-option> <other-options> <scripts...>
396-
397-
Here, the *traffic-option* would be ``-i`` or ``-r`` to arrange for
398-
a source of network traffic. The trace will be written to the file
399-
``mytrace.zeek`` which, as the extension suggests, is itself a Zeek script.
400-
You can then replay the events using:
401-
402-
.. code-block:: console
403-
404-
zeek <other-options> <scripts...> mytrace.zeek
405-
406-
One use case for event-tracing is to turn a sensitive PCAP that can't
407-
be shared into a reflection of that same activity that - with some editing, for
408-
example to change IP addresses - is safe to share. To facilitate such
409-
editing, the generated script includes at the end a summary of all of
410-
the constants present in the script that might be sensitive and require
411-
editing (such as addresses and strings), to make it easier to know what
412-
to search for and edit in the script. The generated script also includes
413-
a global ``__base_time`` that's used to make it easy to alter (most of)
414-
the times in the trace without altering their relative offsets.
415-
416-
The generated script aims to ensure that event values that were related
417-
during the original run stay related when replayed; re-execution should
418-
proceed in a manner identical to how it did originally. There are however
419-
several considerations:
420-
421-
* Zeek is unable to accurately trace events that include values that cannot
422-
be faithfully recreated in a Zeek script, namely those having types of
423-
``opaque``, ``file``, or ``any``. Upon encountering these, it generates
424-
variables reflecting their unsupported nature, such as ``global
425-
__UNSUPPORTED21: opaque of x509;``, and initializes them with code like
426-
``__UNSUPPORTED21 = UNSUPPORTED opaque of x509;``. The generated script
427-
is meant to produce syntax errors if run directly, and the names make
428-
it easy to search for the elements that need to somehow be addressed.
429-
430-
* Zeek only traces events that reflect traffic processing, i.e., those
431-
occurring after :zeek:id:`network_time` is set. Even if you don't include
432-
a network traffic source, it skips the :zeek:id:`zeek_init` event
433-
(since it is always automatically generated).
434-
435-
* The trace does *not* include events generated by scripts, only those
436-
generated by the "event engine".
437-
438-
* The trace is generated upon Zeek cleanly exiting, so if Zeek crashes,
439-
no trace will be produced. Stopping Zeek via *ctrl-c* does trigger a
440-
clean exit.
441-
442-
* A subtle issue arises regarding any changes that the scripts in the
443-
original execution made to values present in subsequent events. If
444-
you re-run using the event trace script as well as those scripts,
445-
the changes the scripts make during the re-run will be discarded and
446-
instead replaced with the changes made during the original execution.
447-
This generally won't matter if you're using the exact same scripts for
448-
replay as originally, but if you've made changes to those scripts, then
449-
it could. If you need the replay script to "respond" to changes made
450-
during the re-execution, you can delete from the replay script every
451-
line marked with the comment ``# from script``.
452-
453-
.. note::
454-
455-
It's possible that some timers will behave differently upon replay
456-
than originally. If you encounter this and it creates a problem, we
457-
would be interested to hear about it so we can consider whether the
458-
problem can be remedied.
459-
460-
461375
Telling Zeek Which Scripts to Load
462376
----------------------------------
463377

scripting/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Introduction to Scripting
99
basics
1010
usage
1111
event-groups
12+
tracing-events
1213
optimization
1314
javascript

scripting/tracing-events.rst

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
.. _tracing_events:
2+
3+
==============
4+
Tracing Events
5+
==============
6+
7+
Zeek provides a mechanism for recording the events that occur during
8+
an execution run (on live traffic, or from a pcap) in a manner that you
9+
can then later replay to get the same effect but without the traffic source.
10+
You can also edit the recording to introduce differences between the original,
11+
such as introducing corner-cases to aid in testing, or anonymizing sensitive
12+
information.
13+
14+
You create a trace using:
15+
16+
.. code-block:: console
17+
18+
zeek --event-trace=mytrace.zeek <traffic-option> <other-options> <scripts...>
19+
20+
or, equivalently:
21+
22+
.. code-block:: console
23+
24+
zeek -E mytrace.zeek <traffic-option> <other-options> <scripts...>
25+
26+
Here, the *traffic-option* would be ``-i`` or ``-r`` to arrange for
27+
a source of network traffic. The trace will be written to the file
28+
``mytrace.zeek`` which, as the extension suggests, is itself a Zeek script.
29+
You can then replay the events using:
30+
31+
.. code-block:: console
32+
33+
zeek <other-options> <scripts...> mytrace.zeek
34+
35+
One use case for event-tracing is to turn a sensitive PCAP that can't
36+
be shared into a reflection of that same activity that - with some editing, for
37+
example to change IP addresses - is safe to share. To facilitate such
38+
editing, the generated script includes at the end a summary of all of
39+
the constants present in the script that might be sensitive and require
40+
editing (such as addresses and strings), to make it easier to know what
41+
to search for and edit in the script. The generated script also includes
42+
a global ``__base_time`` that's used to make it easy to alter (most of)
43+
the times in the trace without altering their relative offsets.
44+
45+
The generated script aims to ensure that event values that were related
46+
during the original run stay related when replayed; re-execution should
47+
proceed in a manner identical to how it did originally. There are however
48+
several considerations:
49+
50+
* Zeek is unable to accurately trace events that include values that cannot
51+
be faithfully recreated in a Zeek script, namely those having types of
52+
``opaque``, ``file``, or ``any``. Upon encountering these, it generates
53+
variables reflecting their unsupported nature, such as ``global
54+
__UNSUPPORTED21: opaque of x509;``, and initializes them with code like
55+
``__UNSUPPORTED21 = UNSUPPORTED opaque of x509;``. The generated script
56+
is meant to produce syntax errors if run directly, and the names make
57+
it easy to search for the elements that need to somehow be addressed.
58+
59+
* Zeek only traces events that reflect traffic processing, i.e., those
60+
occurring after :zeek:id:`network_time` is set. Even if you don't include
61+
a network traffic source, it skips the :zeek:id:`zeek_init` event
62+
(since it is always automatically generated).
63+
64+
* The trace does *not* include events generated by scripts, only those
65+
generated by the "event engine".
66+
67+
* The trace is generated upon Zeek cleanly exiting, so if Zeek crashes,
68+
no trace will be produced. Stopping Zeek via *ctrl-c* does trigger a
69+
clean exit.
70+
71+
* A subtle issue arises regarding any changes that the scripts in the
72+
original execution made to values present in subsequent events. If
73+
you re-run using the event trace script as well as those scripts,
74+
the changes the scripts make during the re-run will be discarded and
75+
instead replaced with the changes made during the original execution.
76+
This generally won't matter if you're using the exact same scripts for
77+
replay as originally, but if you've made changes to those scripts, then
78+
it could. If you need the replay script to "respond" to changes made
79+
during the re-execution, you can delete from the replay script every
80+
line marked with the comment ``# from script``.
81+
82+
.. note::
83+
84+
It's possible that some timers will behave differently upon replay
85+
than originally. If you encounter this and it creates a problem, we
86+
would be interested to hear about it so we can consider whether the
87+
problem can be remedied.

0 commit comments

Comments
 (0)