1
# Copyright (C) 2009 PreludeIDS Technologies. All Rights Reserved.
2
# Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
4
# This file is part of the Prelude-Correlator program.
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2, or (at your option)
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; see the file COPYING. If not, write to
18
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
from PreludeCorrelator import utils
24
_RegexType = type(re.compile(""))
26
class IDMEF(PreludeEasy.IDMEF):
27
def __setstate__(self, dict):
28
fd = tempfile.TemporaryFile("r+")
29
fd.write(dict["idmef_encoded"])
32
PreludeEasy.IDMEF.__init__(self)
35
del(dict["idmef_encoded"])
36
self.__dict__.update(dict)
38
def __getstate__(self):
39
fd = tempfile.TemporaryFile("r+")
43
odict = self.__dict__.copy()
44
odict["idmef_encoded"] = fd.read()
49
def Get(self, path, flatten=True, replacement=None):
50
path = PreludeEasy.IDMEFPath(path)
52
value = path.Get(self)
54
if path.IsAmbiguous() and flatten:
55
return replacement or []
59
if flatten and type(value) is tuple:
60
value = utils.flatten(value)
64
def Set(self, path, value):
65
if type(value) == PreludeEasy.IDMEFValue:
67
if cur and value.Match(cur, PreludeEasy.IDMEFCriterion.OPERATOR_EQUAL) > 0:
70
PreludeEasy.IDMEF.Set(self, path, value)
72
def _match(self, path, needle):
73
value = self.Get(path)
75
if not isinstance(needle, _RegexType):
78
m = needle.search(value or "")
86
def match(self, *args):
87
if (len(args) % 2) != 0:
88
raise("Invalid number of arguments.")
94
r = self._match(args[i], args[i + 1])
98
elif isinstance(r, tuple):
112
global prelude_client
113
prelude_client.correlationAlert(self)
115
def addAlertReference(self, idmef):
116
self.Set("alert.source(>>)", idmef.Get("alert.source"))
117
self.Set("alert.target(>>)", idmef.Get("alert.target"))
118
self.Set("alert.correlation_alert.alertident(>>).alertident", idmef.Get("alert.messageid"))
119
self.Set("alert.correlation_alert.alertident(-1).analyzerid", idmef.Get("alert.analyzer(*).analyzerid")[-1])
123
def set_prelude_client(client):
124
global prelude_client
125
prelude_client = client