Lesson 07 · 50 minutes
Spot signs of AI-enhanced attacks in your data and hold risky requests
- Say what changes for a defender when attackers use AI, and what does not
- Detect a burst of many different but similar messages with a similarity cluster
- Apply controls that do not depend on how well a message is written
The lab folder as it stands after this lesson. Unzip it in ~/krlab.
More
The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.
Scenario
On Tuesday morning the finance team of Harbourline Logistics gets many mails that say a supplier "has changed its bank details". No two mails have the same text, and the senders are different. At the same time the finance manager gets a short video call from someone who looks and sounds like the CEO and asks for an urgent payment, "no time for the usual approval". Your lead asks: "Is this one campaign? Which of our checks would catch it, and which would not?" You have the day of mail as a data set and a list of twelve payment requests. This lesson is about what a defender sees. It does not teach how to write such messages.
Recall
Lesson 5: which feature of a message lasted when the attackers changed their wording?
The domain mismatch: the link points to a domain that is not the sender's. The attacker must control the place that the link points to, so this fact does not depend on style.
Lesson 6: a claim carries a source and the check passes. What else must an analyst read?
The warnings: stale, conflict and unverified. A pass shows that the source holds the claim, and it does not show that the source is right.
The idea
Attackers who use AI can write fluent mail in any language, change the wording of each message, copy a writing style and, with enough samples, imitate a voice or a face in a call. For the defender this changes three things.
| What weakens | Why | What still works |
|---|---|---|
| Spotting bad grammar and typos | Fluent text costs the attacker nothing | Facts that the attacker cannot choose: sender domain, link, timing |
| Matching exact copies or file hashes | Every message and every file can be different | Similarity, behaviour and family: each variant of a program has a new hash, but it acts alike (lesson 8 tests this on a file of samples) |
| "It sounds like him, so it is him" | A voice, a face and a style can be imitated | A process that does not trust the channel |
The same few items appear in the data of a defender:
- Many unique but similar messages, from several senders, in a short time. Each text is new, so a list of known bad texts finds nothing. The group is visible when you measure similarity.
- A display name of a manager on an address outside the company. The name is free to choose, and the domain of the address is not.
- A request by voice or video that skips the normal approval. The pressure ("urgent", "secret", "no time") is part of the method.
- Attacker → Finance mailbox: 26 different mails from 9 senders
- Finance mailbox → Burst detector: near-copies form one group
- Attacker → Finance manager: a video call as the CEO
- Finance manager → Approval rule: a payment request for 90,000
- Approval rule → Bank payment (blocked): held until call-back and approval
The controls that work do not depend on judging the message. A call-back rule says that you confirm a payment request on a number from the directory, never on the number in the request. Out-of-band approval means approval in a different system from the request. Dual control means that two people must act. Header and domain checks compare who the message claims to be with what the mail system can prove (SPF, DKIM and DMARC, lesson 5). A fluent message and a perfect voice pass none of these by being good.
AI also makes fake content in your company's name: a fake video of the CEO, a fake statement about a breach. Misinformation is false content that people share because they believe it, with no aim to harm. Disinformation is false content that someone makes and spreads on purpose. You cannot tell which one it is from the content, so the first step is the same: check the claim against your own facts, say what is true on an official channel, and ask the platform to remove the fake.
Worked example
1. See why exact matching fails
mail_stream() returns one day of mail: 288 messages, each with the minute of the day, a display name, an address, a recipient and a text. In it are 220 ordinary mails, a newsletter of 30 equal mails from one sender, a reminder of 12 similar mails from one sender, and 26 messages of one campaign from 9 senders.
Save bursts.py. Counter counts equal texts. cosine_similarity(TfidfVectorizer().fit_transform(texts)) gives the similarity of every message with every other (lesson 6). clusters joins messages that are similar to each other into groups. It uses a union-find structure, a way to merge items: if A is similar to B, and B to C, then A, B and C are one group, and find returns the representative of the group of one item. bursts keeps the groups that are big, from many senders and short in time. fake_executive checks a display name against the address.
bursts.py
"""bursts.py: find a burst of near-duplicate messages, and check the sender header of each message."""
from collections import Counter
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from gen import CORP, EXECS, mail_stream
SIMILAR = 0.5 # cosine similarity above which two messages count as the same message
MIN_SIZE = 8 # a burst has at least this many messages
MIN_SENDERS = 4 # from at least this many different addresses
MAX_SPAN = 60 # inside this many minutes
def clusters(rows, similar=SIMILAR):
"""Group messages that are similar to each other. Returns a list of lists of row numbers."""
sims = cosine_similarity(TfidfVectorizer().fit_transform([m["text"] for m in rows]))
parent = list(range(len(rows)))
def find(i):
while parent[i] != i:
parent[i] = parent[parent[i]]
i = parent[i]
return i
for i in range(len(rows)):
for j in range(i + 1, len(rows)):
if sims[i][j] >= similar:
parent[find(i)] = find(j)
groups = {}
for i in range(len(rows)):
groups.setdefault(find(i), []).append(i)
return list(groups.values())
def bursts(rows, similar=SIMILAR):
"""The clusters that are big, from many senders and short in time."""
found = []
for g in clusters(rows, similar):
ms = [rows[i] for i in g]
span = max(m["minute"] for m in ms) - min(m["minute"] for m in ms)
if len(ms) >= MIN_SIZE and len({m["addr"] for m in ms}) >= MIN_SENDERS and span <= MAX_SPAN:
found.append(ms)
return found
def fake_executive(m):
"""The display name is that of an executive, but the address is not in the company domain."""
return m["name"] in EXECS and not m["addr"].endswith("@" + CORP)
if __name__ == "__main__":
rows = mail_stream()
texts = Counter(m["text"] for m in rows)
print("messages:", len(rows), " different texts:", len(texts))
print("largest group of exactly equal texts:", max(texts.values()))
print("groups of equal texts that have 8 or more messages:", sum(1 for v in texts.values() if v >= MIN_SIZE))
for b in bursts(rows):
print("burst:", len(b), "messages,", len({m["addr"] for m in b}), "senders, minutes",
min(m["minute"] for m in b), "to", max(m["minute"] for m in b), ", different texts:", len({m["text"] for m in b}))
print("sender names of executives with a foreign address:", sum(fake_executive(m) for m in rows))python3 bursts.pymessages: 288 different texts: 133
largest group of exactly equal texts: 30
groups of equal texts that have 8 or more messages: 1
burst: 26 messages, 9 senders, minutes 601 to 637 , different texts: 26
sender names of executives with a foreign address: 62. Read the result
The first lines show the failure of exact matching: the only group of 8 or more equal texts is the newsletter, which is harmless. The 26 messages of the campaign are 26 different texts, and an exact test sees none of them.
The similarity cluster finds one burst: 26 messages from 9 senders between minute 601 and minute 637, with 26 different texts. It does not flag the newsletter, because it has one sender, or the reminder, because it has one sender too. The ordinary mails also form large clusters of similar sentences, but they spread over the whole day, which is more than 60 minutes. The burst rule has three conditions on purpose. Each one removes a kind of harmless group. The detector depends on one constant: with SIMILAR at 0.5 it finds 26 messages, at 0.7 it finds 24, and at 0.8 it finds none. The union-find joins by chaining, so a campaign that paraphrases more can split, and similar mail can merge groups.
The last line counts 6 messages whose display name is that of an executive and whose address is outside the company. The header check finds the impersonation without reading the text. It is a rule, and it can be wrong: a real executive may write from a personal address. A person reads each hit.
3. Hold requests that skip the approval
Save approvals.py. hold(req) returns the reasons to hold one payment request, and an empty list means release. It holds a large amount that is not approved in the finance system, a request by voice or video with no call-back, and a new payee with no call-back. The limit of 5,000 is a policy choice that you can change.
approvals.py
"""approvals.py: hold a payment request that skips the normal approval."""
from gen import payment_requests
LIMIT = 5000
def hold(req):
"""Return the reasons to hold a request. An empty list means that it may go on."""
why = []
if req["amount"] > LIMIT and not req["approved_in_system"]:
why.append("no approval in the finance system")
if req["channel"] in ("voice", "video") and not req["callback_done"]:
why.append("voice or video request with no call-back")
if req["new_payee"] and not req["callback_done"]:
why.append("new payee with no call-back")
return why
if __name__ == "__main__":
reqs = payment_requests()
for r in reqs:
why = hold(r)
print(r["id"], f"{r['channel']:6}{r['amount']:>7}", "HOLD: " + "; ".join(why) if why else "release")
print("held:", sum(bool(hold(r)) for r in reqs), "of", len(reqs))python3 approvals.pyR01 email 1200 release
R02 email 48000 HOLD: no approval in the finance system; new payee with no call-back
R03 voice 25000 HOLD: no approval in the finance system; voice or video request with no call-back
R04 video 90000 HOLD: no approval in the finance system; voice or video request with no call-back; new payee with no call-back
R05 chat 300 release
R06 voice 15000 release
R07 email 7000 release
R08 video 60000 HOLD: no approval in the finance system
R09 email 9500 release
R10 voice 4000 HOLD: voice or video request with no call-back; new payee with no call-back
R11 email 52000 release
R12 chat 18000 HOLD: no approval in the finance system
held: 6 of 12Six of twelve are held. R04 is the pattern of the scenario: video, 90,000, a new payee, no approval and no call-back, with three reasons. R06 is a voice request for 15,000 that was released: it is approved in the system, and the call-back was done. The rule does not care how convincing the caller was. It asks only whether the steps took place.
4. What the checks do not do
The burst detector reads texts, so a campaign of one message to one person, written well, is not a burst. The header check sees a foreign address, and it does not see a hijacked real account. The approval rule does not look at the content at all, which is its strength, and it works only if people use it. The three checks cover different gaps, and none is enough alone.
Style is not on the list. A detector that says "this is not how the CEO writes" is weak, because the same technology that writes the message can copy the style. Do not build a control on it. Use it at most as a hint for a person.
Your turn
Use bursts.py and approvals.py. Change the settings and count. You write the changes.
- Set
SIMILARto 0.7. How many messages does the burst hold now? - Set
SIMILARto 0.8. How many bursts are found? - Set the limit of
approvals.pyto 20,000. How many of the twelve requests are held? - How many messages of the stream fail the executive header check?
Last, write two sentences for the finance manager on what to do when a video call asks for an urgent payment with no approval.
Check yourself
Why does an exact-duplicate test miss the burst?
Every message has different words, so no two texts are equal. The burst is visible only as a group of texts that are close to each other. Similarity measures that, and equality does not.
Why does the burst rule need three conditions and not only "many similar messages"?
Harmless groups exist: a newsletter has many similar messages from one sender, and ordinary templates repeat all day. The conditions of senders and of a short time remove them. Each condition is a choice that you review when mail changes.
A caller sounds exactly like the CEO. Why does the call-back rule still work?
It does not ask whether the voice is right. It asks the real CEO, on a number from the directory, whether the request is real. An imitated voice cannot answer a call that never reaches it.
A fake video says that your company has a breach. Is it misinformation or disinformation, and what do you do first?
Disinformation if someone made it on purpose, misinformation if people share it believing it. You cannot know at first, and you do not need to: check the claim against your own facts, say what is true on an official channel, and ask the platform to remove the fake.
A campaign is missed at the similarity 0.8. What does that tell you about the burst rule?
The rule is only as good as its threshold. Measure it on several days of mail, and keep a second signal that does not depend on the text, such as the header check or the approval rule.
Field notes
- Many AI-enhanced attacks are old attacks that are cheaper and wider. The first defence is still process: approval limits, call-back, two people, and least privilege (lesson 4 of "Security fundamentals").
- Authenticate the channel, not the face. A video call proves nothing about who is on it. A pre-agreed code word or a call to a known number does.
- Train staff on the process, not on spotting fakes. People cannot reliably see a good fake, and they can follow a rule such as "no payment on a call alone".
- Phishing is MITRE ATT&CK technique T1566, and it also covers voice phishing. Take the current text from MITRE, and map each of your detections to it.
- Test your controls with your own staff and your own tools, with permission, and measure how often the process held. Do this in a lab or in a sanctioned exercise, never on a real person without approval.