I already
wrote about OSSEC's active response feature, and I said that I'm going to write a bit more after I study a bit more thorougly how it works. After I did
analysis of log collecting feature of OSSEC, I decided to finally look at this too. So, here is cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 essey about what I found out by analysing code of
OSSEC 2.6 with respect to active response. This essay will intergrate also cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 previous post, so, you don't have to read that previous one if you didn't already. Since active responses are bound to rules - triggering rule triggers active response - I'll touch also on rules, but not in a lot of details. Only as much is necessary to explaing active response.
I'll start with cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 purpose of active response, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n I'll continue to configuration of active response, and I'll finish with implementation details and conclusions.
Purpose of active response
The idea behind active response in OSSEC's is to activelly block potential offenders and in that way to allow system to defend itself instead of passively monitoring what's happening. In some way this classifies OSSEC also as an IPS. As with all ocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r IPSes, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 feature is great but can bite you in case you are not careful, or, if you are using it without realising how it actually works. In cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 current implementation of OSSEC, active response is restricted to act on offending IP addresses and users.
Configuring active response
Active response configuration consists of two parts. In cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first part you define all cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 commands, and in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 second part -
active response - you define how and when cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y are called. When writing configuration you should first list all of you commands, and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n active responses that reference cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m. The reason is cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 way how cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 code was written, i.e., you will get undefined command error in case you don't list commands before cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y are used.
Note that final component, and important, connection between rules and active responses. Namely, rules are those that get triggered, and if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y are triggered cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n active responses bound to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m will be activated. In this post, we'll use manual method of activation, but I'll also describe how active responses are connected to rules.
It is interesting, and important, that when cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 configuration files are analyzed, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 code writes all enabled active responses into cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 file
shared/ar.conf, which is placed underneath cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 main OSSEC directory (by default it is
/var/ossec). We'll come to exact format and purpose of that file later.
The following text is based on cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 analysis of
config/active-response.[ch],
analysisd/active-response.[ch] files,
util/agent_control.c and some ocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365rs.
Defining commands
All cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 commands that will be run as cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 part of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 active response should be defined using
element placed directly beneath
top-level element. The structure should look something like this:
...
...
...
Each
element can have cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following subelements:
- name - This will be identifier by which cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command will be referenced in active response definitions, i.e. cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 second part. Obviously, this is a mandatory subelement. You shouldn't use dashes here because cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 way parsing is done throughout OSSEC and that will most likely confuse it! It is also advasible to avoid using spaces for cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 same reasons!
- expect - Mandatory to specify. The value can be eicá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r user or srcip. Due to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 use of OS_Regex, and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 way it calls OSRegex_Compile, those two strings are case insensitive, i.e. you can capitalize cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m as you wish, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 meaning is cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 same.
- executable - Mandatory element, defines cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 exact name of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 executable. The path where cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 executable is placed is predefined during compilation time. Default value is active-response/bin.
- timeout_allowed - Allowed values are yes and no. Basically, this tells OSSEC if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 effect of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command (after it is called) should be reversed, i.e., it's effect have to be cleared by new invocation. This is optional and default value is no. To signal to a script if it is called for cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first time, or as a part of a reversal process, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first argument to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 script will be add or delete.
Defining active responses
The second part of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 configuration defines active responses cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365mselves. Active responses are configured (again) in OSSEC's configuration file using
elements that are placed directly within
top-level element, like this:
...
...
...
Under each
element cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following subelements can be used to more specifically define active response:
- command - string value that references one element. This is mandatory to specify.
- location - one of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following values: AS, analysisd, analysis-server, server, local, defined-agent, all, or any. AS, analysisd, analysis-server, server are synonyms, and so are all and any. You must specify this.
- agent_id - in case cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 value of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 location is defined-agent, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n this defines which agent and is mandatory to specify.
- rules_id - comma separated list of rule IDs to which this active response should be bound. This is an optional element without a default value.
- rules_group - name of a rule group to which this active response will be bound.
- level - Integer between 0 and 20, inclusive. If some rule has level equal to or grater than this value than it is bound to active response.
- timeout - Numerical value without constraints.
- disabled - Can have values yes or no.
- repeated_offenders - This element and its value are ignored.
Note one interesting thing. Namely, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re is no ID bound to a specific active response. This means that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 relationship between command and active response is 1:1. It seems somehow meaningless, beacuse, it is not possible to have some command (i.e. one
element) bind to multiple active responses commands each with a different set of parameters. Or, I'm missing something important?
When OSSEC agent starts it reads and parses
and
elements and writes
shared/ar.conf file (actually, when any component of ossec starts if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 previous paragraph is true). In that file each line defines one active response. Lines have cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following printf like format:
%s - %s - %d
The first string is name of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 active response and of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command (becaues active response doesn't have it's own name, as I explained). The second string is cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 executable. Finally, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 third is a timeout value if it is defined. If not, 0 will be written in that field.
Manually triggering active responses - execution flow
To manually test how active response works you can use cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 utility
agent_control whose source can be found in
util/ top-level directory of OSSEC source. Note that only responses that require IP address can be activated. This tool should be run on a manager node and it actually connects to local
ossec-remoted instance and sends it cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 appropriate commands that will trigger requested active response.
To trigger active reponse, using cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 utility, you have to specify three things:
- Offending IP address (option -b).
- ID of an agent where active response will be triggered (option -u).
- Which active response to run (option -f).
For example, to tell an agent whose ID is 003 that it should run firewall-drop600 active response and pass it IP adress 192.168.1.1, you would invoke agent_control in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following way:
agent_control -u 003 -f firewall-drop600 -b 192.168.1.1
What will happen than is that
agent_control will connect to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 local
ossec-remoted instance and send it cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following command:
(msg_to_agent) [] NNS 002 firewall-drop600 - 192.168.1.1 (from_cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365_server) (no_rule_id)
The interesting thing here is that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re is possibility to run active response on all nodes but this functionality is not enabled in
agent_control utility. It boils down not to specify agent ID, in which case all agents are assumed and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 previous command would look now like this:
(msg_to_agent) [] ANN (null) firewall-drop600 - 192.168.1.1 (from_cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365_server) (no_rule_id)
ossec-remoted accepts message from agent_control utility and based on that message sends a message over cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 network to agent. This message is encrypted, but in our case (running firewall-drop600 with IP address 192.168.1.1 as an argument) it will have cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following format:
#!-execd firewall-drop600 - 192.168.1.1 (from_cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365_server) (no_rule_id)
The three characters at cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 beginning (#!-) are message header, and "
execd " is a command. More commands can be seen in
headers/rc.h file. Note that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re is no agent ID in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 message. That is because this information is used only by
ossec-remoted so that it knows to whom it should send cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 message. So, no matter if you sent cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 message to some specific agent, or all of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 message will look cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 same.
The message is received and preparsed by
ossec-clientd in function receive_msg (in file
client-agent/receiver.c) and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n sent to
ossec-execd (in top-level directory
os_execd) via local message queue starting with a letter f, i.e. message header and command are stripped off by
ossec-clientd.
It is interesting that ossec-execd, when started, reads standard configuration file (in XML) and, based on active response configuration, creates
shared/ar.conf (unless changed during compilation). Then, it enters main loop, and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re when active response is triggered for cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first time, it reads
shared/ar.conf instead of main XML configuration file. It has also one additional interesting behavior. Namely, if unknown active response is triggered it will first reread shared/ar.conf and if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 active response isn't found cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n it will signal error. This, I suppose, can be used to dynamically update a set of active responses.
But, back to our example. ossec-execd receives message and assumes that everything to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first space is cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command name. Using that token it cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n searches for a command. There are two interesting thing here:
- The list of commands is taken from shared/ar.conf file that is dynamically created, not from ossec.conf or some similar.
- If cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command isn't found, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 shared/ar.conf is read again, and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 search is peformed again. Only now, if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re is no command, an error is reported and processing of a message is stopped. Note that no return message is sent to manager!
When cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command is found, standard
execve(2) structures are created, but twice. One for cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first execution and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 ocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r for timeout value. Only later it is checked if timeout is supported/requested by command, and if it is not cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n memory is released. The arguments are copied from cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 message (spaces are used to separate arguments) with additional argument inserted first. Namely,
add is inserted if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command is called first time, while
delete is inserted in case it is called as a consequence of a timeout.
Finally, before executing command, one more check is performed. Namely, if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command was run, and timeout is hanging waiting to trigger, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n command will not be called again, nor new timeout value will be called. The message from cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 manager will be ignored!
Automatic triggering of active responses
An active response is tirggered when cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 rule it is bound to is triggered. A single rule can have multiple active responses attached to it. Note that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re are three ways in which you can bind rule and active response:
- Using level element in active response. Namely, if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 rule has attached level that is greater than or equal to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 level of active response cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 active response is attached to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 rule.
- If a rule ID is listed in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 rules_id element of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 active response, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 active response is attached to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 rule.
- If cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 group name to which rule belongs is listed in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 rules_group element of active response, than cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y are bound togecá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r. The check is done very simply, namely it only checks that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 value specified in rules_group occurs within group name. For example, if group name is "syslog,pam" cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n rules_group value "syslog" will match, as well as "pam", but "apache" will not. Note that even cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 value "syslog,pam" will match!
Rules and active responses are bound togecá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r (cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 code in
analysisd/rules.c) when cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365
ossec-analysisd is started.
Some implementation details
Configuration reading and parsing is implemented in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365
config/active-response.c file.
The data contained in each
element is kept in a structure active_response defined in src/config/active-response.h file. The elements of that structure quite closely mimic cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 configuration layout, i.e. this structure is defined as follows:
/** Active response data **/
typedef struct _ar{
int timeout;
int location;
int level;
char *name;
char *command;
char *agent_id;
char *rules_id;
char *rules_group;
ar_command *ar_cmd;
}active_response;
That's it, not much. :)
Conclusion
Ok, I think I managed to document active response in OSSEC at least better cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 majority of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 existing documents. Tell me what you think. :)
Next, let me say that I'm impressed with XML parsers shipped with OSSEC. It seems to be very featerfull even though it is written in C, which is usually not used for XML processing.
One of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 interesting things of OSSEC is that it reads cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 same configuration files multiple times. For example, in ossec-analysisd deamon, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 configuration file is first read by active response initialization code (active-response.c) and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n by cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 deamon itself. The reason why is this so interesting is that, during parsing of element cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 file shared/ar.conf is written each time. In ocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r words, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 operation isn't idempotent. This is also problematic from cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 performance reasons standpoint, but probably less so.
While reading cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 code I sumbled on several interesting things, not directly related to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 topic of this post. But since cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y are important, I'll mention cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m here and maybe I devote some future post to some of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m:
- Top level directory addagent is misleading. It actually contains binary manage-agents which is much more encompassing cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n that. So, it should be renamed.
- In cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 top-level directory util/ cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re are some tools that should be moved or integrated with manage-agents utility.