pymisp 2.5.3__py3-none-any.whl → 2.5.7__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 (162) hide show
  1. CHANGELOG.txt +5380 -0
  2. examples/__init__.py +0 -0
  3. examples/add_attributes_from_csv.py +74 -0
  4. examples/add_email_object.py +29 -0
  5. examples/add_fail2ban_object.py +86 -0
  6. examples/add_feed.py +25 -0
  7. examples/add_file_object.py +47 -0
  8. examples/add_filetype_object_from_csv.py +53 -0
  9. examples/add_generic_object.py +26 -0
  10. examples/add_github_user.py +65 -0
  11. examples/add_gitlab_user.py +56 -0
  12. examples/add_named_attribute.py +25 -0
  13. examples/add_organisations.py +57 -0
  14. examples/add_ssh_authorized_keys.py +29 -0
  15. examples/add_user.py +22 -0
  16. examples/add_vehicle_object.py +22 -0
  17. examples/addtag2.py +45 -0
  18. examples/asciidoc_generator.py +114 -0
  19. examples/cache_all.py +10 -0
  20. examples/copyTagsFromAttributesToEvent.py +68 -0
  21. examples/copy_list.py +93 -0
  22. examples/create_events.py +26 -0
  23. examples/cytomic_orion.py +549 -0
  24. examples/del.py +22 -0
  25. examples/delete_user.py +16 -0
  26. examples/edit_organisation.py +20 -0
  27. examples/edit_user.py +20 -0
  28. examples/falsepositive_disabletoids.py +136 -0
  29. examples/fetch_events_feed.py +15 -0
  30. examples/fetch_warninglist_hits.py +38 -0
  31. examples/freetext.py +22 -0
  32. examples/generate_file_objects.py +78 -0
  33. examples/generate_meta_feed.py +15 -0
  34. examples/get.py +37 -0
  35. examples/get_csv.py +37 -0
  36. examples/get_network_activity.py +187 -0
  37. examples/last.py +48 -0
  38. examples/load_csv.py +94 -0
  39. examples/lookup.py +28 -0
  40. examples/misp2cef.py +71 -0
  41. examples/misp2clamav.py +52 -0
  42. examples/openioc_to_misp.py +27 -0
  43. examples/proofpoint_tap.py +203 -0
  44. examples/proofpoint_vap.py +65 -0
  45. examples/search.py +48 -0
  46. examples/search_attributes_yara.py +40 -0
  47. examples/search_sighting.py +42 -0
  48. examples/server_sync_check_conn.py +32 -0
  49. examples/sharing_groups.py +15 -0
  50. examples/show_sightings.py +168 -0
  51. examples/stats_report.py +405 -0
  52. examples/sync_sighting.py +171 -0
  53. examples/tags.py +25 -0
  54. examples/test_sign.py +19 -0
  55. examples/trustar_misp.py +59 -0
  56. examples/up.py +21 -0
  57. examples/upload.py +60 -0
  58. examples/users_list.py +15 -0
  59. examples/vmray_automation.py +281 -0
  60. examples/vt_to_misp.py +182 -0
  61. examples/warninglists.py +22 -0
  62. examples/yara.py +38 -0
  63. examples/yara_dump.py +98 -0
  64. pymisp/api.py +33 -5
  65. pymisp/data/misp-objects/objects/android-app/definition.json +8 -2
  66. pymisp/data/misp-objects/objects/instagram-account/definition.json +66 -0
  67. pymisp/data/misp-objects/objects/lnk/definition.json +13 -1
  68. pymisp/data/misp-objects/objects/rmm/definition.json +88 -0
  69. pymisp/data/misp-objects/objects/spambee-report/definition.json +54 -0
  70. pymisp/data/misp-objects/objects/target-system/definition.json +2 -2
  71. pymisp/data/misp-objects/objects/vulnerability/definition.json +5 -4
  72. pymisp/data/misp-objects/relationships/definition.json +17 -1
  73. pymisp/data/misp-objects/schema_objects.json +1 -1
  74. pymisp/mispevent.py +95 -23
  75. {pymisp-2.5.3.dist-info → pymisp-2.5.7.dist-info}/METADATA +23 -28
  76. {pymisp-2.5.3.dist-info → pymisp-2.5.7.dist-info}/RECORD +144 -30
  77. {pymisp-2.5.3.dist-info → pymisp-2.5.7.dist-info}/WHEEL +1 -1
  78. tests/57c4445b-c548-4654-af0b-4be3950d210f.json +1 -0
  79. tests/__init__.py +0 -0
  80. tests/csv_testfiles/invalid_fieldnames.csv +11 -0
  81. tests/csv_testfiles/valid_fieldnames.csv +4 -0
  82. tests/email_testfiles/mail_1.eml.zip +0 -0
  83. tests/email_testfiles/mail_1.msg +0 -0
  84. tests/email_testfiles/mail_1_bom.eml +858 -0
  85. tests/email_testfiles/mail_1_headers_only.eml +28 -0
  86. tests/email_testfiles/mail_2.eml +32 -0
  87. tests/email_testfiles/mail_3.eml +170 -0
  88. tests/email_testfiles/mail_3.msg +0 -0
  89. tests/email_testfiles/mail_4.msg +0 -0
  90. tests/email_testfiles/mail_5.msg +0 -0
  91. tests/email_testfiles/mail_multiple_to.eml +15 -0
  92. tests/email_testfiles/source +1 -0
  93. tests/git-vuln-finder-quagga.json +1493 -0
  94. tests/misp_event.json +76 -0
  95. tests/mispevent_testfiles/attribute.json +21 -0
  96. tests/mispevent_testfiles/attribute_del.json +23 -0
  97. tests/mispevent_testfiles/def_param.json +53 -0
  98. tests/mispevent_testfiles/event.json +8 -0
  99. tests/mispevent_testfiles/event_obj_attr_tag.json +57 -0
  100. tests/mispevent_testfiles/event_obj_def_param.json +62 -0
  101. tests/mispevent_testfiles/event_obj_tag.json +29 -0
  102. tests/mispevent_testfiles/event_tags.json +18 -0
  103. tests/mispevent_testfiles/existing_event.json +4599 -0
  104. tests/mispevent_testfiles/existing_event_edited.json +4601 -0
  105. tests/mispevent_testfiles/galaxy.json +25 -0
  106. tests/mispevent_testfiles/malware.json +19 -0
  107. tests/mispevent_testfiles/malware_exist.json +163 -0
  108. tests/mispevent_testfiles/misp_custom_obj.json +38 -0
  109. tests/mispevent_testfiles/overwrite_file/definition.json +457 -0
  110. tests/mispevent_testfiles/proposals.json +35 -0
  111. tests/mispevent_testfiles/shadow.json +148 -0
  112. tests/mispevent_testfiles/sighting.json +5 -0
  113. tests/mispevent_testfiles/simple.json +2 -0
  114. tests/mispevent_testfiles/test_object_template/definition.json +29 -0
  115. tests/new_misp_event.json +34 -0
  116. tests/reportlab_testfiles/HTML_event.json +1 -0
  117. tests/reportlab_testfiles/galaxy_1.json +1250 -0
  118. tests/reportlab_testfiles/image_event.json +2490 -0
  119. tests/reportlab_testfiles/japanese_test.json +156 -0
  120. tests/reportlab_testfiles/japanese_test_heavy.json +318 -0
  121. tests/reportlab_testfiles/long_event.json +3730 -0
  122. tests/reportlab_testfiles/mainly_objects_1.json +1092 -0
  123. tests/reportlab_testfiles/mainly_objects_2.json +977 -0
  124. tests/reportlab_testfiles/sighting_1.json +305 -0
  125. tests/reportlab_testfiles/sighting_2.json +221 -0
  126. tests/reportlab_testfiles/to_delete1.json +804 -0
  127. tests/reportlab_testfiles/to_delete2.json +1 -0
  128. tests/reportlab_testfiles/to_delete3.json +1 -0
  129. tests/reportlab_testfiles/very_long_event.json +1006 -0
  130. tests/reportlab_testoutputs/to_delete1.json.pdf +391 -0
  131. tests/reportlab_testoutputs/to_delete2.json.pdf +506 -0
  132. tests/reportlab_testoutputs/to_delete3.json.pdf +277 -0
  133. tests/search_index_result.json +69 -0
  134. tests/sharing_groups.json +98 -0
  135. tests/stix1.xml-utf8 +110 -0
  136. tests/stix2.json +1 -0
  137. tests/test_analyst_data.py +123 -0
  138. tests/test_emailobject.py +157 -0
  139. tests/test_fileobject.py +20 -0
  140. tests/test_mispevent.py +473 -0
  141. tests/test_reportlab.py +431 -0
  142. tests/testlive_comprehensive.py +3734 -0
  143. tests/testlive_sync.py +474 -0
  144. pymisp/data/misp-objects/.git +0 -1
  145. pymisp/data/misp-objects/.gitchangelog.rc +0 -289
  146. pymisp/data/misp-objects/.github/workflows/codeql.yml +0 -41
  147. pymisp/data/misp-objects/.github/workflows/nosetests.yml +0 -39
  148. pymisp/data/misp-objects/.travis.yml +0 -16
  149. pymisp/data/misp-objects/LICENSE-software-only.md +0 -661
  150. pymisp/data/misp-objects/LICENSE.md +0 -36
  151. pymisp/data/misp-objects/README.md +0 -566
  152. pymisp/data/misp-objects/docs/time-related-objects.ods +0 -0
  153. pymisp/data/misp-objects/docs/time-related-objects.pdf +0 -0
  154. pymisp/data/misp-objects/jq_all_the_things.sh +0 -29
  155. pymisp/data/misp-objects/tools/adoc_objects.py +0 -145
  156. pymisp/data/misp-objects/tools/alfred_links_to_relarelationships.py +0 -48
  157. pymisp/data/misp-objects/tools/list_of_objects.py +0 -50
  158. pymisp/data/misp-objects/tools/updated.sh +0 -6
  159. pymisp/data/misp-objects/tools/validate_opposites.sh +0 -17
  160. pymisp/data/misp-objects/unique_uuid.py +0 -16
  161. pymisp/data/misp-objects/validate_all.sh +0 -38
  162. {pymisp-2.5.3.dist-info → pymisp-2.5.7.dist-info}/LICENSE +0 -0
examples/addtag2.py ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from pymisp import PyMISP
4
+ from keys import misp_url, misp_key, misp_verifycert
5
+ import argparse
6
+
7
+
8
+ def init(url, key):
9
+ return PyMISP(url, key, misp_verifycert, 'json')
10
+
11
+
12
+ if __name__ == '__main__':
13
+ parser = argparse.ArgumentParser(description='Tag something.')
14
+ parser.add_argument("-u", "--uuid", help="UUID to tag.")
15
+ parser.add_argument("-e", "--event", help="Event ID to tag.")
16
+ parser.add_argument("-a", "--attribute", help="Attribute ID to tag")
17
+ parser.add_argument("-t", "--tag", required=True, help="Tag ID.")
18
+ args = parser.parse_args()
19
+
20
+ if not args.event and not args.uuid and not args.attribute:
21
+ print("Please provide at least one of the following : uuid, eventID or attribute ID, see --help")
22
+ exit()
23
+
24
+ misp = init(misp_url, misp_key)
25
+
26
+ if args.event and not args.attribute:
27
+ result = misp.search(eventid=args.event)
28
+ for event in result:
29
+ uuid = event['Event']['uuid']
30
+
31
+ if args.attribute:
32
+ if not args.event:
33
+ print("Please provide event ID also")
34
+ exit()
35
+ result = misp.search(eventid=args.event)
36
+ for event in result:
37
+ for attribute in event['Event']['Attribute']:
38
+ if attribute["id"] == args.attribute:
39
+ uuid = attribute["uuid"]
40
+
41
+ if args.uuid:
42
+ uuid = args.uuid
43
+
44
+ print("UUID tagged: %s" % uuid)
45
+ misp.tag(uuid, args.tag)
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import argparse
5
+ from datetime import date
6
+ import importlib
7
+
8
+ from pymisp import MISPEvent
9
+ from defang import defang
10
+ from pytaxonomies import Taxonomies
11
+
12
+
13
+ class ReportGenerator():
14
+ def __init__(self, profile="daily_report"):
15
+ self.taxonomies = Taxonomies()
16
+ self.report = ''
17
+ profile_name = "profiles.{}".format(profile)
18
+ self.template = importlib.import_module(name=profile_name)
19
+
20
+ def from_remote(self, event_id):
21
+ from pymisp import PyMISP
22
+ from keys import misp_url, misp_key, misp_verifycert
23
+ misp = PyMISP(misp_url, misp_key, misp_verifycert)
24
+ result = misp.get(event_id)
25
+ self.misp_event = MISPEvent()
26
+ self.misp_event.load(result)
27
+
28
+ def from_file(self, path):
29
+ self.misp_event = MISPEvent()
30
+ self.misp_event.load_file(path)
31
+
32
+ def attributes(self):
33
+ if not self.misp_event.attributes:
34
+ return ''
35
+ list_attributes = []
36
+ for attribute in self.misp_event.attributes:
37
+ if attribute.type in self.template.types_to_attach:
38
+ list_attributes.append("* {}".format(defang(attribute.value)))
39
+ for obj in self.misp_event.Object:
40
+ if obj.name in self.template.objects_to_attach:
41
+ for attribute in obj.Attribute:
42
+ if attribute.type in self.template.types_to_attach:
43
+ list_attributes.append("* {}".format(defang(attribute.value)))
44
+ return self.template.attributes.format(list_attributes="\n".join(list_attributes))
45
+
46
+ def _get_tag_info(self, machinetag):
47
+ return self.taxonomies.revert_machinetag(machinetag)
48
+
49
+ def report_headers(self):
50
+ content = {'org_name': 'name',
51
+ 'date': date.today().isoformat()}
52
+ self.report += self.template.headers.format(**content)
53
+
54
+ def event_level_tags(self):
55
+ if not self.misp_event.Tag:
56
+ return ''
57
+ for tag in self.misp_event.Tag:
58
+ # Only look for TLP for now
59
+ if tag['name'].startswith('tlp'):
60
+ tax, predicate = self._get_tag_info(tag['name'])
61
+ return self.template.event_level_tags.format(value=predicate.predicate.upper(), expanded=predicate.expanded)
62
+
63
+ def title(self):
64
+ internal_id = ''
65
+ summary = ''
66
+ # Get internal refs for report
67
+ for obj in self.misp_event.Object:
68
+ if obj.name != 'report':
69
+ continue
70
+ for a in obj.Attribute:
71
+ if a.object_relation == 'case-number':
72
+ internal_id = a.value
73
+ if a.object_relation == 'summary':
74
+ summary = a.value
75
+
76
+ return self.template.title.format(internal_id=internal_id, title=self.misp_event.info,
77
+ summary=summary)
78
+
79
+ def asciidoc(self, lang='en'):
80
+ self.report += self.title()
81
+ self.report += self.event_level_tags()
82
+ self.report += self.attributes()
83
+
84
+
85
+ if __name__ == '__main__':
86
+ try:
87
+ parser = argparse.ArgumentParser(description='Create a human-readable report out of a MISP event')
88
+ parser.add_argument("--profile", default="daily_report", help="Profile template to use")
89
+ parser.add_argument("-o", "--output", help="Output file to write to (generally ends in .adoc)")
90
+ group = parser.add_mutually_exclusive_group(required=True)
91
+ group.add_argument("-e", "--event", default=[], nargs='+', help="Event ID to get.")
92
+ group.add_argument("-p", "--path", default=[], nargs='+', help="Path to the JSON dump.")
93
+
94
+ args = parser.parse_args()
95
+
96
+ report = ReportGenerator(args.profile)
97
+ report.report_headers()
98
+
99
+ if args.event:
100
+ for eid in args.event:
101
+ report.from_remote(eid)
102
+ report.asciidoc()
103
+ else:
104
+ for f in args.path:
105
+ report.from_file(f)
106
+ report.asciidoc()
107
+
108
+ if args.output:
109
+ with open(args.output, "w") as ofile:
110
+ ofile.write(report.report)
111
+ else:
112
+ print(report.report)
113
+ except ModuleNotFoundError as err:
114
+ print(err)
examples/cache_all.py ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from keys import misp_url, misp_key, misp_verifycert
5
+ from pymisp import ExpandedPyMISP
6
+
7
+
8
+ if __name__ == '__main__':
9
+ misp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
10
+ misp.cache_all_feeds()
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import PyMISP
5
+ from keys import misp_url, misp_key, misp_verifycert
6
+ import argparse
7
+ import os
8
+
9
+ SILENT = False
10
+
11
+
12
+ def getTagToApplyToEvent(event):
13
+ tags_to_apply = set()
14
+
15
+ event_tags = { tag.name for tag in event.tags }
16
+ for galaxy in event.galaxies:
17
+ for cluster in galaxy.clusters:
18
+ event_tags.add(cluster.tag_name)
19
+
20
+ for attribute in event.attributes:
21
+ for attribute_tag in attribute.tags:
22
+ if attribute_tag.name not in event_tags:
23
+ tags_to_apply.add(attribute_tag.name)
24
+
25
+ return tags_to_apply
26
+
27
+
28
+ def TagEvent(event, tags_to_apply):
29
+ for tag in tags_to_apply:
30
+ event.add_tag(tag)
31
+ return event
32
+
33
+
34
+ def condPrint(text):
35
+ if not SILENT:
36
+ print(text)
37
+
38
+
39
+ if __name__ == '__main__':
40
+ parser = argparse.ArgumentParser(description='Get an event from a MISP instance.')
41
+ parser.add_argument("-e", "--event", required=True, help="Event ID to get.")
42
+ parser.add_argument("-y", "--yes", required=False, default=False, action='store_true', help="Automatically accept prompt.")
43
+ parser.add_argument("-s", "--silent", required=False, default=False, action='store_true', help="No output to stdin.")
44
+
45
+ args = parser.parse_args()
46
+ SILENT = args.silent
47
+
48
+ misp = PyMISP(misp_url, misp_key, misp_verifycert)
49
+
50
+ event = misp.get_event(args.event, pythonify=True)
51
+ tags_to_apply = getTagToApplyToEvent(event)
52
+ condPrint('Tag to apply at event level:')
53
+ for tag in tags_to_apply:
54
+ condPrint(f'- {tag}')
55
+
56
+ confirmed = False
57
+ if args.yes:
58
+ confirmed = True
59
+ else:
60
+ confirm = input('Confirm [Y/n]: ')
61
+ confirmed = len(confirm) == 0 or confirm == 'Y' or confirm == 'y'
62
+ if confirmed:
63
+ event = TagEvent(event, tags_to_apply)
64
+ condPrint(f'Updating event {args.event}')
65
+ misp.update_event(event)
66
+ condPrint(f'Event {args.event} tagged with {len(tags_to_apply)} tags')
67
+ else:
68
+ condPrint('Operation cancelled')
examples/copy_list.py ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import sys
5
+
6
+ from pymisp import PyMISP
7
+
8
+ from keys import cert, priv
9
+
10
+ url_cert = 'https://misp.circl.lu'
11
+ url_priv = 'https://misppriv.circl.lu'
12
+ cert_cert = 'misp.circl.lu.crt'
13
+ cert_priv = 'misppriv.circl.lu.crt'
14
+ source = None
15
+ destination = None
16
+
17
+
18
+ def init(cert_to_priv=True):
19
+ global source
20
+ global destination
21
+ print(cert_to_priv)
22
+ if cert_to_priv:
23
+ source = PyMISP(url_cert, cert, cert_cert, 'xml')
24
+ destination = PyMISP(url_priv, priv, cert_priv, 'xml')
25
+ else:
26
+ source = PyMISP(url_priv, priv, cert_priv, 'xml')
27
+ destination = PyMISP(url_cert, cert, cert_cert, 'xml')
28
+
29
+
30
+ def copy_event(event_id):
31
+ e = source.get_event(event_id)
32
+ return destination.add_event(e)
33
+
34
+
35
+ def update_event(event_id, event_to_update):
36
+ e = source.get_event(event_id)
37
+ return destination.update_event(event_to_update, e)
38
+
39
+
40
+ def list_copy(filename):
41
+ with open(filename, 'r') as f:
42
+ for l in f:
43
+ copy(l)
44
+
45
+
46
+ def loop_copy():
47
+ while True:
48
+ line = sys.stdin.readline()
49
+ copy(line)
50
+
51
+
52
+ def copy(eventid):
53
+ eventid = eventid.strip()
54
+ if len(eventid) == 0 or not eventid.isdigit():
55
+ print('empty line or NaN.')
56
+ return
57
+ eventid = int(eventid)
58
+ print(eventid, 'copying...')
59
+ r = copy_event(eventid)
60
+ if r.status_code >= 400:
61
+ loc = r.headers['location']
62
+ if loc is not None:
63
+ event_to_update = loc.split('/')[-1]
64
+ print('updating', event_to_update)
65
+ r = update_event(eventid, event_to_update)
66
+ if r.status_code >= 400:
67
+ print(r.status_code, r.headers)
68
+ else:
69
+ print(r.status_code, r.headers)
70
+ print(eventid, 'done.')
71
+
72
+
73
+ def export_our_org():
74
+ circl = source.search(org='CIRCL')
75
+ return circl
76
+
77
+ if __name__ == '__main__':
78
+ import argparse
79
+ parser = argparse.ArgumentParser(
80
+ description='Copy the events from one MISP instance to an other.')
81
+ parser.add_argument('-f', '--filename', type=str,
82
+ help='File containing a list of event id.')
83
+ parser.add_argument(
84
+ '-l', '--loop', action='store_true',
85
+ help='Endless loop: eventid in the terminal and it will be copied.')
86
+ parser.add_argument('--priv_to_cert', action='store_false', default=True,
87
+ help='Copy from MISP priv to MISP CERT.')
88
+ args = parser.parse_args()
89
+ init(args.priv_to_cert)
90
+ if args.filename is not None:
91
+ list_copy(args.filename)
92
+ else:
93
+ loop_copy()
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import ExpandedPyMISP, MISPEvent
5
+ from keys import misp_url, misp_key, misp_verifycert
6
+ import argparse
7
+
8
+
9
+ if __name__ == '__main__':
10
+ parser = argparse.ArgumentParser(description='Create an event on MISP.')
11
+ parser.add_argument("-d", "--distrib", type=int, help="The distribution setting used for the attributes and for the newly created event, if relevant. [0-3].")
12
+ parser.add_argument("-i", "--info", help="Used to populate the event info field if no event ID supplied.")
13
+ parser.add_argument("-a", "--analysis", type=int, help="The analysis level of the newly created event, if applicable. [0-2]")
14
+ parser.add_argument("-t", "--threat", type=int, help="The threat level ID of the newly created event, if applicable. [1-4]")
15
+ args = parser.parse_args()
16
+
17
+ misp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
18
+
19
+ event = MISPEvent()
20
+ event.distribution = args.distrib
21
+ event.threat_level_id = args.threat
22
+ event.analysis = args.analysis
23
+ event.info = args.info
24
+
25
+ event = misp.add_event(event, pythonify=True)
26
+ print(event)