-
Notifications
You must be signed in to change notification settings - Fork 2
/
analysis.py
69 lines (54 loc) · 2.07 KB
/
analysis.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2018 Éireann Leverett and Bruce Stenning
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# For progress bars
from tqdm import tqdm
def analyse(misp_data):
"""
Programmatically analyse the MISP data
This is an analysis tool for learning the structure the data
misp_data - The events and attributes loaded from the MISP server
"""
print("Analysing MISP data")
levels = {}
categories = {}
events = misp_data["events"]
attributes = misp_data["attributes"]
for event in tqdm(events):
event_id = int(event["id"])
if event_id in attributes:
event_attributes = attributes[event_id]
else:
event_attributes = []
levels[event["threat_level_id"]] = True
for attribute in event_attributes:
category = attribute["category"]
if not category in categories:
categories[category] = {}
ty = attribute["type"]
if not ty in categories[category]:
categories[category][ty] = 0
else:
categories[category][ty] += 1
print("\nResults of analysis: threat level")
for level in levels.keys():
print(level)
print("\nResults of analysis: categories")
for category in categories.keys():
print("Category: " + category)
for ty in sorted(categories[category].keys(), key=lambda x: -categories[category][x]):
print(" Type: " + ty + " / Count: " +
str(categories[category][ty]))
print("")