聪明的黑客将 53.7 万个域名塞进了一个 5 美元的 ESP32 广告拦截适配器中
Clever hacker fits 537,000 domains in a $5 ESP32 ad-blocking dongle

原始链接: https://www.tomshardware.com/networking/clever-hacker-fits-537-000-domains-in-a-tiny-usd5-esp32-ad-blocking-dongle-firmware-uses-only-around-50kb-of-ram-and-can-answer-blocked-lookups-in-10-milliseconds

开发者 ZedAxis 利用一款 5 美元的 ESP32-C3 “SuperMini” 微控制器,创建了一个高效且低成本的广告拦截 DNS 过滤器。该设备旨在作为 Pi-hole 等完善系统的可靠备份,能够提供全网范围的广告拦截,且延迟仅约 10 毫秒。 由于 ESP32-C3 的内存有限,该项目采用了一种巧妙的哈希技术。它没有存储纯文本域名列表,而是将待拦截的域名转换为 40 位 FNV-1a 哈希值。通过牺牲无线(OTA)固件更新功能,该设备能够在闪存中存储多达 537,000 条目。当收到 DNS 请求时,设备会对主机名进行哈希处理,并通过二分查找来决定是否拦截。 该项目维护成本极低,仅需几十毫安的电力,完全可以从路由器的 USB 端口取电。虽然它缺乏专用服务器的高级日志记录和管理功能,但作为家庭网络的“设置好即无需管”的保险方案,它表现卓越,证明了在极为受限的硬件上也能实现强大的功能。

抱歉。
相关文章

原文

How cheap can you build a hardware-based ad-blocking DNS filter? "Free," if you're willing to salvage some used hardware that's being thrown away. What if you aren't so lucky? In the era of the RAMageddon, even a Raspberry Pi will cost you a couple hundred bucks. But you know, you don't even need something that powerful. In fact, you can use a $5 microcontroller to build a fully functional ad-blocking filter with over 500,000 domains blocked and around 10ms latency.

We know that's possible because Egyptian full-stack developer ZedAxis (@M-Abozaid on GitHub) has already built one. Using an ESP32-C3 "SuperMini" board, he's created a backup DNS for his home network that still provides ad blocking. His primary router is a Pi-hole, which is a Raspberry Pi running specialized software to manage DHCP addressing and DNS resolution with integrated ad-blocking. The SuperMini serves as a backup when the Pi-Hole is rebooting or otherwise unavailable.

A photo of the tiny ESP32 SuperMini board, bare of any casing.

The specific ESP32-C3 SuperMini board that ZedAxis used. (Image credit: ZedAxis/YouTube)

Strictly speaking, we haven't seen ZedAxis' creation in action, but there's no reason to believe it doesn't work. The ESP32 family of embedded Wi-Fi-enabled microcontrollers is a well-known quantity, and this functionality is by no means outside the realm of its capabilities. In fact, this specific trick allows the use of the ESP32-C3, which is a cost-reduced version of the chip that doesn't have the 8MB of PSRAM found on some higher-end models. (There are MANY variants of the ESP32.)

Instead, the ESP32-C3 used by ZedAxis has just 400KB of RAM, and 4MB of flash memory. With these limited specifications, he wasn't able to store a plaintext blocklist of any real size; it's simply too much data. So, he did what any enterprising hacker would do: he started hashing the data to reduce its size. Using 40-bit FNV-1a hashes, because 32-bit would give too many collisions and 64-bit wastes too much space, he can store some 537,000 domains in the flash memory of the device.

A screenshot of the rudimentary GUI for the C3 AdBlocker.

The project includes a rudimentary GUI where you can see some statistics and configure custom domains for blocking. (Image credit: ZedAxis/YouTube)

The clever part isn't really the hashing, though. Rather than storing the domains themselves, the build process downloads one or more public blocklists, strips out duplicate entries and comments, hashes each remaining domain into a 40-bit value, sorts the resulting list, and writes the finished database into the ESP32's flash memory. When a DNS query arrives, the device hashes the requested hostname the same way and performs a binary search against the sorted hash table. If it finds a match, the request is blocked. Otherwise, the query is forwarded to an upstream resolver. According to ZedAxis, the finished firmware uses only around 50KB of RAM while answering blocked lookups in roughly 10 milliseconds.

联系我们 contact @ memedata.com