Introductions
In OSSEC, the rules are classified in multiple levels from the lowest (00) to the maximum level 16. But some levels are not used right now and below explain level details.
00 - Ignored
01 – None
05 – Error is generated by user
06 - Low relevance attack
08 - First time seen
12 - High important event
15 - Severe attack ( There is no chances of false positives)
Rules group are used specify groups for specific rules. It’s used for active response reasons and for correlation.
Checking Rules
You can find the OSSEC rule list ‘var/ossec/rules’. All this xml files in this directory contains the rules.
In rule xml file we have name group (‘group name’) at parent level of the xml <group name="web,accesslog,">. In there you can define the rules as below
As example I need to get all 400
<rule id="31101" level="5">
<if_sid>31100</if_sid>
<id>^4</id>
<description>Web server 400 error code.</description>
</rule>
Then you need to skip resources file which end with .jpg, .css and .js
<rule id="31102" level="0">
<if_sid>31101</if_sid>
<url>.jpg$|.css$|.js$</url>
<compiled_rule>is_simple_http_request</compiled_rule>
<description>Ignored extensions on 400 error codes.</description>
</rule>
‘is_simple_http_request’ [1] is function which already inbuilt in OSSEC, if you building ossec from source you can customizing the this functions or added new function that will improve your rules.
Testing the Rules
Initial Test Case
To test above rules you can add custom log record as below
In here we need to get current time by the terminal with below format.
23/Aug/2016:10:09:28 +0530
- Setup sample apache log as below
now=$(date +"%d/%b/%Y:%T %z")
echo "192.168.100.78 - - [$now] \"GET /ossim/services HTTP/1.1\" 200 2295 \”-\” \"Mozilla Firefox/47.0\""
Log record adding to log file
httpStatus=400
logRecord="192.168.100.78 - - [$(date +"%d/%b/%Y:%T %z")] \"GET /ossim/services HTTP/1.1\" $httpStatus 2295 \”-\” \"Mozilla Firefox/47.0\""
- Then add it the log file for testing our use case with custom rules
echo '{string}' >> file.txt
Our apache log is in /var/log/apache2/access.log
logRecord="192.168.100.78 - - [$(date +"%d/%b/%Y:%T %z")] \"GET /ossim/services HTTP/1.1\" $httpStatus 2295 \"Mozilla Firefox/47.0\""
echo '$logRecord' >> access.log
Or you can try this for testing
echo "192.168.100.78 - - [$(date +"%d/%b/%Y:%T %z")] \"GET /ossim/foo/ HTTP/1.1\" $httpStatus 3360 \"-\" \"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36\"" >> access.log
Second use case
Customizing the rule id="31104" which is in ‘var/ossec/rules/web_rules.xml’ as below to testing
<rule id="31104" level="6">
<if_sid>31100</if_sid>
<url>foo</url>
<description>Common web attack.</description>
<group>attack</group>
</rule>
Then restart OSSEC server which is content to OSSIM or AlienVault.
Then send rule triggering log record as below
echo "192.168.100.78 - frank [$(date +"%d/%b/%Y:%T %z")] \"GET /ossim/go/foo HTTP/1.1\" $httpStatus 3360 \"-\" \"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36\"" >> ../../log/apache2/access.log
Here is the trigger in OSSIM UI.
Add a comment