Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Writing threat intelligence as STIX objects

After this lesson: I can write a threat report as a STIX 2.1 bundle of linked objects.

65 min lesson8 commandsDetection engineering lab: Suricata rules, Sigma rules and Zeek-style logs on one private Ubuntu VM

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

A report a machine can read

A PDF report is easy for a person and useless to a firewall. Somebody has to copy each address out by hand, and somebody else makes a typo.

If the report is written as structured data, a tool can load it, link it and act on it in seconds. You write the made-up Copper Lantern report that way, in your own lab copy.

By the end of this lesson

Note

I can write a threat report as a STIX 2.1 bundle of linked objects.

Key words

WordWhat it meansExample
STIXa JSON language for threat intelligence
Objectone thing in STIX, with a type and an idindicator--8f1c...
Patternthe test an indicator applies to data[ipv4-addr:value = '198.51.100.23']
Relationshipan object that links two others
Bundlea set of objects sent together
TAXIIthe protocol that carries STIX between servers

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The one rule

Important

Write and test only in your own lab copy. Every object here is made up. A real bundle can name victims and people. Share it only as its label allows, which is the next lesson.

A report becomes typed objects

STIX 2.1, from the standards body OASIS, describes intelligence as JSON objects. Every object has a type and an id, made of the type, two dashes and a UUID. It also has a spec_version of 2.1 and created and modified times.

Some describe the threat: a threat-actor, a malware family, an attack-pattern, an indicator. Two kinds connect them: a relationship and a sighting.

Worked example: the objects of the report

typenameWhat it says
identityNorthgate CERTWho wrote the report
identityRiverside officeWhere it was seen
threat-actorCopper LanternThe group, made up
malwareupdaterIts implant, a family
attack-patternWeb ProtocolsT1071.001, by external_id
indicatorcdn-update.example and four moreWhat to look for
relationshipeight of themuses, targets, indicates
sightingof cdn-update.exampleSeen 5 times at Riverside

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The script builds and links the bundle

The Runs write a script with only Python's standard library. It makes each object, gives it an id from its type and name, links the objects and writes intel/bundle.json.

The ids are made from the names (uuid5) and every time is fixed. So your bundle is byte for byte the same as everybody else's.

Move into the lab's folder

Command
cd ~/detect

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Make sure the intelligence folder exists

Command
mkdir -p intel

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the bundle script, part 1

Command
printf '%s\n' 'import json, uuid' 'NS, T, Q = uuid.UUID("6f6e3a5c-1d2b-4c8e-9a7f-3b5d0c2e1a90"), "2026-11-03T10:00:00.000Z", chr(39)' 'objs = []' 'def add(kind, key, **more):' '    obj = {"type": kind, "spec_version": "2.1", "id": kind + "--" + str(uuid.uuid5(NS, kind + key)), "created": T, "modified": T}' '    obj.update(more)' '    objs.append(obj)' '    return obj["id"]' 'def ind(name, path, until=None):' '    more = {"valid_until": until} if until else {}' '    return add("indicator", name, name=name, pattern="[" + path + " = " + Q + name + Q + "]", pattern_type="stix", valid_from="2026-09-01T00:00:00Z", **more)' 'cert = add("identity", "Northgate CERT", name="Northgate CERT", identity_class="organization")' 'office = add("identity", "Riverside office", name="Riverside office", identity_class="organization")' 'actor = add("threat-actor", "Copper Lantern", name="Copper Lantern")' 'implant = add("malware", "updater", name="updater", is_family=True)' > intel/bundle.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the bundle script, part 2

Command
printf '%s\n' 'web = add("attack-pattern", "Web Protocols", name="Web Protocols", external_references=[{"source_name": "mitre-attack", "external_id": "T1071.001"}])' 'dom = ind("cdn-update.example", "domain-name:value")' 'ips = [ind("198.51.100.23", "ipv4-addr:value"), ind("203.0.113.99", "ipv4-addr:value", "2026-10-31T00:00:00Z")]' 'ua = ind("updater/1.4", "network-traffic:extensions." + Q + "http-request-ext" + Q + ".request_header." + Q + "User-Agent" + Q)' 'doc = ind("60065055603b91d13dc69c589f08730dd503f0d86f354d0b07ce3a9607814e3d", "file:hashes." + Q + "SHA-256" + Q)' 'for src, rel, dst in [[actor, "uses", implant], [actor, "targets", office], [implant, "uses", web], [dom, "indicates", implant], [ips[0], "indicates", implant], [ips[1], "indicates", implant], [ua, "indicates", implant], [doc, "indicates", actor]]:' '    add("relationship", src + rel + dst, relationship_type=rel, source_ref=src, target_ref=dst)' >> intel/bundle.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the bundle script, part 3

Command
printf '%s\n' 'add("sighting", "sighting" + dom, sighting_of_ref=dom, where_sighted_refs=[office], count=5)' 'bundle = {"type": "bundle", "id": "bundle--" + str(uuid.uuid5(NS, "bundle")), "objects": objs}' 'json.dump(bundle, open("intel/bundle.json", "w"), indent=2)' 'kinds = [o["type"] for o in objs]' 'for kind in sorted(set(kinds)):' '    print(kinds.count(kind), kind)' 'print(len(objs), "objects in the bundle")' >> intel/bundle.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Build the bundle

Command
python3 intel/bundle.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

An indicator holds a pattern

An indicator does not hold a bare value. It holds a pattern, a test in square brackets. A pattern names an object type and a property, then compares it with a value in single quotes.

It also has valid_from and can have valid_until. The old address 203.0.113.99 stopped being valid on 31 October 2026.

Read the five patterns

Command
grep '"pattern"' intel/bundle.json

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Find the indicator that has expired

Command
grep -B 4 '"valid_until"' intel/bundle.json | grep '"name"'

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think STIX is a feed you subscribe to. STIX is only the language of the objects. TAXII is the protocol that carries them: a server offers collections and a client fetches bundles over HTTPS. A bundle in a file or an email is still STIX.

Try it: write a pattern

Code: python
q = chr(39)
kind = "domain-name"
value = "cdn-update.example"

pattern = "[" + kind + ":value = " + q + value + q + "]"
print(pattern)
# Make the pattern for the address 198.51.100.23, whose kind is ipv4-addr.

Make a free account to save your work and track your progress.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Assignment: write patterns and check a bundle

Write two functions.

pattern_for(kind, value) returns a STIX pattern: for "domain", [domain-name:value = 'VALUE']; for "ipv4", [ipv4-addr:value = 'VALUE']; for "sha256", [file:hashes.'SHA-256' = 'VALUE']. For any other kind return None.

problems(bundle) checks a bundle, a dictionary with a list under "objects", and returns a list of problems in the objects' order. For each object: "bad id ID" when its id does not start with its type and --; "bad version ID" when spec_version is not "2.1"; for a relationship, "missing REF" for a source_ref or target_ref that is no object's id; for an indicator, "no pattern ID" when it has no pattern. An empty list means the bundle is fine.

Code: python
def pattern_for(kind, value):
    return None

def problems(bundle):
    return []

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.