mmisp-lib 0.1.0__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.
Files changed (161) hide show
  1. mmisp/api_schemas/__init__.py +0 -0
  2. mmisp/api_schemas/attributes/__init__.py +0 -0
  3. mmisp/api_schemas/attributes/add_attribute_body.py +34 -0
  4. mmisp/api_schemas/attributes/add_attribute_response.py +33 -0
  5. mmisp/api_schemas/attributes/add_remove_tag_attribute_response.py +13 -0
  6. mmisp/api_schemas/attributes/delete_attribute_response.py +8 -0
  7. mmisp/api_schemas/attributes/delete_selected_attribute_body.py +9 -0
  8. mmisp/api_schemas/attributes/delete_selected_attribute_response.py +13 -0
  9. mmisp/api_schemas/attributes/edit_attribute_body.py +24 -0
  10. mmisp/api_schemas/attributes/edit_attributes_response.py +42 -0
  11. mmisp/api_schemas/attributes/get_all_attributes_response.py +38 -0
  12. mmisp/api_schemas/attributes/get_attribute_response.py +41 -0
  13. mmisp/api_schemas/attributes/get_attribute_statistics_response.py +137 -0
  14. mmisp/api_schemas/attributes/get_describe_types_response.py +29 -0
  15. mmisp/api_schemas/attributes/restore_attribute_reponse.py +25 -0
  16. mmisp/api_schemas/attributes/search_attributes_body.py +74 -0
  17. mmisp/api_schemas/attributes/search_attributes_response.py +52 -0
  18. mmisp/api_schemas/auth_keys/__init__.py +0 -0
  19. mmisp/api_schemas/auth_keys/add_auth_key_body.py +10 -0
  20. mmisp/api_schemas/auth_keys/add_auth_key_response.py +20 -0
  21. mmisp/api_schemas/auth_keys/edit_auth_key_body.py +8 -0
  22. mmisp/api_schemas/auth_keys/edit_auth_key_response.py +24 -0
  23. mmisp/api_schemas/auth_keys/search_auth_keys_body.py +17 -0
  24. mmisp/api_schemas/auth_keys/search_get_all_auth_keys_users_response.py +28 -0
  25. mmisp/api_schemas/auth_keys/view_auth_key_response.py +24 -0
  26. mmisp/api_schemas/authentication/__init__.py +0 -0
  27. mmisp/api_schemas/authentication/exchange_token_login_body.py +5 -0
  28. mmisp/api_schemas/authentication/password_login_body.py +6 -0
  29. mmisp/api_schemas/authentication/start_login_body.py +5 -0
  30. mmisp/api_schemas/authentication/start_login_response.py +21 -0
  31. mmisp/api_schemas/authentication/token_response.py +5 -0
  32. mmisp/api_schemas/events/FreeTextImportWorkerBody.py +17 -0
  33. mmisp/api_schemas/events/__init__.py +0 -0
  34. mmisp/api_schemas/events/add_attribute_via_free_text_import_event_body.py +12 -0
  35. mmisp/api_schemas/events/add_attribute_via_free_text_import_event_response.py +14 -0
  36. mmisp/api_schemas/events/add_edit_get_event_response.py +234 -0
  37. mmisp/api_schemas/events/add_event_body.py +30 -0
  38. mmisp/api_schemas/events/add_remove_tag_events_response.py +11 -0
  39. mmisp/api_schemas/events/delete_event_response.py +14 -0
  40. mmisp/api_schemas/events/edit_event_body.py +28 -0
  41. mmisp/api_schemas/events/get_all_events_response.py +99 -0
  42. mmisp/api_schemas/events/get_event_response.py +8 -0
  43. mmisp/api_schemas/events/index_events_body.py +30 -0
  44. mmisp/api_schemas/events/index_events_response.py +40 -0
  45. mmisp/api_schemas/events/publish_event_response.py +13 -0
  46. mmisp/api_schemas/events/search_events_body.py +43 -0
  47. mmisp/api_schemas/events/search_events_response.py +10 -0
  48. mmisp/api_schemas/events/unpublish_event_response.py +13 -0
  49. mmisp/api_schemas/feeds/__init__.py +0 -0
  50. mmisp/api_schemas/feeds/cache_feed_response.py +12 -0
  51. mmisp/api_schemas/feeds/create_feed_body.py +30 -0
  52. mmisp/api_schemas/feeds/enable_disable_feed_response.py +10 -0
  53. mmisp/api_schemas/feeds/fetch_feeds_response.py +8 -0
  54. mmisp/api_schemas/feeds/get_feed_response.py +47 -0
  55. mmisp/api_schemas/feeds/toggle_feed_body.py +8 -0
  56. mmisp/api_schemas/feeds/update_feed_body.py +30 -0
  57. mmisp/api_schemas/galaxies/__init__.py +0 -0
  58. mmisp/api_schemas/galaxies/attach_galaxy_cluster_body.py +12 -0
  59. mmisp/api_schemas/galaxies/attach_galaxy_cluster_response.py +10 -0
  60. mmisp/api_schemas/galaxies/delete_force_update_import_galaxy_response.py +12 -0
  61. mmisp/api_schemas/galaxies/export_galaxies_body.py +16 -0
  62. mmisp/api_schemas/galaxies/export_galaxies_response.py +44 -0
  63. mmisp/api_schemas/galaxies/galaxy_schema.py +18 -0
  64. mmisp/api_schemas/galaxies/get_all_search_galaxies_response.py +22 -0
  65. mmisp/api_schemas/galaxies/get_galaxy_response.py +37 -0
  66. mmisp/api_schemas/galaxies/import_galaxies_body.py +15 -0
  67. mmisp/api_schemas/galaxies/search_galaxies_body.py +22 -0
  68. mmisp/api_schemas/noticelists/__init__.py +0 -0
  69. mmisp/api_schemas/noticelists/get_all_noticelist_response.py +10 -0
  70. mmisp/api_schemas/noticelists/get_noticelist_response.py +38 -0
  71. mmisp/api_schemas/objects/__init__.py +0 -0
  72. mmisp/api_schemas/objects/create_object_body.py +19 -0
  73. mmisp/api_schemas/objects/get_object_response.py +50 -0
  74. mmisp/api_schemas/objects/search_objects_body.py +49 -0
  75. mmisp/api_schemas/organisations/__init__.py +0 -0
  76. mmisp/api_schemas/organisations/organisation.py +24 -0
  77. mmisp/api_schemas/roles/__init__.py +0 -0
  78. mmisp/api_schemas/roles/role.py +71 -0
  79. mmisp/api_schemas/sharing_groups/__init__.py +0 -0
  80. mmisp/api_schemas/sharing_groups/add_org_to_sharing_group_body.py +6 -0
  81. mmisp/api_schemas/sharing_groups/add_org_to_sharing_group_legacy_body.py +5 -0
  82. mmisp/api_schemas/sharing_groups/add_server_to_sharing_group_body.py +6 -0
  83. mmisp/api_schemas/sharing_groups/add_server_to_sharing_group_legacy_body.py +5 -0
  84. mmisp/api_schemas/sharing_groups/create_sharing_group_body.py +12 -0
  85. mmisp/api_schemas/sharing_groups/create_sharing_group_legacy_body.py +23 -0
  86. mmisp/api_schemas/sharing_groups/create_sharing_group_legacy_response.py +18 -0
  87. mmisp/api_schemas/sharing_groups/delete_sharing_group_legacy_response.py +5 -0
  88. mmisp/api_schemas/sharing_groups/get_all_sharing_groups_response.py +53 -0
  89. mmisp/api_schemas/sharing_groups/get_sharing_group_info_response.py +44 -0
  90. mmisp/api_schemas/sharing_groups/sharing_group.py +19 -0
  91. mmisp/api_schemas/sharing_groups/sharing_group_org.py +8 -0
  92. mmisp/api_schemas/sharing_groups/sharing_group_server.py +8 -0
  93. mmisp/api_schemas/sharing_groups/update_sharing_group_body.py +10 -0
  94. mmisp/api_schemas/sharing_groups/update_sharing_group_legacy_body.py +28 -0
  95. mmisp/api_schemas/sharing_groups/view_update_sharing_group_legacy_response.py +40 -0
  96. mmisp/api_schemas/sightings/__init__.py +0 -0
  97. mmisp/api_schemas/sightings/create_sighting_body.py +49 -0
  98. mmisp/api_schemas/sightings/get_sighting_response.py +27 -0
  99. mmisp/api_schemas/standard_status_response.py +13 -0
  100. mmisp/api_schemas/tags/__init__.py +0 -0
  101. mmisp/api_schemas/tags/create_tag_body.py +15 -0
  102. mmisp/api_schemas/tags/delete_tag_response.py +10 -0
  103. mmisp/api_schemas/tags/get_tag_response.py +31 -0
  104. mmisp/api_schemas/tags/search_tags_response.py +26 -0
  105. mmisp/api_schemas/tags/update_tag_body.py +15 -0
  106. mmisp/api_schemas/taxonomies/__init__.py +0 -0
  107. mmisp/api_schemas/taxonomies/export_taxonomies_response.py +30 -0
  108. mmisp/api_schemas/taxonomies/get_taxonomy_by_id_response.py +30 -0
  109. mmisp/api_schemas/taxonomies/get_taxonomy_response.py +21 -0
  110. mmisp/api_schemas/taxonomies/get_taxonomy_tags_response.py +32 -0
  111. mmisp/api_schemas/user_settings/__init__.py +0 -0
  112. mmisp/api_schemas/user_settings/get_uid_user_setting_response.py +21 -0
  113. mmisp/api_schemas/user_settings/get_user_settings_response.py +13 -0
  114. mmisp/api_schemas/user_settings/search_user_setting_body.py +7 -0
  115. mmisp/api_schemas/user_settings/search_user_setting_response.py +11 -0
  116. mmisp/api_schemas/user_settings/set_user_setting_body.py +5 -0
  117. mmisp/api_schemas/user_settings/set_user_setting_response.py +13 -0
  118. mmisp/api_schemas/user_settings/view_user_setting_response.py +13 -0
  119. mmisp/api_schemas/users/__init__.py +0 -0
  120. mmisp/api_schemas/users/user.py +42 -0
  121. mmisp/api_schemas/users/users_view_me_response.py +12 -0
  122. mmisp/api_schemas/warninglists/__init__.py +0 -0
  123. mmisp/api_schemas/warninglists/check_value_warninglists_body.py +8 -0
  124. mmisp/api_schemas/warninglists/check_value_warninglists_response.py +14 -0
  125. mmisp/api_schemas/warninglists/create_warninglist_body.py +220 -0
  126. mmisp/api_schemas/warninglists/delete_warninglist_response.py +13 -0
  127. mmisp/api_schemas/warninglists/get_selected_all_warninglists_response.py +14 -0
  128. mmisp/api_schemas/warninglists/get_selected_warninglists_body.py +9 -0
  129. mmisp/api_schemas/warninglists/toggle_enable_warninglists_body.py +10 -0
  130. mmisp/api_schemas/warninglists/toggle_enable_warninglists_response.py +10 -0
  131. mmisp/api_schemas/warninglists/warninglist_response.py +42 -0
  132. mmisp/db/__init__.py +0 -0
  133. mmisp/db/config.py +17 -0
  134. mmisp/db/database.py +42 -0
  135. mmisp/db/models/__init__.py +0 -0
  136. mmisp/db/models/attribute.py +92 -0
  137. mmisp/db/models/auth_key.py +24 -0
  138. mmisp/db/models/event.py +62 -0
  139. mmisp/db/models/feed.py +32 -0
  140. mmisp/db/models/galaxy.py +22 -0
  141. mmisp/db/models/galaxy_cluster.py +52 -0
  142. mmisp/db/models/identity_provider.py +22 -0
  143. mmisp/db/models/noticelist.py +22 -0
  144. mmisp/db/models/object.py +39 -0
  145. mmisp/db/models/organisation.py +26 -0
  146. mmisp/db/models/role.py +42 -0
  147. mmisp/db/models/server.py +33 -0
  148. mmisp/db/models/sharing_group.py +43 -0
  149. mmisp/db/models/sighting.py +21 -0
  150. mmisp/db/models/tag.py +19 -0
  151. mmisp/db/models/taxonomy.py +41 -0
  152. mmisp/db/models/user.py +44 -0
  153. mmisp/db/models/user_setting.py +29 -0
  154. mmisp/db/models/warninglist.py +33 -0
  155. mmisp/db/print_changes.py +59 -0
  156. mmisp/lib/__init__.py +0 -0
  157. mmisp/lib/attributes.py +1386 -0
  158. mmisp_lib-0.1.0.dist-info/METADATA +77 -0
  159. mmisp_lib-0.1.0.dist-info/RECORD +161 -0
  160. mmisp_lib-0.1.0.dist-info/WHEEL +5 -0
  161. mmisp_lib-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,92 @@
1
+ from typing import Self, Type
2
+
3
+ from sqlalchemy import BigInteger, Boolean, Column, ForeignKey, Integer, String, Text, inspect
4
+ from sqlalchemy.ext.hybrid import hybrid_property
5
+ from sqlalchemy.orm import relationship
6
+ from sqlalchemy.orm.decl_api import DeclarativeMeta
7
+
8
+ from mmisp.lib.attributes import categories, default_category, mapper_safe_clsname_val, to_ids
9
+ from mmisp.util.uuid import uuid
10
+
11
+ from ..database import Base
12
+ from .event import Event
13
+ from .tag import Tag
14
+
15
+
16
+ class DictMixin:
17
+ def asdict(self: Self) -> dict:
18
+ d = {}
19
+ for key in self.__mapper__.c.keys():
20
+ if not key.startswith("_"):
21
+ d[key] = getattr(self, key)
22
+
23
+ for key, prop in inspect(self.__class__).all_orm_descriptors.items():
24
+ if isinstance(prop, hybrid_property):
25
+ d[key] = getattr(self, key)
26
+ return d
27
+
28
+
29
+ class Attribute(Base, DictMixin):
30
+ __tablename__ = "attributes"
31
+
32
+ id = Column(Integer, primary_key=True, nullable=False)
33
+ uuid = Column(String(40), unique=True, default=uuid, index=True)
34
+ event_id = Column(Integer, ForeignKey("events.id", ondelete="CASCADE"), nullable=False, index=True)
35
+ object_id = Column(Integer, nullable=False, default=0, index=True)
36
+ object_relation = Column(String(255), index=True)
37
+ category = Column(String(255), nullable=False, index=True)
38
+ type = Column(String(100), nullable=False, index=True)
39
+ value1 = Column(Text, nullable=False)
40
+ value2 = Column(Text, nullable=False, default="")
41
+ to_ids = Column(Boolean, default=True, nullable=False)
42
+ timestamp = Column(Integer, nullable=False, default=0)
43
+ distribution = Column(Integer, nullable=False, default=0)
44
+ sharing_group_id = Column(Integer, index=True, default=0)
45
+ comment = Column(Text)
46
+ deleted = Column(Boolean, nullable=False, default=False)
47
+ disable_correlation = Column(Boolean, nullable=False, default=False)
48
+ first_seen = Column(BigInteger, index=True)
49
+ last_seen = Column(BigInteger, index=True)
50
+
51
+ event = relationship("Event", back_populates="attributes", lazy="joined")
52
+
53
+ @property
54
+ def event_uuid(self: "Attribute") -> str:
55
+ return self.event.uuid
56
+
57
+ @hybrid_property
58
+ def value(self: Self) -> str:
59
+ if self.value2 == "":
60
+ return self.value1
61
+ return f"{self.value1}|{self.value2}"
62
+
63
+ @value.setter
64
+ def value(self: Self, value: str) -> None:
65
+ split = value.split("|", 1)
66
+ self.value1 = split[0]
67
+ if len(split) == 2:
68
+ self.value2 = split[1]
69
+
70
+
71
+ class AttributeTag(Base):
72
+ __tablename__ = "attribute_tags"
73
+
74
+ id = Column(Integer, primary_key=True, nullable=False)
75
+ attribute_id = Column(Integer, ForeignKey(Attribute.id, ondelete="CASCADE"), nullable=False, index=True)
76
+ event_id = Column(Integer, ForeignKey(Event.id, ondelete="CASCADE"), nullable=False, index=True)
77
+ tag_id = Column(Integer, ForeignKey(Tag.id, ondelete="CASCADE"), nullable=False, index=True)
78
+ local = Column(Boolean, nullable=False, default=False)
79
+
80
+
81
+ class AttributeMeta(DeclarativeMeta):
82
+ def __new__(cls: Type[type], clsname: str, bases: tuple, dct: dict) -> "AttributeMeta":
83
+ key = clsname[len("Attribute") :]
84
+ dct["default_category"] = default_category[mapper_safe_clsname_val[key]]
85
+ dct["categories"] = categories[mapper_safe_clsname_val[key]]
86
+ dct["to_ids"] = to_ids[mapper_safe_clsname_val[key]]
87
+ dct["__mapper_args__"] = {"polymorphic_identity": mapper_safe_clsname_val[key]}
88
+ return super().__new__(cls, clsname, bases, dct)
89
+
90
+
91
+ for k, _ in mapper_safe_clsname_val.items():
92
+ vars()["Attribute" + k] = AttributeMeta("Attribute" + k, (Attribute,), dict())
@@ -0,0 +1,24 @@
1
+ from time import time
2
+
3
+ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
4
+
5
+ from mmisp.util.uuid import uuid
6
+
7
+ from ..database import Base
8
+
9
+
10
+ class AuthKey(Base):
11
+ __tablename__ = "auth_keys"
12
+
13
+ id = Column(Integer, primary_key=True, nullable=False)
14
+ uuid = Column(String(255), unique=True, default=uuid, nullable=False)
15
+ authkey = Column(String(255), nullable=False)
16
+ authkey_start = Column(String(255), nullable=False)
17
+ authkey_end = Column(String(255), nullable=False)
18
+ created = Column(Integer, nullable=False, default=time)
19
+ expiration = Column(Integer, nullable=False, default=0)
20
+ read_only = Column(Boolean, nullable=False, default=0)
21
+ comment = Column(String(255))
22
+ allowed_ips = Column(String(255))
23
+ unique_ips = Column(String(255))
24
+ user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
@@ -0,0 +1,62 @@
1
+ from datetime import datetime
2
+
3
+ from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
4
+ from sqlalchemy.orm import relationship
5
+
6
+ from mmisp.util.uuid import uuid
7
+
8
+ from ..database import Base
9
+ from .organisation import Organisation
10
+ from .tag import Tag
11
+ from .user import User
12
+
13
+
14
+ class Event(Base):
15
+ __tablename__ = "events"
16
+
17
+ id = Column(Integer, primary_key=True, nullable=False)
18
+ uuid = Column(String(40), unique=True, default=uuid, nullable=False, index=True)
19
+ org_id = Column(Integer, ForeignKey(Organisation.id), nullable=False, index=True)
20
+ date = Column(DateTime, default=datetime.utcnow, nullable=False)
21
+ info = Column(Text, nullable=False)
22
+ user_id = Column(Integer, ForeignKey(User.id), nullable=False)
23
+ published = Column(Boolean, nullable=False, default=False)
24
+ analysis = Column(Integer, nullable=False)
25
+ attribute_count = Column(Integer, default=0)
26
+ orgc_id = Column(Integer, ForeignKey(Organisation.id), nullable=False, index=True)
27
+ timestamp = Column(Integer, nullable=False, default=0)
28
+ distribution = Column(Integer, nullable=False, default=0)
29
+ sharing_group_id = Column(Integer, nullable=False, index=True, default=0)
30
+ proposal_email_lock = Column(Boolean, nullable=False, default=False)
31
+ locked = Column(Boolean, nullable=False, default=False)
32
+ threat_level_id = Column(Integer, nullable=False)
33
+ publish_timestamp = Column(Integer, nullable=False, default=0)
34
+ sighting_timestamp = Column(Integer, nullable=False, default=0)
35
+ disable_correlation = Column(Boolean, nullable=False, default=False)
36
+ extends_uuid = Column(String(40), default="", index=True)
37
+ protected = Column(Boolean)
38
+
39
+ attributes = relationship("Attribute", back_populates="event")
40
+
41
+
42
+ class EventReport(Base):
43
+ __tablename__ = "event_reports"
44
+
45
+ id = Column(Integer, primary_key=True, nullable=False)
46
+ uuid = Column(String(40), unique=True, nullable=False, default=uuid)
47
+ event_id = Column(Integer, ForeignKey(Event.id), nullable=False, index=True)
48
+ name = Column(String(255), nullable=False, index=True)
49
+ content = Column(Text)
50
+ distribution = Column(Integer, nullable=False, default=0)
51
+ sharing_group_id = Column(Integer)
52
+ timestamp = Column(Integer, nullable=False)
53
+ deleted = Column(Boolean, nullable=False, default=False)
54
+
55
+
56
+ class EventTag(Base):
57
+ __tablename__ = "event_tags"
58
+
59
+ id = Column(Integer, primary_key=True, nullable=False)
60
+ event_id = Column(Integer, ForeignKey(Event.id, ondelete="CASCADE"), nullable=False, index=True)
61
+ tag_id = Column(Integer, ForeignKey(Tag.id, ondelete="CASCADE"), nullable=False, index=True)
62
+ local = Column(Boolean, nullable=False, default=False)
@@ -0,0 +1,32 @@
1
+ from sqlalchemy import Boolean, Column, Integer, String, Text
2
+
3
+ from mmisp.db.database import Base
4
+
5
+
6
+ class Feed(Base):
7
+ __tablename__ = "feeds"
8
+
9
+ id = Column(Integer, primary_key=True, nullable=False)
10
+ name = Column(String(255), nullable=False)
11
+ provider = Column(String(255), nullable=False)
12
+ url = Column(String(255), nullable=False)
13
+ rules = Column(Text, default=None)
14
+ enabled = Column(Boolean, default=False)
15
+ distribution = Column(Integer, nullable=False, default=0)
16
+ sharing_group_id = Column(Integer, nullable=False, default=0, index=True)
17
+ tag_id = Column(Integer, nullable=False, default=0)
18
+ default = Column(Boolean, default=False)
19
+ source_format = Column(String(255), default="misp")
20
+ fixed_event = Column(Boolean, nullable=False, default=False)
21
+ delta_merge = Column(Boolean, nullable=False, default=False)
22
+ event_id = Column(Integer, nullable=False, default=0)
23
+ publish = Column(Boolean, nullable=False, default=False)
24
+ override_ids = Column(Boolean, nullable=False, default=False)
25
+ settings = Column(Text)
26
+ input_source = Column(String(255), nullable=False, default="network", index=True)
27
+ delete_local_file = Column(Boolean, default=False)
28
+ lookup_visible = Column(Boolean, default=False)
29
+ headers = Column(Text)
30
+ caching_enabled = Column(Boolean, nullable=False, default=False)
31
+ force_to_ids = Column(Boolean, nullable=False, default=False)
32
+ orgc_id = Column(Integer, nullable=False, default=0, index=True)
@@ -0,0 +1,22 @@
1
+ from sqlalchemy import Boolean, Column, Integer, String, Text
2
+
3
+ from mmisp.util.uuid import uuid
4
+
5
+ from ..database import Base
6
+
7
+
8
+ class Galaxy(Base):
9
+ __tablename__ = "galaxies"
10
+
11
+ id = Column(Integer, primary_key=True, nullable=False)
12
+ uuid = Column(String(255), nullable=False, unique=True, default=uuid)
13
+ name = Column(String(255), nullable=False, default="", index=True)
14
+ type = Column(String(255), nullable=False, index=True)
15
+ description = Column(Text, nullable=False)
16
+ version = Column(String(255), nullable=False)
17
+ icon = Column(String(255), nullable=False, default="")
18
+ namespace = Column(String(255), nullable=False, default="misp", index=True)
19
+ kill_chain_order = Column(String(255))
20
+ """must be serialized"""
21
+ enabled = Column(Boolean, nullable=False, default=True)
22
+ local_only = Column(Boolean, default=False)
@@ -0,0 +1,52 @@
1
+ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text
2
+
3
+ from mmisp.util.uuid import uuid
4
+
5
+ from ..database import Base
6
+ from .galaxy import Galaxy
7
+
8
+
9
+ class GalaxyCluster(Base):
10
+ __tablename__ = "galaxy_clusters"
11
+
12
+ id = Column(Integer, primary_key=True, nullable=False)
13
+ uuid = Column(String(255), unique=True, default=uuid, index=True)
14
+ collection_uuid = Column(String(255), nullable=False, index=True, default="0")
15
+ type = Column(String(255), nullable=False, index=True)
16
+ value = Column(Text, nullable=False)
17
+ tag_name = Column(String(255), nullable=False, default="", index=True)
18
+ description = Column(Text, nullable=False)
19
+ galaxy_id = Column(Integer, ForeignKey(Galaxy.id, ondelete="CASCADE"), nullable=False, index=True)
20
+ source = Column(String(255), nullable=False, default="")
21
+ authors = Column(Text, nullable=False)
22
+ version = Column(Integer, default=0, index=True)
23
+ distribution = Column(Integer, nullable=False, default=0)
24
+ sharing_group_id = Column(Integer, index=True, default=0)
25
+ org_id = Column(Integer, nullable=False, index=True, default=0)
26
+ orgc_id = Column(Integer, nullable=False, index=True, default=0)
27
+ default = Column(Boolean, nullable=False, default=False, index=True)
28
+ locked = Column(Boolean, nullable=False, default=False)
29
+ extends_uuid = Column(String(40), index=True)
30
+ extends_version = Column(Integer, default=0, index=True)
31
+ published = Column(Boolean, nullable=False, default=False)
32
+ deleted = Column(Boolean, nullable=False, default=False)
33
+
34
+
35
+ class GalaxyElement(Base):
36
+ __tablename__ = "galaxy_elements"
37
+
38
+ id = Column(Integer, primary_key=True, nullable=False)
39
+ galaxy_cluster_id = Column(Integer, ForeignKey(GalaxyCluster.id, ondelete="CASCADE"), nullable=False, index=True)
40
+ key = Column(String(255), nullable=False, default="", index=True)
41
+ value = Column(Text, nullable=False)
42
+
43
+
44
+ class GalaxyReference(Base):
45
+ __tablename__ = "galaxy_reference"
46
+
47
+ id = Column(Integer, primary_key=True, nullable=False)
48
+ galaxy_cluster_id = Column(Integer, ForeignKey(GalaxyCluster.id, ondelete="CASCADE"), nullable=False, index=True)
49
+ referenced_galaxy_cluster_id = Column(Integer, nullable=False, index=True)
50
+ referenced_galaxy_cluster_uuid = Column(String(255), nullable=False, index=True)
51
+ referenced_galaxy_cluster_type = Column(Text, nullable=False)
52
+ referenced_galaxy_cluster_value = Column(Text, nullable=False)
@@ -0,0 +1,22 @@
1
+ from datetime import datetime
2
+
3
+ from sqlalchemy import Boolean, Column, DateTime, Integer, String
4
+
5
+ from ..database import Base
6
+
7
+
8
+ class OIDCIdentityProvider(Base):
9
+ __tablename__ = "oidc_identity_providers"
10
+
11
+ id = Column(Integer, primary_key=True)
12
+ name = Column(String(255), nullable=False)
13
+ org_id = Column(Integer, nullable=False)
14
+ active = Column(Boolean, default=True)
15
+ base_url = Column(String(255), nullable=False)
16
+ client_id = Column(String(255), nullable=False)
17
+ client_secret = Column(String(255), nullable=False)
18
+ scope = Column(String(255))
19
+ """Possibility to add more scopes to be requested from the idp in addition to the default scopes,
20
+ currently not used."""
21
+ created = Column(DateTime, default=datetime.utcnow)
22
+ modified = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
@@ -0,0 +1,22 @@
1
+ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text
2
+
3
+ from mmisp.db.database import Base
4
+
5
+
6
+ class Noticelist(Base):
7
+ __tablename__ = "noticelists"
8
+
9
+ id = Column(Integer, primary_key=True, nullable=False)
10
+ name = Column(String(255), nullable=False, index=True)
11
+ expanded_name = Column(String(255), nullable=False)
12
+ ref = Column(String(255)) # data serialized as json
13
+ geographical_area = Column(String(255)) # data serialized as json
14
+ version = Column(Integer, nullable=False, default=1)
15
+ enabled = Column(Boolean, nullable=False, default=False)
16
+
17
+
18
+ class NoticelistEntry(Base):
19
+ __tablename__ = "noticelist_entries"
20
+ id = Column(Integer, primary_key=True, nullable=False)
21
+ noticelist_id = Column(Integer, ForeignKey(Noticelist.id, ondelete="CASCADE"), nullable=False)
22
+ data = Column(Text, nullable=False) # data serialized as json
@@ -0,0 +1,39 @@
1
+ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
2
+
3
+ from mmisp.db.database import Base
4
+ from mmisp.util.uuid import uuid
5
+
6
+
7
+ class Object(Base):
8
+ __tablename__ = "objects"
9
+
10
+ id = Column(Integer, primary_key=True, nullable=False)
11
+ uuid = Column(String(255), unique=True, default=uuid, index=True)
12
+ name = Column(String(255), index=True)
13
+ meta_category = Column("meta-category", String(255), index=True, key="meta_category")
14
+ description = Column(String(255))
15
+ template_uuid = Column(String(255), index=True, default=None)
16
+ template_version = Column(Integer, index=True, nullable=False)
17
+ event_id = Column(Integer, ForeignKey("events.id"), index=True, nullable=False)
18
+ timestamp = Column(Integer, index=True, nullable=False, default=0)
19
+ distribution = Column(Integer, index=True, nullable=False, default=0)
20
+ sharing_group_id = Column(Integer, ForeignKey("sharing_groups.id"), index=True)
21
+ comment = Column(String(255), nullable=False)
22
+ deleted = Column(Boolean, nullable=False, default=False)
23
+ first_seen = Column(Integer, index=True, default=None)
24
+ last_seen = Column(Integer, index=True, default=None)
25
+
26
+
27
+ class ObjectTemplate(Base):
28
+ __tablename__ = "object_templates"
29
+
30
+ id = Column(Integer, primary_key=True, nullable=False)
31
+ uuid = Column(String(255), unique=True, default=uuid, index=True)
32
+ name = Column(String(255), index=True)
33
+ user_id = Column(Integer, ForeignKey("users.id"), index=True, nullable=False)
34
+ org_id = Column(Integer, ForeignKey("organisations.id"), index=True, nullable=False)
35
+ description = Column(String(255))
36
+ version = Column(Integer, nullable=False)
37
+ requirements = Column(String(255))
38
+ fixed = Column(Boolean, nullable=False, default=False)
39
+ active = Column(Boolean, nullable=False, default=False)
@@ -0,0 +1,26 @@
1
+ from datetime import datetime
2
+
3
+ from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text
4
+
5
+ from mmisp.util.uuid import uuid
6
+
7
+ from ..database import Base
8
+
9
+
10
+ class Organisation(Base):
11
+ __tablename__ = "organisations"
12
+
13
+ id = Column(Integer, primary_key=True, nullable=False)
14
+ name = Column(String(255), nullable=False, unique=True)
15
+ date_created = Column(DateTime, default=datetime.utcnow, nullable=False)
16
+ date_modified = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
17
+ description = Column(Text)
18
+ type = Column(String(255))
19
+ nationality = Column(String(255))
20
+ sector = Column(String(255))
21
+ created_by = Column(Integer, nullable=False, default=0)
22
+ uuid = Column(String(255), unique=True, default=uuid)
23
+ contacts = Column(Text)
24
+ local = Column(Boolean, nullable=False, default=False)
25
+ restricted_to_domain = Column(Text)
26
+ landingpage = Column(Text)
@@ -0,0 +1,42 @@
1
+ from sqlalchemy import Boolean, Column, DateTime, Integer, String
2
+
3
+ from ..database import Base
4
+
5
+
6
+ class Role(Base):
7
+ __tablename__ = "roles"
8
+
9
+ id = Column(Integer, primary_key=True, nullable=False)
10
+ name = Column(String(255), nullable=False)
11
+ created = Column(DateTime, default=None)
12
+ modified = Column(DateTime, default=None)
13
+ perm_add = Column(Boolean, default=False)
14
+ perm_modify = Column(Boolean, default=False)
15
+ perm_modify_org = Column(Boolean, default=False)
16
+ perm_publish = Column(Boolean, default=False)
17
+ perm_delegate = Column(Boolean, nullable=False, default=False)
18
+ perm_sync = Column(Boolean, default=False)
19
+ perm_admin = Column(Boolean, default=False)
20
+ perm_audit = Column(Boolean, default=False)
21
+ perm_full = Column(Boolean, default=False)
22
+ perm_auth = Column(Boolean, nullable=False, default=False)
23
+ perm_site_admin = Column(Boolean, nullable=False, default=False)
24
+ perm_regexp_access = Column(Boolean, nullable=False, default=False)
25
+ perm_tagger = Column(Boolean, nullable=False, default=False)
26
+ perm_template = Column(Boolean, nullable=False, default=False)
27
+ perm_sharing_group = Column(Boolean, nullable=False, default=False)
28
+ perm_tag_editor = Column(Boolean, nullable=False, default=False)
29
+ perm_sighting = Column(Boolean, nullable=False, default=False)
30
+ perm_object_template = Column(Boolean, nullable=False, default=False)
31
+ default_role = Column(Boolean, nullable=False, default=False)
32
+ memory_limit = Column(String(255), default="")
33
+ max_execution_time = Column(String(255), default="")
34
+ restricted_to_site_admin = Column(Boolean, nullable=False, default=False)
35
+ perm_publish_zmq = Column(Boolean, nullable=False, default=False)
36
+ perm_publish_kafka = Column(Boolean, nullable=False, default=False)
37
+ perm_decaying = Column(Boolean, nullable=False, default=False)
38
+ enforce_rate_limit = Column(Boolean, nullable=False, default=False)
39
+ rate_limit_count = Column(Integer, nullable=False, default=0)
40
+ perm_galaxy_editor = Column(Boolean, default=False)
41
+ perm_warninglist = Column(Boolean, default=False)
42
+ perm_view_feed_correlations = Column(Boolean, default=False)
@@ -0,0 +1,33 @@
1
+ from sqlalchemy import VARCHAR, Boolean, Column, Integer, Text
2
+
3
+ from ..database import Base
4
+
5
+
6
+ class Server(Base):
7
+ __tablename__ = "servers"
8
+
9
+ id = Column(Integer, primary_key=True, nullable=False)
10
+ name = Column(VARCHAR(255), nullable=False)
11
+ url = Column(VARCHAR(255), nullable=False)
12
+ authkey = Column(VARCHAR(40), nullable=False)
13
+ org_id = Column(Integer, nullable=False, index=True)
14
+ push = Column(Boolean, nullable=False)
15
+ pull = Column(Boolean, nullable=False)
16
+ push_sightings = Column(Boolean, nullable=False, default=False)
17
+ push_galaxy_clusters = Column(Boolean, default=False)
18
+ pull_galaxy_clusters = Column(Boolean, default=False)
19
+ lastpulledid = Column(Integer)
20
+ lastpushedid = Column(Integer)
21
+ organization = Column(VARCHAR(10), default=None)
22
+ remote_org_id = Column(Integer, nullable=False, index=True)
23
+ publish_without_email = Column(Boolean, nullable=False, default=False)
24
+ unpublish_event = Column(Boolean, nullable=False, default=False)
25
+ self_signed = Column(Boolean, nullable=False)
26
+ pull_rules = Column(Text, nullable=False)
27
+ push_rules = Column(Text, nullable=False)
28
+ cert_file = Column(VARCHAR(255))
29
+ client_cert_file = Column(VARCHAR(255))
30
+ internal = Column(Boolean, nullable=False, default=False)
31
+ skip_proxy = Column(Boolean, nullable=False, default=False)
32
+ caching_enabled = Column(Boolean, nullable=False, default=False)
33
+ priority = Column(Integer, nullable=False, default=0, index=True)
@@ -0,0 +1,43 @@
1
+ from datetime import datetime
2
+
3
+ from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text
4
+
5
+ from mmisp.util.uuid import uuid
6
+
7
+ from ..database import Base
8
+
9
+
10
+ class SharingGroup(Base):
11
+ __tablename__ = "sharing_groups"
12
+
13
+ id = Column(Integer, primary_key=True, nullable=False)
14
+ name = Column(String(255), nullable=False, unique=True)
15
+ releasability = Column(Text, nullable=False)
16
+ description = Column(Text, nullable=False, default="")
17
+ uuid = Column(String(40), unique=True, default=uuid, nullable=False)
18
+ organisation_uuid = Column(String(40), nullable=False)
19
+ org_id = Column(Integer, nullable=False, index=True)
20
+ sync_user_id = Column(Integer, nullable=False, default=0, index=True)
21
+ active = Column(Boolean, nullable=False, default=False)
22
+ created = Column(DateTime, default=datetime.utcnow, nullable=False)
23
+ modified = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
24
+ local = Column(Boolean, nullable=False, default=True)
25
+ roaming = Column(Boolean, default=False, nullable=False)
26
+
27
+
28
+ class SharingGroupOrg(Base):
29
+ __tablename__ = "sharing_group_orgs"
30
+
31
+ id = Column(Integer, primary_key=True, nullable=False)
32
+ sharing_group_id = Column(Integer, index=True, nullable=False)
33
+ org_id = Column(Integer, index=True, nullable=False)
34
+ extend = Column(Boolean, default=False, nullable=False)
35
+
36
+
37
+ class SharingGroupServer(Base):
38
+ __tablename__ = "sharing_group_servers"
39
+
40
+ id = Column(Integer, primary_key=True, nullable=False)
41
+ sharing_group_id = Column(Integer, index=True, nullable=False)
42
+ server_id = Column(Integer, index=True, nullable=False)
43
+ all_orgs = Column(Boolean, index=True, nullable=False, default=False)
@@ -0,0 +1,21 @@
1
+ from sqlalchemy import BigInteger, Column, ForeignKey, Integer, String
2
+
3
+ from mmisp.db.database import Base
4
+ from mmisp.util.uuid import uuid
5
+
6
+ from .attribute import Attribute
7
+ from .event import Event
8
+ from .organisation import Organisation
9
+
10
+
11
+ class Sighting(Base):
12
+ __tablename__ = "sightings"
13
+
14
+ id = Column(Integer, primary_key=True, nullable=False)
15
+ uuid = Column(String(40), unique=True, default=uuid)
16
+ attribute_id = Column(Integer, ForeignKey(Attribute.id), index=True, nullable=False)
17
+ event_id = Column(Integer, ForeignKey(Event.id), index=True, nullable=False)
18
+ org_id = Column(Integer, ForeignKey(Organisation.id), index=True, nullable=False)
19
+ date_sighting = Column(BigInteger, nullable=False)
20
+ source = Column(String(255), index=True, default="")
21
+ type = Column(Integer, index=True, default=0)
mmisp/db/models/tag.py ADDED
@@ -0,0 +1,19 @@
1
+ from sqlalchemy import Boolean, Column, Integer, String
2
+
3
+ from mmisp.db.database import Base
4
+
5
+
6
+ class Tag(Base):
7
+ __tablename__ = "tags"
8
+
9
+ id = Column(Integer, primary_key=True, nullable=False)
10
+ name = Column(String(255), unique=True, nullable=False)
11
+ colour = Column(String(7), nullable=False)
12
+ exportable = Column(Boolean, nullable=False)
13
+ org_id = Column(Integer, nullable=False, default=0, index=True)
14
+ user_id = Column(Integer, nullable=False, default=0, index=True)
15
+ hide_tag = Column(Boolean, nullable=False, default=False)
16
+ numerical_value = Column(Integer, index=True)
17
+ is_galaxy = Column(Boolean, default=False)
18
+ is_custom_galaxy = Column(Boolean, default=False)
19
+ local_only = Column(Boolean, default=False)
@@ -0,0 +1,41 @@
1
+ from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text
2
+
3
+ from ..database import Base
4
+
5
+
6
+ class Taxonomy(Base):
7
+ __tablename__ = "taxonomies"
8
+
9
+ id = Column(Integer, primary_key=True, nullable=False)
10
+ namespace = Column(String(255), nullable=False)
11
+ description = Column(Text, nullable=False)
12
+ version = Column(Integer, nullable=False)
13
+ enabled = Column(Boolean, nullable=False, default=False)
14
+ exclusive = Column(Boolean, default=False)
15
+ required = Column(Boolean, nullable=False, default=False)
16
+ highlighted = Column(Boolean)
17
+
18
+
19
+ class TaxonomyPredicate(Base):
20
+ __tablename__ = "taxonomy_predicates"
21
+
22
+ id = Column(Integer, primary_key=True, nullable=False)
23
+ taxonomy_id = Column(Integer, ForeignKey(Taxonomy.id), nullable=False, index=True)
24
+ value = Column(Text, nullable=False)
25
+ expanded = Column(Text)
26
+ colour = Column(String(7))
27
+ description = Column(Text)
28
+ exclusive = Column(Boolean, default=False)
29
+ numerical_value = Column(Integer, index=True)
30
+
31
+
32
+ class TaxonomyEntry(Base):
33
+ __tablename__ = "taxonomy_entries"
34
+
35
+ id = Column(Integer, primary_key=True, nullable=False)
36
+ taxonomy_predicate_id = Column(Integer, ForeignKey(TaxonomyPredicate.id), nullable=False, index=True)
37
+ value = Column(Text, nullable=False)
38
+ expanded = Column(Text)
39
+ colour = Column(String(7))
40
+ description = Column(Text)
41
+ numerical_value = Column(Integer, index=True)
@@ -0,0 +1,44 @@
1
+ from time import time
2
+
3
+ from sqlalchemy import BigInteger, Boolean, Column, DateTime, ForeignKey, Integer, String, Text
4
+
5
+ from ..database import Base
6
+ from .organisation import Organisation
7
+
8
+
9
+ class User(Base):
10
+ __tablename__ = "users"
11
+
12
+ id = Column(Integer, primary_key=True, nullable=False)
13
+ password = Column(String(255), nullable=False)
14
+ org_id = Column(Integer, ForeignKey(Organisation.id), nullable=False, index=True)
15
+ server_id = Column(Integer, nullable=False, default=0, index=True)
16
+ email = Column(String(255), nullable=False, unique=True)
17
+ autoalert = Column(Boolean, default=False, nullable=False)
18
+ authkey = Column(String(40), nullable=True, default=None)
19
+ invited_by = Column(Integer, default=0, nullable=False)
20
+ gpgkey = Column(Text)
21
+ certif_public = Column(Text)
22
+ nids_sid = Column(Integer, default=0, nullable=False)
23
+ termsaccepted = Column(Boolean, default=False, nullable=False)
24
+ newsread = Column(Integer, default=0)
25
+ role_id = Column(Integer, nullable=False, default=0)
26
+ change_pw = Column(Integer, default=0, nullable=False)
27
+ contactalert = Column(Boolean, default=False, nullable=False)
28
+ disabled = Column(Boolean, default=False, nullable=False)
29
+ expiration = Column(DateTime, default=None)
30
+ current_login = Column(Integer, default=0)
31
+ last_login = Column(Integer, default=0)
32
+ force_logout = Column(Boolean, default=False, nullable=False)
33
+ date_created = Column(Integer, default=time)
34
+ date_modified = Column(Integer, default=time, onupdate=time)
35
+ sub = Column(String(255), unique=True)
36
+ external_auth_required = Column(Boolean, nullable=False, default=False)
37
+ external_auth_key = Column(Text)
38
+ last_api_access = Column(Integer, default=0)
39
+ notification_daily = Column(Boolean, nullable=False, default=False)
40
+ notification_weekly = Column(Boolean, nullable=False, default=False)
41
+ notification_monthly = Column(Boolean, nullable=False, default=False)
42
+ totp = Column(String(255))
43
+ hotp_counter = Column(Integer)
44
+ last_pw_change = Column(BigInteger)