stix2arango 1.1.2__py3-none-any.whl → 1.1.4__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 stix2arango might be problematic. Click here for more details.
- stix2arango/__main__.py +63 -9
- stix2arango/services/arangodb_service.py +2 -2
- stix2arango/stix2arango/stix2arango.py +9 -5
- stix2arango/utils.py +6 -8
- {stix2arango-1.1.2.dist-info → stix2arango-1.1.4.dist-info}/METADATA +17 -17
- {stix2arango-1.1.2.dist-info → stix2arango-1.1.4.dist-info}/RECORD +9 -9
- {stix2arango-1.1.2.dist-info → stix2arango-1.1.4.dist-info}/WHEEL +0 -0
- {stix2arango-1.1.2.dist-info → stix2arango-1.1.4.dist-info}/entry_points.txt +0 -0
- {stix2arango-1.1.2.dist-info → stix2arango-1.1.4.dist-info}/licenses/LICENSE +0 -0
stix2arango/__main__.py
CHANGED
|
@@ -1,27 +1,81 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
from stix2arango.stix2arango import Stix2Arango
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
def parse_bool(value: str):
|
|
5
6
|
value = value.lower()
|
|
6
7
|
# ["false", "no", "n"]
|
|
7
8
|
return value in ["yes", "y", "true", "1"]
|
|
8
9
|
|
|
10
|
+
def parse_ref(value: str):
|
|
11
|
+
if not (value.endswith('_ref') or value.endswith('_refs')):
|
|
12
|
+
raise argparse.ArgumentTypeError('value must end with _ref or _refs')
|
|
13
|
+
return value
|
|
14
|
+
|
|
15
|
+
|
|
9
16
|
def parse_arguments():
|
|
10
17
|
parser = argparse.ArgumentParser(description="Import STIX JSON into ArangoDB")
|
|
11
18
|
parser.add_argument("--file", required=True, help="Path to STIX JSON file")
|
|
12
|
-
parser.add_argument(
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--is_large_file",
|
|
21
|
+
action="store_true",
|
|
22
|
+
help="Use large file mode [Use this mode when the bundle is very large, this will enable you stix2arango to chunk before loading into memory]",
|
|
23
|
+
)
|
|
13
24
|
parser.add_argument("--database", required=True, help="ArangoDB database name")
|
|
14
|
-
parser.add_argument(
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--create_db",
|
|
27
|
+
default=True,
|
|
28
|
+
type=parse_bool,
|
|
29
|
+
help="whether or not to skip the creation of database, requires admin permission",
|
|
30
|
+
)
|
|
15
31
|
parser.add_argument("--collection", required=True, help="ArangoDB collection name")
|
|
16
|
-
parser.add_argument(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
parser.add_argument(
|
|
20
|
-
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"--stix2arango_note", required=False, help="Note for the import", default=""
|
|
34
|
+
)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"--ignore_embedded_relationships",
|
|
37
|
+
required=False,
|
|
38
|
+
help="Ignore Embedded Relationship for the import",
|
|
39
|
+
type=parse_bool,
|
|
40
|
+
default=False,
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--ignore_embedded_relationships_sro",
|
|
44
|
+
required=False,
|
|
45
|
+
help="Ignore Embedded Relationship for imported SROs",
|
|
46
|
+
type=parse_bool,
|
|
47
|
+
default=False,
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument(
|
|
50
|
+
"--ignore_embedded_relationships_smo",
|
|
51
|
+
required=False,
|
|
52
|
+
help="Ignore Embedded Relationship for imported SMOs",
|
|
53
|
+
type=parse_bool,
|
|
54
|
+
default=False,
|
|
55
|
+
)
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"--include_embedded_relationships_attributes",
|
|
58
|
+
required=False,
|
|
59
|
+
help="Only create embedded relationships for keys",
|
|
60
|
+
action="extend",
|
|
61
|
+
nargs="+",
|
|
62
|
+
type=parse_ref
|
|
63
|
+
)
|
|
21
64
|
return parser.parse_args()
|
|
22
65
|
|
|
23
66
|
|
|
24
67
|
def main():
|
|
25
68
|
args = parse_arguments()
|
|
26
|
-
stix_obj = Stix2Arango(
|
|
27
|
-
|
|
69
|
+
stix_obj = Stix2Arango(
|
|
70
|
+
database=args.database,
|
|
71
|
+
collection=args.collection,
|
|
72
|
+
file=args.file,
|
|
73
|
+
create_db=args.create_db,
|
|
74
|
+
stix2arango_note=args.stix2arango_note,
|
|
75
|
+
ignore_embedded_relationships=args.ignore_embedded_relationships,
|
|
76
|
+
ignore_embedded_relationships_sro=args.ignore_embedded_relationships_sro,
|
|
77
|
+
ignore_embedded_relationships_smo=args.ignore_embedded_relationships_smo,
|
|
78
|
+
is_large_file=args.is_large_file,
|
|
79
|
+
include_embedded_relationships_attributes=args.include_embedded_relationships_attributes,
|
|
80
|
+
)
|
|
81
|
+
stix_obj.run()
|
|
@@ -63,7 +63,7 @@ class ArangoDBService:
|
|
|
63
63
|
|
|
64
64
|
if self.db.has_graph(self.ARANGO_GRAPH):
|
|
65
65
|
self.cti2stix_graph = self.db.graph(self.ARANGO_GRAPH)
|
|
66
|
-
elif
|
|
66
|
+
elif create_db:
|
|
67
67
|
self.cti2stix_graph = self.db.create_graph(self.ARANGO_GRAPH)
|
|
68
68
|
|
|
69
69
|
self.collections: dict[str, StandardCollection] = {}
|
|
@@ -199,7 +199,7 @@ class ArangoDBService:
|
|
|
199
199
|
|
|
200
200
|
@staticmethod
|
|
201
201
|
def fix_edge_ref(_id):
|
|
202
|
-
c, _, _key = _id.
|
|
202
|
+
c, _, _key = _id.rpartition('/')
|
|
203
203
|
if not c:
|
|
204
204
|
c = "missing_collection"
|
|
205
205
|
return f"{c}/{_key}"
|
|
@@ -42,6 +42,7 @@ class Stix2Arango:
|
|
|
42
42
|
ignore_embedded_relationships=False,
|
|
43
43
|
ignore_embedded_relationships_sro=True,
|
|
44
44
|
ignore_embedded_relationships_smo=True,
|
|
45
|
+
include_embedded_relationships_attributes=None,
|
|
45
46
|
bundle_id=None,
|
|
46
47
|
username=config.ARANGODB_USERNAME,
|
|
47
48
|
password=config.ARANGODB_PASSWORD,
|
|
@@ -80,15 +81,16 @@ class Stix2Arango:
|
|
|
80
81
|
self.file = file
|
|
81
82
|
self._is_large_file = is_large_file
|
|
82
83
|
self.note = stix2arango_note or ""
|
|
83
|
-
self.identity_ref = utils.load_file_from_url(config.STIX2ARANGO_IDENTITY)
|
|
84
|
+
self.identity_ref = utils.load_file_from_url(config.STIX2ARANGO_IDENTITY).copy()
|
|
84
85
|
self.default_ref_objects = [
|
|
85
|
-
utils.load_file_from_url(link)
|
|
86
|
+
utils.load_file_from_url(link).copy()
|
|
86
87
|
for link in config.MARKING_DEFINITION_REFS + config.IDENTITY_REFS
|
|
87
88
|
]
|
|
88
89
|
self.bundle_id = bundle_id
|
|
89
90
|
self.ignore_embedded_relationships = ignore_embedded_relationships
|
|
90
91
|
self.ignore_embedded_relationships_smo = ignore_embedded_relationships_smo
|
|
91
92
|
self.ignore_embedded_relationships_sro = ignore_embedded_relationships_sro
|
|
93
|
+
self.include_embedded_relationships_attributes = include_embedded_relationships_attributes
|
|
92
94
|
self.object_key_mapping = {}
|
|
93
95
|
if create_collection:
|
|
94
96
|
self.create_s2a_indexes()
|
|
@@ -472,14 +474,16 @@ class Stix2Arango:
|
|
|
472
474
|
for obj in tqdm(bundle_objects, desc="upload_embedded_edges"):
|
|
473
475
|
if obj["id"] not in inserted_object_ids:
|
|
474
476
|
continue
|
|
475
|
-
if
|
|
477
|
+
if self.include_embedded_relationships_attributes:
|
|
478
|
+
pass
|
|
479
|
+
elif (
|
|
476
480
|
self.ignore_embedded_relationships_smo and obj["type"] in SMO_TYPES
|
|
477
481
|
) or (
|
|
478
482
|
self.ignore_embedded_relationships_sro and obj["type"] == "relationship"
|
|
479
483
|
):
|
|
480
484
|
continue
|
|
481
485
|
|
|
482
|
-
for ref_type, targets in utils.get_embedded_refs(obj):
|
|
486
|
+
for ref_type, targets in utils.get_embedded_refs(obj, attributes=self.include_embedded_relationships_attributes):
|
|
483
487
|
utils.create_relationship_obj(
|
|
484
488
|
obj=obj,
|
|
485
489
|
source=obj.get("id"),
|
|
@@ -578,7 +582,7 @@ class Stix2Arango:
|
|
|
578
582
|
self.filename, all_objects
|
|
579
583
|
)
|
|
580
584
|
|
|
581
|
-
if not self.ignore_embedded_relationships:
|
|
585
|
+
if (not self.ignore_embedded_relationships) or self.include_embedded_relationships_attributes:
|
|
582
586
|
module_logger.info(
|
|
583
587
|
"Creating new embedded relationships using _refs and _ref"
|
|
584
588
|
)
|
stix2arango/utils.py
CHANGED
|
@@ -8,7 +8,7 @@ import json
|
|
|
8
8
|
import hashlib
|
|
9
9
|
import os
|
|
10
10
|
from . import config
|
|
11
|
-
from datetime import datetime
|
|
11
|
+
from datetime import UTC, datetime
|
|
12
12
|
|
|
13
13
|
module_logger = logging.getLogger("data_ingestion_service")
|
|
14
14
|
from arango.database import StandardDatabase
|
|
@@ -67,10 +67,6 @@ def create_relationship_obj(
|
|
|
67
67
|
relationship_object["_bundle_id"] = bundle_id
|
|
68
68
|
relationship_object["_file_name"] = os.path.basename(arango_obj.file or "")
|
|
69
69
|
relationship_object["_stix2arango_note"] = arango_obj.note
|
|
70
|
-
relationship_object["_record_created"] = datetime.now().strftime(
|
|
71
|
-
"%Y-%m-%dT%H:%M:%S.%f"
|
|
72
|
-
)
|
|
73
|
-
relationship_object["_record_modified"] = relationship_object["_record_created"]
|
|
74
70
|
relationship_object["_is_ref"] = True
|
|
75
71
|
relationship_object["type"] = "relationship"
|
|
76
72
|
relationship_object["spec_version"] = "2.1"
|
|
@@ -120,7 +116,7 @@ def remove_duplicates(objects):
|
|
|
120
116
|
return list(objects_hashmap.values())
|
|
121
117
|
|
|
122
118
|
|
|
123
|
-
def get_embedded_refs(object: list | dict, xpath: list = []):
|
|
119
|
+
def get_embedded_refs(object: list | dict, xpath: list = [], attributes=None):
|
|
124
120
|
embedded_refs = []
|
|
125
121
|
if isinstance(object, dict):
|
|
126
122
|
for key, value in object.items():
|
|
@@ -129,11 +125,13 @@ def get_embedded_refs(object: list | dict, xpath: list = []):
|
|
|
129
125
|
if match := EMBEDDED_RELATIONSHIP_RE.fullmatch(key):
|
|
130
126
|
relationship_type = "-".join(xpath + match.group(1).split("_"))
|
|
131
127
|
targets = value if isinstance(value, list) else [value]
|
|
128
|
+
if attributes and key not in attributes:
|
|
129
|
+
continue
|
|
132
130
|
embedded_refs.append((relationship_type, targets))
|
|
133
131
|
elif isinstance(value, list):
|
|
134
|
-
embedded_refs.extend(get_embedded_refs(value, xpath + [key]))
|
|
132
|
+
embedded_refs.extend(get_embedded_refs(value, xpath + [key], attributes=attributes))
|
|
135
133
|
elif isinstance(object, list):
|
|
136
134
|
for obj in object:
|
|
137
135
|
if isinstance(obj, dict):
|
|
138
|
-
embedded_refs.extend(get_embedded_refs(obj, xpath))
|
|
136
|
+
embedded_refs.extend(get_embedded_refs(obj, xpath, attributes=attributes))
|
|
139
137
|
return embedded_refs
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stix2arango
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.4
|
|
4
4
|
Summary: stix2arango is a command line tool that takes a group of STIX 2.1 objects in a bundle and inserts them into ArangoDB. It can also handle updates to existing objects in ArangoDB imported in a bundle.
|
|
5
5
|
Project-URL: Homepage, https://github.com/muchdogesec/stix2arango
|
|
6
6
|
Project-URL: Issues, https://github.com/muchdogesec/stix2arango/issues
|
|
@@ -60,20 +60,6 @@ Note, the installation assumes ArangoDB is already installed locally.
|
|
|
60
60
|
|
|
61
61
|
[You can install ArangoDB here](https://arangodb.com/download/). stix2arango is compatible with both the Enterprise and Community versions.
|
|
62
62
|
|
|
63
|
-
#### A note for Mac users
|
|
64
|
-
|
|
65
|
-
Fellow Mac users, ArangoDB can be installed and run using homebrew as follows;
|
|
66
|
-
|
|
67
|
-
```shell
|
|
68
|
-
## Install
|
|
69
|
-
brew install arangodb
|
|
70
|
-
## Run
|
|
71
|
-
brew services start arangodb
|
|
72
|
-
## will now be accessible in a browser at: http://127.0.0.1:8529 . Default username is root with no password set (leave blank)
|
|
73
|
-
## Stop
|
|
74
|
-
brew services stop arangodb
|
|
75
|
-
```
|
|
76
|
-
|
|
77
63
|
### Configuration options
|
|
78
64
|
|
|
79
65
|
stix2arango has various settings that are defined in an `.env` file.
|
|
@@ -100,12 +86,14 @@ python3 stix2arango.py \
|
|
|
100
86
|
Where;
|
|
101
87
|
|
|
102
88
|
* `--file` (required): is the path to the valid STIX 2.1 bundle .json file
|
|
103
|
-
* `--database` (required): is the name of the Arango database the objects should be stored in.
|
|
89
|
+
* `--database` (required): is the name of the Arango database the objects should be stored in.
|
|
90
|
+
* `--create_db` (default `true`): If database does not exist, stix2arango will create it. You can set to `false` to stop this behaviour (and avoid the risk of incorrect DBs being created). Generally setting to `false` is a good idea if you know the databases exist. This setting will only work if the Arango user being used to authenticate has permissions to create new databases.
|
|
104
91
|
* `--collection` (required): is the name of the Arango collection in the database specified the objects should be stored in. If the collection does not exist, stix2arango will create it
|
|
105
92
|
* `--stix2arango_note` (optional): Will be stored under the `_stix2arango_note` custom attribute in ArangoDB. Useful as can be used in AQL. `a-z` characters only. Max 24 chars.
|
|
106
93
|
* `--ignore_embedded_relationships` (optional, boolean): if `true` passed, this will stop ANY embedded relationships from being generated. This applies for all object types (SDO, SCO, SRO, SMO). If you want to target certain object types see `ignore_embedded_relationships_sro` and `ignore_embedded_relationships_sro` flags. ` Default is `false`
|
|
107
94
|
* `--ignore_embedded_relationships_sro` (optional, boolean): if `true` passed, will stop any embedded relationships from being generated from SRO objects (`type` = `relationship`). Default is `false`
|
|
108
|
-
* `--ignore_embedded_relationships_smo` (optional, boolean): if `true` passed, will stop any embedded relationships from being generated from SMO objects (`type` = `marking-
|
|
95
|
+
* `--ignore_embedded_relationships_smo` (optional, boolean): if `true` passed, will stop any embedded relationships from being generated from SMO objects (`type` = `marking-defirnition`, `extension-definition`, `language-content`). Default is `false`
|
|
96
|
+
* `--include_embedded_relationships_attributes` (optional, stix `_ref` or `_refs` attribute): if you only want to create embedded relationships from certain keys (attributes) in a STIX object you can pass a list of attributes here. e.g. `object_refs created_by_ref` . In this example, embedded relationships to all objects listed in `object_refs` and objects in `created_by_ref` will be created between source (the objects that house these attibutes) and destinations (the objects listed as values for these attributes)
|
|
109
97
|
* `--is_large_file` (pass flag): Use this mode when the bundle is very large (>100mb), this will chunk the input into multiple files before loading into memory.
|
|
110
98
|
|
|
111
99
|
For example, [using the MITRE ATT&CK Enterprise bundle](https://raw.githubusercontent.com/mitre/cti/master/enterprise-attack/enterprise-attack.json);
|
|
@@ -132,6 +120,18 @@ python3 stix2arango.py \
|
|
|
132
120
|
--is_large_file
|
|
133
121
|
```
|
|
134
122
|
|
|
123
|
+
If you want to include embedded relationships for `created_by_ref` and `object_marking_refs` attibutes collection, you would run;
|
|
124
|
+
|
|
125
|
+
```shell
|
|
126
|
+
python3 stix2arango.py \
|
|
127
|
+
--file cti_knowledge_base_store/mitre-attack-enterprise/enterprise-attack-15_1.json \
|
|
128
|
+
--database stix2arango_demo \
|
|
129
|
+
--collection demo_2 \
|
|
130
|
+
--stix2arango_note v15.1 \
|
|
131
|
+
--include_embedded_relationships_attributes object_refs created_by_ref \
|
|
132
|
+
--is_large_file
|
|
133
|
+
```
|
|
134
|
+
|
|
135
135
|
#### A note on embedded relationships
|
|
136
136
|
|
|
137
137
|
stix2arango can handle all embedded references to other STIX objects under `_ref` and `_refs` properties in a STIX object when `--ignore_embedded_relationships` is set to false.
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
stix2arango/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
stix2arango/__main__.py,sha256=
|
|
2
|
+
stix2arango/__main__.py,sha256=zsCi_bfDULLDkqlRwXyGhFuLvSRcvESEc4MMN7h1lbQ,2835
|
|
3
3
|
stix2arango/config.py,sha256=NZFrcnEfz-0QBrut2Rh7xMF78v0bk6U6y2TY_7mHxSs,1407
|
|
4
|
-
stix2arango/utils.py,sha256=
|
|
4
|
+
stix2arango/utils.py,sha256=bUKJBQ2owbCQKWs_m-VYjYCHuQLykizabE4D3LPspW8,4636
|
|
5
5
|
stix2arango/services/__init__.py,sha256=E87fB-dxI4mPxMVs00jdLhjp9jFhkVfjhMKIqGLRJlY,45
|
|
6
|
-
stix2arango/services/arangodb_service.py,sha256=
|
|
6
|
+
stix2arango/services/arangodb_service.py,sha256=jr6zXFueluCU60WOJy7XuA9Ty0zW5FzGNBJGtJzq0PY,11964
|
|
7
7
|
stix2arango/services/version_annotator.py,sha256=Sd1MIaXzK0fpNopNxRoB_3etodzAjX5D_p3uGQSWzOI,2946
|
|
8
8
|
stix2arango/stix2arango/__init__.py,sha256=OqxWEEsHqR1QQpznM5DbFJ5bO5numKYtoYhjXYJMEyg,36
|
|
9
9
|
stix2arango/stix2arango/bundle_loader.py,sha256=qi-0E_bMIMPZXzISvjhrWX8K-f7iFv9vOekldOGVczU,4603
|
|
10
|
-
stix2arango/stix2arango/stix2arango.py,sha256=
|
|
10
|
+
stix2arango/stix2arango/stix2arango.py,sha256=HJXDqA9NWxXVQSHPmbpkEKurpWEbZmy5bng5SQ1OsjE,22412
|
|
11
11
|
stix2arango/templates/marking-definition.json,sha256=0q9y35mUmiF6xIWSLpkATL4JTHGSCNyLbejqZiQ0AuE,3113
|
|
12
|
-
stix2arango-1.1.
|
|
13
|
-
stix2arango-1.1.
|
|
14
|
-
stix2arango-1.1.
|
|
15
|
-
stix2arango-1.1.
|
|
16
|
-
stix2arango-1.1.
|
|
12
|
+
stix2arango-1.1.4.dist-info/METADATA,sha256=Hre8CoZ_6ic_jNFQ1ONrA8jTr3wLL54wFT-_nLYGsmY,7797
|
|
13
|
+
stix2arango-1.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
stix2arango-1.1.4.dist-info/entry_points.txt,sha256=k2WnxMsHFLoyC6rqfvjhIMS1zwtWin51-MbNCGmSMYE,58
|
|
15
|
+
stix2arango-1.1.4.dist-info/licenses/LICENSE,sha256=BK8Ppqlc4pdgnNzIxnxde0taoQ1BgicdyqmBvMiNYgY,11364
|
|
16
|
+
stix2arango-1.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|