This file is indexed.

/usr/share/pyshared/PreludeCorrelator/idmef.py is in prelude-correlator 1.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Copyright (C) 2009 PreludeIDS Technologies. All Rights Reserved.
# Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
#
# This file is part of the Prelude-Correlator program.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

import tempfile, re
import PreludeEasy
from PreludeCorrelator import utils

_RegexType = type(re.compile(""))

class IDMEF(PreludeEasy.IDMEF):
        def __setstate__(self, dict):
                fd = tempfile.TemporaryFile("r+")
                fd.write(dict["idmef_encoded"])
                fd.seek(0)

                PreludeEasy.IDMEF.__init__(self)
                self.Read(fd)

                del(dict["idmef_encoded"])
                self.__dict__.update(dict)

        def __getstate__(self):
                fd = tempfile.TemporaryFile("r+")
                self.Write(fd)
                fd.seek(0)

                odict = self.__dict__.copy()
                odict["idmef_encoded"] = fd.read()
                del(odict["this"])

                return odict

        def getTime(self):
                itime = self.Get("alert.detect_time")
                if not itime:
                        itime = self.Get("alert.create_time")

                return itime

        def Get(self, path, flatten=True, replacement=None):
                path = PreludeEasy.IDMEFPath(path)

                value = path.Get(self)
                if not value:
                        if path.IsAmbiguous() and flatten:
                                return replacement or ()

                        return replacement

                if flatten and type(value) is tuple:
                        value = utils.flatten(value)

                return value

        def Set(self, path, value):
                if type(value) == PreludeEasy.IDMEFValue:
                        cur = self.Get(path)
                        if cur and value.Match(cur, PreludeEasy.IDMEFCriterion.OPERATOR_EQUAL) > 0:
                                return

                PreludeEasy.IDMEF.Set(self, path, value)

        def _match(self, path, needle):
                value = self.Get(path)

                if not isinstance(needle, _RegexType):
                        ret = value == needle
                else:
                        m = needle.search(value or "")
                        if not m:
                                return False

                        ret = m.groups()

                return ret

        def match(self, *args):
                if (len(args) % 2) != 0:
                        raise("Invalid number of arguments.")

                ret = []

                i = 0
                while i < len(args):
                        r = self._match(args[i], args[i + 1])
                        if r is False:
                                return None

                        elif isinstance(r, tuple):
                                ret.extend(r)

                        i += 2

                if ret:
                        return ret

                return True

        def alert(self):
                global prelude_client
                prelude_client.correlationAlert(self)

        def addAlertReference(self, idmef, auto_set_detect_time=True):
                if auto_set_detect_time is True:
                    intime = idmef.getTime()
                    curtime = self.getTime()
                    if (not curtime) or intime < curtime:
                        self.Set("alert.detect_time", intime)

                self.Set("alert.source(>>)", idmef.Get("alert.source"))
                self.Set("alert.target(>>)", idmef.Get("alert.target"))
                self.Set("alert.correlation_alert.alertident(>>).alertident", idmef.Get("alert.messageid"))
                self.Set("alert.correlation_alert.alertident(-1).analyzerid", idmef.Get("alert.analyzer(*).analyzerid")[-1])



def set_prelude_client(client):
        global prelude_client
        prelude_client = client