nullcone 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {nullcone-0.1.1 → nullcone-0.1.2}/PKG-INFO +1 -1
  2. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/agent.py +39 -0
  3. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/confidence.py +50 -1
  4. nullcone-0.1.2/nullcone/curation.py +91 -0
  5. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/models.py +11 -2
  6. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/validators.py +23 -1
  7. {nullcone-0.1.1 → nullcone-0.1.2}/pyproject.toml +1 -1
  8. {nullcone-0.1.1 → nullcone-0.1.2}/LICENSE +0 -0
  9. {nullcone-0.1.1 → nullcone-0.1.2}/README.md +0 -0
  10. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/__init__.py +0 -0
  11. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/adaptive_codebook.py +0 -0
  12. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/attack_detector.py +0 -0
  13. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/classifier.py +0 -0
  14. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/cli.py +0 -0
  15. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/client.py +0 -0
  16. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/compressor.py +0 -0
  17. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/delta_sync.py +0 -0
  18. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/ei_client.py +0 -0
  19. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/fingerprinting.py +0 -0
  20. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/freshness.py +0 -0
  21. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/integrations/__init__.py +0 -0
  22. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/integrations/langchain.py +0 -0
  23. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/integrations/smolagents.py +0 -0
  24. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/mcp_fingerprinter.py +0 -0
  25. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/mcp_registry_monitor.py +0 -0
  26. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/observability.py +0 -0
  27. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/prompt_cache.py +0 -0
  28. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/py.typed +0 -0
  29. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/revocation.py +0 -0
  30. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/sensor.py +0 -0
  31. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/skill_scanner.py +0 -0
  32. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/stego_detector.py +0 -0
  33. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/threat_bounds.py +0 -0
  34. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/threat_graph.py +0 -0
  35. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/token_stream_validator.py +0 -0
  36. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/tool_attestation.py +0 -0
  37. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/unicode_scanner.py +0 -0
  38. {nullcone-0.1.1 → nullcone-0.1.2}/nullcone/validation_observer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: nullcone
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Distributed threat intelligence for AI agents — real-time IOC sharing via SpacetimeDB
5
5
  Project-URL: Homepage, https://nullcone.ai
6
6
  Project-URL: Repository, https://github.com/maco144/nullcone
@@ -43,6 +43,7 @@ from .models import (
43
43
  ActionTaken,
44
44
  DetectionEvent,
45
45
  IOC,
46
+ IOCType,
46
47
  MalwareFamily,
47
48
  SubmitResult,
48
49
  ThreatSignature,
@@ -278,6 +279,44 @@ class NullconeAgent:
278
279
  sigs.sort(key=lambda s: (s.last_seen or "", s.id), reverse=True)
279
280
  return sigs[:limit]
280
281
 
282
+ def threats_by_type(
283
+ self, ioc_type: str, limit: int = 50, min_severity: int = 0
284
+ ) -> list[ThreatSignature]:
285
+ """Most recently added signatures of one IOC type, newest first.
286
+
287
+ Raises ValueError for an unknown type — the value is enum-checked before
288
+ it reaches SQL. No LIMIT paging: pages come back unordered (see poll_since),
289
+ so a rare type is read whole and a common one is walked down by id range.
290
+ """
291
+ t = IOCType(ioc_type).value
292
+ limit = max(1, int(limit))
293
+ where = f"ioc_type = '{t}'"
294
+ if min_severity:
295
+ where += f" AND severity >= {int(min_severity)}"
296
+
297
+ n = int(self._client.sql(f"SELECT COUNT(*) AS n FROM threat_signature WHERE {where}")[0]["n"])
298
+ if n == 0:
299
+ return []
300
+ if n <= 5000:
301
+ rows = self._client.sql(f"SELECT * FROM threat_signature WHERE {where}")
302
+ sigs = sorted((ThreatSignature.from_dict(r) for r in rows), key=lambda s: s.id, reverse=True)
303
+ return sigs[:limit]
304
+
305
+ # Dense type: find the top of the id space, then walk windows downward.
306
+ total = int(self._client.sql("SELECT COUNT(*) AS n FROM threat_signature")[0]["n"])
307
+ hi = total
308
+ while self._client.sql(f"SELECT id FROM threat_signature WHERE id > {hi} LIMIT 1"):
309
+ hi += 10_000
310
+ window, sigs = 20_000, []
311
+ for _ in range(25): # bounded: 500k ids per call
312
+ lo = max(0, hi - window)
313
+ rows = self._client.sql(f"SELECT * FROM threat_signature WHERE id > {lo} AND id <= {hi} AND {where}")
314
+ sigs.extend(sorted((ThreatSignature.from_dict(r) for r in rows), key=lambda s: s.id, reverse=True))
315
+ if len(sigs) >= limit or lo == 0:
316
+ break
317
+ hi = lo
318
+ return sigs[:limit]
319
+
281
320
  def family_threats(self, family_name: str) -> list[ThreatSignature]:
282
321
  """Return all IOCs associated with a specific malware family."""
283
322
  rows = self._client.sql(
@@ -55,6 +55,53 @@ _SOURCE_PREFIXES: list[tuple[str, float]] = [
55
55
 
56
56
  _DEFAULT_SCORE = 0.45 # truly unknown submitter
57
57
 
58
+ # Carriers of several feeds under ONE agent id. Scoring them by agent id scored
59
+ # CERT Polska's official warning list the same as urlscan's submitter-tagged scans
60
+ # (extended-feeds-ingestor), and 617k OTX/URLhaus/ThreatFox rows as "unknown
61
+ # submitter" (bulk-sync-agent), because the feed only survives in the first tag.
62
+ # Measured 2026-09-15: that pushed real abuse.ch-grade data to "unverified".
63
+ MULTI_FEED_SOURCES = frozenset({"extended-feeds-ingestor", "bulk-sync-agent"})
64
+
65
+ FEED_TAG_CREDIBILITY: dict[str, float] = {
66
+ # abuse.ch family — same tier as abusech-ingestor
67
+ "urlhaus": 0.92, "urlhaus-archive": 0.90, "threatfox": 0.92,
68
+ "malwarebazaar": 0.92, "sslbl": 0.90, "feodo": 0.92,
69
+ # national CERT warning list
70
+ "cert-pl": 0.88,
71
+ # public blocklists — same tier as public-feeds-ingestor
72
+ "spamhaus": 0.88, "dshield": 0.85, "cins": 0.83, "blocklist.de": 0.80,
73
+ "ipsum": 0.80, "cybercrime-tracker": 0.80, "tor": 0.85,
74
+ # community + vetted
75
+ "otx": 0.82,
76
+ # enrichment, not a verdict
77
+ "shodan": 0.60,
78
+ # urlscan.io free tier: task.tags are set by whoever SUBMITTED the scan — no
79
+ # better than an unknown submitter. At 0.55 its URLs went from 2 to 1,469
80
+ # guard-blockable per 30k sampled rows (2026-09-15); held at the default.
81
+ "urlscan": 0.45,
82
+ }
83
+
84
+ # Provenance that stays unverified however often it repeats. A urlscan scan's
85
+ # page.domain is the HOST of a page someone tagged malicious — shared platforms
86
+ # (example.com, github.com, discord.com) reached severity 7 that way, and repeat
87
+ # scans are not independent confirmation, so detection_count must not lift them.
88
+ _UNVERIFIED_CAP = 0.49
89
+ _CAPPED_PROVENANCE = frozenset({("urlscan", "domain")})
90
+
91
+
92
+ def _feed_tag(sig: "ThreatSignature") -> str:
93
+ tags = sig.tags if isinstance(sig.tags, str) else ",".join(sig.tags or [])
94
+ return tags.split(",", 1)[0].strip().lower()
95
+
96
+
97
+ def _provenance_score(sig: "ThreatSignature") -> float:
98
+ """Credibility of where this row really came from."""
99
+ if sig.source_agent_id in MULTI_FEED_SOURCES:
100
+ tag_score = FEED_TAG_CREDIBILITY.get(_feed_tag(sig))
101
+ if tag_score is not None:
102
+ return tag_score
103
+ return _source_score(sig.source_agent_id)
104
+
58
105
 
59
106
  def _source_score(source_agent_id: str) -> float:
60
107
  """Resolve source credibility for a given agent_id."""
@@ -83,7 +130,7 @@ def compute_confidence_score(sig: "ThreatSignature") -> float:
83
130
  confirmation_bonus — multi-source confirmation via detection_count
84
131
  fp_penalty — fraction of detection events that voted false positive
85
132
  """
86
- source_score = _source_score(sig.source_agent_id)
133
+ source_score = _provenance_score(sig)
87
134
  submission_score = sig.confidence / 100.0
88
135
 
89
136
  # Each additional detection_count beyond 1 adds confirmation weight.
@@ -106,6 +153,8 @@ def compute_confidence_score(sig: "ThreatSignature") -> float:
106
153
  fp_penalty = min(0.50, fp_ratio)
107
154
 
108
155
  score = raw * (1.0 - fp_penalty)
156
+ if (_feed_tag(sig), sig.ioc_type) in _CAPPED_PROVENANCE:
157
+ score = min(score, _UNVERIFIED_CAP)
109
158
  return round(max(0.0, min(1.0, score)), 4)
110
159
 
111
160
 
@@ -0,0 +1,91 @@
1
+ """
2
+ Maintainer curation: values that must never act as threat indicators.
3
+
4
+ WHY THIS EXISTS
5
+ ---------------
6
+ The module's only suppression path is crowd false-positive voting, which needs
7
+ MIN_FP_VOTES distinct registered agents — a floor that exists precisely so no
8
+ single actor can suppress an IOC. Minting identities to clear our own floor would
9
+ be that attack, and deleting rows loses history and trips the backup's
10
+ row-count check. So curation lives here: reviewed, versioned, and applied at read
11
+ time through ThreatSignature.is_likely_fp, which the API, MCP server, SDK, the
12
+ Claude Code guard and downstream scanners (agent-kit) all already honour.
13
+
14
+ Found 2026-09-15: urlscan.io scans tagged "malicious" by their submitters turned
15
+ the scanned page's HOST into a severity-7 DOMAIN IOC. example.com, github.com and
16
+ discord.com were listed; the guard blocked `curl https://discord.com/...` and code
17
+ that touched example.com.
18
+
19
+ Two layers, and the validators reuse the first so nothing new gets in:
20
+ 1. reserved_reason() — rule-based: RFC 2606/6761/6762 names, non-routable IPs.
21
+ 2. CURATED_FALSE_POSITIVES — explicit, each with a dated reason.
22
+ """
23
+ from __future__ import annotations
24
+
25
+ import ipaddress
26
+ from typing import Optional
27
+ from urllib.parse import urlparse
28
+
29
+ # RFC 2606 / RFC 6761 special-use names, plus RFC 6762 .local (mDNS).
30
+ _RESERVED_TLDS = frozenset({"example", "test", "invalid", "localhost", "local"})
31
+ _RESERVED_DOMAINS = frozenset({"example.com", "example.net", "example.org"})
32
+
33
+ _DOC_NETS = tuple(ipaddress.ip_network(n) for n in (
34
+ "192.0.2.0/24", "198.51.100.0/24", "203.0.113.0/24", "2001:db8::/32",
35
+ ))
36
+
37
+ # (ioc_type, value) -> reason. Keep entries specific; a registrable domain here
38
+ # suppresses every lookup of that exact value, not its subdomains.
39
+ CURATED_FALSE_POSITIVES: dict[tuple[str, str], str] = {
40
+ ("domain", "github.com"): "2026-09-15: shared code host; listed via a submitter-tagged urlscan scan",
41
+ ("domain", "discord.com"): "2026-09-15: shared chat platform; listed via a submitter-tagged urlscan scan",
42
+ }
43
+
44
+
45
+ def reserved_domain_reason(domain: str) -> Optional[str]:
46
+ d = (domain or "").strip().lower().rstrip(".")
47
+ if not d:
48
+ return None
49
+ if d in _RESERVED_DOMAINS or any(d.endswith("." + r) for r in _RESERVED_DOMAINS):
50
+ return f"{d!r} is an RFC 2606 documentation domain"
51
+ tld = d.rsplit(".", 1)[-1]
52
+ if tld in _RESERVED_TLDS:
53
+ return f"{d!r} uses the special-use TLD .{tld} (RFC 2606/6761/6762)"
54
+ return None
55
+
56
+
57
+ def reserved_ip_reason(value: str) -> Optional[str]:
58
+ try:
59
+ addr = ipaddress.ip_address((value or "").strip().strip("[]"))
60
+ except ValueError:
61
+ return None
62
+ if any(addr in net for net in _DOC_NETS if net.version == addr.version):
63
+ return f"{addr} is a documentation address (RFC 5737/3849)"
64
+ if addr.is_loopback or addr.is_unspecified or addr.is_link_local or addr.is_multicast:
65
+ return f"{addr} is not a routable address"
66
+ if addr.is_private:
67
+ return f"{addr} is a private address"
68
+ return None
69
+
70
+
71
+ def reserved_reason(ioc_type: str, value: str) -> Optional[str]:
72
+ """Why this value can never be a global threat indicator, or None."""
73
+ t = (ioc_type or "").lower()
74
+ if t == "domain":
75
+ return reserved_domain_reason(value)
76
+ if t == "ip":
77
+ return reserved_ip_reason(value)
78
+ if t == "ip_port":
79
+ host = (value or "").rsplit(":", 1)[0]
80
+ return reserved_ip_reason(host.strip("[]"))
81
+ if t == "url":
82
+ host = urlparse((value or "").strip()).hostname or ""
83
+ return reserved_ip_reason(host) or reserved_domain_reason(host)
84
+ return None
85
+
86
+
87
+ def false_positive_reason(ioc_type: str, value: str) -> Optional[str]:
88
+ """Maintainer verdict that this indicator is a false positive, or None."""
89
+ t = (ioc_type or "").lower()
90
+ v = (value or "").strip().lower().rstrip(".")
91
+ return CURATED_FALSE_POSITIVES.get((t, v)) or reserved_reason(t, v)
@@ -109,15 +109,24 @@ class ThreatSignature:
109
109
  tags: str
110
110
  delivered_at_us: int = 0 # microseconds since epoch; 0 = not stamped
111
111
 
112
+ @property
113
+ def fp_reason(self) -> Optional[str]:
114
+ """Maintainer curation verdict (nullcone.curation), or None."""
115
+ from .curation import false_positive_reason
116
+ return false_positive_reason(self.ioc_type, self.value)
117
+
112
118
  @property
113
119
  def is_likely_fp(self) -> bool:
114
- """Heuristic: at least MIN_FP_VOTES agents, and >20% of them, voted FP.
120
+ """Maintainer-curated FP, or: at least MIN_FP_VOTES agents, and >20% of them, voted FP.
115
121
 
116
122
  The ratio alone was exploitable: a signature with detection_count=4 was
117
123
  suppressed by a single vote, which removed it from the public feed and
118
124
  from every guard hook. The absolute floor means suppression always
119
- requires corroboration, never one actor.
125
+ requires corroboration, never one actor. Curation is the reviewed,
126
+ versioned exception to that floor — see nullcone/curation.py.
120
127
  """
128
+ if self.fp_reason:
129
+ return True
121
130
  return (
122
131
  self.detection_count > 0
123
132
  and self.false_positive_votes >= MIN_FP_VOTES
@@ -13,6 +13,7 @@ import ipaddress
13
13
  import re
14
14
  from urllib.parse import urlparse
15
15
 
16
+ from .curation import reserved_domain_reason, reserved_ip_reason
16
17
  from .models import IOCType
17
18
 
18
19
  # ---------------------------------------------------------------------------
@@ -23,9 +24,14 @@ def _validate_ip(value: str) -> str:
23
24
  """IPv4 or IPv6 address. Returns normalized form (compressed IPv6)."""
24
25
  try:
25
26
  addr = ipaddress.ip_address(value)
26
- return str(addr) # normalizes IPv6 to compressed form
27
27
  except ValueError:
28
28
  raise ValueError(f"Invalid IP address: {value!r}")
29
+ # Private, loopback and documentation addresses are nobody's global threat —
30
+ # listed, they would make every consumer's guard block its own network.
31
+ reason = reserved_ip_reason(str(addr))
32
+ if reason:
33
+ raise ValueError(f"{reason} — not a global threat indicator")
34
+ return str(addr) # normalizes IPv6 to compressed form
29
35
 
30
36
 
31
37
  def _validate_ip_port(value: str) -> str:
@@ -63,6 +69,10 @@ def _validate_ip_port(value: str) -> str:
63
69
  if not (1 <= port <= 65535):
64
70
  raise ValueError(f"Port must be 1–65535, got {port}")
65
71
 
72
+ reason = reserved_ip_reason(str(addr))
73
+ if reason:
74
+ raise ValueError(f"{reason} — not a global threat indicator")
75
+
66
76
  if isinstance(addr, ipaddress.IPv6Address):
67
77
  return f"[{addr}]:{port}"
68
78
  return f"{addr}:{port}"
@@ -127,6 +137,13 @@ def _validate_domain(value: str) -> str:
127
137
  f"ingest them as DOMAIN IOCs."
128
138
  )
129
139
 
140
+ # A documentation domain reached severity 7 on 2026-09-15 and the guard then
141
+ # blocked code that touched it. Special-use names resolve to nothing an
142
+ # attacker controls.
143
+ reason = reserved_domain_reason(d)
144
+ if reason:
145
+ raise ValueError(f"{reason} — not a threat indicator")
146
+
130
147
  return d
131
148
 
132
149
 
@@ -156,6 +173,11 @@ def _validate_url(value: str) -> str:
156
173
  if not parsed.netloc:
157
174
  raise ValueError("URL must include a host")
158
175
 
176
+ host = parsed.hostname or ""
177
+ reason = reserved_ip_reason(host) or reserved_domain_reason(host)
178
+ if reason:
179
+ raise ValueError(f"URL host: {reason} — not a threat indicator")
180
+
159
181
  return v
160
182
 
161
183
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nullcone"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Distributed threat intelligence for AI agents — real-time IOC sharing via SpacetimeDB"
9
9
  readme = "README.md"
10
10
  license = { text = "Rising Sun License v1.0" }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes