关于「反爬虫:令牌桶与陷阱页」,《单兵零信任母典》给出的定量结论是什么?

结论:金丝雀十条:外流副本 1,000 条时,检出机会 0.0956;10,000 条,0.6513;50,000 条,0.9990。金丝雀五十条:1,000 条副本,0.3951;10,000 条,0.9949。金丝雀两百条:1,000 条副本,0.8663。要让 1,000 条之副本,以 0.95 之机会,至少含一条金丝雀,需埋 298 条,副本里平均有 2.980 条。

数据口径:全书只写防守,不写任何攻击、入侵、绕过或规避检测手法;书中主机、域名、令牌全为合成,参数为示意,全部计算由书中程序生成;本书为非个人化经营分析,不构成安全审计或法律意见,任何生产变更须经人工复核放行。 书中以标注框区分已发表之证据、可运行之 Python 计算(20 段程序)、原典与作者之假说。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.0956, 0.3951, 0.6513, 0.8663, 0.95, 0.9949

trap pages hfetch 50fetch 500fetch 2,500
50.04900.40960.9688
200.18240.87891.0000
500.39650.99501.0000
people: 2,000 sessions a day x e = 0.0005 -> 1.0 touches a day
P(some person touches a trap in a day) = 0.6322
canaries ccopy 1,000copy 10,000copy 50,000
100.09560.65130.9990
500.39510.99491.0000
2000.86631.00001.0000
canaries needed so a 1,000-row copy shows one with 0.95: 298
expected canaries in that copy: 2.980

核心公式

\[P=1-\frac{\binom{N-h}{n}}{\binom{N}{n}}.\]
查看完整验算程序
# Chapter 5. p52: trap links and canary records, exact detection odds.
# A site has N pages; h of them are trap pages that no visible link,
# sitemap or menu leads to and that the robots rules exclude. A client
# that fetches n distinct pages at random hits at least one trap with
#   P = 1 - C(N - h, n) / C(N, n) = 1 - prod_{i<h} (N - n - i) / (N - i).
# A data set of M records carries c canary records, fake rows unique to
# one account key. A copy of k records found elsewhere holds at least one
# canary with the same formula. People can touch a trap by accident (for
# example through assistive software): rate e per session, illustrative.
import math


def p_hit(total, marked, drawn):
    if drawn > total - marked:
        return 1.0
    miss = 1.0
    for i in range(marked):
        miss = miss * (total - drawn - i) / (total - i)
    return 1.0 - miss


if __name__ == "__main__":
    N = 5000
    print("trap pages h   fetch 50   fetch 500   fetch 2,500")
    for h in (5, 20, 50):
        print("{:>12} {:>10.4f} {:>11.4f} {:>13.4f}".format(
            h, p_hit(N, h, 50), p_hit(N, h, 500), p_hit(N, h, 2500)))
    e, sessions = 0.0005, 2000
    fmt = "people: {:,} sessions a day x e = {} -> {:.1f} touches a day"
    print(fmt.format(sessions, e, sessions * e))
    print("P(some person touches a trap in a day) = {:.4f}".format(
        1.0 - (1.0 - e) ** sessions))
    M = 100000
    print("canaries c   copy 1,000   copy 10,000   copy 50,000")
    for c in (10, 50, 200):
        print("{:>10} {:>12.4f} {:>13.4f} {:>13.4f}".format(
            c, p_hit(M, c, 1000), p_hit(M, c, 10000), p_hit(M, c, 50000)))
    need = [c for c in range(1, 2001) if p_hit(M, c, 1000) >= 0.95][0]
    print("canaries needed so a 1,000-row copy shows one with 0.95: {}"
          .format(need))
    print("expected canaries in that copy: {:.3f}".format(need * 1000 / M))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《单兵硅基帝国零信任网安架构、源站隧道隐身与反爬虫防勒索母典》第 5 章「反爬虫:令牌桶与陷阱页」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-336 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026336,
  author    = {Fan, Yafu},
  title     = {Zero-Trust Cybersecurity for a One-Commander Silicon Empire: Origin Cloaking, Secret Hygiene and Anti-Scraper Defense},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论