|
NAMElogsurfer.conf - configuration file for logsurferSYNOPSIS/usr/local/etc/logsurfer/logsurfer.confDESCRIPTIONThe logsurfer.conf file is used to configure the logsurfer program. It contains initial rule definitions. Be careful if you need to debug your configuration file: the logsurfer is able to create or delete rules at runtime --- see NOTES.The configuration file uses regular expressions to specify match patterns for message lines. Unfortunately there are a lot of different regular expression definitions available. The logsurfer program uses the definition of regex within egrep(1) as defined by the POSIX standard. For a complete description of the available operators you should read the excellent documentation of the GNU regex-library (which is part of the logsurfer distribution). Lines in the configuration file that have a # in the first column are handled as comments and are not processed. If the character in the first column is a whitespace (space or tab) the line is processed as a continuation of the previous line. All other starting characters are interpreted as a beginning of a new rule. There are three different methods of quoting for all strings: If no quotes are used the string is terminated at the first whitespace character (space or tab). If you use single quotes (') the string is terminated at the first single quote following the initial one and the contents are used "as is". If you use double quotes (") for a string, the string is terminated by the corresponding quote. In this case the backslash character is the "escape" character (that is: you can use \" to specify a double quote which is not the end of the string). Be careful to escape all backslashes by an extra backslash. To avoid confusion it is advised to always quote your strings. If you use double quoted strings in the action part (see below), than you can use special variables $0 to $9 to specify submatches within the matching regular expression. $0 refers to the entire message line, $1 to the string that has matched the given regular expression (the match_regex as described later on) and the other variables may reference to submatches within the regular expression (these are regular expressions within the complete regular expression, that are enclosed in brackets --- for more information read the documentation on regular expressions). The basic format of a rule definition is: match_regex not_match_regex stop_regex not_stop_regex timeout [continue] action
Within rules you are able to specify one of the following action types:
Once a logline has matched a rule this rule perform certain actions. Rules form the "active" part of the logsurfer. Contexts are a kind of "big box" where messages that match certain regular expressions are stored. They are "passive" and can be used by other actions like reports to retrieve the stored information. The idea is to store all messages (for a certain period of time) in contexts (even if they seem to be unimportant). If you detect some unusual activity later on you might be interested in those messages, that are normally not important. Instead of re-reading the loginformation (which maybe not possible --- e.g. if you are reading from standard input) you use the created contexts for the retrieval of the message categories. Example: you might want to put all actions from one ftp-session into one context. If nothing "unusual" happens then you are not interested in the complete session and delete it after the user has logged out. But if the user tries to alter or upload files then you are interested in getting the whole session to see what this user has done before he triggered the alert. Be careful: the order of rules is important because the logsurfer stops finding matches after the first matching rule that has no "continue" keyword. Also the performance of the logsurfer maybe better if you put the rules with the most matches (the rule that is being used for most messages --- e.g. an ignore rule for certain actions) at the top. Contexts have the following format: match_regex match_not_regex line_limit timeout_abs timeout_rel [min_lines] default_action
All externals programs (for example in the "exec", "pipe" and "report" actions) must be given with a full pathname. They are started in the background and the logsurfer continues to process message lines while the other programs are running. The idea was not to stop message processing if an external program hangs or takes a long time to finish. If you need to specify a context (for example in the "open", "delete" and "report" actions) you have to do this by giving the exact regular expression that this context uses for matching (match_regex), alternatively if you specify "-" as the context, then logsurfer will apply the contents of the context under which the action is being performed. The timeout functions require timestamps for each message that is processed. To be independent of the message format the logsurfer uses the time when he first sees the message as an internal timestamp. Timeout values are always working on those timestamps. This might give some unexpected results if you don't follow the end of a logfile but instead use the logsurfer to process one logfile once. In this case all timestamps are from the current time instead of the time the message was created. EXAMPLESThe logsurfer program was designed to work with any kind of ascii loginformation. Most people may want to use the program to monitor the syslog-messages (for example stored in /var/adm/messages). There are several things you should consider if you use this program to monitor such files. One important thing is to realize that the contents of the logmessages are usually under the control of (possible remote) user. This is especially important if you invoke external programs and use parts of the message as arguments or as standard input (exec or pipe actions). Remember that those messages may contain any arbitrary data and that the invoked program may not be able to handle this or may allow certain actions that are under control of the person who created the message. This may open a big security hole! For example: do not use /bin/mail or mailx to mail the message or a report to an email-address. Those programs have special escape-features "~" that can be used to invoke other programs or to modify files!Another known pitfall is to open a context for a hostname. Remember, that a message is stored in this context if the hostname appears anywhere in the line. Especially if you forward syslog() messages to another host then the messages file may contain the name of the host who forwarded the message to the central loghost. To avoid matching in the hostname part you might want to ignore the first 20 chars using "^.{20,}hostname" or describe the format of the logmessage file in detail. Example: ignore the first 16 chars (the timestamp) and the first following word (the hostname) "^.{16}[^ ]*hostname". Another problem is the use of submatches in new definitions of regular expressions. For example: the hostname may contain dots "." which is interpreted (while matching lines against match_regex definitions) as "any character". You will usually not miss entries but also match a little bit more than expected. Let's say you have a hostname like "what.is.this.de" and create a context using this as match_regex. This regex will also match strings like "what-is.this.de" or "what7is+this_de". This maybe called a bug in the program, but correct escaping of regular expressions is not trivial and is currently not implemented in the logsurfer. Now to some real example configuration lines: ´.*´ - - - 0 exec "/bin/echo $0" This is a very simple testrule that matches everything ('.*') without exceptions (the first "-"). It has no "self-destroy matching rules (the next to "-") and no timeout (the "0"). For each message line it invokes the external command "/bin/echo" with the complete message line as an argument. The result will be, that every input line is echoed to the standard output. If you put the example line in a file called "testconf" then you might want to use "logsurfer -c testconf" to start the logsurfer program with this configuration file. Every line you type in should be echoed. ´ftpd\[([0-9]*)\]: connection from´ - - - 0 open "ftpd\\[$2\\]:" - 4000 10800 1800 ignore This line will open a new context for each new ftp connection. The context will include every logline that contains "ftpd[<pid>]:" (with pid the process id of the ftp-session) in it. One session has a maximum of 4000 lines and is a maximum of 3 hours long. It is expected that there will be at least every 30 minutes a new ftp-command - otherwise the default action will be executed. Of course you won't use ignore in real life (this was just to shorten the example here). ´ftpd\[([0-9]*)\]: FTP session closed´ - - - 0 delete "ftpd\\[$2\\]:" We delete (forget) the collected context if the ftp session ends. ´ftpd\[([0-9]*)\]: failed login from ([^ ]*) \[([0-9.]*)´ - - - 0 report "/usr/lib/sendmail -odq root" "ftpd\\[$2\\]:" "^.{19,}$3" "^.{19,}$4" If you get a failed login via FTP you will sent all information about the current ftp-session, about the hostname and about the ip-address via sendmail to the sysadmin (root). This example assumes, that you also have opened contexts for the hostname "^.{19,}$3" and the ip-addr. The string "^.{19,}" was used to not match the hostname in the first 19 chars (in the syslog information this is the host that has generated the syslog message). ´ftpd\[([0-9]*)\]: cmd failure - not logged in´ - - - 0 rule before "ftpd\\[($2)\\]: FTP session closed" - ´.*´ - 1800 report "/usr/lib/sendmail -odq root" "ftpd\\[$2\\]:" If someone has tried to issue an ftp command without being logged in then you add another rule, that waits for the end of the ftp-session, sends the summary of the ftp-session via sendmail to root and deletes itself (we do not need this rule any longer, because the ftp-session has been closed). Remember to put this rule before the general rule that handles the "FTP session closed" message or this rule won't be reached. This configuration examples might look a little bit confusing but if you play a with the configuration facilities you will learn how to use them. FILES
SEE ALSOlogsurfer(1), swatch(8)NOTESIf you need to debug or control the work of the logsurfer it is important to be able to get an image of the currently active rules and contexts. This can be done be sending special signals to the logsurfer program to initiate dumping of the state. This is discussed in the NOTES section of the logsurfer manpage.If you work on messages that were written by the syslog daemon you may loose some information if the daemon summarizes repeated messages. Instead of the original message you might get a message like "last message repeated X times".
Visit the GSP FreeBSD Man Page Interface. |