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
| Word | What it means | Example |
|---|---|---|
| Threat intelligence | evidence about attackers that helps somebody decide | |
| Indicator of compromise | a value that suggests an intrusion | 198.51.100.23 |
| Hash | a fingerprint of a file's bytes | |
| Artefact | a trace a tool leaves on a network or a machine | |
| TTP | how an attacker works: tactics, techniques and procedures | |
| Pyramid of pain | indicators 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 questionsThe 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
| Type | Value | What the report says |
|---|---|---|
| sha256 | 60065055603b... | The Word document sent by email |
| ip | 203.0.113.99 | Its old server, used until October |
| ip | 198.51.100.23 | Its current server |
| domain | cdn-update.example | The name the implant looks up |
| uri | /api/check | The page it calls every minute |
| useragent | updater/1.4 | The name it gives itself |
| cmdline | -nop -w hidden -enc | How its PowerShell starts |
The cells students fill in are left blank in this preview.
Check
Have a go
Check
3 questionsA 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
cd ~/detectShown here, not run. Press Start lab to type it into your own lab’s terminal.
Make a folder for the intelligence
mkdir -p intelShown here, not run. Press Start lab to type it into your own lab’s terminal.
Save the seven indicators
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.txtShown here, not run. Press Start lab to type it into your own lab’s terminal.
Turn the capture into logs
zeek-lite -r pcaps/office.pcapShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write the sweep, part 1
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.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write the sweep, part 2
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.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Run the sweep
python3 intel/sweep.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsSome 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
| Level | Kind | From the report | Cost to change |
|---|---|---|---|
| 6, top | TTPs | Word starts hidden PowerShell, then calls home each minute | Tough |
| 5 | Tools | The updater implant itself | Challenging |
| 4 | Artefacts | /api/check, updater/1.4, -nop -w hidden -enc | Annoying |
| 3 | Domain names | cdn-update.example | Simple |
| 2 | IP addresses | 198.51.100.23, 203.0.113.99 | Easy |
| 1, bottom | Hash values | 60065055603b... | 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 questionsDefang 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
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.
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