05.02.2013 Views

download issue 24 here - Help Net Security

download issue 24 here - Help Net Security

download issue 24 here - Help Net Security

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The first tag of interest is the - this<br />

refers to the earlier decoder rules. Any message<br />

that is decoded as PAM is picked up this<br />

rule.<br />

The tag looks for a string that<br />

starts with the word “session”, followed by one<br />

or more other words. If these prerequisites<br />

are met, weʼre ready to grab some information<br />

(in this case the username). We do that by<br />

using a regular expression, hence the <br />

tag that we tell to start after the prematch.<br />

Any information we need from the pattern<br />

we put between round brackets. With the<br />

tag, we tell OSSEC in which order we<br />

find our information. That will become clearer<br />

in a message from which we extract - more<br />

information.<br />

<br />

pam<br />

rhost=\S+\s+user=\S+<br />

rhost=(\S+)\s+user=(\S+)<br />

srcip, user<br />

<br />

This is w<strong>here</strong> things become interesting. Notice<br />

that the tag doesnʼt contain the<br />

prematch parameter because we want to extract<br />

information from the same string that we<br />

use to match on. From this message we want<br />

to extract the source IP address and the user-<br />

name and we tell OSSEC that the first string<br />

we captured in round brackets is that IP address<br />

and the second one is the username.<br />

Hereafter, everything builds upon the decoders.<br />

Letʼs have a look at the PAM rules.<br />

<br />

pam<br />

Grouping of the pam_unix rules.<br />

<br />

Every rule gets a unique id, a number between<br />

100 and 99999. The level can be any<br />

number between 0 and 14 - it allows you to<br />

granularly rank alerts by severity. Level 0<br />

means that this event is of no significance as<br />

we use it only to group the pam_unix alerts.<br />

With noalert we specify that no alerts are re-<br />

quired. In the tag we tell OS-<br />

SEC that this rule applies to all messaged decoded<br />

as PAM by our decoder rules and with<br />

we tell everyone who has never<br />

seen an OSSEC rule before what this is<br />

about.<br />

<br />

5500<br />

session opened for user <br />

Login session opened.<br />

authentication_success,<br />

<br />

Now it gets really exciting! Rule 5501 is a<br />

level 3 event and builds on rule 5500. We look<br />

for the string “session opened for user” to register<br />

a successful login event. OSSEC allows<br />

us to build so-called rule trees - chains of<br />

alerts that allow us exact control about what<br />

gets logged and with which alert level. A good<br />

example would be the following: We want to<br />

be alerted when Chris logs on to the alpha<br />

server at any time, but not if any other users<br />

log on. It would look a little like this:<br />

www.insecuremag.com 60

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!