.\" .\" SEC (Simple Event Correlator) 2.6.2 - sec.man .\" Copyright (C) 2000-2012 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 "January 2012" "SEC 2.6.2" .SH NAME sec \- simple event correlator .SH SYNOPSIS .TP .B sec [--conf= ...] .br [--input=[=] ...] .br [--input-timeout=] .br [--timeout-script=] .br [--reopen-timeout=] .br [--check-timeout=] .br [--poll-timeout=] .br [--blocksize=] .br [--bufsize=] .br [--evstoresize=] .br [--cleantime=] .br [--log=] .br [--syslog=] .br [--debug=] .br [--pid=] .br [--dump=] .br [--quoting | --noquoting] .br [--tail | --notail] .br [--fromstart | --nofromstart] .br [--detach | --nodetach] .br [--jointbuf | --nojointbuf] .br [--keepopen | --nokeepopen] .br [--intevents | --nointevents] .br [--intcontexts | --nointcontexts] .br [--testonly | --notestonly] .br [--help] [-?] .br [--version] .SH DESCRIPTION SEC is a tool for accomplishing event correlation tasks in the domains of log analysis, system monitoring, network and security management, etc. 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. .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 calling precompiled Perl subroutines, etc. .PP Some 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. 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. 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 (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 init=create USER_COUNTING .br end=delete USER_COUNTING .br ptype=RegExp .br pattern=3_SSH_LOGIN_FAILURES_FOR_(\\S+) .br context=!USER_$1_COUNTED .br count=alias USER_COUNTING USER_$1_COUNTED .br desc=Repeated SSH login failures for 30 distinct users within 1m .br action=pipe '%s' /bin/mail -s 'SSH login alert' root@localhost .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_. Although synthetic events are created by SEC, they are treated like regular events received from input sources and are matched against rules. The regular expression pattern of the second rule will match the 3_SSH_LOGIN_FAILURES_FOR_ event and start a new event correlation operation if no such events have been previously seen. When the operation is initialized, the context USER_COUNTING is created, and when the operation finishes, this context is deleted (as specified by the .I init and .I end fields). Also, each time a synthetic event for some user name has matched the rule, a context alias 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 can match the rule only if the context alias USER__COUNTED *does not* exist (as requested by the .I context field; see CONTEXT EXPRESSIONS section for more information). The operation started by the 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__COUNTED aliases, all synthetic events concern different user names. After sending an e-mail warning, the operation will continue to run until the 1 minute event correlation window expires. When the operation finishes, the deletion of the USER_COUNTING context also erases the USER__COUNTED aliases. .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= expand 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, is re-evaluated. See also INPUT PROCESSING AND TIMING section for a discussion on rule processing order for multiple configuration files. .TP .B \-\-input=[=] expand 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, 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 is given, SEC will set up the context each time it reads a line from input files that correspond to . 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 specified, it will automatically enable the .B \-\-intcontexts option. See INTERNAL EVENTS AND CONTEXTS section for more information. .TP .BR \-\-input\-timeout= ", " \-\-timeout\-script= if SEC has not observed new data in an input file during seconds (or the file was closed seconds ago), will be executed with command line parameters 1 and . If fresh data become available again, will be executed with command line parameters 0 and . 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= 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 seconds until open succeeds. Note that .B \-\-reopen_timeout is a synonym for .BR \-\-reopen\-timeout . .TP .B \-\-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 seconds. Note that .B \-\-check_timeout is a synonym for .BR \-\-check\-timeout . .TP .B \-\-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 \-\-blocksize= the number of bytes SEC will attempt to read at once from an input file. Default is 1024 (i.e., read from input files by 1KB blocks). .TP .B \-\-bufsize= set all input buffers to hold last lines. The content of input buffers will be compared with patterns that are part of rule definitions (i.e., no more than lines can be matched by a pattern at a time). Default buffer size is 10 lines. .TP .B \-\-evstoresize= set an upper limit to the number of events in context event stores. .TP .B \-\-cleantime= 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= use 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= use syslog for logging SEC activities. All messages will be logged with the 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 logfiles, because message loops might occur. .TP .B \-\-debug= set logging verbosity for SEC. Setting debuglevel to means that all messages of level and lower are logged (e.g., if 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 is 6 (i.e., log everything). See SIGNALS section for information on how to change at runtime. .TP .B \-\-pid= SEC will store its process ID to at startup. .TP .B \-\-dump= SEC will use as its dumpfile. See SIGNALS section for more information. Default is /tmp/sec.dump. .TP .BR \-\-quoting ", " \-\-noquoting if the .B \-\-quoting option is specified, operation description strings that are supplied to command lines of .I shellcmd and .I spawn actions will be put inside apostrophes. All apostrophes ' 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. Default is .B \-\-tail -- SEC will jump to the end of input files and wait for new lines to arrive. With the .B \-\-tail option, SEC follows an input file both by its name and i-node, and thus handles input file rotations 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. .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. Default is .BR \-\-jointbuf . .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 \-\-nokeepopen . .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= and .B \-\-conf options are equivalent. .SH CONFIGURATION FILE The SEC configuration file consists of rule definitions which are separated by empty and comment lines. Each rule definition consists of keyword=value fields, one keyword and value per line. Values are case sensitive only where character case is important (like the values specifying regular expressions). 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, or end of file will terminate the preceding rule definition. For inserting comments into rule definitions, the .I rem keyword can be used. .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