STIX 2.1 104.5: Creating Extension Schemas

TutorialsStix

If you are reading this blog post via a 3rd party source it is very likely that many parts of it will not render correctly. Please view the post on signalscorps.com for the full interactive viewing experience. In this post I will show you how I craft STIX schemas for STIX 2.1 Extensions.

Last year I wrote a post on customising STIX Objects using extensions. That post proved rather useful to us recently as we needed to create our own for file2stix.

In April I showed you a proof-of-concept for adding a custom extension to represent a full Sigma Rules more logically (in addition to the entire YAML in the Indicator SDOs pattern field).

file2stix uses this extension definition when creating Indicator SDOs when representing Sigma Rules.

file2stix also uses other extensions (where extension_type = property-extension) to extend Indicator SDO and Software SCO Objects when representing;

  • MISP / Custom Warning List Matches (Indicator SDO)
  • NVD CPE enrichments (Software SCO)
  • NVD CVE enrichments (Vulnerability SDO)

file2stix also creates 4 types of custom SCOs (where extension_type = new-sco) using extensions for the following detections;

  • User agent (user-agent)
  • Credit card (credit-card)
  • Bank account (bank-account)
  • Cryptocurrency wallet (cryptocurrency-wallet)

You can view them all on GitHub here.

Creating the extension definition objects is easy — simply create an extension-definition object with the required properties.

However, one of the crucial parts I glossed over in previous posts was defining the schema for available properties used in an extension.

In the extension definition objects you might have seen the schema property that typically links to a public site where the schema can be viewed, for example;

A well defined schema is vital for creators of STIX objects wanting to use your schema to understand the properties and data types available for them to use. It’s equally important for consumers to understand the type of values that can be returned.

When getting started with defining a schema (especially if you’re new to it, like I was, and still am, is to take a look at some existing examples — the schemas for native STIX objects created by OASIS are perfect for this. For example, the Vulnerability SDO schema.

This guide, Understanding JSON Schema, is also a helpful resource for newbies too.

And that is important to keep in mind, I am a newbie. I am sharing how I built our schemas. It is definitely not the best way and If someone drops into the community Slack to tell me a better way, I’d be very grateful!

The top level part of the schema defines its purpose and format.

e.g.

Breaking down each of these properties;

Below the top-level schema information you will see the allOf property, which the full schema is nested within.

One of the useful features when defining a schema is the ability to inherit other schemas.

For example, the Vulnerability SDO Schema, inherits the core STIX schema], defined in the Vulnerability SDO Schema like so;

This includes the common STIX 2.1 properties.

In the crytocurrency-wallet new-sco schema I inherit the core SCO schema;

Similarly in the CPE property-extension for Software SCOs, I inherit the Software SCO schema, like so;

…which in turn inherits the SCO core schema (in the Software SCO schema).

In the CPE property you will also see the following property;

Which in addition to the STIX schemas being inherited, is also pulling in an external schema.

Nesting property-extensions

In the case of the extension_type = property-extension I need to define how the extension will be nested in the original STIX Object.

Using the example CPE extension nested in the software SCO);

Nested under the Software SCOs extensions property will be the id of the extension definition object for my CPE definition ( extension-definition--6c453e0f-9895-498f-a273-2e2dda473377).

Nested below that will the extension_type is declared and then the nvd_cpe property which contains all the NVD enrichment data nested within it.

Complete example here for clarity.

Which represented in my schema looks like;

Auto-generating schema from an example object

I have found the easiest way to generate the schema for each property in an extension (if there is not an external schema available, like for the CPE extension) was to first mock it up in an example, and use an automated schema creation tool to create a skeleton schema that can be built upon.

GenSON proved to be a good tool for auto-generating a schema. GenSON can be installed an used like so;

Once installed, I can then run it on one of the example STIX 2.1 Objects like so;

The output will provide a full JSON schema listing all the properties in the object. In this case, this includes both the core Software SCO properties (e.g. id, type, etc) and the nested extension definition properties inside it (e.g. cpe23Uri, part, etc.).

Firstly, the core properties can all be cut from the file (these are already defined in the inherited STIX core schemas).

The output for the custom properties tries to identify the correct datatype, however, unless you write very detailed examples the identified for most fields will string (unless the data type is obvious to GenSON e.g. deprecated = boolean);

Nonetheless this data is still useful. It is these properties extracted by GenSON we can use as the skeleton to define our schema.

The next step is to go one by one through each property.

Let me show you by going over a few examples.

Cleaning up the json schema

Defining fixed fields

Starting with extension_type, for property extensions I know this must always be property-extension.

Therefore for my Warning List schema I can define an enum for this property with only property-extension available.

Going from the GenSON output;

to;

As shown, it is useful to add a description property to the definition to provide more clarity to those reading it.

Dealing with arrays

Now lets look at the input property in the crytocurrency-wallet schema.

The input property contains objects with the properties address_ref and amount_sent

The two nested properties in an object make the data type an array. Within the array are the two items.

The output from GenSON is correct without modification; the general structure and data types identified are all correct. All I did was to add description s that gave a schema as follows;

Pattern validation

In our Credit Card SCO, there’s a few more constraints to the fields I decided to add a bit more logic to the field values to ensure users avoid making mistakes when creating objects.

For the id field the values must always start with credit-card--. This can be defined in a pattern property.

Regular expression patterns like this can be made much more complex, if required.

When it comes to the value of the credit card (the number property), it's also possible to be even more specific about the values accepted using the schema.

Firstly, the type is not a string. Credit card numbers, by definition, only contain numbers.

Secondly I also know that most major credit cards do not have more than 20 digits.

Therefore I can change the simplistic GenSON output (where only "type": "string" is defined) to a tighter schema definition as follows;

If I really wanted, I could use other schema properties to further define acceptable values (e.g. number must start with 4242 if issuer is visa, etc.).

Required fields

Finally, we can define the required fields. By default GenSON assumes all properties are required, which for my extensions is not the case.

For our Credit Card new-sco I define the following top-level properties inside the extension as always required;

It is also a requirement in the STIX specification that extension_type is declared for custom extensions.

In the credit card SCO you can see this defined in the nested objects, extensions and extension-definition--abd6fc0e-749e-4e6c-a20c-1faa419f5ee4 respectively.

Sharing your extension

Once you’ve create a schema for your extensions it’s time to start using it in STIX objects.

There is no requirement to share your extension if the objects you create from them are never shared outside your organisation.

Of course, if you want to share objects that use extensions then it is important that the schema and extension definition objects are available.

Signals Corps extensions are share publicly in our STIX2 Objects repository.

OASIS also accept pull requests to their STIX common object repository here. There are a few examples in the extension-definition-specification directory (ignore the stix1x ones).

Submission to the OASIS repository can ultimately end up in your extensions being adopted into the core STIX schema. There is a very detailed policy from OASIS outlining this.

STIX 2.1 Certification (Virtual and In Person)

The content used in this post is a small subset of our full training material used in our STIX 2.1 training.

If you want to join a select group of certified STIX 2.1 professionals, subscribe to our newsletter below to be notified of new course dates.

Similar Posts You Will Enjoy Reading…

Originally published at https://www.signalscorps.com on October 16, 2022.

--

--

I help early stage cyber-security companies to build products that make users go; “Wow! That’s what I need!”. https://www.himynamesdave.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
David G

I help early stage cyber-security companies to build products that make users go; “Wow! That’s what I need!”. https://www.himynamesdave.com/