-
Notifications
You must be signed in to change notification settings - Fork 19
/
sec.man
6861 lines (6861 loc) · 225 KB
/
sec.man
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\"
.\" SEC (Simple Event Correlator) 2.9.3 - sec.man
.\" Copyright (C) 2000-2024 Risto Vaarandi
.\"
.\" This program is free software; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License
.\" as published by the Free Software Foundation; either version 2
.\" of the License, or (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program; if not, write to the Free Software
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
.\"
.TH sec 1 "November 2024" "SEC 2.9.3"
.SH NAME
sec \- simple event correlator
.SH SYNOPSIS
.TP
.B sec
[--conf=<file pattern> ...]
.br
[--input=<file pattern>[=<context>] ...]
.br
[--input-timeout=<input timeout>]
.br
[--timeout-script=<timeout script>]
.br
[--reopen-timeout=<reopen timeout>]
.br
[--check-timeout=<check timeout>]
.br
[--poll-timeout=<poll timeout>]
.br
[--socket-timeout=<socket timeout>]
.br
[--blocksize=<io block size>]
.br
[--bufsize=<input buffer size>]
.br
[--evstoresize=<event store size>]
.br
[--cleantime=<clean time>]
.br
[--log=<logfile>]
.br
[--syslog=<facility>]
.br
[--debug=<debuglevel>]
.br
[--pid=<pidfile>]
.br
[--dump=<dumpfile>]
.br
[--user=<username>]
.br
[--group=<groupname> ...]
.br
[--umask=<mode>]
.br
[--ruleperf | --noruleperf]
.br
[--dumpfts | --nodumpfts]
.br
[--dumpfjson | --nodumpfjson]
.br
[--quoting | --noquoting]
.br
[--tail | --notail]
.br
[--fromstart | --nofromstart]
.br
[--detach | --nodetach]
.br
[--jointbuf | --nojointbuf]
.br
[--keepopen | --nokeepopen]
.br
[--rwfifo | --norwfifo]
.br
[--childterm | --nochildterm]
.br
[--intevents | --nointevents]
.br
[--intcontexts | --nointcontexts]
.br
[--testonly | --notestonly]
.br
[--help] [-?]
.br
[--version]
.SH DESCRIPTION
SEC is an event correlation tool for advanced event processing which can
be harnessed for event log monitoring, for network and security management,
for fraud detection, and for any other task which involves event correlation.
Event correlation is a procedure where a stream of events is processed,
in order to detect (and act on) certain event groups that occur within
predefined time windows. Unlike many other event correlation products which
are heavyweight solutions, SEC is a lightweight and platform-independent
event correlator which runs as a single process. The user can start it as
a daemon, employ it in shell pipelines, execute it interactively in
a terminal, run many SEC processes simultaneously for different tasks,
and use it in a wide variety of other ways.
.PP
SEC reads lines from files, named pipes, or standard input,
matches the lines with patterns (regular expressions, Perl subroutines, etc.)
for recognizing input events, and
correlates events according to the rules in its configuration file(s).
Rules are matched against input in the order they are given in
the configuration file.
If there are two or more configuration files, rule sequence from every file
is matched against input (unless explicitly specified otherwise).
SEC can produce output by executing external programs (e.g.,
.BR snmptrap (1)
or
.BR mail (1)),
by writing to files, by sending data to TCP and UDP based servers,
by calling precompiled Perl subroutines, etc.
.PP
SEC can be run in various ways. For example, the following command line
starts it as a daemon, in order to monitor events appended to the
/var/log/messages syslog file with rules from /etc/sec/syslog.rules:
.PP
/usr/bin/sec --detach --conf=/etc/sec/syslog.rules \\
--input=/var/log/messages
.PP
Each time /var/log/messages is rotated, a new instance of /var/log/messages
is opened and processed from the beginning. The following command line
runs SEC in a shell pipeline, configuring it to process lines from standard
input, and to exit when the /usr/bin/nc tool closes its standard output
and exits:
.PP
/usr/bin/nc -l 8080 | /usr/bin/sec --notail --input=- \\
--conf=/etc/sec/my.conf
.PP
Some SEC rules start event correlation operations, while other rules react
immediately to input events or system clock. For example, suppose that SEC
has been started with the following command line
.PP
/usr/bin/sec --conf=/etc/sec/sshd.rules --input=/var/log/secure
.PP
in order to monitor the /var/log/secure syslog file for sshd events.
Also, suppose that the /etc/sec/sshd.rules configuration file contains
the following rule for correlating SSH failed login syslog events:
.PP
type=SingleWithThreshold
.br
ptype=RegExp
.br
pattern=sshd\\[\\d+\\]: Failed .+ for (\\S+) from [\\d.]+ port \\d+ ssh2
.br
desc=Three SSH login failures within 1m for user $1
.br
action=pipe '%s' /bin/mail -s 'SSH login alert' root@localhost
.br
window=60
.br
thresh=3
.PP
The
.I pattern
field of the rule defines the pattern for recognizing input events, while the
.I ptype
field defines its type (regular expression). Suppose that user risto fails to
log in over SSH and the following message is logged to /var/log/secure:
.PP
Dec 16 16:24:59 myserver sshd[13685]: Failed password for risto from 10.12.2.5 port 41063 ssh2
.PP
This input message will match the regular expression
pattern of the above rule, and the match variable $1 will be set to the string
.I risto
(see
.BR perlre (1)
for details).
After a match, SEC will evaluate the operation description string given with
the
.I desc
field. This is done by substituting $1 with its current value which yields
.IR "Three SSH login failures within 1m for user risto" .
SEC will then check if there already exists an event correlation operation
identified with this string and triggered by the same rule.
If the operation is not found, SEC will create
a new operation for the user name risto, and the occurrence time of the input
event will be recorded into the operation.
Note that for event occurrence time SEC always uses the current time
as returned by the
.BR time (2)
system call, *not* the timestamp extracted from the event.
.PP
Suppose that after 25 seconds,
a similar SSH login failure event for the same user name is observed. In this
case, a running operation will be found for the operation description string
.IR "Three SSH login failures within 1m for user risto" ,
and the occurrence time of the second event is recorded into the operation.
If after 30 seconds a third event for the user name risto is observed,
the operation has processed 3 events within 55 seconds. Since the threshold
condition "3 events within 60 seconds" (as defined by the
.I thresh
and
.I window
fields) is now satisfied, SEC will execute the action defined with the
.I action
field -- it will fork a command
.PP
/bin/mail -s 'SSH login alert' root@localhost
.PP
with a pipe connected to its standard input. Then, SEC writes the operation
description string
.I "Three SSH login failures within 1m for user risto"
(held by the %s special variable)
to the standard input of the command through the pipe.
In other words, an e-mail warning is sent to the local root-user.
Finally, since there are 5 seconds left until the end of
the event correlation window, the operation will consume the following SSH
login failure events for user risto without any further action, and finish
after 5 seconds.
.PP
The above example illustrates that the
.I desc
field of a rule defines the scope of event correlation and influences the
number of operations created by the rule. For example, if we set the
.I desc
field to
.IR "Three SSH login failures within 1m" ,
the root-user would be also alerted on 3 SSH login failure events
for *different* users within 1 minute.
In order to avoid clashes between operations started by different rules,
operation ID contains not only the value set by the
.I desc
field, but also the rule file name and the rule number inside the file.
For example, if the rule file /etc/sec/sshd.rules contains one rule
.PP
type=SingleWithThreshold
.br
ptype=RegExp
.br
pattern=sshd\\[\\d+\\]: Failed .+ for (\\S+) from [\\d.]+ port \\d+ ssh2
.br
desc=Three SSH login failures within 1m for user $1
.br
action=pipe '%s' /bin/mail -s 'SSH login alert' root@localhost
.br
window=60
.br
thresh=3
.PP
and the event
.PP
Dec 16 16:24:59 myserver sshd[13685]: Failed password for risto from 10.12.2.5 port 41063 ssh2
.PP
is the first matching event for the above rule, this event will trigger
a new event correlation operation with the ID
.PP
/etc/sec/sshd.rules | 0 | Three SSH login failures within 1m for user risto
.PP
(0 is the number assigned to the first rule in the file,
see EVENT CORRELATION OPERATIONS section for more information).
.PP
The following simple example demonstrates that event correlation schemes
can be defined by combining several rules. In this example, two rules
harness contexts and synthetic events for achieving their goal:
.PP
type=SingleWithThreshold
.br
ptype=RegExp
.br
pattern=sshd\\[\\d+\\]: Failed .+ for (\\S+) from [\\d.]+ port \\d+ ssh2
.br
desc=Three SSH login failures within 1m for user $1
.br
action=event 3_SSH_LOGIN_FAILURES_FOR_$1
.br
window=60
.br
thresh=3
.PP
type=EventGroup
.br
ptype=RegExp
.br
pattern=3_SSH_LOGIN_FAILURES_FOR_(\\S+)
.br
context=!USER_$1_COUNTED && !COUNTING_OFF
.br
count=create USER_$1_COUNTED 60
.br
desc=Repeated SSH login failures for 30 distinct users within 1m
.br
action=pipe '%s' /bin/mail -s 'SSH login alert' root@localhost; \\
create COUNTING_OFF 3600
.br
window=60
.br
thresh=30
.PP
The first rule looks almost identical to the rule from the previous example,
but its
.I action
field is different -- after three SSH login failures have been observed for
the same user name within one minute by an event correlation operation,
the operation will emit the synthetic event
3_SSH_LOGIN_FAILURES_FOR_<username>. Although synthetic events are created
by SEC, they are treated like regular events received from input sources and
are matched against rules.
.PP
The regular expression pattern of the second rule will match the
3_SSH_LOGIN_FAILURES_FOR_<username> event and start a new event correlation
operation if no such events have been previously seen.
Also, each time a synthetic event for some user name has matched the rule,
a context with the lifetime of 1 minute for that user name is created (see the
.I count
field).
Note that this prevents further matches for the same user name, since
a synthetic event for <username> can match the rule only if the context
USER_<username>_COUNTED *does not* exist (as requested by the boolean
expression in the
.I context
field; see CONTEXTS AND CONTEXT EXPRESSIONS section for more information).
.PP
The operation started by the second rule sends an e-mail warning to the local
root-user if 30 synthetic events have been observed within 1 minute (see the
.I thresh
and
.I window
fields). Note that due to the use of the USER_<username>_COUNTED contexts, all
synthetic events concern different user names. After sending an e-mail warning,
the operation will also create the context COUNTING_OFF with the lifetime of
1 hour, and will continue to run until the 1 minute event correlation
window expires. After the operation has finished, the presence of the
COUNTING_OFF context will keep the second rule disabled (as requested by
the boolean expression in the
.I context
field). Therefore, at most one e-mail warning per 1 hour is issued by
above rules.
.PP
The above examples have presented the event correlation capabilities of SEC
in a very brief fashion.
The following sections will provide an in-depth discussion of SEC features.
.SH OPTIONS
.TP
.B \-\-conf=<file_pattern>
expand <file_pattern> to filenames (with the Perl
.BR glob ()
function) and read event correlation rules from every file. Multiple
.B \-\-conf
options can be specified at command line. Each time SEC receives a signal
that forces a configuration reload, <file_pattern> is re-evaluated. See also
INPUT PROCESSING AND TIMING section for a discussion on rule processing order
for multiple configuration files.
.TP
.B \-\-input=<file_pattern>[=<context>]
expand <file_pattern> to filenames (with the Perl
.BR glob ()
function) and use the files as input sources. An input file can be a regular
file, named pipe, or standard input if
.B \-
was specified. Multiple
.B \-\-input
options can be specified at command line. Each time SEC receives the
.B SIGHUP
or
.B SIGABRT
signal, <file_pattern> is re-evaluated.
If SEC experiences a system error when reading from an input file, it will
close the file (use the
.B \-\-reopen\-timeout
option for reopening the file). If <context> is given, SEC will set up the
context <context> each time it reads a line from input files that correspond
to <file_pattern>. This will help the user to write rules that match data from
particular input source(s) only. When there is an
.B \-\-input
option with <context> specified, it will automatically enable the
.B \-\-intcontexts
option. See INTERNAL EVENTS AND CONTEXTS section for more information.
.TP
.BR \-\-input\-timeout=<input_timeout> ", " \-\-timeout\-script=<timeout_script>
if SEC has not observed new data in an input file during <input_timeout>
seconds (or the file was closed <input_timeout> seconds ago), <timeout_script>
will be executed with command line parameters 1 and <the name of the input
file>. If fresh data become available again, <timeout_script> will be executed
with command line parameters 0 and <the name of the input file>.
Setting <input_timeout> to 0 disables this behavior (this is also the default).
Note that
.B \-\-input_timeout
and
.B \-\-timeout_script
options can be used as synonyms for
.B \-\-input\-timeout
and
.BR \-\-timeout\-script ,
respectively.
.TP
.B \-\-reopen\-timeout=<reopen_timeout>
if an input file is in the closed state (e.g., SEC fails to open the file at
startup, because it has not been created yet), SEC will attempt
to reopen the file after every <reopen_timeout> seconds until open succeeds.
Setting <reopen_timeout> to 0 disables this behavior (this is also the default).
This option has no meaning when the
.B \-\-notail
option is also specified.
Note that
.B \-\-reopen_timeout
is a synonym for
.BR \-\-reopen\-timeout .
.TP
.B \-\-check\-timeout=<check_timeout>
if SEC has not observed new data in an input file, the file will not be polled
(both for status and data) during the next <check_timeout> seconds.
Setting <check_timeout> to 0 disables this behavior (this is also the default).
Note that
.B \-\-check_timeout
is a synonym for
.BR \-\-check\-timeout .
.TP
.B \-\-poll\-timeout=<poll_timeout>
a real number that specifies how many seconds SEC will sleep when no new data
were read from input files. Default is 0.1 seconds.
Note that
.B \-\-poll_timeout
is a synonym for
.BR \-\-poll\-timeout .
.TP
.B \-\-socket\-timeout=<socket_timeout>
if a network connection to a remote peer can't be established within
<socket_timeout> seconds, give up. Default is 60 seconds.
Note that
.B \-\-socket_timeout
is a synonym for
.BR \-\-socket\-timeout .
.TP
.B \-\-blocksize=<io_block_size>
the number of bytes SEC will attempt to read at once from an input file.
Default is 8192 bytes (i.e., read from input files by 8KB blocks).
.TP
.B \-\-bufsize=<input_buffer_size>
set all input buffers to hold <input_buffer_size> lines.
The content of input buffers will be compared with
patterns that are part of rule definitions (i.e., no more than
<input_buffer_size> lines can be matched by a pattern at a time).
If <input_buffer_size> is set to 0, SEC will determine the proper value
for <input_buffer_size> by checking event matching patterns of all SEC rules.
Default is 0 (i.e., determine the size of input buffers automatically).
.TP
.B \-\-evstoresize=<event_store_size>
set an upper limit to the number of events in context event stores.
Default is 0 which sets no limit.
.TP
.B \-\-cleantime=<clean_time>
time interval in seconds that specifies how often internal event correlation
and context lists are processed, in order to accomplish time-related tasks
and to remove obsolete elements. See INPUT PROCESSING AND TIMING section for
more information.
Default is 1 second.
.TP
.B \-\-log=<logfile>
use <logfile> for logging SEC activities. Note that if the SEC standard error
is connected to a terminal, messages will also be logged there, in order to
facilitate debugging.
.TP
.B \-\-syslog=<facility>
use syslog for logging SEC activities. All messages will be logged with the
facility <facility>, e.g.,
.I local0
(see
.BR syslog (3)
for possible facility values). Warning: be careful with using this option if
SEC is employed for monitoring syslog log files, because message loops might
occur.
.TP
.B \-\-debug=<debuglevel>
set logging verbosity for SEC. Setting debuglevel to <debuglevel>
means that all messages of level <debuglevel> and lower are logged (e.g.,
if <debuglevel> is 3, messages from levels 1-3 are logged). The
following levels are recognized by SEC:
.br
1 - critical messages (severe faults that cause SEC to terminate, e.g.,
a failed system call)
.br
2 - error messages (faults that need attention, e.g., an incorrect rule
definition in a configuration file)
.br
3 - warning messages (possible faults, e.g., a command forked from SEC
terminated with a non-zero exit code)
.br
4 - notification messages (normal system level events and interrupts, e.g.,
the reception of a signal)
.br
5 - informative messages (information about external programs forked
from SEC)
.br
6 - debug messages (detailed information about all SEC activities)
.br
Default <debuglevel> is 6 (i.e., log everything). See SIGNALS section
for information on how to change <debuglevel> at runtime.
.TP
.B \-\-pid=<pidfile>
SEC will store its process ID to <pidfile> at startup.
.TP
.B \-\-dump=<dumpfile>
SEC will use <dumpfile> as its dump file for writing performance and debug
data. With the
.B \-\-dumpfts
option, a timestamp suffix is appended to the dump file name. With the
.B \-\-dumpfjson
option, dump file is produced in JSON format.
See SIGNALS section for more information. Default is /tmp/sec.dump.
.TP
.BR \-\-user=<username> ", " \-\-group=<groupname>
if SEC is started with effective user ID 0, it will drop root privileges by
switching to user <username> and group <groupname>.
The
.B \-\-group
option can't be used without the
.B \-\-user
option. If the
.B \-\-user
option is given without
.BR \-\-group ,
primary group of the user <username> is assumed for <groupname>.
If several groups are provided with multiple
.B \-\-group
options, SEC switches to the first group with other groups as supplementary
groups.
.TP
.B \-\-umask=<mode>
set file mode creation mask to <mode> at SEC startup, where <mode>
is a value from the range 0..0777 (see also
.BR umask (2)).
Octal, decimal, hexadecimal, and binary values can be specified for <mode>
(e.g., octal mask 0027 can also be expressed as 23, 0x17, and 0b000010111).
.TP
.BR \-\-ruleperf ", " \-\-noruleperf
if the
.B \-\-ruleperf
option is specified, performance data (e.g., total consumed CPU time)
is collected for each rule and reported in dump file. Default is
.BR \-\-noruleperf .
.TP
.BR \-\-dumpfts ", " \-\-nodumpfts
if the
.B \-\-dumpfts
option is specified, a timestamp suffix (seconds since Epoch) is appended
to the dump file name that reflects the file creation time. Default is
.BR \-\-nodumpfts .
.TP
.BR \-\-dumpfjson ", " \-\-nodumpfjson
if the
.B \-\-dumpfjson
option is specified, dump file is produced in JSON format.
Default is
.BR \-\-nodumpfjson .
.TP
.BR \-\-quoting ", " \-\-noquoting
if the
.B \-\-quoting
option is specified, operation description strings that are supplied to
command lines of
.IR shellcmd ,
.IR spawn ,
and
.I cspawn
actions will be put inside single quotes. Each single quote (') that strings
originally contain will be masked. This option prevents the shell from
interpreting special symbols that operation description strings might contain.
Default is
.BR \-\-noquoting .
.TP
.BR \-\-tail ", " \-\-notail
if the
.B \-\-notail
option is specified, SEC will process all data that are currently available
in input files and exit after reaching all EOFs.
If all input is received from a pipe and the
.B \-\-notail
option is given, SEC terminates when the last writer closes the pipe
(EOF condition). Please note that with named pipes
.B \-\-notail
should be used with
.BR \-\-norwfifo .
With the
.B \-\-tail
option, SEC will jump to the end of input files and wait for new lines to
arrive.
Each input file is tracked both by its name and i-node, and
input file rotations are handled seamlessly.
If the input file is recreated or truncated, SEC will reopen it and process
its content from the beginning. If the input file is removed (i.e., there is
just an i-node left without a name), SEC will keep the i-node open and wait
for the input file recreation.
Default is
.BR \-\-tail .
.TP
.BR \-\-fromstart ", " \-\-nofromstart
these flags have no meaning when the
.B \-\-notail
option is also specified. When used in combination with
.B \-\-tail
(or alone, since
.B \-\-tail
is enabled by default),
.B \-\-fromstart
will force SEC to read and process input files from the beginning to
the end, before the 'tail' mode is entered. Default is
.BR \-\-nofromstart .
.TP
.BR \-\-detach ", " \-\-nodetach
if the
.B \-\-detach
option is specified, SEC will disassociate itself from the controlling
terminal and become a daemon at startup (note that SEC will close its standard
input, standard output, and standard error, and change its working directory
to the root directory). Default is
.BR \-\-nodetach .
.TP
.BR \-\-jointbuf ", " \-\-nojointbuf
if the
.B \-\-jointbuf
option is specified, SEC uses joint input buffer for all input sources
(the size of the buffer is set with the
.B \-\-bufsize
option). The
.B \-\-nojointbuf
option creates a separate input buffer for each input file, and a separate
buffer for all synthetic and internal events (the sizes of all buffers are
set with the
.B \-\-bufsize
option). The
.B \-\-jointbuf
option allows multiline patterns to match lines from several input
sources, while the
.B \-\-nojointbuf
pattern restricts the matching to lines from one input source only.
See INPUT PROCESSING AND TIMING section for more information.
If the size of input buffer(s) is 1 (either explicitly set with
.B \-\-bufsize=1
or automatically determined from SEC rules),
.B \-\-jointbuf
option is enabled, otherwise the default is
.BR \-\-nojointbuf .
.TP
.BR \-\-keepopen ", " \-\-nokeepopen
if the
.B \-\-keepopen
option is specified, SEC will keep input files open across soft restarts.
When the
.B SIGABRT
signal is received, SEC will not reopen input files which have been opened
previously, but will only open input files which are in the closed state.
The
.B \-\-nokeepopen
option forces SEC to close and (re)open all input files during soft restarts.
Default is
.BR \-\-keepopen .
.TP
.BR \-\-rwfifo ", " \-\-norwfifo
if the
.BR \-\-norwfifo
option is specified, named pipe input files are opened in read-only mode.
In this mode, the named pipe has to be reopened when the last writer
closes the pipe, in order to clear the EOF condition on the pipe. With the
.BR \-\-rwfifo
option, named pipe input files are opened in read-write mode, although
SEC never writes to the pipes. In this mode, the pipe does not need to be
reopened when an external writer closes it, since there is always at least
one writer on the pipe and EOF will never appear. Therefore, if the
.BR \-\-notail
option has been given,
.BR \-\-norwfifo
should also be specified.
Default is
.BR \-\-rwfifo .
.TP
.BR \-\-childterm ", " \-\-nochildterm
if the
.B \-\-childterm
option is specified, SEC will send the
.B SIGTERM
signal to all its child processes
when it terminates or goes through a full restart. Default is
.BR \-\-childterm .
.TP
.BR \-\-intevents ", " \-\-nointevents
SEC will generate internal events when it starts up, when it receives
certain signals, and when it terminates gracefully. Specific rules can be
written to match those internal events, in order to accomplish special
tasks at SEC startup, restart, and shutdown.
See INTERNAL EVENTS AND CONTEXTS section for more information. Default is
.BR \-\-nointevents .
.TP
.BR \-\-intcontexts ", " \-\-nointcontexts
SEC will create an internal context when it reads a line from an input file.
This will help the user to write rules that match data from particular input
source only. See INTERNAL EVENTS AND CONTEXTS section for more information.
Default is
.BR \-\-nointcontexts .
.TP
.BR \-\-testonly ", " \-\-notestonly
if the
.B \-\-testonly
option is specified, SEC will exit immediately after parsing the configuration
file(s). If the configuration file(s) contained no faulty rules, SEC will exit
with 0, otherwise with 1. Default is
.BR \-\-notestonly .
.TP
.BR \-\-help ", " \-?
SEC will output usage information and exit.
.TP
.B \-\-version
SEC will output version information and exit.
.PP
Note that options can be introduced both with the single dash (-) and double
dash (--), and both the equal sign (=) and whitespace can be used for
separating the option name from the option value. For example,
.B \-conf=<file_pattern>
and
.B \-\-conf <file_pattern>
options are equivalent.
.SH CONFIGURATION FILES
Each SEC configuration file consists of rule definitions which are separated
by empty lines, whitespace lines and/or comment lines.
Each rule definition consists of keyword=value fields, one keyword and value
per line. Values are case insensitive only where character case is not
important (like the values specifying rule types, e.g., 'Single' and 'single'
are treated identically).
The backslash character (\\) may be used at the end of a line to continue
the current rule field in the next line.
Lines which begin with the number sign (#) are treated as comments and
ignored (whitespace characters may precede #). Any comment line,
empty line, whitespace line, or end of file will terminate the preceding
rule definition.
For inserting comments into rule definitions, the
.I rem
keyword can be used. For example, the following lines define two rules:
.PP
type=Single
.br
rem=this rule matches any line which contains \\
three consecutive A characters and writes the string \\
"three A characters were observed" to standard output
.br
ptype=SubStr
.br
pattern=AAA
.br
desc=Three A characters
.br
action=write - three A characters were observed
.br
# This comment line ends preceding rule definition.
.br
# The following rule works like the previous rule,
.br
# but looks for three consecutive B characters and
.br
# writes the string "three B characters were observed"
.br
# to standard output
.br
type=Single
.br
ptype=SubStr
.br
pattern=BBB
.br
desc=Three B characters
.br
action=write - three B characters were observed
.PP
Apart from keywords that are part of rule definitions,
.I label
keywords may appear anywhere in the configuration file. The value of each
.I label
keyword will be treated as a label that can be referred to in rule definitions
as a point-of-continue.
This allows for continuing event processing at a rule that follows the label,
after the current rule has matched and processed the event.
.PP
The points-of-continue are defined with
.I continue*
fields. Accepted values for these fields are:
.TP
.I TakeNext
after an event has matched the rule, search for matching rules
in the configuration file will continue from the next rule.
.TP
.I GoTo <label>
after an event has matched the rule, search for matching rules will continue
from the location of <label> in the configuration file (<label> must
be defined with the
.I label
keyword anywhere in the configuration file *after* the current rule
definition).
.TP
.IR DontCont " (default value)"
after an event has matched the rule, search for matching rules ends
in the *current* configuration file.
.TP
.I EndMatch
after an event has matched the rule, search for matching rules ends
for *all* configuration files.
.PP
SEC rules from the same configuration file are matched against input
in the order they have been given in the file.
For example, consider a configuration file which contains the following
rule sequence:
.PP
type=Single
.br
ptype=SubStr
.br
pattern=AAA
.br
rem=after this rule has matched, continue from last rule
.br
continue=GoTo lastRule
.br
desc=Three A characters
.br
action=write - three A characters were observed
.PP
type=Single
.br
ptype=SubStr
.br
pattern=BBB
.br
rem=after this rule has matched, don't consider following rules, \\
since 'continue' defaults to 'DontCont'
.br
desc=Three B characters
.br
action=write - three B characters were observed
.PP
type=Single
.br
ptype=SubStr
.br
pattern=CCC
.br
rem=after this rule has matched, continue from next rule
.br
continue=TakeNext
.br
desc=Three C characters
.br
action=write - three C characters were observed
.PP
label=lastRule
.PP
type=Single
.br
ptype=SubStr
.br
pattern=DDD
.br
desc=Three D characters
.br
action=write - three D characters were observed
.PP
For the input line "AAABBBCCCDDD", this ruleset writes strings
"three A characters were observed" and "three D characters were observed"
to standard output. If the input line is "BBBCCCDDD", the string
"three B characters were observed" is written to standard output.
For the input line "CCCDDD", strings "three C characters were observed"
and "three D characters were observed" are sent to standard output, while
the input line "DDD" produces the output string
"three D characters were observed".
.PP
If there are two or more configuration files, rule sequence from every file
is matched against input (unless explicitly specified otherwise).
For example, suppose SEC is started with the command line
.PP
/usr/bin/sec --input=- \\
--conf=/etc/sec/sec1.rules --conf=/etc/sec/sec2.rules
.PP
and the configuration file /etc/sec/sec1.rules has the following content:
.PP
type=Single
.br
ptype=SubStr
.br
pattern=AAA
.br
desc=Three A characters
.br
action=write - three A characters were observed
.PP
type=Single
.br
ptype=SubStr
.br
pattern=BBB
.br
continue=EndMatch
.br
desc=Three B characters
.br
action=write - three B characters were observed
.PP
Also, suppose the configuration file /etc/sec/sec2.rules has the following
content:
.PP
type=Single
.br
ptype=SubStr
.br
pattern=CCC
.br
desc=Three C characters
.br
action=write - three C characters were observed
.PP
If SEC receives the line "AAABBBCCC" from standard input, rules from both
configuration files are tried, and as a result, the strings
"three A characters were observed" and "three C characters were observed"
are written to standard output. Note that rules from /etc/sec/sec1.rules
are tried first against the input line, since the option
.B --conf=/etc/sec/sec1.rules
is given before
.B --conf=/etc/sec/sec2.rules
in the SEC command line (see also INPUT PROCESSING AND TIMING section for
a more detailed discussion).
If SEC receives the line "BBBCCC" from standard input, the second rule
from /etc/sec/sec1.rules produces a match, and the string
"three B characters were observed" is written to standard output.
Since the rule contains
.I continue=EndMatch
statement,
the search for matching rules will end for all configuration files, and
rules from /etc/sec/sec2.rules will not be not tried. Without this statement,
the search for matching rules would continue in /etc/sec/sec2.rules,
and the first rule would write the string "three C characters were observed"
to standard output.
.SH "PATTERNS, PATTERN TYPES AND MATCH VARIABLES"
Patterns and pattern types are defined with
.I pattern*
and
.I ptype*
rule fields.
Many pattern types define the number of lines
.I N
which the pattern matches (if
.I N
is omitted, 1 is assumed). If
.I N
is greater than 1, the scope of matching is set with the
.B \-\-jointbuf
and
.B \-\-nojointbuf
options.
With
.BR \-\-jointbuf ,
the pattern is used for matching
.I N
last input lines taken from the joint input buffer (the lines can come from
different input sources).
With
.BR \-\-nojointbuf ,
the source of the last input line is identified, and the pattern
is matched with
.I N
last input lines from the input buffer of the identified source.
.TP
.I SubStr[N]
pattern is a string that is searched in the last N input lines
L1, L2, ..., LN. If N is greater than 1, the input lines are joined into
a string "L1<NEWLINE>L2<NEWLINE>...<NEWLINE>LN", and the pattern
string will be searched from it.
If the pattern string is found in input line(s), the pattern matches.
Backslash sequences \\t, \\n, \\r, \\s, and \\0 can be used in the
pattern for denoting tabulation, newline, carriage return, space character,
and empty string, respectively, while \\\\ denotes backslash itself.
For example, consider the following pattern definition:
.sp
ptype=substr
.br
pattern=Backup done:\\tsuccess
.sp
The pattern matches lines containing "Backup done:<TAB>success".
.sp
Note that since the
.I SubStr[N]
pattern type has been designed for fast matching, it does not support match
variables.
.TP
.I RegExp[N]
pattern is a Perl regular expression (see
.BR perlre (1)
for more information) for matching the last N input lines
L1, L2, ..., LN. If N is greater than 1, the input lines are joined into
a string "L1<NEWLINE>L2<NEWLINE>...<NEWLINE>LN", and the regular expression
is matched with this string.
If the regular expression matches, match variables will be set, and these
match variables can be used in other parts of the rule definition.
.sp
In addition to numbered match variables ($1, $2, etc.), SEC supports named