-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpatrowl.py
More file actions
executable file
·77 lines (61 loc) · 2.57 KB
/
patrowl.py
File metadata and controls
executable file
·77 lines (61 loc) · 2.57 KB
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
#!/usr/bin/env python
# encoding: utf-8
"""Patrowl Analyzer for Cortex."""
import requests
from cortexutils.analyzer import Analyzer
class PatrowlAnalyzer(Analyzer):
"""PatrowlAnalyzer Class definition."""
def __init__(self):
"""Initialize the Analyzer."""
Analyzer.__init__(self)
self.service = self.getParam('config.service', None, 'Patrowl service is missing')
self.url = self.getParam('config.url', None, 'Patrowl URL is missing').rstrip("/")
self.username = self.getParam('config.username', None, 'Patrowl Username is missing')
self.password = self.getParam('config.password', None, 'Patrowl Password is missing')
def summary(self, raw):
"""Parse, format and return scan summary."""
taxonomies = []
level = "info"
namespace = "Patrowl"
# getreport service
if self.service == 'getreport':
if 'risk_level' in raw and raw['risk_level']:
# Grade
if raw['risk_level']['grade'] in ["A", "B"]:
level = "safe"
else:
level = "suspicious"
taxonomies.append(self.build_taxonomy(
level, namespace, "Grade", raw['risk_level']['grade']))
# Findings
if raw['risk_level']['high'] > 0:
level = "malicious"
elif raw['risk_level']['medium'] > 0 or raw['risk_level']['low'] > 0:
level = "suspicious"
else:
level = "info"
taxonomies.append(self.build_taxonomy(
level, namespace, "Findings", "{}/{}/{}/{}".format(
raw['risk_level']['high'],
raw['risk_level']['medium'],
raw['risk_level']['low'],
raw['risk_level']['info']
)))
#todo: add_asset service
return {"taxonomies": taxonomies}
def run(self):
"""Run the analyzer."""
Analyzer.run(self)
data = self.getData()
try:
if self.service == 'getreport':
service_url = self.url+"/assets/api/v1/details/"+data
response = requests.get(service_url, auth=requests.auth.HTTPBasicAuth(self.username, self.password))
self.report(response.json())
else:
self.error('Unknown Patrowl service')
except Exception as e:
self.unexpectedError(e)
if __name__ == '__main__':
"""Main function."""
PatrowlAnalyzer().run()