OpenGFW is a flexible, easy-to-use, open source implementation of GFW on Linux OpenGFW 是 GFW 在 Linux 上的灵活、易于使用的开源实现
Go to file
2024-02-23 18:31:16 -08:00
.github/workflows ci: add release workflow action 2024-01-20 10:42:14 -08:00
analyzer fix: typo in test 2024-02-18 12:26:03 +08:00
cmd feat: quic analyzer (client side only) 2024-02-11 22:25:37 -08:00
docs docs: add QUIC 2024-02-17 13:56:33 -08:00
engine fix: incorrect "virgin" handling causing rules with only built-in keywords to fail (#61) 2024-02-16 19:08:19 -08:00
io feat: nftables support (#50) 2024-02-11 13:04:49 -08:00
modifier first 2024-01-19 16:45:01 -08:00
ruleset Add CIDR support for expr (#62) 2024-02-17 14:21:12 -08:00
.gitignore first 2024-01-19 16:45:01 -08:00
go.mod Merge branch 'master' into wip-quic 2024-02-17 14:38:19 -08:00
go.sum fix merge 2024-02-17 14:39:12 -08:00
LICENSE first 2024-01-19 16:45:01 -08:00
main.go first 2024-01-19 16:45:01 -08:00
README.ja.md docs: update README 2024-02-23 18:31:16 -08:00
README.md docs: update README 2024-02-23 18:31:16 -08:00
README.zh.md chore: better README 2024-02-23 15:43:08 -08:00

OpenGFW

License

中文文档 日本語ドキュメント

OpenGFW is your very own DIY Great Firewall of China (https://en.wikipedia.org/wiki/Great_Firewall), available as a flexible, easy-to-use open source program on Linux. Why let the powers that be have all the fun? It's time to give power to the people and democratize censorship. Bring the thrill of cyber-sovereignty right into your home router and start filtering like a pro - you too can play Big Brother.

Telegram group: https://t.me/OpGFW

Caution

This project is still in very early stages of development. Use at your own risk.

Note

We are looking for contributors to help us with this project, especially implementing analyzers for more protocols!!!

Features

  • Full IP/TCP reassembly, various protocol analyzers
  • Full IPv4 and IPv6 support
  • Flow-based multicore load balancing
  • Connection offloading
  • Powerful rule engine based on expr
  • Hot-reloadable rules (send SIGHUP to reload)
  • Flexible analyzer & modifier framework
  • Extensible IO implementation (only NFQueue for now)
  • [WIP] Web UI

Use cases

  • Ad blocking
  • Parental control
  • Malware protection
  • Abuse prevention for VPN/proxy services
  • Traffic analysis (log only mode)
  • Help you fulfill your dictatorial ambitions

Usage

Build

go build

Run

export OPENGFW_LOG_LEVEL=debug
./OpenGFW -c config.yaml rules.yaml

OpenWrt

OpenGFW has been tested to work on OpenWrt 23.05 (other versions should also work, just not verified).

Install the dependencies:

opkg install kmod-nft-queue kmod-nf-conntrack-netlink

Example config

io:
  queueSize: 1024
  local: true # set to false if you want to run OpenGFW on FORWARD chain

workers:
  count: 4
  queueSize: 16
  tcpMaxBufferedPagesTotal: 4096
  tcpMaxBufferedPagesPerConn: 64
  udpMaxStreams: 4096

# The path to load specific local geoip/geosite db files.
# If not set, they will be automatically downloaded from https://github.com/Loyalsoldier/v2ray-rules-dat
# geo:
#   geoip: geoip.dat
#   geosite: geosite.dat

Example rules

Analyzer properties

For syntax of the expression language, please refer to Expr Language Definition.

- name: block v2ex http
  action: block
  expr: string(http?.req?.headers?.host) endsWith "v2ex.com"

- name: block v2ex https
  action: block
  expr: string(tls?.req?.sni) endsWith "v2ex.com"

- name: block v2ex quic
  action: block
  expr: string(quic?.req?.sni) endsWith "v2ex.com"

- name: block shadowsocks
  action: block
  expr: fet != nil && fet.yes

- name: block trojan
  action: block
  expr: trojan != nil && trojan.yes

- name: v2ex dns poisoning
  action: modify
  modifier:
    name: dns
    args:
      a: "0.0.0.0"
      aaaa: "::"
  expr: dns != nil && dns.qr && any(dns.questions, {.name endsWith "v2ex.com"})

- name: block google socks
  action: block
  expr: string(socks?.req?.addr) endsWith "google.com" && socks?.req?.port == 80

- name: block wireguard by handshake response
  action: drop
  expr: wireguard?.handshake_response?.receiver_index_matched == true

- name: block bilibili geosite
  action: block
  expr: geosite(string(tls?.req?.sni), "bilibili")

- name: block CN geoip
  action: block
  expr: geoip(string(ip.dst), "cn")

- name: block cidr
  action: block
  expr: cidr(string(ip.dst), "192.168.0.0/16")

Supported actions

  • allow: Allow the connection, no further processing.
  • block: Block the connection, no further processing.
  • drop: For UDP, drop the packet that triggered the rule, continue processing future packets in the same flow. For TCP, same as block.
  • modify: For UDP, modify the packet that triggered the rule using the given modifier, continue processing future packets in the same flow. For TCP, same as allow.