-
Notifications
You must be signed in to change notification settings - Fork 385
/
Copy pathsinkdb.py
executable file
·52 lines (38 loc) · 1.46 KB
/
sinkdb.py
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
#!/usr/bin/env python
import subprocess
from cortexutils.analyzer import Analyzer
class SinkDBAnalyzer(Analyzer):
def __init__(self):
Analyzer.__init__(self)
if self.data_type != 'ip':
self.error('SinkDB Analyzer only usable with ip data type.')
self.apikey = self.get_param('config.key', None, 'API Key needed for querying SinkDB.')
self.data = self.get_data().split('.')
self.data.reverse()
self.data = '.'.join(self.data)
def dig(self, ip):
proc = subprocess.Popen(['dig', '+short', '{}.{}.sinkdb-api.abuse.ch'.format(ip, self.apikey)],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate()
out = out.decode('utf-8').strip('\n')
if err:
self.error('Error while calling dig: {}.'.format(err))
if out == '127.0.0.2':
return True
return False
def run(self):
self.report({
"is_sinkhole": self.dig(self.data)
})
def summary(self, raw):
taxonomies = []
if raw.get('is_sinkhole'):
taxonomies.append(self.build_taxonomy('safe', 'SinkDB', 'IsSinkhole', 'True'))
else:
taxonomies.append(self.build_taxonomy('suspicious', 'SinkDB', 'IsSinkhole', 'False'))
return {
"taxonomies": taxonomies
}
if __name__ == '__main__':
SinkDBAnalyzer().run()