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

Free lesson

Indicators of compromise and the pyramid of pain

After this lesson: I can rank indicators of compromise by how hard each one is for an attacker to change.

60 min lesson7 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

Seven clues in an email

A partner team sends your college's security team a short report. A group they call Copper Lantern attacked another college last week. The report ends with seven clues: two addresses, a domain, a file fingerprint and more.

Which clue is worth your time, and which will be useless by Friday? The group and the report are made up, and you work in your own lab copy only.

By the end of this lesson

Note

I can rank indicators of compromise by how hard each one is for an attacker to change.

Key words

WordWhat it meansExample
Threat intelligenceevidence about attackers that helps somebody decide
Indicator of compromisea value that suggests an intrusion198.51.100.23
Hasha fingerprint of a file's bytes
Artefacta trace a tool leaves on a network or a machine
TTPhow an attacker works: tactics, techniques and procedures
Pyramid of painindicators ranked by what they cost an attacker to change

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

Search only your own lab copy. Never visit, scan or log in to an address from a real report. Using a computer without permission is an offence under the Computer Misuse Act 1990, even an attacker's. Every name and address here is made up.

Intelligence answers a question

A list of addresses is data. Knowing they belong to one group's servers is information. Threat intelligence is information that helps somebody decide, such as which alert to raise.

An indicator of compromise, or IOC, is a value you can search for: a file's hash, an address, a domain, a user agent. The report's seven are in the table.

Worked example: the report's seven indicators

TypeValueWhat the report says
sha25660065055603b...The Word document sent by email
ip203.0.113.99Its old server, used until October
ip198.51.100.23Its current server
domaincdn-update.exampleThe name the implant looks up
uri/api/checkThe page it calls every minute
useragentupdater/1.4The name it gives itself
cmdline-nop -w hidden -encHow its PowerShell starts

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

A sweep searches your logs for each indicator

A sweep searches the data you already have for every indicator. The Runs save the seven indicators, make the office's logs from its capture, and write a short script that searches them.

The script looks in conn.log, dns.log, http.log and the Windows events table. It prints each indicator's level on the pyramid, then its hits and the machines that had them.

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 a folder for the intelligence

Command
mkdir -p intel

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

Save the seven indicators

Command
printf '%s\n' 'sha256 60065055603b91d13dc69c589f08730dd503f0d86f354d0b07ce3a9607814e3d' 'ip 203.0.113.99' 'ip 198.51.100.23' 'domain cdn-update.example' 'uri /api/check' 'useragent updater/1.4' 'cmdline -nop -w hidden -enc' > intel/iocs.txt

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

Turn the capture into logs

Command
zeek-lite -r pcaps/office.pcap

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

Write the sweep, part 1

Command
printf '%s\n' 'import sqlite3' 'def log(name):' '    rows, fields = [], []' '    for line in open(name):' '        parts = line.rstrip(chr(10)).split(chr(9))' '        if parts[0] == "#fields":' '            fields = parts[1:]' '        elif not line.startswith("#"):' '            rows.append(dict(zip(fields, parts)))' '    return rows' 'conn, dns, http = log("conn.log"), log("dns.log"), log("http.log")' 'cmds = sqlite3.connect("logs/events.db").execute("SELECT Computer, CommandLine FROM logs").fetchall()' 'LEVEL = {"sha256": 1, "ip": 2, "domain": 3, "uri": 4, "useragent": 4, "cmdline": 4}' 'for line in open("intel/iocs.txt"):' '    kind, value = line.strip().split(" ", 1)' '    if kind == "sha256":' '        print(LEVEL[kind], kind, value[:12], "no file hashes in these logs")' '        continue' '    if kind == "ip":' '        hits = [r["id.orig_h"] for r in conn if r["id.resp_h"] == value]' > intel/sweep.py

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

Write the sweep, part 2

Command
printf '%s\n' '    elif kind == "domain":' '        hits = [r["id.orig_h"] for r in dns if r["query"] == value or r["query"].endswith("." + value)]' '    elif kind == "uri":' '        hits = [r["id.orig_h"] for r in http if r["uri"] == value]' '    elif kind == "useragent":' '        hits = [r["id.orig_h"] for r in http if r["user_agent"] == value]' '    else:' '        hits = [c[0] for c in cmds if value in c[1]]' '    print(LEVEL[kind], kind, value, len(hits), "hits", " ".join(sorted(set(hits))))' >> intel/sweep.py

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

Run the sweep

Command
python3 intel/sweep.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

Some indicators hurt an attacker more

David Bianco's pyramid of pain (2013) ranks indicators by the cost to an attacker of changing them. A hash changes if one byte changes. An address or a domain costs minutes and a little money.

An artefact, such as a user agent or a page name, means editing and testing the tool. A tool means writing a new one. TTPs, how the group works, mean learning new habits.

Worked example: the report on the pyramid

LevelKindFrom the reportCost to change
6, topTTPsWord starts hidden PowerShell, then calls home each minuteTough
5ToolsThe updater implant itselfChallenging
4Artefacts/api/check, updater/1.4, -nop -w hidden -encAnnoying
3Domain namescdn-update.exampleSimple
2IP addresses198.51.100.23, 203.0.113.99Easy
1, bottomHash values60065055603b...Trivial

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

A common mistake

Warning

Many people think the more indicators you block, the safer you are. A list of hashes and addresses goes stale as soon as the group rebuilds, as 203.0.113.99 did. Spend your effort near the top, because artefacts and behaviour cost the attacker most to change.

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

Defang an indicator before you share it

A report full of live addresses is a risk: a mail program turns them into links, and a click connects to the attacker. So analysts defang them. A dot becomes [.] and http becomes hxxp.

Before a tool searches for a value, it is refanged, put back as it was. The code shows the idea.

Try it: defang an address

Code: python
value = "http://cdn-update.example/api/check"

safe = value.replace(".", "[.]")
if safe.startswith("http"):
    safe = "hxxp" + safe[4:]
print(safe)
# Defang the address 198.51.100.23 as well.

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

Assignment: defang and rank indicators

Write three functions.

defang(value) returns the value with every . replaced by [.], and a value that starts with http starts with hxxp instead. refang(value) undoes both, so refang(defang(x)) is x.

rank(iocs): iocs is a list of [kind, value] pairs. The kinds, from the top of the pyramid down, are ttp, tool, artefact, domain, ip and hash. Return the values from the top of the pyramid to the bottom. Values of the same kind keep their order, and a kind not on the list goes last.

Code: python
def defang(value):
    return value

def refang(value):
    return value

def rank(iocs):
    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.