1- # SPDX-FileCopyrightText: 2015 Sebastian Wagner
1+ # SPDX-FileCopyrightText: 2023 Filip Pokorný
22#
33# SPDX-License-Identifier: AGPL-3.0-or-later
44
5- # -*- coding: utf-8 -*-
6- import base64
7- import os
85import unittest
96
107import intelmq .lib .test as test
118from intelmq .bots .parsers .turris .parser import TurrisGreylistParserBot
9+ from intelmq .lib import utils
1210
13- with open (os .path .join (os .path .dirname (__file__ ), 'greylist-latest.csv' ), 'rb' ) as fh :
14- RAW = base64 .b64encode (fh .read ()).decode ()
15-
16- OUTPUT1 = {'__type' : 'Event' ,
17- 'classification.type' : 'scanner' ,
18- 'event_description.text' : 'dns' ,
19- 'source.geolocation.cc' : 'AU' ,
20- 'source.asn' : 15169 ,
21- 'raw' : 'MS4xLjEuMixBVSxkbnMsMTUxNjk=' ,
22- 'source.ip' : '1.1.1.2' }
23- OUTPUT2 = {'__type' : 'Event' ,
24- 'classification.type' : 'scanner' ,
25- 'event_description.text' : 'telnet' ,
26- 'raw' : 'MS4yMC45Ni4xNDIsVEgsdGVsbmV0LDU2MTIw' ,
27- 'source.geolocation.cc' : 'TH' ,
28- 'source.asn' : 56120 ,
29- 'source.ip' : '1.20.96.142' }
11+ INPUT = """\
12+ # For the terms of use see https://view.sentinel.turris.cz/greylist-data/LICENSE.txt
13+ Address,Tags
14+ 159.203.8.168,http
15+ 103.155.105.100,"ftp,http"
16+ 117.247.161.208,telnet
17+ 103.185.234.2,telnet
18+ 152.32.236.101,"ftp,http,port_scan,smtp,telnet"
19+ 61.219.175.42,telnet
20+ """
21+
22+ OUTPUT = [
23+ {
24+ "protocol.transport" : "tcp" ,
25+ "protocol.application" : "http" ,
26+ "classification.type" : "brute-force" ,
27+ "destination.port" : 80 ,
28+ "raw" : "QWRkcmVzcyxUYWdzCjE1OS4yMDMuOC4xNjgsaHR0cA==" ,
29+ "source.ip" : "159.203.8.168" ,
30+ "__type" : "Event"
31+ },
32+ {
33+ "protocol.transport" : "tcp" ,
34+ "protocol.application" : "ftp" ,
35+ "classification.type" : "brute-force" ,
36+ "destination.port" : 21 ,
37+ "raw" : "QWRkcmVzcyxUYWdzCjEwMy4xNTUuMTA1LjEwMCwiZnRwLGh0dHAi" ,
38+ "source.ip" : "103.155.105.100" ,
39+ "__type" : "Event"
40+ },
41+ {
42+ "protocol.transport" : "tcp" ,
43+ "protocol.application" : "http" ,
44+ "classification.type" : "brute-force" ,
45+ "destination.port" : 80 ,
46+ "raw" : "QWRkcmVzcyxUYWdzCjEwMy4xNTUuMTA1LjEwMCwiZnRwLGh0dHAi" ,
47+ "source.ip" : "103.155.105.100" ,
48+ "__type" : "Event"
49+ },
50+ {
51+ "protocol.transport" : "tcp" ,
52+ "protocol.application" : "telnet" ,
53+ "classification.type" : "brute-force" ,
54+ "destination.port" : 23 ,
55+ "raw" : "QWRkcmVzcyxUYWdzCjExNy4yNDcuMTYxLjIwOCx0ZWxuZXQ=" ,
56+ "source.ip" : "117.247.161.208" ,
57+ "__type" : "Event"
58+ },
59+ {
60+ "protocol.transport" : "tcp" ,
61+ "protocol.application" : "telnet" ,
62+ "classification.type" : "brute-force" ,
63+ "destination.port" : 23 ,
64+ "raw" : "QWRkcmVzcyxUYWdzCjEwMy4xODUuMjM0LjIsdGVsbmV0" ,
65+ "source.ip" : "103.185.234.2" ,
66+ "__type" : "Event"
67+ },
68+ {
69+ "protocol.transport" : "tcp" ,
70+ "protocol.application" : "ftp" ,
71+ "classification.type" : "brute-force" ,
72+ "destination.port" : 21 ,
73+ "raw" : "QWRkcmVzcyxUYWdzCjE1Mi4zMi4yMzYuMTAxLCJmdHAsaHR0cCxwb3J0X3NjYW4sc210cCx0ZWxuZXQi" ,
74+ "source.ip" : "152.32.236.101" ,
75+ "__type" : "Event"
76+ },
77+ {
78+ "protocol.transport" : "tcp" ,
79+ "protocol.application" : "http" ,
80+ "classification.type" : "brute-force" ,
81+ "destination.port" : 80 ,
82+ "raw" : "QWRkcmVzcyxUYWdzCjE1Mi4zMi4yMzYuMTAxLCJmdHAsaHR0cCxwb3J0X3NjYW4sc210cCx0ZWxuZXQi" ,
83+ "source.ip" : "152.32.236.101" ,
84+ "__type" : "Event"
85+ },
86+ {
87+ "classification.type" : "scanner" ,
88+ "raw" : "QWRkcmVzcyxUYWdzCjE1Mi4zMi4yMzYuMTAxLCJmdHAsaHR0cCxwb3J0X3NjYW4sc210cCx0ZWxuZXQi" ,
89+ "source.ip" : "152.32.236.101" ,
90+ "__type" : "Event"
91+ },
92+ {
93+ "protocol.transport" : "tcp" ,
94+ "protocol.application" : "smtp" ,
95+ "classification.type" : "brute-force" ,
96+ "raw" : "QWRkcmVzcyxUYWdzCjE1Mi4zMi4yMzYuMTAxLCJmdHAsaHR0cCxwb3J0X3NjYW4sc210cCx0ZWxuZXQi" ,
97+ "source.ip" : "152.32.236.101" ,
98+ "__type" : "Event"
99+ },
100+ {
101+ "protocol.transport" : "tcp" ,
102+ "protocol.application" : "telnet" ,
103+ "classification.type" : "brute-force" ,
104+ "destination.port" : 23 ,
105+ "raw" : "QWRkcmVzcyxUYWdzCjE1Mi4zMi4yMzYuMTAxLCJmdHAsaHR0cCxwb3J0X3NjYW4sc210cCx0ZWxuZXQi" ,
106+ "source.ip" : "152.32.236.101" ,
107+ "__type" : "Event"
108+ },
109+ {
110+ "protocol.transport" : "tcp" ,
111+ "protocol.application" : "telnet" ,
112+ "classification.type" : "brute-force" ,
113+ "destination.port" : 23 ,
114+ "raw" : "QWRkcmVzcyxUYWdzCjYxLjIxOS4xNzUuNDIsdGVsbmV0" ,
115+ "source.ip" : "61.219.175.42" ,
116+ "__type" : "Event"
117+ }
118+ ]
30119
31120
32121class TestTurrisGreylistParserBot (test .BotTestCase , unittest .TestCase ):
@@ -37,12 +126,22 @@ class TestTurrisGreylistParserBot(test.BotTestCase, unittest.TestCase):
37126 @classmethod
38127 def set_bot (cls ):
39128 cls .bot_reference = TurrisGreylistParserBot
40- cls .default_input_message = {'__type' : 'Report' , 'raw' : RAW }
129+ cls .default_input_message = {'__type' : 'Report' , 'raw' : utils . base64_encode ( INPUT ) }
41130
42131 def test_event (self ):
43132 self .run_bot ()
44- self .assertMessageEqual (0 , OUTPUT1 )
45- self .assertMessageEqual (1 , OUTPUT2 )
133+ self .assertMessageEqual (0 , OUTPUT [0 ])
134+ self .assertMessageEqual (1 , OUTPUT [1 ])
135+ self .assertMessageEqual (2 , OUTPUT [2 ])
136+ self .assertMessageEqual (3 , OUTPUT [3 ])
137+ self .assertMessageEqual (4 , OUTPUT [4 ])
138+ self .assertMessageEqual (5 , OUTPUT [5 ])
139+ self .assertMessageEqual (6 , OUTPUT [6 ])
140+ self .assertMessageEqual (7 , OUTPUT [7 ])
141+ self .assertMessageEqual (8 , OUTPUT [8 ])
142+ self .assertMessageEqual (9 , OUTPUT [9 ])
143+ self .assertMessageEqual (10 , OUTPUT [10 ])
144+
46145
47146if __name__ == '__main__' : # pragma: no cover
48147 unittest .main ()
0 commit comments