OSSEC HIDS, Host Based Intrusion Detection System Aurora Mazzone, INFN Sezione di Torino Parte Terza
Feb 13, 2016
OSSEC HIDS, Host Based Intrusion Detection System
Aurora Mazzone, INFN Sezione di Torino
Parte Terza
Analisi dei log: file di configurazione
decoder:
/var/ossec/etc/decoder.xml/var/ossec/etc/local_decoder.xml
rules:
/var/ossec/rules/*.xml/var/ossec/rules/local_rules.xml
Analisi dei log: file di configurazione
ossec.conf:
<rules> <include>rules_config.xml</include> <include>pam_rules.xml</include> <include>sshd_rules.xml</include> <include>telnetd_rules.xml</include>[...]</rules>
Analisi dei log
Tre fasi:
pre-decoding decoding rules
Pre-decoding
Informazioni statiche:
hostname program_name data/timestamp log
Pre-decoding
Oct 28 14:21:39 atropo sshd[855]: Accepted password for jack from 192.135.19.13 port 45018 ssh2
Pre-decoding
**Phase 1: Completed pre-decoding. full event: 'Oct 28 14:21:39 atropo sshd[855]:
Accepted password for jack from 192.135.19.13 port 45018 ssh2'
hostname: 'atropo' program_name: 'sshd' log: 'Accepted password for jack from 192.135.19.13
port 45018 ssh2'
La parte di log analizzata in questa fase è:“Oct 28 14:21:39 atropo sshd[855]:”
Decoding
Informazioni dinamiche:
user protocol source/destination port source/destination ip action id url [...]
Decoding
Oct 28 14:21:39 atropo sshd[855]: Accepted password for jack from 192.135.19.13 port 45018 ssh2
Decoding
**Phase 2: Completed decoding.
decoder: 'sshd' dstuser: 'jack' srcip: '192.135.19.13'
Decoding
Sshd parent decoder:
<decoder name="sshd"> <program_name>^sshd</program_name></decoder>
Dal pre-decoding: program_name: 'sshd'
Decoding
Sshd child decoder:
<decoder name="sshd-success"> <parent>sshd</parent> <prematch>^Accepted</prematch> <regex offset="after_prematch">^ \S+ for (\
S+) from (\S+) port </regex> <order>user, srcip</order> <fts>name, user, location</fts></decoder>
Decoding: alcuni tag
Sshd child decoder:
<parent>: nome del decoder padre da cui dipende.
<prematch>: match di una stringa (anche con espressioni regolari) (os_regex)
<regex>: espressioni regolari (os_regex) + “capture groups”
@offset: punto da cui partire per regex <order>: etichette per le informazioni estratte
Decoding: os_regex
espressioni regolarinon troppe opzioni ma velociutilizzata da tutte le opzioni dei decoder con
espressioni regolari o match di stringhe (<prematch> e <regex>) e dal tag <regex> nelle regole
Rules
Oct 28 14:21:39 atropo sshd[855]: Accepted password for jack from 192.135.19.13 port 45018 ssh2
Rules: filtering
**Phase 3: Completed filtering (rules). Rule id: '5715' Level: '3' Description: 'SSHD authentication success.'**Alert to be generated.
Rules: filtering
Sshd parent rule:
<rule id="5700" level="0" noalert="1"> <decoded_as>sshd</decoded_as> <description>SSHD messages
grouped.</description> </rule>
Rules: alcuni tag
@id : id univoco che identifica ogni regola (più di 800)
@level: da 0 a 15, livello di importanza.
<decoded_as>: nome del decoder che ha già decodificato il log (se presente)
Rules: filtering
Sshd child rules:
<rule id="5715" level="3"> <if_sid>5700</if_sid> <match>^Accepted|authenticated.$</match> <description>SSHD authentication
success.</description> <group>authentication_success,</group></rule>
Rules: alcuni tag
<if_sid>: id della regola padre da cui questa dipende
<match>: match di una stringa (os_match)
<group>: gruppo aggiuntivo assegnato all'evento
Rules: os_match
match veloce di una stringanon supporta espressioni regolarimolto semplice ma più veloce di os_regexusata nelle regole da tutti i tag che confrontano un dato (non da regex)
Relazione tra regole e decoder
Decoder: utilizzato solo nel caso in cui sia necessario estrarre informazioni dinamiche dal log da confrontare successivamente nelle regole, da utilizzare per l'fts o nell'active-response.
Regole: possono esserci regole che non fanno riferimento a nessun decoder.
Regole composite
Correlazione di eventi:
condizionecountertimeframeelementi in comune (stesso utente, stesso ip sorgente, ...)
Regole composite
Correlazione di eventi:
condizione
<if_matched_sid><if_matched_group><if_matched_regex>
Regole composite
Correlazione di eventi:
counter
@frequency[rule]
timeframe
@timeframe[rule]
Regole composite
Correlazione di eventi:
elementi in comune
same_source_ipsame_src_portsame_dst_portsame_usersame_locationsame_iddifferent_url
Regole composite
10xDec 8 23:56:33 localhost sshd[2688]: Failed password for root from 192.168.108.1 port 57084 ssh2
+ 1xDec 8 23:56:51 localhost sshd[2699]: Accepted password for root from 192.168.108.1 port 57087 ssh2
Regole composite
Failed login:
**Phase 2: Completed decoding. decoder: 'sshd' dstuser: 'root' srcip: '192.168.108.1'
**Phase 3: Completed filtering (rules). Rule id: '5716' Level: '5' Description: 'SSHD authentication failed.'**Alert to be generated.
Regole composite
Rule 5716
<rule id="5716" level="5"> <if_sid>5700</if_sid> <match>^Failed|^error: PAM: Authentication</match> <description>SSHD authentication
failed.</description> <group>authentication_failed,</group></rule>
Regole composite
Authentication success:
**Phase 2: Completed decoding. decoder: 'sshd' dstuser: 'root' srcip: '192.168.108.1'
**Phase 3: Completed filtering (rules). Rule id: '5715' Level: '3' Description: 'SSHD authentication success.'**Alert to be generated.
Regole composite
Regola 5715
<rule id="5715" level="3"> <if_sid>5700</if_sid> <match>^Accepted|authenticated.$</match> <description>SSHD authentication
success.</description> <group>authentication_success,</group></rule>
Regole composite
Regola 5720
<rule id="5720" level="10" frequency="6"> <if_matched_sid>5716</if_matched_sid> <same_source_ip /> <description>Multiple SSHD authentication
failures.</description> <group>authentication_failures,</group> </rule>
Match dopo 6 login falliti su ssh (5716).
Regole composite
Failed login:
6 tentativi di accesso falliti = 6 match della regola 5716 = regola 5720
regola 5720: group: authentication_failures srcip: '192.168.108.1'
Regole composite
Authentication success:
1 login corretto = 1 match della regola 5715 regola 5715: group: authentication_success srcip: '192.168.108.1'
Regole composite
Regola 40112
<rule id="40112" level="12" timeframe="240"> <if_group>authentication_success</if_group> <if_matched_group>authentication_failures</if_matched_group>
<same_source_ip /> <description>Multiple authentication failures followed
</description> <description>by a success.</description></rule>
Regole composite
6x 5716 (authentication failed) = 5720 (authentication_failures)
+1x 5715 (authentication_success)=40112 (same_source_ip)
Regole composite
**Phase 2: Completed decoding. decoder: 'sshd' dstuser: 'root' srcip: '192.168.108.1'
**Phase 3: Completed filtering (rules). Rule id: '40112' Level: '12' Description: 'Multiple authentication
failures followed by a success.'**Alert to be generated.