All Projects → springzfx → Cgproxy

springzfx / Cgproxy

Licence: gpl-2.0
Transparent Proxy with cgroup v2。透明代理,配合v2ray/Qv2ray食用最佳

Projects that are alternatives of or similar to Cgproxy

Asuswrt Merlin Transparent Proxy
transparent proxy base on ss, v2ray, ipset, iptables, chinadns on asuswrt merlin.
Stars: ✭ 367 (+143.05%)
Mutual labels:  v2ray, transparent-proxy
Ss Tproxy
搭建 SS/SSR/V2Ray/Socks5 透明代理环境的简易脚本
Stars: ✭ 1,561 (+933.77%)
Mutual labels:  v2ray, transparent-proxy
Cproxy
Easy per application transparent proxy built on cgroup.
Stars: ✭ 145 (-3.97%)
Mutual labels:  v2ray, transparent-proxy
Glider
glider is a forward proxy with multiple protocols support, and also a dns/dhcp server with ipset management features(like dnsmasq).
Stars: ✭ 1,710 (+1032.45%)
Mutual labels:  transparent-proxy
Goproxy
🔥 Proxy is a high performance HTTP(S) proxies, SOCKS5 proxies,WEBSOCKET, TCP, UDP proxy server implemented by golang. Now, it supports chain-style proxies,nat forwarding in different lan,TCP/UDP port forwarding, SSH forwarding.Proxy是golang实现的高性能http,https,websocket,tcp,socks5代理服务器,支持内网穿透,链式代理,通讯加密,智能HTTP,SOCKS5代理,黑白名单,限速,限流量,限连接数,跨平台,KCP支持,认证API。
Stars: ✭ 11,334 (+7405.96%)
Mutual labels:  transparent-proxy
V2rayc
a GUI for v2ray on Mac
Stars: ✭ 133 (-11.92%)
Mutual labels:  v2ray
Go Tproxy
Linux Transparent Proxy library for Golang
Stars: ✭ 148 (-1.99%)
Mutual labels:  transparent-proxy
V2ray Deep Packet Inspection
Notebook demo V2Ray traffic classification by deep packet inspection
Stars: ✭ 113 (-25.17%)
Mutual labels:  v2ray
Swiftv2ray
V2Ray-Core的iOS工具
Stars: ✭ 139 (-7.95%)
Mutual labels:  v2ray
Fanqiang Book
2021科学上网指南,小白图文攻略 | 翻墙/梯子/自由上网/SSR/V2Ray/
Stars: ✭ 127 (-15.89%)
Mutual labels:  v2ray
Xray Plugin
A SIP003 plugin based on Xray-core
Stars: ✭ 126 (-16.56%)
Mutual labels:  v2ray
Ssvpn
V2free for android, a V2ray and Shadowsocks client with many builtin free servers.
Stars: ✭ 121 (-19.87%)
Mutual labels:  v2ray
Sslproxy
Transparent SSL/TLS proxy for decrypting and diverting network traffic to other programs, such as UTM services, for deep SSL inspection
Stars: ✭ 134 (-11.26%)
Mutual labels:  transparent-proxy
Kitsunebi Android
A fully-featured V2Ray client for Android.
Stars: ✭ 1,587 (+950.99%)
Mutual labels:  v2ray
Ladder
梯子,科学上网,翻墙 , 代理, 外网, 加速器, 路由, V2Ray,SS,shadowsocks, SSR
Stars: ✭ 141 (-6.62%)
Mutual labels:  v2ray
Subscribevue
ss ssr v2ray 订阅管理 vue前端界面
Stars: ✭ 114 (-24.5%)
Mutual labels:  v2ray
V2ray Panel Master
Deprecated
Stars: ✭ 136 (-9.93%)
Mutual labels:  v2ray
V2fly Github Io
V2Fly Website & Documentation
Stars: ✭ 124 (-17.88%)
Mutual labels:  v2ray
Linux Router
Set Linux as router in one command. Support Internet sharing, redsocks, Wifi hotspot, IPv6. Can also be used for routing VM/containers
Stars: ✭ 129 (-14.57%)
Mutual labels:  transparent-proxy
Onesubscribe
ss ssr v2ray 订阅管理 node 后端
Stars: ✭ 122 (-19.21%)
Mutual labels:  v2ray

Transparent Proxy powered by cgroup v2

Introduction

cgproxy will transparent proxy anything running in specific cgroup. It resembles with proxychains and tsocks in default setting.

Main feature:

  • supports cgroup/program level proxy control.
  • supports global transparent proxy and gateway proxy.

Contents

Prerequest

  • cgroup2

    Both cgroup and cgroup2 are enabled in linux by default. So you don't have to do anything about this.

    • systemd-cgls to see the cgroup hierarchical tree.
    • Why cgroup v2? Because simple, elegant and intuitive.
  • TPROXY

    A process listening on port (e.g. 12345) to accept iptables TPROXY, for example v2ray's dokodemo-door in tproxy mode.

  • Iptables

    Iptables version should be at least 1.6.0, run iptables --version to check.

    ubuntu 16.04, debian 9, fedora 27 and later are desired

How to build and install

distro install

  • For debian and redhat series, download from Release page

  • For archlinux series, already in archlinuxcn repo, or see archlinux AUR

  • Tested on archlinux, fedora 32, ubuntu 18.04, ubuntu 20.04, deepin 15.11, deepin v20 beta

build

  • before build, install depencies: clang(if to build bpf obj from scratch), nlohmann-json, libbpf
  • then cmake standard build
# ready build dir
mkdir build
cd build
# generate
cmake -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -Dbuild_execsnoop_dl=ON \
      -Dbuild_static=OFF \
      ..
# compile
make

Default usage

  • First enable and start service

    sudo systemctl enable --now cgproxy.service
    
  • Then prefix with cgproxy with your command, just like proxychains

    cgproxy [--debug] <CMD>
    
  • For example, test proxy

    cgproxy curl -vI https://www.google.com
    
  • To completely stop

    sudo systemctl disable --now cgproxy.service
    

Configuration

Config file: /etc/cgproxy/config.json

{
    "port": 12345,
    "program_noproxy": ["v2ray", "qv2ray"],
    "program_proxy": [],
    "cgroup_noproxy": ["/system.slice/v2ray.service"],
    "cgroup_proxy": [],
    "enable_gateway": false,
    "enable_dns": true,
    "enable_udp": true,
    "enable_tcp": true,
    "enable_ipv4": true,
    "enable_ipv6": true,
    "table": 10007,
    "fwmark": 39283
}

  • port tproxy listenning port

  • program level proxy control, need execsnoop enabled:

    • program_proxy program need to be proxied
    • program_noproxy program that won't be proxied
  • cgroup level proxy control:

    • cgroup_noproxy cgroup array that no need to proxy, /noproxy.slice is preserved
    • cgroup_proxy cgroup array that need to proxy, /proxy.slice is preserved
  • enable_gateway enable gateway proxy for local devices

  • enable_dns enable dns to go to proxy

  • enable_tcp

  • enable_udp

  • enable_ipv4

  • enable_ipv6

  • table, fwmark you can specify iptables and route table related parameter in case conflict.

  • options priority

    program_noproxy > program_proxy > cgroup_noproxy > cgroup_proxy
    enable_ipv6 = enable_ipv4 > enable_dns > enable_tcp = enable_udp
    command cgproxy and cgnoproxy always have highest priority
    

Note: cgroup in configuration need to be exist, otherwise ignored

If you changed config, remember to restart service

sudo systemctl restart cgproxy.service

Global transparent proxy

  • Set "cgroup_proxy":["/"] in configuration, this will proxy all connection

  • Allow your proxy program (v2ray) direct to internet to avoid loop. Two ways:

    • active way, run command

      example: cgnoproxy sudo v2ray -config config_file

      example: cgnoproxy qv2ray

    • passive way, persistent config

      example: "program_noproxy":["v2ray" ,"qv2ray"]

      example: "cgroup_noproxy":["/system.slice/v2ray.service"]

  • Finally, restart cgproxy service, that's all

Gateway proxy

  • Set "enable_gateway":true in configuration
  • And allow your proxy software (v2ray) direct to internet if necessary, described above
  • Other device set this host as gateway, and set public dns if need

Other useful tools provided in this project

  • cgnoproxy run program wihout proxy, very useful in global transparent proxy

    cgnoproxy [--debug] <CMD>
    cgnoproxy [--debug] --pid <PID>
    
  • For more detail command usage, see man cgproxyd man cgproxy man cgnoproxy

NOTES

TIPS

  • systemd-cgls to see the cgroup hierarchical tree.
  • Check cgroup2 support findmnt -t cgroup2
  • Offer you v2ray service and full config exmaple in v2ray_config
  • Offer you qv2ray config example

Qv2ray config example

Licences

cgproxy is licenced under License: GPL v3

Known Issues

  • docker breaks cgroup v2 path match, add kernel parameter cgroup_no_v1=net_cls,net_prio to resolve, see issue #3 for detail

  • docker load br_netfilter module due to hairpin nat, which is not a big deal, see commit.

    It enables data link layer packet to go through iptables and only once. However TPROXY do not accept this kind of packets. So to get it working, set following parameter to disable this behavior or unload br_netfilter module manualy. see issue #10 for detail.

    sudo sysctl -w net.bridge.bridge-nf-call-iptables=0
    sudo sysctl -w net.bridge.bridge-nf-call-ip6tables=0
    sudo sysctl -w net.bridge.bridge-nf-call-arptables = 0
    
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].