pymisp 2.5.7__py3-none-any.whl → 2.5.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pymisp might be problematic. Click here for more details.

Files changed (135) hide show
  1. pymisp/api.py +1 -0
  2. pymisp/data/misp-objects/objects/rmm/definition.json +1 -1
  3. {pymisp-2.5.7.dist-info → pymisp-2.5.8.dist-info}/METADATA +4 -4
  4. {pymisp-2.5.7.dist-info → pymisp-2.5.8.dist-info}/RECORD +6 -135
  5. CHANGELOG.txt +0 -5380
  6. examples/__init__.py +0 -0
  7. examples/add_attributes_from_csv.py +0 -74
  8. examples/add_email_object.py +0 -29
  9. examples/add_fail2ban_object.py +0 -86
  10. examples/add_feed.py +0 -25
  11. examples/add_file_object.py +0 -47
  12. examples/add_filetype_object_from_csv.py +0 -53
  13. examples/add_generic_object.py +0 -26
  14. examples/add_github_user.py +0 -65
  15. examples/add_gitlab_user.py +0 -56
  16. examples/add_named_attribute.py +0 -25
  17. examples/add_organisations.py +0 -57
  18. examples/add_ssh_authorized_keys.py +0 -29
  19. examples/add_user.py +0 -22
  20. examples/add_vehicle_object.py +0 -22
  21. examples/addtag2.py +0 -45
  22. examples/asciidoc_generator.py +0 -114
  23. examples/cache_all.py +0 -10
  24. examples/copyTagsFromAttributesToEvent.py +0 -68
  25. examples/copy_list.py +0 -93
  26. examples/create_events.py +0 -26
  27. examples/cytomic_orion.py +0 -549
  28. examples/del.py +0 -22
  29. examples/delete_user.py +0 -16
  30. examples/edit_organisation.py +0 -20
  31. examples/edit_user.py +0 -20
  32. examples/falsepositive_disabletoids.py +0 -136
  33. examples/fetch_events_feed.py +0 -15
  34. examples/fetch_warninglist_hits.py +0 -38
  35. examples/freetext.py +0 -22
  36. examples/generate_file_objects.py +0 -78
  37. examples/generate_meta_feed.py +0 -15
  38. examples/get.py +0 -37
  39. examples/get_csv.py +0 -37
  40. examples/get_network_activity.py +0 -187
  41. examples/last.py +0 -48
  42. examples/load_csv.py +0 -94
  43. examples/lookup.py +0 -28
  44. examples/misp2cef.py +0 -71
  45. examples/misp2clamav.py +0 -52
  46. examples/openioc_to_misp.py +0 -27
  47. examples/proofpoint_tap.py +0 -203
  48. examples/proofpoint_vap.py +0 -65
  49. examples/search.py +0 -48
  50. examples/search_attributes_yara.py +0 -40
  51. examples/search_sighting.py +0 -42
  52. examples/server_sync_check_conn.py +0 -32
  53. examples/sharing_groups.py +0 -15
  54. examples/show_sightings.py +0 -168
  55. examples/stats_report.py +0 -405
  56. examples/sync_sighting.py +0 -171
  57. examples/tags.py +0 -25
  58. examples/test_sign.py +0 -19
  59. examples/trustar_misp.py +0 -59
  60. examples/up.py +0 -21
  61. examples/upload.py +0 -60
  62. examples/users_list.py +0 -15
  63. examples/vmray_automation.py +0 -281
  64. examples/vt_to_misp.py +0 -182
  65. examples/warninglists.py +0 -22
  66. examples/yara.py +0 -38
  67. examples/yara_dump.py +0 -98
  68. tests/57c4445b-c548-4654-af0b-4be3950d210f.json +0 -1
  69. tests/__init__.py +0 -0
  70. tests/csv_testfiles/invalid_fieldnames.csv +0 -11
  71. tests/csv_testfiles/valid_fieldnames.csv +0 -4
  72. tests/email_testfiles/mail_1.eml.zip +0 -0
  73. tests/email_testfiles/mail_1.msg +0 -0
  74. tests/email_testfiles/mail_1_bom.eml +0 -858
  75. tests/email_testfiles/mail_1_headers_only.eml +0 -28
  76. tests/email_testfiles/mail_2.eml +0 -32
  77. tests/email_testfiles/mail_3.eml +0 -170
  78. tests/email_testfiles/mail_3.msg +0 -0
  79. tests/email_testfiles/mail_4.msg +0 -0
  80. tests/email_testfiles/mail_5.msg +0 -0
  81. tests/email_testfiles/mail_multiple_to.eml +0 -15
  82. tests/email_testfiles/source +0 -1
  83. tests/git-vuln-finder-quagga.json +0 -1493
  84. tests/misp_event.json +0 -76
  85. tests/mispevent_testfiles/attribute.json +0 -21
  86. tests/mispevent_testfiles/attribute_del.json +0 -23
  87. tests/mispevent_testfiles/def_param.json +0 -53
  88. tests/mispevent_testfiles/event.json +0 -8
  89. tests/mispevent_testfiles/event_obj_attr_tag.json +0 -57
  90. tests/mispevent_testfiles/event_obj_def_param.json +0 -62
  91. tests/mispevent_testfiles/event_obj_tag.json +0 -29
  92. tests/mispevent_testfiles/event_tags.json +0 -18
  93. tests/mispevent_testfiles/existing_event.json +0 -4599
  94. tests/mispevent_testfiles/existing_event_edited.json +0 -4601
  95. tests/mispevent_testfiles/galaxy.json +0 -25
  96. tests/mispevent_testfiles/malware.json +0 -19
  97. tests/mispevent_testfiles/malware_exist.json +0 -163
  98. tests/mispevent_testfiles/misp_custom_obj.json +0 -38
  99. tests/mispevent_testfiles/overwrite_file/definition.json +0 -457
  100. tests/mispevent_testfiles/proposals.json +0 -35
  101. tests/mispevent_testfiles/shadow.json +0 -148
  102. tests/mispevent_testfiles/sighting.json +0 -5
  103. tests/mispevent_testfiles/simple.json +0 -2
  104. tests/mispevent_testfiles/test_object_template/definition.json +0 -29
  105. tests/new_misp_event.json +0 -34
  106. tests/reportlab_testfiles/HTML_event.json +0 -1
  107. tests/reportlab_testfiles/galaxy_1.json +0 -1250
  108. tests/reportlab_testfiles/image_event.json +0 -2490
  109. tests/reportlab_testfiles/japanese_test.json +0 -156
  110. tests/reportlab_testfiles/japanese_test_heavy.json +0 -318
  111. tests/reportlab_testfiles/long_event.json +0 -3730
  112. tests/reportlab_testfiles/mainly_objects_1.json +0 -1092
  113. tests/reportlab_testfiles/mainly_objects_2.json +0 -977
  114. tests/reportlab_testfiles/sighting_1.json +0 -305
  115. tests/reportlab_testfiles/sighting_2.json +0 -221
  116. tests/reportlab_testfiles/to_delete1.json +0 -804
  117. tests/reportlab_testfiles/to_delete2.json +0 -1
  118. tests/reportlab_testfiles/to_delete3.json +0 -1
  119. tests/reportlab_testfiles/very_long_event.json +0 -1006
  120. tests/reportlab_testoutputs/to_delete1.json.pdf +0 -391
  121. tests/reportlab_testoutputs/to_delete2.json.pdf +0 -506
  122. tests/reportlab_testoutputs/to_delete3.json.pdf +0 -277
  123. tests/search_index_result.json +0 -69
  124. tests/sharing_groups.json +0 -98
  125. tests/stix1.xml-utf8 +0 -110
  126. tests/stix2.json +0 -1
  127. tests/test_analyst_data.py +0 -123
  128. tests/test_emailobject.py +0 -157
  129. tests/test_fileobject.py +0 -20
  130. tests/test_mispevent.py +0 -473
  131. tests/test_reportlab.py +0 -431
  132. tests/testlive_comprehensive.py +0 -3734
  133. tests/testlive_sync.py +0 -474
  134. {pymisp-2.5.7.dist-info → pymisp-2.5.8.dist-info}/LICENSE +0 -0
  135. {pymisp-2.5.7.dist-info → pymisp-2.5.8.dist-info}/WHEEL +0 -0
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- import requests
4
- import json
5
-
6
- # Suppress those "Unverified HTTPS request is being made"
7
- import urllib3
8
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
9
-
10
- from keys import misp_url, misp_key, misp_verifycert
11
- proxies = {
12
-
13
- }
14
-
15
- '''
16
- Checks if the connection to a sync server works
17
- returns json object
18
- '''
19
-
20
- def check_connection(connection_number):
21
-
22
- misp_headers = {'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': misp_key}
23
- req = requests.get(misp_url + 'servers/testConnection/{}'.format(connection_number), verify=misp_verifycert, headers=misp_headers, proxies=proxies)
24
-
25
- result = json.loads(req.text)
26
- return(result)
27
-
28
-
29
- if __name__ == "__main__":
30
-
31
- result = check_connection(1)
32
- print(result)
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- from pymisp import ExpandedPyMISP
5
- from keys import misp_url, misp_key, misp_verifycert
6
- import argparse
7
-
8
-
9
- if __name__ == '__main__':
10
- parser = argparse.ArgumentParser(description='Get a list of the sharing groups from the MISP instance.')
11
-
12
- misp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
13
-
14
- sharing_groups = misp.sharing_groups(pythonify=True)
15
- print(sharing_groups)
@@ -1,168 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- '''
4
- Koen Van Impe
5
-
6
- List all the sightings
7
-
8
- Put this script in crontab to run every day
9
- 25 4 * * * mispuser /usr/bin/python3 /home/mispuser/PyMISP/examples/show_sightings.py
10
-
11
- '''
12
-
13
- from pymisp import ExpandedPyMISP
14
- from keys import misp_url, misp_key, misp_verifycert
15
-
16
- import sys
17
- import time
18
- from datetime import datetime
19
- import smtplib
20
- import mimetypes
21
- from email.mime.multipart import MIMEMultipart
22
- from email import encoders
23
- from email.mime.base import MIMEBase
24
- from email.mime.text import MIMEText
25
- import argparse
26
- import string
27
-
28
- def init(url, key, verifycert):
29
- '''
30
- Template to get MISP module started
31
- '''
32
- return ExpandedPyMISP(url, key, verifycert, 'json')
33
-
34
-
35
- def set_drift_timestamp(drift_timestamp, drift_timestamp_path):
36
- '''
37
- Save the timestamp in a (local) file
38
- '''
39
- try:
40
- with open(drift_timestamp_path, 'w+') as f:
41
- f.write(str(drift_timestamp))
42
- return True
43
- except IOError:
44
- sys.exit("Unable to write drift_timestamp %s to %s" % (drift_timestamp, drift_timestamp_path))
45
- return False
46
-
47
-
48
- def get_drift_timestamp(drift_timestamp_path):
49
- '''
50
- From when do we start with the sightings?
51
- '''
52
- try:
53
- with open(drift_timestamp_path) as f:
54
- drift = f.read()
55
- if drift:
56
- drift = int(float(drift))
57
- else:
58
- drift = 0
59
- except IOError:
60
- drift = 0
61
-
62
- return drift
63
-
64
-
65
- def search_sightings(misp, from_timestamp, end_timestamp):
66
- '''
67
- Search all the sightings
68
- '''
69
- completed_sightings = []
70
-
71
- try:
72
- found_sightings = misp.search_sightings(date_from=from_timestamp, date_to=end_timestamp)
73
- except Exception as e:
74
- sys.exit('Unable to search for sightings')
75
-
76
- if found_sightings is not None:
77
- for s in found_sightings:
78
- if 'Sighting' in s:
79
- sighting = s['Sighting']
80
- if 'attribute_id' in sighting:
81
- attribute_id = sighting['attribute_id']
82
-
83
- # Query the attribute and event to get the details
84
- try:
85
- attribute = misp.get_attribute(attribute_id)
86
- except Exception as e:
87
- print("Unable to fetch attribute")
88
- continue
89
-
90
- if 'Attribute' in attribute and 'uuid' in attribute['Attribute']:
91
- event_details = misp.get_event(attribute['Attribute']['event_id'])
92
- event_info = event_details['Event']['info']
93
- attribute_uuid = attribute['Attribute']['uuid']
94
- to_ids = attribute['Attribute']['to_ids']
95
- completed_sightings.append({'attribute_uuid': attribute_uuid, 'date_sighting': sighting['date_sighting'], 'source': sighting['source'], 'type': sighting['type'], 'uuid': sighting['uuid'], 'event_id': attribute['Attribute']['event_id'], 'value': attribute['Attribute']['value'], 'attribute_id': attribute['Attribute']['id'], 'event_title': event_info, 'to_ids': to_ids})
96
- else:
97
- continue
98
-
99
- return completed_sightings
100
-
101
-
102
- if __name__ == '__main__':
103
- smtp_from = 'INSERT_FROM'
104
- smtp_to = 'INSERT_TO'
105
- smtp_server = 'localhost'
106
- report_sightings = ''
107
- ts_format = '%Y-%m-%d %H:%M:%S'
108
- drift_timestamp_path = '/home/mispuser/PyMISP/examples/show_sightings.drift'
109
-
110
- parser = argparse.ArgumentParser(description="Show all the sightings.")
111
- parser.add_argument('-m', '--mail', action='store_true', help='Mail the report')
112
- parser.add_argument('-o', '--mailoptions', action='store', help='mailoptions: \'smtp_from=INSERT_FROM;smtp_to=INSERT_TO;smtp_server=localhost\'')
113
-
114
- args = parser.parse_args()
115
- misp = init(misp_url, misp_key, misp_verifycert)
116
-
117
- start_timestamp = get_drift_timestamp(drift_timestamp_path=drift_timestamp_path)
118
- end_timestamp = time.time()
119
- start_timestamp_s = datetime.fromtimestamp(start_timestamp).strftime(ts_format)
120
- end_timestamp_s = datetime.fromtimestamp(end_timestamp).strftime(ts_format)
121
-
122
- # Get all attribute sightings
123
- found_sightings = search_sightings(misp, start_timestamp, end_timestamp)
124
- if found_sightings:
125
- for s in found_sightings:
126
- if int(s['type']) == 0:
127
- s_type = 'TP'
128
- else:
129
- s_type = 'FP'
130
- date_sighting = datetime.fromtimestamp(int(s['date_sighting'])).strftime(ts_format)
131
- s_title = s['event_title']
132
- s_title = s_title.replace('\r','').replace('\n','').replace('\t','')
133
- source = s['source']
134
- if not s['source']:
135
- source = 'N/A'
136
- report_sightings = report_sightings + '%s for [%s] (%s) in event [%s] (%s) on %s from %s (to_ids flag: %s) \n' % ( s_type, s['value'], s['attribute_id'], s_title, s['event_id'], date_sighting, source, s['to_ids'])
137
-
138
- set_drift_timestamp(end_timestamp, drift_timestamp_path)
139
- else:
140
- report_sightings = 'No sightings found'
141
-
142
- # Mail options
143
- if args.mail:
144
- if args.mailoptions:
145
- mailoptions = args.mailoptions.split(';')
146
- for s in mailoptions:
147
- if s.split('=')[0] == 'smtp_from':
148
- smtp_from = s.split('=')[1]
149
- if s.split('=')[0] == 'smtp_to':
150
- smtp_to = s.split('=')[1]
151
- if s.split('=')[0] == 'smtp_server':
152
- smtp_server = s.split('=')[1]
153
-
154
- report_sightings_body = 'MISP Sightings report for %s between %s and %s\n-------------------------------------------------------------------------------\n\n' % (misp_url, start_timestamp_s, end_timestamp_s)
155
- report_sightings_body = report_sightings_body + report_sightings
156
- subject = 'Report of sightings between %s and %s' % (start_timestamp_s, end_timestamp_s)
157
-
158
- msg = MIMEMultipart()
159
- msg['From'] = smtp_from
160
- msg['To'] = smtp_to
161
- msg['Subject'] = subject
162
-
163
- msg.attach(MIMEText(report_sightings_body, 'text'))
164
- server = smtplib.SMTP(smtp_server)
165
- server.sendmail(smtp_from, smtp_to, msg.as_string())
166
-
167
- else:
168
- print(report_sightings)
examples/stats_report.py DELETED
@@ -1,405 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- '''
4
- Koen Van Impe
5
- Maxime Thiebaut
6
-
7
- Generate a report of your MISP statistics
8
- Put this script in crontab to run every /15 or /60
9
- */5 * * * * mispuser /usr/bin/python3 /home/mispuser/PyMISP/examples/stats_report.py -t 30d -m -v
10
-
11
- Do inline config in "main"
12
-
13
- '''
14
-
15
- from pymisp import ExpandedPyMISP
16
- from keys import misp_url, misp_key, misp_verifycert
17
- import argparse
18
- import os
19
- from datetime import datetime
20
- from datetime import date
21
- import time
22
- import sys
23
- import smtplib
24
- import mimetypes
25
- from email.mime.multipart import MIMEMultipart
26
- from email import encoders
27
- from email.mime.base import MIMEBase
28
- from email.mime.text import MIMEText
29
-
30
- # Suppress those "Unverified HTTPS request is being made"
31
- import urllib3
32
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
33
-
34
-
35
- def init(url, key, verifycert):
36
- '''
37
- Template to get MISP module started
38
- '''
39
- return ExpandedPyMISP(url, key, verifycert, 'json')
40
-
41
-
42
- def get_data(misp, timeframe, date_from=None, date_to=None):
43
- '''
44
- Get the event date to build our report
45
- '''
46
- number_of_misp_events = 0
47
- number_of_attributes = 0
48
- number_of_attributes_to_ids = 0
49
- attr_type = {}
50
- attr_category = {}
51
- tags_type = {}
52
- tags_tlp = {'tlp:white': 0, 'tlp:green': 0, 'tlp:amber': 0, 'tlp:red': 0}
53
- tags_misp_galaxy_mitre = {}
54
- tags_misp_galaxy = {}
55
- tags_misp_galaxy_threat_actor = {}
56
- galaxies = {}
57
- galaxies_cluster = {}
58
- threat_levels_counts = [0, 0, 0, 0]
59
- analysis_completion_counts = [0, 0, 0]
60
- report = {}
61
-
62
- try:
63
- if date_from and date_to:
64
- stats_event_response = misp.search(date_from=date_from, date_to=date_to)
65
- else:
66
- stats_event_response = misp.search(last=timeframe)
67
-
68
- # Number of new or updated events since timestamp
69
- report['number_of_misp_events'] = len(stats_event_response)
70
- report['misp_events'] = []
71
-
72
- for event in stats_event_response:
73
- event_data = event['Event']
74
-
75
- timestamp = datetime.utcfromtimestamp(int(event_data['timestamp'])).strftime(ts_format)
76
- publish_timestamp = datetime.utcfromtimestamp(int(event_data['publish_timestamp'])).strftime(ts_format)
77
-
78
- threat_level_id = int(event_data['threat_level_id']) - 1
79
- threat_levels_counts[threat_level_id] = threat_levels_counts[threat_level_id] + 1
80
- threat_level_id = threat_levels[threat_level_id]
81
-
82
- analysis_id = int(event_data['analysis'])
83
- analysis_completion_counts[analysis_id] = analysis_completion_counts[analysis_id] + 1
84
- analysis = analysis_completion[analysis_id]
85
-
86
- report['misp_events'].append({'id': event_data['id'], 'title': event_data['info'].replace('\n', '').encode('utf-8'), 'date': event_data['date'], 'timestamp': timestamp, 'publish_timestamp': publish_timestamp, 'threat_level': threat_level_id, 'analysis_completion': analysis})
87
-
88
- # Walk through the attributes
89
- if 'Attribute' in event_data:
90
- event_attr = event_data['Attribute']
91
- for attr in event_attr:
92
- number_of_attributes = number_of_attributes + 1
93
-
94
- type = attr['type']
95
- category = attr['category']
96
- to_ids = attr['to_ids']
97
-
98
- if to_ids:
99
- number_of_attributes_to_ids = number_of_attributes_to_ids + 1
100
-
101
- if type in attr_type:
102
- attr_type[type] = attr_type[type] + 1
103
- else:
104
- attr_type[type] = 1
105
-
106
- if category in attr_category:
107
- attr_category[category] = attr_category[category] + 1
108
- else:
109
- attr_category[category] = 1
110
-
111
- # Process tags
112
- if 'Tag' in event_data:
113
- tags_attr = event_data['Tag']
114
- for tag in tags_attr:
115
- tag_title = tag['name']
116
-
117
- if tag_title.lower().replace(' ', '') in tags_tlp:
118
- tags_tlp[tag_title.lower().replace(' ', '')] = tags_tlp[tag_title.lower().replace(' ', '')] + 1
119
-
120
- if 'misp-galaxy:mitre-' in tag_title:
121
- if tag_title in tags_misp_galaxy_mitre:
122
- tags_misp_galaxy_mitre[tag_title] = tags_misp_galaxy_mitre[tag_title] + 1
123
- else:
124
- tags_misp_galaxy_mitre[tag_title] = 1
125
-
126
- if 'misp-galaxy:threat-actor=' in tag_title:
127
- if tag_title in tags_misp_galaxy_threat_actor:
128
- tags_misp_galaxy_threat_actor[tag_title] = tags_misp_galaxy_threat_actor[tag_title] + 1
129
- else:
130
- tags_misp_galaxy_threat_actor[tag_title] = 1
131
- elif 'misp-galaxy:' in tag_title:
132
- if tag_title in tags_misp_galaxy:
133
- tags_misp_galaxy[tag_title] = tags_misp_galaxy[tag_title] + 1
134
- else:
135
- tags_misp_galaxy[tag_title] = 1
136
-
137
- if tag_title in tags_type:
138
- tags_type[tag_title] = tags_type[tag_title] + 1
139
- else:
140
- tags_type[tag_title] = 1
141
-
142
- # Process the galaxies
143
- if 'Galaxy' in event_data:
144
- galaxy_attr = event_data['Galaxy']
145
- for galaxy in galaxy_attr:
146
- galaxy_title = galaxy['type']
147
-
148
- if galaxy_title in galaxies:
149
- galaxies[galaxy_title] = galaxies[galaxy_title] + 1
150
- else:
151
- galaxies[galaxy_title] = 1
152
-
153
- for cluster in galaxy['GalaxyCluster']:
154
- cluster_value = cluster['type']
155
- if cluster_value in galaxies_cluster:
156
- galaxies_cluster[cluster_value] = galaxies_cluster[cluster_value] + 1
157
- else:
158
- galaxies_cluster[cluster_value] = 1
159
- report['number_of_attributes'] = number_of_attributes
160
- report['number_of_attributes_to_ids'] = number_of_attributes_to_ids
161
- report['attr_type'] = attr_type
162
- report['attr_category'] = attr_category
163
- report['tags_type'] = tags_type
164
- report['tags_tlp'] = tags_tlp
165
- report['tags_misp_galaxy_mitre'] = tags_misp_galaxy_mitre
166
- report['tags_misp_galaxy'] = tags_misp_galaxy
167
- report['tags_misp_galaxy_threat_actor'] = tags_misp_galaxy_threat_actor
168
- report['galaxies'] = galaxies
169
- report['galaxies_cluster'] = galaxies_cluster
170
-
171
- # General MISP statistics
172
- user_statistics = misp.users_statistics()
173
- if user_statistics and 'errors' not in user_statistics:
174
- report['user_statistics'] = user_statistics
175
-
176
- # Return the report data
177
- return report
178
- except Exception as e:
179
- sys.exit('Unable to get statistics from MISP')
180
-
181
-
182
- def build_report(report, timeframe, misp_url, sanitize_report=True):
183
- '''
184
- Build the body of the report and optional attachments
185
- '''
186
- attachments = {}
187
-
188
- now = datetime.now()
189
- current_date = now.strftime(ts_format)
190
- if timeframe:
191
- report_body = "MISP Report %s for last %s on %s\n-------------------------------------------------------------------------------" % (current_date, timeframe, misp_url)
192
- else:
193
- report_body = "MISP Report %s from %s to %s on %s\n-------------------------------------------------------------------------------" % (current_date, date_from, date_to, misp_url)
194
-
195
- report_body = report_body + '\nNew or updated events: %s' % report['number_of_misp_events']
196
- report_body = report_body + '\nNew or updated attributes: %s' % report['number_of_attributes']
197
- report_body = report_body + '\nNew or updated attributes with IDS flag: %s' % report['number_of_attributes_to_ids']
198
- report_body = report_body + '\n'
199
- if 'user_statistics' in report:
200
- report_body = report_body + '\nTotal events: %s' % report['user_statistics']['stats']['event_count']
201
- report_body = report_body + '\nTotal attributes: %s' % report['user_statistics']['stats']['attribute_count']
202
- report_body = report_body + '\nTotal users: %s' % report['user_statistics']['stats']['user_count']
203
- report_body = report_body + '\nTotal orgs: %s' % report['user_statistics']['stats']['org_count']
204
- report_body = report_body + '\nTotal correlation: %s' % report['user_statistics']['stats']['correlation_count']
205
- report_body = report_body + '\nTotal proposals: %s' % report['user_statistics']['stats']['proposal_count']
206
-
207
- report_body = report_body + '\n\n'
208
-
209
- if args.mispevent:
210
- report_body = report_body + '\nNew or updated events\n-------------------------------------------------------------------------------'
211
- attachments['misp_events'] = 'ID;Title;Date;Updated;Published;ThreatLevel;AnalysisStatus'
212
- for el in report['misp_events']:
213
- report_body = report_body + '\n #%s %s (%s) \t%s \n\t\t\t\t(Date: %s, Updated: %s, Published: %s)' % (el['id'], el['threat_level'], el['analysis_completion'], el['title'].decode('utf-8'), el['date'], el['timestamp'], el['publish_timestamp'])
214
- attachments['misp_events'] = attachments['misp_events'] + '\n%s;%s;%s;%s;%s;%s;%s' % (el['id'], el['title'].decode('utf-8'), el['date'], el['timestamp'], el['publish_timestamp'], el['threat_level'], el['analysis_completion'])
215
-
216
- report_body, attachments['attr_category'] = add_report_body(report_body, 'New or updated attributes - Category', report['attr_category'], 'AttributeCategory;Qt')
217
- report_body, attachments['attr_type'] = add_report_body(report_body, 'New or updated attributes - Type', report['attr_type'], 'AttributeType;Qt')
218
- report_body, attachments['tags_tlp'] = add_report_body(report_body, 'TLP Codes', report['tags_tlp'], 'TLP;Qt')
219
- report_body, attachments['tags_misp_galaxy'] = add_report_body(report_body, 'Tag MISP Galaxy', report['tags_misp_galaxy'], 'MISPGalaxy;Qt')
220
- report_body, attachments['tags_misp_galaxy_mitre'] = add_report_body(report_body, 'Tag MISP Galaxy Mitre', report['tags_misp_galaxy_mitre'], 'MISPGalaxyMitre;Qt')
221
- report_body, attachments['tags_misp_galaxy_threat_actor'] = add_report_body(report_body, 'Tag MISP Galaxy Threat Actor', report['tags_misp_galaxy_threat_actor'], 'MISPGalaxyThreatActor;Qt')
222
- report_body, attachments['tags_type'] = add_report_body(report_body, 'Tags', report['tags_type'], 'Tag;Qt')
223
- report_body, attachments['galaxies'] = add_report_body(report_body, 'Galaxies', report['galaxies'], 'Galaxies;Qt')
224
- report_body, attachments['galaxies_cluster'] = add_report_body(report_body, 'Galaxies Cluster', report['galaxies_cluster'], 'Galaxies;Qt')
225
-
226
- if sanitize_report:
227
- mitre_tactic = get_sanitized_report(report['tags_misp_galaxy_mitre'], 'ATT&CK Tactic')
228
- mitre_group = get_sanitized_report(report['tags_misp_galaxy_mitre'], 'ATT&CK Group')
229
- mitre_software = get_sanitized_report(report['tags_misp_galaxy_mitre'], 'ATT&CK Software')
230
- threat_actor = get_sanitized_report(report['tags_misp_galaxy_threat_actor'], 'MISP Threat Actor')
231
- misp_tag = get_sanitized_report(report['tags_type'], 'MISP Tags', False, True)
232
-
233
- report_body, attachments['mitre_tactics'] = add_report_body(report_body, 'MITRE ATT&CK Tactics (sanitized)', mitre_tactic, 'MITRETactics;Qt')
234
- report_body, attachments['mitre_group'] = add_report_body(report_body, 'MITRE ATT&CK Group (sanitized)', mitre_group, 'MITREGroup;Qt')
235
- report_body, attachments['mitre_software'] = add_report_body(report_body, 'MITRE ATT&CK Software (sanitized)', mitre_software, 'MITRESoftware;Qt')
236
- report_body, attachments['threat_actor'] = add_report_body(report_body, 'MISP Threat Actor (sanitized)', threat_actor, 'MISPThreatActor;Qt')
237
- report_body, attachments['misp_tag'] = add_report_body(report_body, 'Tags (sanitized)', misp_tag, 'MISPTags;Qt')
238
-
239
- report_body = report_body + "\n\nMISP Reporter Finished\n"
240
-
241
- return report_body, attachments
242
-
243
-
244
- def add_report_body(report_body, subtitle, data_object, csv_title):
245
- '''
246
- Add a section to the report body text
247
- '''
248
- if report_body:
249
- report_body = report_body + '\n\n'
250
- report_body = report_body + '\n%s\n-------------------------------------------------------------------------------' % subtitle
251
- data_object_s = sorted(data_object.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
252
- csv_attachment = csv_title
253
- for el in data_object_s:
254
- report_body = report_body + "\n%s \t %s" % (el[0], el[1])
255
- csv_attachment = csv_attachment + '\n%s;%s' % (el[0], el[1])
256
-
257
- return report_body, csv_attachment
258
-
259
-
260
- def msg_attach(content, filename):
261
- '''
262
- Return an message attachment object
263
- '''
264
- part = MIMEBase('application', "octet-stream")
265
- part.set_payload(content)
266
- part.add_header('Content-Disposition', 'attachment; filename="%s"' % filename)
267
- return part
268
-
269
-
270
- def print_report(report_body, attachments, smtp_from, smtp_to, smtp_server, misp_url):
271
- '''
272
- Print (or send) the report
273
- '''
274
- if args.mail:
275
- now = datetime.now()
276
- current_date = now.strftime(ts_format)
277
-
278
- if timeframe:
279
- subject = "MISP Report %s for last %s on %s" % (current_date, timeframe, misp_url)
280
- else:
281
- subject = "MISP Report %s from %s to %s on %s" % (current_date, date_from, date_to, misp_url)
282
-
283
- msg = MIMEMultipart()
284
- msg['From'] = smtp_from
285
- msg['To'] = smtp_to
286
- msg['Subject'] = subject
287
-
288
- msg.attach(MIMEText(report_body, 'text'))
289
-
290
- if args.mispevent:
291
- part = MIMEBase('application', "octet-stream")
292
- part.set_payload(attachments['misp_events'])
293
- part.add_header('Content-Disposition', 'attachment; filename="misp_events.csv"')
294
- msg.attach(part)
295
-
296
- msg.attach(msg_attach(attachments['attr_type'], 'attr_type.csv'))
297
- msg.attach(msg_attach(attachments['attr_category'], 'attr_category.csv'))
298
- msg.attach(msg_attach(attachments['tags_tlp'], 'tags_tlp.csv'))
299
- msg.attach(msg_attach(attachments['tags_misp_galaxy_mitre'], 'tags_misp_galaxy_mitre.csv'))
300
- msg.attach(msg_attach(attachments['tags_misp_galaxy'], 'tags_misp_galaxy.csv'))
301
- msg.attach(msg_attach(attachments['tags_misp_galaxy_threat_actor'], 'tags_misp_galaxy_threat_actor.csv'))
302
- msg.attach(msg_attach(attachments['tags_type'], 'tags_type.csv'))
303
- msg.attach(msg_attach(attachments['galaxies'], 'galaxies.csv'))
304
- msg.attach(msg_attach(attachments['galaxies_cluster'], 'galaxies_cluster.csv'))
305
- msg.attach(msg_attach(attachments['misp_tag'], 'misp_tag.csv'))
306
- msg.attach(msg_attach(attachments['threat_actor'], 'threat_actor.csv'))
307
- msg.attach(msg_attach(attachments['mitre_software'], 'mitre_software.csv'))
308
- msg.attach(msg_attach(attachments['mitre_group'], 'mitre_group.csv'))
309
- msg.attach(msg_attach(attachments['mitre_tactics'], 'mitre_tactics.csv'))
310
-
311
- server = smtplib.SMTP(smtp_server)
312
- server.sendmail(smtp_from, smtp_to, msg.as_string())
313
-
314
- else:
315
- print(report_body)
316
-
317
-
318
- def get_sanitized_report(dataset, sanitize_selector='ATT&CK Tactic', lower=False, add_not_sanitized=False):
319
- '''
320
- Remove or bundle some of the tags
321
- 'quick'n'dirty ; could also do this by using the galaxy/tags definition
322
- '''
323
- # If you add the element completely then it gets removed by an empty string; this allows to filter out non-relevant items
324
- sanitize_set = {
325
- 'ATT&CK Tactic': ['misp-galaxy:mitre-enterprise-attack-pattern="', 'misp-galaxy:mitre-pre-attack-pattern="', 'misp-galaxy:mitre-mobile-attack-pattern="', 'misp-galaxy:mitre-attack-pattern="', 'misp-galaxy:mitre-enterprise-attack-attack-pattern="', 'misp-galaxy:mitre-pre-attack-attack-pattern="', 'misp-galaxy:mitre-enterprise-attack-attack-pattern="', 'misp-galaxy:mitre-mobile-attack-attack-pattern="'],
326
- 'ATT&CK Group': ['misp-galaxy:mitre-enterprise-intrusion-set="', 'misp-galaxy:mitre-pre-intrusion-set="', 'misp-galaxy:mitre-mobile-intrusion-set="', 'misp-galaxy:mitre-intrusion-set="', 'misp-galaxy:mitre-enterprise-attack-intrusion-set="', 'misp-galaxy:mitre-pre-attack-intrusion-set="', 'misp-galaxy:mitre-mobile-attack-intrusion-set="'],
327
- 'ATT&CK Software': ['misp-galaxy:mitre-enterprise-malware="', 'misp-galaxy:mitre-pre-malware="', 'misp-galaxy:mitre-mobile-malware="', 'misp-galaxy:mitre-malware="', 'misp-galaxy:mitre-enterprise-attack-tool="', 'misp-galaxy:mitre-enterprise-tool="', 'misp-galaxy:mitre-pre-tool="', 'misp-galaxy:mitre-mobile-tool="', 'misp-galaxy:mitre-tool="', 'misp-galaxy:mitre-enterprise-attack-malware="'],
328
- 'MISP Threat Actor': ['misp-galaxy:threat-actor="'],
329
- 'MISP Tags': ['circl:incident-classification="', 'osint:source-type="blog-post"', 'misp-galaxy:tool="', 'CERT-XLM:malicious-code="', 'circl:topic="', 'ddos:type="', 'ecsirt:fraud="', 'dnc:malware-type="', 'enisa:nefarious-activity-abuse="', 'europol-incident:information-gathering="', 'misp-galaxy:ransomware="', 'misp-galaxy:rat="', 'misp-galaxy:social-dark-patterns="', 'misp-galaxy:tool="', 'misp:threat-level="', 'ms-caro-malware:malware-platform=', 'ms-caro-malware:malware-type=', 'veris:security_incident="', 'veris:attribute:integrity:variety="', 'veris:actor:motive="', 'misp-galaxy:banker="', 'misp-galaxy:malpedia="', 'misp-galaxy:botnet="', 'malware_classification:malware-category="', 'TLP: white', 'TLP: Green',
330
- 'inthreat:event-src="feed-osint"', 'tlp:white', 'tlp:amber', 'tlp:green', 'tlp:red', 'osint:source-type="blog-post"', 'Partner Feed', 'IBM XForce', 'type:OSINT', 'malware:', 'osint:lifetime="perpetual"', 'Actor:', 'osint:certainty="50"', 'Banker:', 'Group:', 'Threat:',
331
- 'ncsc-nl-ndn:feed="selected"', 'misp-galaxy:microsoft-activity-group="', 'admiralty-scale:source-reliability="b"', 'admiralty-scale:source-reliability="a"', 'admiralty-scale:information-credibility="2"', 'admiralty-scale:information-credibility="3"',
332
- 'feed:source="CESICAT"', 'osint:source-type="automatic-analysis"', 'workflow:state="complete"', 'osint:source-type="technical-report"',
333
- 'csirt_case_classification:incident-category="', 'dnc:driveby-type="', 'veris:action:social:variety="', 'osint:source-type="',
334
- 'osint:source-type="microblog-post"', 'ecsirt:malicious-code="', 'misp-galaxy:sector="', 'veris:action:variety=', 'label=', 'csirt_case_classification:incident-category="', 'admiralty-scale:source-reliability="c"', 'workflow:todo="review"', 'LDO-CERT:detection="toSIEM"', 'Threat tlp:White', 'Threat Type:', 'adversary:infrastructure-state="active"', 'cirl:incident-classification:', 'misp-galaxy:android="', 'dnc:infrastructure-type="', 'ecsirt:information-gathering="', 'ecsirt:intrusions="', 'dhs-ciip-sectors:DHS-critical-sectors="', 'malware_classification:obfuscation-technique="no-obfuscation"',
335
- 'riskiq:threat-type="', 'veris:action:hacking:variety="', 'veris:action:social:target="', 'workflow:state="incomplete"', 'workflow:todo="add-tagging"', 'workflow:todo="add-context"', 'europol-incident:availability="', 'label=', 'misp-galaxy:stealer="', 'misp-galaxy:exploit-kit="', 'rsit:availability="', 'rsit:fraud="', 'ransomware:type="', 'veris:action:variety=', 'malware:',
336
- 'ecsirt:abusive-content="']}
337
- if sanitize_selector == 'MISP Tags':
338
- sanitize_set['MISP Tags'] = sanitize_set['MISP Tags'] + sanitize_set['ATT&CK Tactic'] + sanitize_set['ATT&CK Group'] + sanitize_set['ATT&CK Software'] + sanitize_set['MISP Threat Actor']
339
- result_sanitize_set = {}
340
-
341
- if dataset:
342
- for element in dataset:
343
- sanited = False
344
- for sanitize_el in sanitize_set[sanitize_selector]:
345
- if sanitize_el in element:
346
- sanited = True
347
- new_el = element.replace(sanitize_el, '').replace('"', '').strip()
348
- if lower:
349
- new_el = new_el.lower()
350
- result_sanitize_set[new_el] = dataset[element]
351
- if add_not_sanitized and not sanited:
352
- new_el = element.strip()
353
- if lower:
354
- new_el = new_el.lower()
355
- result_sanitize_set[new_el] = dataset[element]
356
-
357
- return result_sanitize_set
358
-
359
-
360
- if __name__ == '__main__':
361
- parser = argparse.ArgumentParser(description='Generate a report of your MISP statistics.')
362
- group = parser.add_mutually_exclusive_group(required=True)
363
- group.add_argument('-t', '--timeframe', action='store', help='Timeframe to include in the report')
364
- group.add_argument('-f', '--date_from', action='store', help='Start date of query (YYYY-MM-DD)')
365
- parser.add_argument('-u', '---date-to', action='store', help='End date of query (YYYY-MM-DD)')
366
- parser.add_argument('-e', '--mispevent', action='store_true', help='Include MISP event titles')
367
- parser.add_argument('-m', '--mail', action='store_true', help='Mail the report')
368
- parser.add_argument('-o', '--mailoptions', action='store', help='mailoptions: \'smtp_from=INSERT_FROM;smtp_to=INSERT_TO;smtp_server=localhost\'')
369
-
370
- args = parser.parse_args()
371
- misp = init(misp_url, misp_key, misp_verifycert)
372
-
373
- timeframe = args.timeframe
374
- if not timeframe:
375
- date_from = args.date_from
376
- if not args.date_to:
377
- today = date.today()
378
- date_to = today.strftime("%Y-%m-%d")
379
- else:
380
- date_to = args.date_to
381
- else:
382
- date_from = None
383
- date_to = None
384
-
385
- ts_format = '%Y-%m-%d %H:%M:%S'
386
- threat_levels = ['High', 'Medium', 'Low', 'Undef']
387
- analysis_completion = ['Initial', 'Ongoing', 'Complete']
388
- smtp_from = 'INSERT_FROM'
389
- smtp_to = 'INSERT_TO'
390
- smtp_server = 'localhost'
391
-
392
- if args.mailoptions:
393
- mailoptions = args.mailoptions.split(';')
394
- for s in mailoptions:
395
- if s.split('=')[0] == 'smtp_from':
396
- smtp_from = s.split('=')[1]
397
- if s.split('=')[0] == 'smtp_to':
398
- smtp_to = s.split('=')[1]
399
- if s.split('=')[0] == 'smtp_server':
400
- smtp_server = s.split('=')[1]
401
-
402
- report = get_data(misp, timeframe, date_from, date_to)
403
- if(report):
404
- report_body, attachments = build_report(report, timeframe, misp_url)
405
- print_report(report_body, attachments, smtp_from, smtp_to, smtp_server, misp_url)