Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ first flag relative to the other beacons, across every IP that eventually got fl
tiers from measured median lag, and report when a "slow" source turns out to be fast or the
reverse. The paradox definition then rests on data.

### 3.5 Adversarial test suite · M
### 3.5 Adversarial test suite · M · ✅ shipped

- [ ] **PDX-15: Adversarial test suite.** Done when: CI runs a test for smearing, laundering, dilution and label spoofing, and each pins how far the attack can move the score.
- [x] **PDX-15: Adversarial test suite.** Done when: CI runs a test for smearing, laundering, dilution and label spoofing, and each pins how far the attack can move the score.

Attack the scoring on purpose, with synthetic fixtures:

Expand All @@ -320,6 +320,19 @@ Each attack gets a test that pins down how far it can move the score. This turns
we've done (one vote per author, quality discounts, independence) into guarantees that are
checked on every PR.

*Shipped:* `tests/test_adversarial.py` runs the real OTX parser, reverse DNS check and scorer on synthetic fixtures,
with no network calls. "Guarantee" tests must keep holding, and "known weakness" tests pin attacks that work today.

| Attack | With independent beacons | When OTX is the only witness |
|---|---|---|
| Smearing | One account gets one vote however many pulses it posts; old pulses fade | **Works:** 5 new accounts take a clean IP to paradox 60, Likely malicious; 10 reach 72, Malicious (PDX-38) |
| Laundering | **Holds:** stays Malicious and fires a veneer | **Works:** OTX's own whitelist takes paradox 72, Malicious to 14, Suspicious, with no veneer (PDX-39) |
| Dilution | **Holds:** stays Malicious, and padding can't weaken another author's pulse | **Works:** if every pulse is padded to 20,000 indicators, it reads Likely benign |
| Label spoofing | **Holds:** a forged PTR earns no label and raises a veneer | A clean IP with a forged PTR reads paradox 15, Suspicious |

*Limits:* these pin today's rules against attacks we thought of, on fixtures where the other beacons are set by hand.
They don't show what a real attacker can do, whether OTX would catch sock puppets, or how often this happens.

### 3.6 Rescores that reproduce · S

- [ ] **PDX-28: Score saved scans as of when they were taken.** Done when: `paradox calibrate --rescore` ages each saved scan against its recorded scan time, scans without one say so in the report, and a test shows the same saved scan gets the same score on different days.
Expand All @@ -340,6 +353,21 @@ returned. No vendor is named blocklist.de. IPsum by its README, which describes
and by measuring 88% of blocklist.de, 85% of CINS Army and 99% of ET compromised inside its feed. The list was fixed
before any scores with it existed.

### 3.8 Smearing by new OTX accounts · M

- [ ] **PDX-38: Limit what new accounts can do to a clean IP.** Done when: the smearing test's numbers change, a rescore of the calibration IPs reports detection and benign flagged before and after, and every malicious IP that falls below Suspicious is named.

The adversarial suite shows 5 new OTX accounts taking a clean IP to Likely malicious when no other beacon agrees.
Requiring corroboration before OTX alone can reach that label is one candidate, and its cost is the very early warning
this project exists for. Measure that before choosing. Whether OTX exposes anything about account age is unchecked.

### 3.9 OTX's whitelist clearing its own evidence · S

- [ ] **PDX-39: OTX's whitelist can't clear OTX-only evidence silently.** Done when: the laundering test's numbers change or the report plainly says OTX's evidence was discounted by OTX's own whitelist, and a rescore reports the effect on the benign IPs that discount was built for.

The discount exists because malware contacting a DNS resolver fills OTX with noise, and OTX's whitelist is a fair sign
of that. The same rule lets an attacker on that whitelist drop from Malicious to Suspicious with no veneer.

---

## Phase 4: The detector as a target (AI-security track)
Expand Down Expand Up @@ -551,7 +579,7 @@ and fix the top issues. Repeat after 5.6. It also doubles as class material.
| When | Items | Why first |
|---|---|---|
| Now | ~~1.1, 1.2, 1.5, 3.2, 5.1~~ (done) | Small, keyless, and fix the biggest measured weakness (the scanner rule's dependence on GreyNoise); 5.1 makes that dependence visible |
| Next | 1.3, 3.1, 3.5, 3.6, 4.1, ~~4.6, 4.7, 4.8, 4.9, 4.10, 4.5, 1.7, 1.8, 3.7, 1.4, 1.6, 5.2, 5.4~~ (done) | Close the known false positives, build adversarial and hiding-place test sets, test the AI summarizer under attack, and show watch state and claim checks in the UI |
| Next | 1.3, 3.1, 3.6, 3.8, 3.9, 4.1, ~~3.5, 4.6, 4.7, 4.8, 4.9, 4.10, 4.5, 1.7, 1.8, 3.7, 1.4, 1.6, 5.2, 5.4~~ (done) | Close the known false positives, build adversarial and hiding-place test sets, test the AI summarizer under attack, and show watch state and claim checks in the UI |
| Then | 2.1, 2.3, 3.3, 3.4, 4.2, ~~4.3, 4.4~~ (done), 5.3, 5.5–5.7 | New unmasking signals plus self-measurement once history has accumulated, with the UI restructured to hold them |
| Later | 2.2, 2.4, 2.5 | Bigger extensions: domains, campaigns, more beacons |

Expand Down
7 changes: 5 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ forge a reverse DNS name.

**Open:**

- How far each attack can move a score isn't measured. That's [PDX-15](ROADMAP.md#35-adversarial-test-suite--m), and
until it's built the protections above are untested as defenses.
- `tests/test_adversarial.py` pins how far each attack moves a score. With independent beacons, laundering, padding and
a forged PTR don't clear a malicious IP. But when OTX is the only witness, [5 new accounts can take a clean IP to
Likely malicious](ROADMAP.md#38-smearing-by-new-otx-accounts--m), [OTX's own whitelist can clear real
evidence](ROADMAP.md#39-otxs-whitelist-clearing-its-own-evidence--s), and padding every pulse hides it.
- Those tests use synthetic fixtures and attacks we thought of, so they don't show what a real attacker can do.
- One-vendor scaling has a cost: an attacker known to exactly one vendor and nothing else can read as Likely benign.
- Independence between VirusTotal's vendors can't be shown, because their sources are closed.

Expand Down
213 changes: 213 additions & 0 deletions tests/test_adversarial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
"""PDX-15: attack the scoring on purpose and pin how far each attack moves the score.

Fixtures are synthetic and everything runs offline, through the real OTX parser, reverse
DNS check and scorer. These numbers say what today's rules do, not what a real attacker
would manage. "Guarantee" tests are protections that must keep holding. "Known weakness"
tests pin attacks that work today, with the story that covers them, so a fix or a
regression has to change the number on purpose.
"""

import socket
import unittest
from datetime import datetime, timedelta, timezone
from unittest import mock

from paradox import sources
from paradox.scoring import compute
from paradox.sources import Signal, apply_otx

IP = "45.1.1.1"
NOW = datetime.now(timezone.utc)
RECENT = (NOW - timedelta(days=1)).date().isoformat()
VALIDATION = [{"name": "Majestic", "source": "majestic"}]


def pulse(author, **fields):
return {"author": {"username": author}, "name": "attack campaign", "tags": ["c2"], "modified": NOW.isoformat(),
"indicator_type_counts": {"IPv4": 20}, **fields}


def accounts(n, **fields):
return [pulse(f"account{i}", **fields) for i in range(n)]


def otx(pulses=(), validation=()):
sig = Signal("otx", "OTX", "fast")
apply_otx(IP, sig, {"pulse_info": {"pulses": list(pulses), "count": len(pulses)}, "validation": list(validation)})
return sig


def clean(**over):
"""Every other beacon reads clean, unless replaced."""
beacons = {"greynoise": Signal("greynoise", "GreyNoise", "fast", threat=0.0, confidence=0.6),
"abuseipdb": Signal("abuseipdb", "AbuseIPDB", "fast", threat=0.0, confidence=0.8),
"spamhaus": Signal("spamhaus", "Spamhaus", "slow", threat=0.0, confidence=0.5),
"virustotal": Signal("virustotal", "VirusTotal", "slow", threat=0.0, confidence=0.8),
"internetdb": Signal("internetdb", "InternetDB", "slow", threat=0.0, confidence=0.5)}
return list({**beacons, **over}.values())


def malicious():
"""Independent beacons that agree an IP is bad."""
return {"abuseipdb": Signal("abuseipdb", "AbuseIPDB", "fast", threat=0.9, confidence=0.8, last_seen=RECENT,
facts={"reporters": 50}),
"virustotal": Signal("virustotal", "VirusTotal", "slow", threat=0.8, confidence=0.8, last_seen=RECENT),
"spamhaus": Signal("spamhaus", "Spamhaus", "slow", threat=1.0, confidence=0.95, facts={"current": True})}


def benign_greynoise():
return Signal("greynoise", "GreyNoise", "fast", threat=0.0, confidence=0.6,
facts={"benign_label": "Google Public DNS", "label_kind": "infrastructure"})


def score(signal, *others, **over):
return compute([signal, *clean(**over), *others], now=NOW)


class AttackCase(unittest.TestCase):
def assertScore(self, result, paradox, threat):
self.assertAlmostEqual(result["paradox"], paradox, delta=0.5)
self.assertAlmostEqual(result["threat"], threat, delta=0.01)


class SmearingTests(AttackCase):
"""A burst of OTX pulses against an innocent IP."""

def test_guarantee_one_account_gets_one_vote(self):
one, flood = score(otx(accounts(1))), score(otx([pulse("account0") for _ in range(100)]))
self.assertEqual((flood["paradox"], flood["threat"]), (one["paradox"], one["threat"]))
self.assertEqual(flood["threat_label"], "Likely benign")

def test_guarantee_old_pulses_fade(self):
old = (NOW - timedelta(days=200)).isoformat()
result = score(otx(accounts(10, modified=old)))
self.assertEqual((result["paradox_label"], result["threat_label"]), ("Coherent", "Likely benign"))

def test_known_weakness_new_accounts_can_condemn_a_clean_ip(self):
"""PDX-38. Anyone can open OTX accounts, and five flip a clean IP to Likely malicious."""
for n, paradox, threat, threat_label in ((1, 18.9, 0.11, "Likely benign"), (2, 33.6, 0.195, "Suspicious"),
(3, 44.9, 0.26, "Suspicious"), (5, 60.3, 0.689, "Likely malicious"),
(10, 72.4, 0.819, "Malicious"), (100, 75.1, 0.85, "Malicious")):
result = score(otx(accounts(n)))
self.assertScore(result, paradox, threat)
self.assertEqual(result["threat_label"], threat_label, n)
self.assertEqual(result["direction"], "emerging")

def test_known_weakness_the_contacted_discount_doesnt_stop_it(self):
"""PDX-38. Sock puppets pick their own pulse contents, so half weight only asks for more of them."""
result = score(otx(accounts(10, indicator_type_counts={"FileHash-MD5": 20, "IPv4": 1})))
self.assertScore(result, 60.9, 0.689)


class LaunderingTests(AttackCase):
"""A malicious IP acquires a whitelist entry or a benign label."""

def test_guarantee_a_label_cant_clear_independent_evidence(self):
bare = score(otx(accounts(10)), **malicious())
self.assertScore(bare, 16.0, 0.87)
self.assertFalse(bare["veneer"]["active"])
for name, result, paradox in (
("OTX whitelist", score(otx(accounts(10), VALIDATION), **malicious()), 49.6),
("GreyNoise label", score(otx(accounts(10)), **{**malicious(), "greynoise": benign_greynoise()}), 37.5),
("both", score(otx(accounts(10), VALIDATION), **{**malicious(), "greynoise": benign_greynoise()}), 47.2)):
with self.subTest(name):
self.assertEqual(result["threat_label"], "Malicious")
self.assertTrue(result["veneer"]["active"])
self.assertAlmostEqual(result["paradox"], paradox, delta=0.5)

def test_guarantee_another_beacons_label_cant_clear_otx(self):
result = score(otx(accounts(10)), greynoise=benign_greynoise())
self.assertScore(result, 98.8, 0.819)
self.assertTrue(result["veneer"]["active"])

def test_guarantee_otx_whitelist_doesnt_clear_other_beacons(self):
result = score(otx((), VALIDATION), abuseipdb=malicious()["abuseipdb"])
self.assertScore(result, 93.1, 0.765)
self.assertTrue(result["veneer"]["active"])

def test_known_weakness_otx_whitelist_clears_otx_only_evidence(self):
"""PDX-39. When OTX is the only witness, its own whitelist entry drops it from Severe paradox and Malicious
to Coherent and Suspicious, and no veneer fires, because a label can't be contradicted by its own origin."""
bare, laundered = score(otx(accounts(10))), score(otx(accounts(10), VALIDATION))
self.assertScore(bare, 72.4, 0.819)
self.assertScore(laundered, 14.5, 0.164)
self.assertEqual((laundered["paradox_label"], laundered["threat_label"]), ("Coherent", "Suspicious"))
self.assertFalse(laundered["veneer"]["active"])


class DilutionTests(AttackCase):
"""Padding pulses to trigger the specificity discount."""

def test_guarantee_padded_pulses_cant_weaken_someone_elses_report(self):
honest = accounts(5)
padded = [pulse(f"padder{i}", indicator_count=200_000) for i in range(100)]
before, after = score(otx(honest)), score(otx(honest + padded))
self.assertGreaterEqual(after["threat"], before["threat"])
self.assertGreaterEqual(after["paradox"], before["paradox"])

def test_guarantee_an_author_padding_a_second_pulse_keeps_their_best(self):
before = score(otx(accounts(5)))
after = score(otx(accounts(5) + accounts(5, indicator_count=200_000)))
self.assertEqual((after["paradox"], after["threat"]), (before["paradox"], before["threat"]))

def test_guarantee_padding_cant_clear_independent_evidence(self):
for size in (20_000, 200_000):
result = score(otx(accounts(10, indicator_count=size)), **malicious())
self.assertEqual(result["threat_label"], "Malicious", size)

def test_known_weakness_padding_hides_otx_only_evidence(self):
"""PDX-38's other edge. If every pulse naming an IP is huge, OTX-only evidence fades to Likely benign. That's
the discount working on sandbox dumps, and also what a bad actor's own padded feed would get."""
for size, paradox, threat, threat_label in ((1_000, 60.3, 0.689, "Likely malicious"),
(3_000, 38.6, 0.441, "Likely malicious"),
(20_000, 12.1, 0.138, "Likely benign"),
(200_000, 2.3, 0.026, "Likely benign")):
result = score(otx(accounts(5, indicator_count=size)))
self.assertScore(result, paradox, threat)
self.assertEqual(result["threat_label"], threat_label, size)

def test_test_names_and_clones_count_for_less(self):
for fields in ({"name": "test"}, {"cloned_from": "x"}):
self.assertScore(score(otx(accounts(5, **fields))), 29.2, 0.334)


class LabelSpoofingTests(AttackCase):
"""A fake PTR record, through the real reverse DNS check."""

def rdns(self, ptr, forward):
sig = Signal("rdns", "Reverse DNS", "context")
with mock.patch.object(sources.socket, "gethostbyaddr", return_value=(ptr, [], [IP])), \
mock.patch.object(sources.socket, "getaddrinfo",
return_value=[(socket.AF_INET, 1, 6, "", (a, 0)) for a in forward]):
sources.check_rdns(IP, sig)
return sig

def test_guarantee_a_forged_ptr_earns_no_label_and_costs_the_forger(self):
forged = self.rdns("census9.shodan.io", ["198.20.69.74"])
self.assertNotIn("benign_label", forged.facts)
result = score(otx(), forged)
self.assertScore(result, 15.0, 0.30)
self.assertTrue(result["veneer"]["active"])
self.assertEqual(result["threat_label"], "Suspicious")

def test_guarantee_a_forged_ptr_doesnt_lower_a_malicious_ip(self):
bare = score(otx(accounts(10)), **malicious())
forged = score(otx(accounts(10)), self.rdns("census9.shodan.io", ["198.20.69.74"]), **malicious())
self.assertGreaterEqual(forged["threat"], bare["threat"])
self.assertGreater(forged["paradox"], bare["paradox"])
self.assertTrue(forged["veneer"]["active"])

def test_guarantee_a_lookalike_domain_claims_nothing(self):
sig = self.rdns("crawl.googlebot.com.evil.example", [IP])
self.assertNotIn("benign_label", sig.facts)
self.assertNotIn("claim", sig.facts)

def test_guarantee_a_real_label_cant_clear_a_malicious_ip(self):
label = Signal("rdns", "Reverse DNS", "context", facts={"benign_label": "Shodan", "label_kind": "scanner"})
result = score(otx(accounts(10)), label, **malicious())
self.assertEqual(result["threat_label"], "Malicious")
self.assertTrue(result["veneer"]["active"])


if __name__ == "__main__":
unittest.main()
Loading