{"id":18255153,"url":"https://github.com/fifilyu/module-http-whitelist","last_synced_at":"2025-10-06T12:58:55.604Z","repository":{"id":28624295,"uuid":"32143035","full_name":"fifilyu/module-http-whitelist","owner":"fifilyu","description":"域名白名单内核模块，基于 Linux Netfilter 过滤 HTTP 协议中的 Host 字段","archived":false,"fork":false,"pushed_at":"2016-01-04T16:10:43.000Z","size":29,"stargazers_count":80,"open_issues_count":1,"forks_count":41,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-13T16:10:26.355Z","etag":null,"topics":["http","linuxmodule","whitelist"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fifilyu.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-13T08:25:08.000Z","updated_at":"2025-04-27T02:48:38.000Z","dependencies_parsed_at":"2022-08-02T16:00:17.592Z","dependency_job_id":null,"html_url":"https://github.com/fifilyu/module-http-whitelist","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/fifilyu/module-http-whitelist","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fifilyu%2Fmodule-http-whitelist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fifilyu%2Fmodule-http-whitelist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fifilyu%2Fmodule-http-whitelist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fifilyu%2Fmodule-http-whitelist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fifilyu","download_url":"https://codeload.github.com/fifilyu/module-http-whitelist/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fifilyu%2Fmodule-http-whitelist/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278614467,"owners_count":26015967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","linuxmodule","whitelist"],"created_at":"2024-11-05T10:14:56.794Z","updated_at":"2025-10-06T12:58:55.574Z","avatar_url":"https://github.com/fifilyu.png","language":"C","readme":"# module-http-whitelist\n\n域名白名单内核模块，基于 Linux Netfilter 过滤 HTTP 协议中的 Host 字段\n\n== 使用场景\n需要一个简单的域名防火墙，只有指定的域名或者网络才能访问本机服务端口(默认 80端口)。\n本机 *直接提供服务* 或 *作为转发网关* 此模块均可用。\n\n== 代替方案\n使用 iptables 的 string 模块，可以实现相同的功能。白名单数量少或 HTTP 流量小时，强烈建议使用此方案。\n\n[NOTE]\n白名单数量增多或 HTTP 流量非常大时，由于 string 模块匹配是在整个包中查找字符串，匹配速度会明显下降。\n\n=== string 模块使用方法\n----\n#1. 创建自定义链\n\n# IP 白名单\niptables -N whitelist_network\n\n# HTTP 头\niptables -N http_header\n\n# 域名白名单\niptables -N whitelist_host\n\n#2. 匹配 IP 白名单匹配\n\n# 访问 TCP 协议 80 端口的包进入 whitelist_network 链\niptables -A INPUT -p tcp --dport 80 -j whitelist_network\n\n# 放行指定网络的包，不做任何过滤\niptables -I whitelist_network -p tcp -s 8.8.8.8/24 -j ACCEPT\n\n# 包进入 http_header 链\niptables -A whitelist_network -p tcp -j http_header\n\n#3. 匹配 HTTP 包\n\n# 匹配包内容里面的 \"Host:\" 字符串，并进入 whitelist_host 链\niptables -I http_header -p tcp -m string --string \"Host:\" --algo bm -j whitelist_host\n\n# 不是 HTTP 包，直接放行\niptables -A http_header -p tcp -j ACCEPT\n\n#4. 匹配域名白名单匹配\n\n# 匹配 HTTP 头中 \"Host: \" 之后的字符串，比如 \"Host: abc.com\"\niptables -I whitelist_host -p tcp -m string --string \"abc.com\" --algo bm -j ACCEPT\niptables -I whitelist_host -p tcp -m string --string \"www.abc.com\" --algo bm -j ACCEPT\niptables -I whitelist_host -p tcp -m string --string \"123.456.798.test.abc.com\" --algo bm -j ACCEPT\niptables -I whitelist_host -p tcp -m string --string \"123.com\" --algo bm -j ACCEPT\niptables -I whitelist_host -p tcp -m string --string \".123.com\" --algo bm -j ACCEPT\n\n# 不在域名白名单中的域名，无法访问 80 端口\niptables -A whitelist_host -p tcp -j REJECT --reject-with tcp-reset\n----\n\n== 端口\n\n默认过滤 80 端口\n\n[NOTE]\n如果 Web 服务端口为 8080，修改源代码中的 `#define HTTP_PORT 80` 为 `#define HTTP_PORT 8080` 即可。\n\n[NOTE]\n端口变化不频繁，所以没考虑写到配置文件。\n\n== 支持内核版本\n2.6.18 及以上版本\n\n== 开发以及测试平台\n* CentOS 5, 内核版本 2.6.18\n* CentOS 6, 内核版本 2.6.32\n* CentOS 7, 内核版本 3.10.0\n* Arch Linux, 内核版本 3.19.2\n* Debian 7, 内核版本 3.16.0\n\n== 配置文件\n主机信息将会保存到 `/etc/http_whitelist` 目录下。\n\n==== 初始化配置文件\n----\n$ sudo mkdir /etc/http_whitelist\n$ sudo touch /etc/http_whitelist/host  /etc/http_whitelist/network\n----\n\n==== 域名白名单 /etc/http_whitelist/host\n\n此名单中的域名可以被任意位置的用户访问。\n\n支持普通域名、无限子域名以及泛域名，每行一个，以回车符分割。\n\n.格式示例\n----\nabc.com\nwww.abc.com\n123.456.798.test.abc.com\n123.com\n*.123.com\n----\n\n==== IP 白名单 /etc/http_whitelist/network\n\n白名单模块会忽略在此文件中的单个 IP 地址 或 属于指定网络的 IP 地址，不会过滤任何 HTTP 包。相当于透明直通(不处理数据)。\n支持单 IP 以及 CIDR 风格的网络地址格式，每行一个，以回车符分割。\n\nCIDR 说明:\nhttp://zh.wikipedia.org/zh/%E6%97%A0%E7%B1%BB%E5%88%AB%E5%9F%9F%E9%97%B4%E8%B7%AF%E7%94%B1[无类别域间路由（Classless Inter-Domain Routing、CIDR）]\n\n.格式示例\n----\n0.0.0.0/0\n1.1.1.1/1\n2.2.2.0/24\n8.8.8.8\n8.8.4.4\n----\n\n0.0.0.0/0 :: 相当于未使用白名单模块，不会过滤来自任何网络的 HTTP 包\n\n[NOTE]\n如果本机作为转发网关，必须添加内网网段，内网网络才能访问公网。\n比如本机 IP 地址为 1.1.1.1，内网网段为 192.168.1.0/24。\n将 192.168.1.0/24 写入 `/etc/http_whitelist/network` 文件，内网网络才能访问公网。\n\n== 编译安装\n\n=== 依赖包\nCentOS 5/6/7:: sudo yum install kernel-devel\nArch Linux:: sudo pacman -S linux-headers\nDebian 7:: sudo apt-get install linux-headers-\\`uname -r`\n\n=== 编译\n----\n$ git clone https://github.com/fifilyu/module-http-whitelist.git\n$ cd module-http-whitelist\n$ make\n----\n\n=== 安装及卸载\n\n==== 加载模块\n----\n$ sudo insmod http_whitelist.ko\n----\n\n加载模块后，会有如下日志：\n\n----\n3月 27 00:44:00 archlinux kernel: Loading module \"http_whitelist\"\n----\n\n==== 卸载模块\n----\n$ sudo rmmod http_whitelist.ko\n----\n\n卸载模块后，会有如下日志：\n\n----\n3月 27 01:16:15 archlinux kernel: Unloading module \"http_whitelist\"\n----\n\n== 测试结果说明\n\n== IP 白名单\n\n. 在此名单中的远程 IP 地址，访问 www.abc.com (*在 域名白名单中*)，将会看到 Web 服务的响应 HTTP 内容\n. 在此名单中的远程 IP 地址，访问 www.xxx.com (*不在 域名白名单中*)，将会看到 Web 服务的响应 HTTP 内容\n. 不在此名单中的远程 IP 地址，访问任何域名，请求都将会被转交给 域名白名单 审核\n\n== 域名白名单\n\n. 在 IP 白名单中的用户（远程 IP 地址）发起的 HTTP 请求，不会出现在此名单中\n. 任意网络位置的用户，访问 www.abc.com (*在 域名白名单中*)，将会看到 Web 服务的响应 HTTP 内容\n. 任意网络位置的用户，访问 www.xxx.com (*不在 域名白名单中*)，不会看到 Web 服务的响应 HTTP 内容，\n只会看到浏览器提示的 “连接被重置” 字样\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffifilyu%2Fmodule-http-whitelist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffifilyu%2Fmodule-http-whitelist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffifilyu%2Fmodule-http-whitelist/lists"}