1
|
From cb97e817ad50190e322b73f5a8dad30701b5a774 Mon Sep 17 00:00:00 2001
|
2
|
From: Wes Young <wes@barely3am.com>
|
3
|
Date: Sun, 13 Sep 2009 19:12:04 +0000
|
4
|
Subject: [PATCH] added spamhausdrop.py to plugins
|
5
|
|
6
|
---
|
7
|
PreludeCorrelator/plugins/spamhausdrop.py | 103 +++++++++++++++++++++++++++++
|
8
|
1 files changed, 103 insertions(+), 0 deletions(-)
|
9
|
create mode 100644 PreludeCorrelator/plugins/spamhausdrop.py
|
10
|
|
11
|
diff --git a/PreludeCorrelator/plugins/spamhausdrop.py b/PreludeCorrelator/plugins/spamhausdrop.py
|
12
|
new file mode 100644
|
13
|
index 0000000..0692cf9
|
14
|
--- /dev/null
|
15
|
+++ b/PreludeCorrelator/plugins/spamhausdrop.py
|
16
|
@@ -0,0 +1,103 @@
|
17
|
+# Copyright (C) 2009 PreludeIDS Technologies. All Rights Reserved.
|
18
|
+# Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
|
19
|
+# Author: Wes Young <wes@barely3am.com>
|
20
|
+#
|
21
|
+# This file is part of the Prelude-Correlator program.
|
22
|
+#
|
23
|
+# This program is free software; you can redistribute it and/or modify
|
24
|
+# it under the terms of the GNU General Public License as published by
|
25
|
+# the Free Software Foundation; either version 2, or (at your option)
|
26
|
+# any later version.
|
27
|
+#
|
28
|
+# This program is distributed in the hope that it will be useful,
|
29
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31
|
+# GNU General Public License for more details.
|
32
|
+#
|
33
|
+# You should have received a copy of the GNU General Public License
|
34
|
+# along with this program; see the file COPYING. If not, write to
|
35
|
+# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
36
|
+
|
37
|
+import os, httplib, time
|
38
|
+from PreludeCorrelator import require
|
39
|
+from PreludeCorrelator.idmef import IDMEF
|
40
|
+from PreludeCorrelator.pluginmanager import Plugin
|
41
|
+from PreludeCorrelator.context import Context, Timer
|
42
|
+from netaddr import IPAddress, IPNetwork
|
43
|
+
|
44
|
+class SpamhausDropPlugin(Plugin):
|
45
|
+ RELOAD = 7 * 24 * 60 * 60
|
46
|
+ SERVER = "www.spamhaus.org"
|
47
|
+ URI = "/drop/drop.lasso"
|
48
|
+ TIMEOUT = 10
|
49
|
+ FILENAME = require.get_data_filename(__name__, "spamhaus_drop.dat")
|
50
|
+
|
51
|
+ def __loadData(self, age=0):
|
52
|
+ for line in open(self.__filename, "r"):
|
53
|
+ if line[0] == ';':
|
54
|
+ continue
|
55
|
+
|
56
|
+ ip, sbl = line.split(';')
|
57
|
+ ip = IPNetwork(ip.strip())
|
58
|
+ self.__mynets.append(ip)
|
59
|
+
|
60
|
+ if self.__reload > 0:
|
61
|
+ Timer(self.__reload - age, self.__retrieveData).start()
|
62
|
+
|
63
|
+ def __downloadData(self):
|
64
|
+ self.info("Downloading host list, this might take some time...")
|
65
|
+
|
66
|
+ try:
|
67
|
+ con = httplib.HTTPConnection(self.__server, timeout=self.__timeout)
|
68
|
+ except TypeError:
|
69
|
+ con = httplib.HTTPConnection(self.__server)
|
70
|
+
|
71
|
+ con.request("GET", self.__uri)
|
72
|
+ r = con.getresponse()
|
73
|
+ if r.status != 200:
|
74
|
+ raise Exception, "Could not download spamhaus DROP list, error %d" % r.status
|
75
|
+
|
76
|
+ fd = open(self.__filename, "w")
|
77
|
+ fd.write(r.read())
|
78
|
+ fd.close()
|
79
|
+
|
80
|
+ self.info("Downloading done, processing data.")
|
81
|
+
|
82
|
+ def __retrieveData(self, timer=None):
|
83
|
+ try:
|
84
|
+ st = os.stat(self.__filename)
|
85
|
+ if self.__reload <= 0 or time.time() - st.st_mtime < self.__reload:
|
86
|
+ return self.__loadData(time.time() - st.st_mtime)
|
87
|
+ except OSError:
|
88
|
+ pass
|
89
|
+
|
90
|
+ self.__downloadData()
|
91
|
+ self.__loadData()
|
92
|
+
|
93
|
+
|
94
|
+ def __init__(self, env):
|
95
|
+ Plugin.__init__(self, env)
|
96
|
+
|
97
|
+ self.__mynets = []
|
98
|
+ self.__reload = self.getConfigValue("reload", self.RELOAD, type=int)
|
99
|
+ self.__filename = self.getConfigValue("filename", self.FILENAME)
|
100
|
+ self.__server = self.getConfigValue("server", self.SERVER)
|
101
|
+ self.__uri = self.getConfigValue("uri", self.URI)
|
102
|
+ self.__timeout = self.getConfigValue("timeout", self.TIMEOUT, type=float)
|
103
|
+ self.__retrieveData()
|
104
|
+
|
105
|
+ def run(self, idmef):
|
106
|
+ for source in idmef.Get("alert.source(*).node.address(*).address"):
|
107
|
+ src = IPAddress(source)
|
108
|
+ InNet = 0
|
109
|
+ for net in self.__mynets:
|
110
|
+ if src in net:
|
111
|
+ InNet = 1
|
112
|
+ if InNet:
|
113
|
+ ca = IDMEF()
|
114
|
+ ca.addAlertReference(idmef)
|
115
|
+ ca.Set("alert.classification.text", "IP source matching Spamhaus DROP dataset")
|
116
|
+ ca.Set("alert.correlation_alert.name", "IP source matching Spamhaus DROP dataset")
|
117
|
+ ca.Set("alert.assessment.impact.description", "Spamhaus gathered this IP address in their DROP list - %s" % (source))
|
118
|
+ ca.Set("alert.assessment.impact.severity", "medium")
|
119
|
+ ca.alert()
|
120
|
--
|
121
|
1.5.6.5
|
122
|
|