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/__init__.py ADDED
File without changes
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import csv
5
+ from pymisp import PyMISP
6
+ from pymisp import ExpandedPyMISP, MISPAttribute
7
+ from keys import misp_url, misp_key, misp_verifycert
8
+ from requests.packages.urllib3.exceptions import InsecureRequestWarning
9
+ import argparse
10
+ import urllib3
11
+ import requests
12
+ requests.packages.urllib3.disable_warnings()
13
+
14
+
15
+ """
16
+
17
+ Sample usage:
18
+
19
+ python3 add_filetype_object_from_csv.py -e <Event_UUID> -f <formated_file_with_attributes>.csv
20
+
21
+
22
+ Attribute CSV file (aach line is an entry):
23
+
24
+ value;category;type;comment;to_ids;first_seen;last_seen;tag1;tag2
25
+ test.pdf;Payload delivery;filename;Email attachment;0;1970-01-01;1970-01-01;tlp:green;ransomware
26
+ 127.0.0.1;Network activity;ip-dst;C2 server;1;;;tlp:white;
27
+
28
+ value = IOC's value
29
+ category = its MISP category (https://www.circl.lu/doc/misp/categories-and-types/)
30
+ type = its MISP type (https://www.circl.lu/doc/misp/categories-and-types/)
31
+ comment = IOC's description
32
+ to_ids = Boolean expected (0 = IDS flag not checked // 1 = IDS flag checked)
33
+ first_seen = First seen date, if any (left empty if not)
34
+ last_seen = Last seen date, if any (left empty if not)
35
+ tag = IOC tag, if any
36
+
37
+ """
38
+
39
+ if __name__ == '__main__':
40
+ parser = argparse.ArgumentParser(description='Add attributes to a MISP event from a semi-colon formated csv file')
41
+ parser.add_argument("-e", "--event_uuid", required=True, help="Event UUID to update")
42
+ parser.add_argument("-f", "--attr_file", required=True, help="Attribute CSV file path")
43
+ args = parser.parse_args()
44
+
45
+ pymisp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
46
+
47
+ f = open(args.attr_file, newline='')
48
+ csv_reader = csv.reader(f, delimiter=";")
49
+
50
+ for line in csv_reader:
51
+ value = line[0]
52
+ category = line[1]
53
+ type = line[2]
54
+ comment = line[3]
55
+ ids = line[4]
56
+ fseen = line[5]
57
+ lseen = line[6]
58
+ tags = line[7:]
59
+
60
+ misp_attribute = MISPAttribute()
61
+ misp_attribute.value = str(value)
62
+ misp_attribute.category = str(category)
63
+ misp_attribute.type = str(type)
64
+ misp_attribute.comment = str(comment)
65
+ misp_attribute.to_ids = str(ids)
66
+ if fseen != '':
67
+ misp_attribute.first_seen = str(fseen)
68
+ if lseen != '':
69
+ misp_attribute.last_seen = str(lseen)
70
+ for x in tags:
71
+ misp_attribute.add_tag(x)
72
+ r = pymisp.add_attribute(args.event_uuid, misp_attribute)
73
+ print(line)
74
+ print("\nAttributes successfully saved :)")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from pymisp import PyMISP
4
+ from pymisp.tools import EMailObject
5
+ import traceback
6
+ from keys import misp_url, misp_key, misp_verifycert # type: ignore
7
+ import glob
8
+ import argparse
9
+
10
+
11
+ if __name__ == '__main__':
12
+ parser = argparse.ArgumentParser(description='Extract indicators out of binaries and add MISP objects to a MISP instance.')
13
+ parser.add_argument("-e", "--event", required=True, help="Event ID to update.")
14
+ parser.add_argument("-p", "--path", required=True, help="Path to process (expanded using glob).")
15
+ args = parser.parse_args()
16
+
17
+ pymisp = PyMISP(misp_url, misp_key, misp_verifycert, debug=True)
18
+
19
+ for f in glob.glob(args.path):
20
+ try:
21
+ eo = EMailObject(f)
22
+ except Exception:
23
+ traceback.print_exc()
24
+ continue
25
+
26
+ if eo:
27
+ response = pymisp.add_object(args.event, eo, pythonify=True)
28
+ for ref in eo.ObjectReference:
29
+ r = pymisp.add_object_reference(ref)
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import ExpandedPyMISP, MISPEvent
5
+ from pymisp.tools import Fail2BanObject
6
+ import argparse
7
+ from base64 import b64decode
8
+ from io import BytesIO
9
+ import os
10
+ from datetime import date, datetime
11
+ from dateutil.parser import parse
12
+
13
+
14
+ try:
15
+ from keys import misp_url, misp_key, misp_verifycert
16
+ except Exception:
17
+ misp_url = 'URL'
18
+ misp_key = 'AUTH_KEY'
19
+ misp_verifycert = True
20
+
21
+
22
+ def create_new_event():
23
+ me = MISPEvent()
24
+ me.info = "Fail2Ban blocking"
25
+ me.add_tag(args.tag)
26
+ start = datetime.now()
27
+ me.add_attribute('datetime', start.isoformat(), comment='Start Time')
28
+ return me
29
+
30
+
31
+ if __name__ == '__main__':
32
+ parser = argparse.ArgumentParser(description='Add Fail2ban object.')
33
+ parser.add_argument("-b", "--banned_ip", required=True, help="Banned IP address.")
34
+ parser.add_argument("-a", "--attack_type", required=True, help="Type of attack.")
35
+ parser.add_argument("-t", "--tag", required=True, help="Tag to search on MISP.")
36
+ parser.add_argument("-p", "--processing_timestamp", help="Processing timestamp.")
37
+ parser.add_argument("-f", "--failures", help="Amount of failures that lead to the ban.")
38
+ parser.add_argument("-s", "--sensor", help="Sensor identifier.")
39
+ parser.add_argument("-v", "--victim", help="Victim identifier.")
40
+ parser.add_argument("-l", "--logline", help="Logline (base64 encoded).")
41
+ parser.add_argument("-F", "--logfile", help="Path to a logfile to attach.")
42
+ parser.add_argument("-n", "--force_new", action='store_true', default=False, help="Force new MISP event.")
43
+ parser.add_argument("-d", "--disable_new", action='store_true', default=False, help="Do not create a new Event.")
44
+ args = parser.parse_args()
45
+
46
+ pymisp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert, debug=True)
47
+ event_id = -1
48
+ me = None
49
+ if args.force_new:
50
+ me = create_new_event()
51
+ else:
52
+ response = pymisp.search_index(tags=args.tag, timestamp='1h', pythonify=True)
53
+ if response:
54
+ if args.disable_new:
55
+ event_id = response[0].id
56
+ else:
57
+ last_event_date = parse(response[0].date).date()
58
+ nb_attr = response[0].attribute_count
59
+ if last_event_date < date.today() or int(nb_attr) > 1000:
60
+ me = create_new_event()
61
+ else:
62
+ event_id = response[0].id
63
+ else:
64
+ me = create_new_event()
65
+
66
+ parameters = {'banned-ip': args.banned_ip, 'attack-type': args.attack_type}
67
+ if args.processing_timestamp:
68
+ parameters['processing-timestamp'] = args.processing_timestamp
69
+ if args.failures:
70
+ parameters['failures'] = args.failures
71
+ if args.sensor:
72
+ parameters['sensor'] = args.sensor
73
+ if args.victim:
74
+ parameters['victim'] = args.victim
75
+ if args.logline:
76
+ parameters['logline'] = b64decode(args.logline).decode()
77
+ if args.logfile:
78
+ with open(args.logfile, 'rb') as f:
79
+ parameters['logfile'] = {'value': os.path.basename(args.logfile),
80
+ 'data': BytesIO(f.read())}
81
+ f2b = Fail2BanObject(parameters=parameters, standalone=False)
82
+ if me:
83
+ me.add_object(f2b)
84
+ pymisp.add_event(me)
85
+ elif event_id:
86
+ a = pymisp.add_object(event_id, f2b)
examples/add_feed.py ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import ExpandedPyMISP, MISPFeed
5
+ from keys import misp_url, misp_key, misp_verifycert
6
+ import argparse
7
+
8
+ if __name__ == '__main__':
9
+ parser = argparse.ArgumentParser(description='Add a feed')
10
+ parser.add_argument("-f", "--format", required=True, choices=['misp', 'csv', 'freetext'], help="Feed source format")
11
+ parser.add_argument("-u", "--url", required=True, help="URL, or local path")
12
+ parser.add_argument("-n", "--name", required=True, help="Name of the feed")
13
+ parser.add_argument("-i", "--input", required=True, choices=['local', 'network'], help="URL, or local path")
14
+ parser.add_argument("-p", "--provider", required=True, help="Provider name")
15
+ args = parser.parse_args()
16
+
17
+ pm = ExpandedPyMISP(misp_url, misp_key, misp_verifycert, debug=True)
18
+ feed = MISPFeed()
19
+ feed.format = args.format
20
+ feed.url = args.url
21
+ feed.name = args.name
22
+ feed.input = args.input
23
+ feed.provider = args.provider
24
+ response = pm.add_feed(feed, pythonify=True)
25
+ print(response.to_json())
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import PyMISP
5
+ from pymisp.tools import make_binary_objects
6
+ import traceback
7
+ from keys import misp_url, misp_key, misp_verifycert
8
+ import glob
9
+ import argparse
10
+
11
+ if __name__ == '__main__':
12
+ parser = argparse.ArgumentParser(description='Extract indicators out of binaries and add MISP objects to a MISP instance.')
13
+ parser.add_argument("-e", "--event", required=True, help="Event ID to update.")
14
+ parser.add_argument("-p", "--path", required=True, help="Path to process (expanded using glob).")
15
+ args = parser.parse_args()
16
+
17
+ pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
18
+
19
+ for f in glob.glob(args.path):
20
+ try:
21
+ fo, peo, seos = make_binary_objects(f)
22
+ except Exception:
23
+ traceback.print_exc()
24
+ continue
25
+
26
+ if seos:
27
+ for s in seos:
28
+ r = pymisp.add_object(args.event, s)
29
+
30
+ if peo:
31
+ if hasattr(peo, 'certificates') and hasattr(peo, 'signers'):
32
+ # special authenticode case for PE objects
33
+ for c in peo.certificates:
34
+ pymisp.add_object(args.event, c, pythonify=True)
35
+ for s in peo.signers:
36
+ pymisp.add_object(args.event, s, pythonify=True)
37
+ del peo.certificates
38
+ del peo.signers
39
+ del peo.sections
40
+ r = pymisp.add_object(args.event, peo, pythonify=True)
41
+ for ref in peo.ObjectReference:
42
+ r = pymisp.add_object_reference(ref)
43
+
44
+ if fo:
45
+ response = pymisp.add_object(args.event, fo, pythonify=True)
46
+ for ref in fo.ObjectReference:
47
+ r = pymisp.add_object_reference(ref)
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import csv
5
+ from pymisp import ExpandedPyMISP, MISPObject
6
+ from keys import misp_url, misp_key, misp_verifycert
7
+ import argparse
8
+
9
+
10
+ """
11
+
12
+ Sample usage:
13
+
14
+ python3 ./add_filetype_object_from_csv.py -e 77bcc9f4-21a8-4252-9353-f4615d6121e3 -f ./attributes.csv
15
+
16
+
17
+ Attribute csv file (2 lines. Each line will be a file MISP Object):
18
+
19
+ test.pdf;6ff19f8b680df260883d61d7c00db14a8bc57aa0;ea307d60ad0bd1df83ab5119df0bf638;b6c9903c9c38400345ad21faa2df50211d8878c96079c43ae64f35b17c9f74a1
20
+ test2.xml;0dcef3d68f43e2badb0bfe3d47fd19633264cd1d;15f453625882f6123e239c9ce2b0fe24;b064514fcc52a769e064c4d61ce0c554fbc81e446af31dddac810879a5ca5b17
21
+
22
+ """
23
+
24
+
25
+ if __name__ == '__main__':
26
+ parser = argparse.ArgumentParser(description='Create a file type MISP Object starting from attributes in a csv file')
27
+ parser.add_argument("-e", "--event_uuid", required=True, help="Event UUID to update")
28
+ parser.add_argument("-f", "--attr_file", required=True, help="Attribute CSV file path")
29
+ args = parser.parse_args()
30
+
31
+ pymisp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
32
+
33
+ f = open(args.attr_file, newline='')
34
+ csv_reader = csv.reader(f, delimiter=";")
35
+
36
+ for line in csv_reader:
37
+ filename = line[0]
38
+ sha1 = line[1]
39
+ md5 = line[2]
40
+ sha256 = line[3]
41
+
42
+ misp_object = MISPObject(name='file', filename=filename)
43
+ obj1 = misp_object.add_attribute("filename", value = filename)
44
+ obj1.add_tag('tlp:green')
45
+ obj2 = misp_object.add_attribute("sha1", value = sha1)
46
+ obj2.add_tag('tlp:amber')
47
+ obj3 = misp_object.add_attribute("md5", value = md5)
48
+ obj3.add_tag('tlp:amber')
49
+ obj4 = misp_object.add_attribute("sha256", value = sha256)
50
+ obj4.add_tag('tlp:amber')
51
+ r = pymisp.add_object(args.event_uuid, misp_object)
52
+ print(line)
53
+ print("\nObjects created :)")
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import json
5
+ from pymisp import ExpandedPyMISP
6
+ from pymisp.tools import GenericObjectGenerator
7
+ from keys import misp_url, misp_key, misp_verifycert
8
+ import argparse
9
+
10
+ """
11
+ Sample usage:
12
+ ./add_generic_object.py -e 5065 -t email -l '[{"to": "undisclosed@ppp.com"}, {"to": "second.to@mail.com"}]'
13
+ """
14
+
15
+ if __name__ == '__main__':
16
+ parser = argparse.ArgumentParser(description='Create a MISP Object selectable by type starting from a dictionary')
17
+ parser.add_argument("-e", "--event", required=True, help="Event ID to update")
18
+ parser.add_argument("-t", "--type", required=True, help="Type of the generic object")
19
+ parser.add_argument("-l", "--attr_list", required=True, help="List of attributes")
20
+ args = parser.parse_args()
21
+
22
+ pymisp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
23
+
24
+ misp_object = GenericObjectGenerator(args.type.replace("|", "-"))
25
+ misp_object.generate_attributes(json.loads(args.attr_list))
26
+ r = pymisp.add_object(args.event, misp_object)
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import PyMISP
5
+ from pymisp import MISPObject
6
+ from pymisp.tools import update_objects
7
+ from keys import misp_url, misp_key, misp_verifycert
8
+ import argparse
9
+ import requests
10
+ import sys
11
+
12
+
13
+ """
14
+
15
+ usage: add_github_user.py [-h] -e EVENT [-f] -u USERNAME
16
+
17
+ Fetch GitHub user details and add it in object in MISP
18
+
19
+ optional arguments:
20
+ -h, --help show this help message and exit
21
+ -e EVENT, --event EVENT
22
+ Event ID to update
23
+ -f, --force-template-update
24
+ -u USERNAME, --username USERNAME
25
+ GitHub username to add
26
+ """
27
+
28
+ if __name__ == '__main__':
29
+ parser = argparse.ArgumentParser(description='Fetch GitHub user details and add it in object in MISP')
30
+ parser.add_argument("-e", "--event", required=True, help="Event ID to update")
31
+ parser.add_argument("-f", "--force-template-update", required=False, action="store_true")
32
+ parser.add_argument("-u", "--username", required=True, help="GitHub username to add")
33
+ args = parser.parse_args()
34
+
35
+ r = requests.get("https://api.github.com/users/{}".format(args.username))
36
+ if r.status_code != 200:
37
+ sys.exit("HTTP return is {} and not 200 as expected".format(r.status_code))
38
+ if args.force_template_update:
39
+ print("Updating MISP Object templates...")
40
+ update_objects()
41
+ pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
42
+
43
+ misp_object = MISPObject(name="github-user")
44
+ github_user = r.json()
45
+ rfollowers = requests.get(github_user['followers_url'])
46
+ followers = rfollowers.json()
47
+ rfollowing = requests.get("https://api.github.com/users/{}/following".format(args.username))
48
+ followings = rfollowing.json()
49
+ rkeys = requests.get("https://api.github.com/users/{}/keys".format(args.username))
50
+ keys = rkeys.json()
51
+ misp_object.add_attributes("follower", *[follower['login'] for follower in followers])
52
+ misp_object.add_attributes("following", *[following['login'] for following in followings])
53
+ misp_object.add_attributes("ssh-public-key", *[sshkey['key'] for sshkey in keys])
54
+ misp_object.add_attribute('bio', github_user['bio'])
55
+ misp_object.add_attribute('link', github_user['html_url'])
56
+ misp_object.add_attribute('user-fullname', github_user['name'])
57
+ misp_object.add_attribute('username', github_user['login'])
58
+ misp_object.add_attribute('twitter_username', github_user['twitter_username'])
59
+ misp_object.add_attribute('location', github_user['location'])
60
+ misp_object.add_attribute('company', github_user['company'])
61
+ misp_object.add_attribute('public_gists', github_user['public_gists'])
62
+ misp_object.add_attribute('public_repos', github_user['public_repos'])
63
+ misp_object.add_attribute('blog', github_user['blog'])
64
+ misp_object.add_attribute('node_id', github_user['node_id'])
65
+ retcode = pymisp.add_object(args.event, misp_object)
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import PyMISP
5
+ from pymisp import MISPObject
6
+ from pymisp.tools import update_objects
7
+ from keys import misp_url, misp_key, misp_verifycert
8
+ import argparse
9
+ import requests
10
+ import sys
11
+
12
+ """
13
+ usage: add_gitlab_user.py [-h] -e EVENT [-f] -u USERNAME [-l LINK]
14
+
15
+ Fetch GitLab user details and add it in object in MISP
16
+
17
+ optional arguments:
18
+ -h, --help show this help message and exit
19
+ -e EVENT, --event EVENT
20
+ Event ID to update
21
+ -f, --force-template-update
22
+ -u USERNAME, --username USERNAME
23
+ GitLab username to add
24
+ -l LINK, --link LINK Url to access the GitLab instance, Default is
25
+ www.gitlab.com.
26
+ """
27
+
28
+ default_url = "http://www.gitlab.com/"
29
+
30
+ parser = argparse.ArgumentParser(description='Fetch GitLab user details and add it in object in MISP')
31
+ parser.add_argument("-e", "--event", required=True, help="Event ID to update")
32
+ parser.add_argument("-f", "--force-template-update", required=False, action="store_true")
33
+ parser.add_argument("-u", "--username", required=True, help="GitLab username to add")
34
+ parser.add_argument("-l", "--link", required=False, help="Url to access the GitLab instance, Default is www.gitlab.com.", default=default_url)
35
+ args = parser.parse_args()
36
+
37
+
38
+ r = requests.get("{}api/v4/users?username={}".format(args.link, args.username))
39
+ if r.status_code != 200:
40
+ sys.exit("HTTP return is {} and not 200 as expected".format(r.status_code))
41
+ if args.force_template_update:
42
+ print("Updating MISP Object templates...")
43
+ update_objects()
44
+
45
+ gitlab_user = r.json()[0]
46
+ pymisp = PyMISP(misp_url, misp_key, misp_verifycert)
47
+ print(gitlab_user)
48
+
49
+ misp_object = MISPObject(name="gitlab-user")
50
+ misp_object.add_attribute('username', gitlab_user['username'])
51
+ misp_object.add_attribute('id', gitlab_user['id'])
52
+ misp_object.add_attribute('name', gitlab_user['name'])
53
+ misp_object.add_attribute('state', gitlab_user['state'])
54
+ misp_object.add_attribute('avatar_url', gitlab_user['avatar_url'])
55
+ misp_object.add_attribute('web_url', gitlab_user['web_url'])
56
+ retcode = pymisp.add_object(args.event, misp_object)
@@ -0,0 +1,25 @@
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
+ # For python2 & 3 compat, a bit dirty, but it seems to be the least bad one
9
+ try:
10
+ input = raw_input
11
+ except NameError:
12
+ pass
13
+
14
+
15
+ if __name__ == '__main__':
16
+ parser = argparse.ArgumentParser(description='Add an attribute to an event')
17
+ parser.add_argument("-e", "--event", help="The id, uuid or json of the event to update.")
18
+ parser.add_argument("-t", "--type", help="The type of the added attribute")
19
+ parser.add_argument("-v", "--value", help="The value of the attribute")
20
+ args = parser.parse_args()
21
+
22
+ misp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
23
+
24
+ event = misp.add_attribute(args.event, {'type': args.type, 'value': args.value}, pythonify=True)
25
+ print(event)
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import ExpandedPyMISP, MISPOrganisation, MISPSharingGroup
5
+ from keys import misp_url, misp_key, misp_verifycert
6
+ import argparse
7
+ import csv
8
+
9
+
10
+ # Suppress those "Unverified HTTPS request is being made"
11
+ import urllib3
12
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
13
+
14
+
15
+ if __name__ == '__main__':
16
+ parser = argparse.ArgumentParser(description='Add organizations from a CSV file')
17
+ parser.add_argument("-c", "--csv-import", required=True, help="The CSV file containing the organizations. Format 'orgname,nationality,sector,type,contacts,uuid,local,sharingroup_uuid'")
18
+ args = parser.parse_args()
19
+
20
+ misp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert)
21
+
22
+ # CSV format
23
+ # orgname,nationality,sector,type,contacts,uuid,local,sharingroup
24
+ with open(args.csv_import) as csv_file:
25
+ count_orgs = 0
26
+ csv_reader = csv.reader(csv_file, delimiter=',')
27
+ for row in csv_reader:
28
+
29
+ org = MISPOrganisation()
30
+ org.name = row[0]
31
+ print("Process {}".format(org.name))
32
+ org.nationality = row[1]
33
+ org.sector = row[2]
34
+ org.type = row[3]
35
+ org.contacts = row[4]
36
+ org.uuid = row[5]
37
+ org.local = row[6]
38
+
39
+ add_org = misp.add_organisation(org, pythonify=True)
40
+
41
+ if 'errors' in add_org:
42
+ print(add_org['errors'])
43
+ else:
44
+ count_orgs = count_orgs + 1
45
+ org_uuid = add_org.uuid
46
+
47
+ if org_uuid:
48
+ sharinggroup = MISPSharingGroup()
49
+ sharinggroup_uuid = row[7]
50
+
51
+ if sharinggroup_uuid:
52
+ sharinggroup.uuid = sharinggroup_uuid
53
+ add_sharing = misp.add_org_to_sharing_group(sharinggroup, org)
54
+ else:
55
+ print("Organisation {} not added to sharing group, missing sharing group uuid".format(org.name))
56
+
57
+ print("Import finished, {} organisations added".format(count_orgs))
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import ExpandedPyMISP
5
+ from pymisp.tools import SSHAuthorizedKeysObject
6
+ import traceback
7
+ from keys import misp_url, misp_key, misp_verifycert
8
+ import glob
9
+ import argparse
10
+
11
+
12
+ if __name__ == '__main__':
13
+ parser = argparse.ArgumentParser(description='Extract indicators out of authorized_keys file.')
14
+ parser.add_argument("-e", "--event", required=True, help="Event ID to update.")
15
+ parser.add_argument("-p", "--path", required=True, help="Path to process (expanded using glob).")
16
+ args = parser.parse_args()
17
+
18
+ pymisp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert, debug=True)
19
+
20
+ for f in glob.glob(args.path):
21
+ try:
22
+ auth_keys = SSHAuthorizedKeysObject(f)
23
+ except Exception:
24
+ traceback.print_exc()
25
+ continue
26
+
27
+ response = pymisp.add_object(args.event, auth_keys, pythonify=True)
28
+ for ref in auth_keys.ObjectReference:
29
+ r = pymisp.add_object_reference(ref)
examples/add_user.py ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp import ExpandedPyMISP, MISPUser
5
+ from keys import misp_url, misp_key, misp_verifycert
6
+ import argparse
7
+
8
+ if __name__ == '__main__':
9
+ parser = argparse.ArgumentParser(description='Add a new user by setting the mandory fields.')
10
+ parser.add_argument("-e", "--email", required=True, help="Email linked to the account.")
11
+ parser.add_argument("-o", "--org_id", required=True, help="Organisation linked to the user.")
12
+ parser.add_argument("-r", "--role_id", required=True, help="Role linked to the user.")
13
+ args = parser.parse_args()
14
+
15
+ misp = ExpandedPyMISP(misp_url, misp_key, misp_verifycert, 'json')
16
+
17
+ user = MISPUser()
18
+ user.email = args.email
19
+ user.org_id = args.org_id
20
+ user.role_id = args.role_id
21
+
22
+ print(misp.add_user(user, pythonify=True))
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pymisp.tools import VehicleObject
5
+ import argparse
6
+
7
+
8
+ if __name__ == '__main__':
9
+ parser = argparse.ArgumentParser(description='Get information for a VehicleObject and add MISP objects to a MISP instance.')
10
+ parser.add_argument("-u", "--username", required=True, help="Account username.")
11
+ parser.add_argument("-c", "--country", required=True, help="Country.")
12
+ parser.add_argument("-r", "--registration", required=True, help="Registration ID.")
13
+ parser.add_argument("-d", "--dump", action='store_true', help="(Debug) Dump the object in the terminal.")
14
+ args = parser.parse_args()
15
+
16
+ if args.dump:
17
+ vehicle = VehicleObject(country=args.country, registration=args.registration, username=args.username)
18
+ print(vehicle.report)
19
+ print(vehicle.to_json())
20
+ else:
21
+ # not Implemented yet.
22
+ pass