-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STIX Custom Object issue with references #565
Comments
It will help if you post code that's runnable as-is. After "fixing" it with regard to imports and some other misc things, I get output: {
"type": "x-priam-action",
"spec_version": "2.1",
"id": "x-priam-action--70f0a1fd-00a4-45f2-8fef-246ddaf8b1c9",
"action": "allow",
"sensor_refs": [
"x-priam-sensor--73076d2d-c193-4e98-8793-f1dac7966891"
],
"object_marking_refs": [
"marking-definition--f88d31f6-486f-44da-b317-01333bde0b82"
]
} So, it works. I tried it with stix2 3.0.1 from pypi. Some notes though:
Here is a sample implementing a part of your code using the extension mechanism: import stix2
from stix2.properties import StringProperty
from stix2.v21.vocab import EXTENSION_TYPE_NEW_SDO
import sys
# Those who use your extension definition will use its ID to refer to it, so
# maybe it is better to fix this ID here instead of randomly regenerating it
# in each run of this script.
PRIAM_SENSOR_EXT_ID="extension-definition--638dd8ff-083a-4e42-adba-702080ceb4a0"
my_ext = stix2.ExtensionDefinition(
id=PRIAM_SENSOR_EXT_ID,
created_by_ref="identity--87c30030-82c5-4e7c-a253-db6d9782ce3a",
name="priam-sensor",
schema="My priam sensor object",
version="1.0",
extension_types=[EXTENSION_TYPE_NEW_SDO]
)
@stix2.CustomObject(
"priam-sensor",
[
("name", StringProperty(required=True)),
("description", StringProperty()),
("priam_version", StringProperty()),
("fqdn", StringProperty())
],
extension_name=PRIAM_SENSOR_EXT_ID
)
class Sensor:
"""Custom Sensor object of type stix2.CustomObject.
Custom Properties
-----------------
fqdn: str
"""
pass
# Show the extension definition too!
my_ext.fp_serialize(sys.stdout, pretty=True)
print()
sensor = Sensor(name='edr', description='an EDR sensor', fqdn='falcon.contoso.com')
sensor.fp_serialize(sys.stdout, pretty=True) There is some documentation of the stix2 extension API here. Sample output: {
"type": "extension-definition",
"spec_version": "2.1",
"id": "extension-definition--638dd8ff-083a-4e42-adba-702080ceb4a0",
"created_by_ref": "identity--87c30030-82c5-4e7c-a253-db6d9782ce3a",
"created": "2023-02-15T02:26:02.161753Z",
"modified": "2023-02-15T02:26:02.161753Z",
"name": "priam-sensor",
"schema": "My priam sensor object",
"version": "1.0",
"extension_types": [
"new-sdo"
]
}
{
"type": "priam-sensor",
"spec_version": "2.1",
"id": "priam-sensor--5957492d-740e-49e6-b54e-5c6269d3c718",
"created": "2023-02-15T02:26:02.2192Z",
"modified": "2023-02-15T02:26:02.2192Z",
"name": "edr",
"description": "an EDR sensor",
"fqdn": "falcon.contoso.com",
"extensions": {
"extension-definition--638dd8ff-083a-4e42-adba-702080ceb4a0": {
"extension_type": "new-sdo"
}
}
} |
Hello Chris, |
For custom SROs, there is an For your "weird" cases at the end of your notebook, notice that the resulting objects have two extensions: one is an instance of the registered extension class, and the other is a plain dict. The library is designed to cope with lack of registration. It will pass through unregistered objects and extensions as they are (as a dict), if it can't find a class to use. It needs to be able to deal with unanticipated object types, where the registry isn't set up with custom classes beforehand. Having multiple extensions of type "new-sdo" in the same object does seem... weird though. Maybe the library should warn about that. |
Hello,
|
Sorry just to be clear my question is if is weird to have on extension for each object (in this case I will need 3 extensions), then how should I approach the problem? |
Using the Another way to use the same extension in each object would be to register the extension yourself first, and then pass in the
Out of curiosity, what new SRO are you creating? Is it something that cannot be modeled by the existing Relationship or Sighting object? You could create a |
That code doesn't register one extension, it tries to register three with the same ID. Perhaps you were thinking of the creation of the extension-definition as a kind of "registration", and then the references to its ID when creating the custom objects as "using" it? That's not what's actually happening. What is actually registered is a custom class which corresponds to the object which must appear in the With regard to the STIX 2.1 spec and how it defines extensions: you tried to use the same extension-definition for two different SDOs. I don't see any specific discussion of that in the spec, but I don't think that's what was intended. I think a hybrid extension-definition can only represent one extension of each type. So if your extension-definition defines the priam-sensor SDO, it can't also define the priam-action SDO, but it could define the priam-generate SRO. I think you'll need to divvy up your extensions into multiple extension-definitions. With regard to the stix2 library: when you use the Anyway, I think the library can support what you need, depending on how complex your needs get! @clenk: The SRO extension he was creating is at the bottom of the notebook, underneath the exception stacktrace ( |
Hi,
would this even be possible considering all that has been said? In other words, should we change the extension_types to extension_type a single value? Would be nice to see a counter example. With regards to SRO, yes I totally get your point I could re-use some of the original ones and add a few properties. I forgot to ask to the previous question, the reason for this extension is to be able to model cyber sources such as ips,av,edr,firewalls generating alerts associated to observables. Let me know if this is something of general interest maybe we can plan a proper official extension? |
Stix2 library APIs for STIX objects basically mirror the spec-defined properties, and I don't think that's likely to change. Regarding your question, the spec allows a single extension-definition with new-sdo and new-sro extension types, but I think it does not allow one to bring an arbitrary collection of object types under the umbrella of a single extension-definition. There are five defined extension types, which means a single extension-definition can be used in at most five different ways. Only three of those extension types (usages) are for new STIX object types. So a single extension-definition can define at most three new STIX object types. There are limits as to what you can do with a single extension-definition, and those limits are not due to the stix2 library. So perhaps the first thing to do is design spec-compliant extension-definition(s) which satisfy your needs, and then to ask whether the stix2 library allows you do work with them adequately, as an implementation. I think you will need a separate extension-definition per SDO. You could lump in the SRO with one of the SDO extensions, but it seems arbitrary which one that should be, so maybe the SRO gets its own extension definition as well? @rpiazza maybe there is a mailing list with a wider user base where he could present these ideas, and gauge general interest? |
Hi @chisholm we are releasing a project soon, will be easier to talk over that once is ready. Thanks for the help. |
I think having only one extension type per extension definition should be a best practice. I think the idea behind having multiple types in one extension definition was to indicate that the extension definition had multiple parts, but were basically one extension "idea". I'm not sure if that is important or adds anything useful. |
Hi, Question: Is it possible to have an Extension Definition that subclasses an existing object? We are working with OCA IoB and they have defined a custom object "Behaviour". I have spoken to them and suggested there is some conceptual overlap with "Indicator". Is it possible to have an Extension Definition that effectively does this?
This approach of extending existing objects, but with new names, is similar to the ATT&CK one, and is pretty useful. Can you advise whether this is one of the five Extension Definition methods (I dont think so), and/or whether it may/can appear in a future Stix release as a feature? Thank you |
I don't think there's any notion of "subclass" or "subtype" in the spec, at least among object types. None of the extension types capture that. Maybe the nearest you could get is devising a relationship of some kind between a behavior and indicator, e.g. an SRO or embedded relationship. Of course, that would only enable relating instances of the "behavior" and "indicator" concepts, not the concepts themselves. I can't speak to getting it into the spec, or similar data model extensions (the latter might require more information about the behavior type anyway). |
There is a concept of "subtypes" in the specification. They were the "original" extensions - see the File SCO https://docs.google.com/document/d/1cGAQy93KuYZAgYUbzSomU_WIeDSUP4H7OVwbaBX5Szc |
Well that's interesting, I had not seen that. Current spec only says (section 3.10) the purpose of predefined extensions is "defining coherent sets of properties beyond the base". Maybe sometimes the intent is to create a subtype, but not always? I think intent is not captured in the STIX content. It's just something to keep in mind, and will guide how the extension gets absorbed into the spec, if that should happen. My takeaway is that "subtypes", at least as far as they're discussed right now, are not separate object types. You'd create a |
@chisholm - Yes - I was using the term "subtype" informally. Predefined extensions were a OO shortcut - I don't think the intent was every anything else. The new extension definition facility usually does not create "subtypes" - it is redefining the extended object type. When an extension definition gets absorbed into the spec - the old definition of the object type is replaced. However, it is possible to use the extension definition facility to create new "predefined" extensions - assuming they get absorbed. Once again see the google doc for more details. |
Hi there,
I am doing some practice to create custom objects to model additional concepts such as a firewall and its actions such as drop/pass to a network object.
This is a very bare bone starting point:
I then try the following:
But I am getting this error:
Is this happening because I am not allowed to create list of references to custom objects?
The text was updated successfully, but these errors were encountered: