Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ALfheimr-SAO/937048d6eef31e30ffa172c0c4b1ffb7 to your computer and use it in GitHub Desktop.
Save ALfheimr-SAO/937048d6eef31e30ffa172c0c4b1ffb7 to your computer and use it in GitHub Desktop.
网站伪装,隐藏代理

原帖来自于Vmess + TCP + TLS 方式的 HTTP 分流和网站伪装

这里只是塞了个trojan进去, 背景 请看原帖。

利用haproxy listen 443端口,同时处理web+trojan+v2ray流量。

流程图如下:( 不知道为啥gist不显示,typora里倒是显示正常

s=>start: Start
e=>end: End
op_haproxy=>operation: haproxy
sub_haproxy=>subroutine: due to tcp

in_haproxy=>inputoutput: https in port:443
out_trojan=>inputoutput: to trojan:port:8080
out_apache=>inputoutput: to apache:port:4443
out_v2ray_tcp=>inputoutput: to v2ray tcp configure:port:2333
out_default=>inputoutput: to default web:port:80

is_trojan=>condition: if trojan domain
is_cdn=>condition: if CDN domain
is_wss=>condition: if WSS domain
is_tcp=>condition: if TCP domain
is_http=>condition: if HTTP request

s->in_haproxy
in_haproxy->op_haproxy
op_haproxy->is_trojan

is_trojan(yes, right)->out_trojan
is_trojan(no)->is_cdn
is_cdn(yes, right)->out_apache
is_cdn(no)->is_wss
is_wss(yes, right)->out_apache
is_wss(no)->is_tcp
is_tcp(yes, right)->sub_haproxy
is_tcp(no)->out_default
sub_haproxy(right)->is_http
is_http(yes)->out_default
is_http(no)->out_v2ray_tcp

out_trojan->e
out_apache->e
out_v2ray_tcp->e
out_default->e

思路

haproxy bind 433端口,对流量进行分流处理。

示例给出trojan代理,v2ray的CDN,WSS和TCP代理方式,分成以下3组:

  1. trojan代理
  2. v2ray的CDN和WSS代理
  3. v2ray的TCP代理

通过sni区分域名请求,转发上述流量。

TCP需要特别处理,在haproxy上处理tls后分流,http流量给web,其余的交给v2ray处理。

  • haproxy1.8以上,apache2.4以上

trojan listen 8080端口,若请求域名是trojan的则分给trojan处理

apache https listen 4443端口,若请求域名是CDN/WSS的则分给apache处理

v2ray TCP listen 2333端口,若请求域名是TCP则在haproxy上终结ssl后分流给apache的80端口和v2ray的tcp配置端口

haproxy配置

global
    log /dev/log local0
    log /dev/log local1 notice
    chroot /var/lib/haproxy
    # mkdir /run/haproxy 要确保这个path存在
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon
#    ca-base /etc/ssl/certs
#    crt-base /etc/ssl/private

    # 仅使用支持 FS 和 AEAD 的加密套件
    ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
    ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
    # 禁用 TLS 1.2 之前的 TLS
    ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11

    tune.ssl.default-dh-param 2048

defaults
    log global
    mode tcp
    option dontlognull
    timeout connect 5s
    # 空闲连接等待时间,这里使用与 V2Ray 默认 connIdle 一致的 300s
    timeout client  300s
    timeout server  300s

frontend tcp_in
    bind *:443 alpn h2,http/1.1

    tcp-request inspect-delay 5s
    tcp-request content accept if { req_ssl_hello_type 1 }

    # trojan域名代理trojan
    # CDN域名代理v2ray wss走CDN的情况
    # WSS域名代理v2ray的wss模式
    acl is_Trojan   req_ssl_sni -i trojan.domain.com
    acl is_CDN      req_ssl_sni -i cdn.domain.com
    acl is_WSS      req_ssl_sni -i wss.domain.com
    # TCP域名分流
    acl is_TCP      req_ssl_sni -i tcp.domain.com

    use_backend TROJAN      if is_Trojan
    use_backend CDN         if is_CDN
    use_backend WSS         if is_WSS

    use_backend TCP         if is_TCP
    # 其它任何tcp 443端口流量交给web
    default_backend default_web

# 8080是trojan端口
# 4443是apache tls端口,CDN和WSS在apache和v2ray里是一样的配置,靠apache解tls反代ws给v2ray处理
# apache可以是其它的web server

backend TROJAN
    server trojan       127.0.0.1:8080

backend CDN
    server v2ray_cdn    127.0.0.1:4443

backend WSS
    server v2ray_wss    127.0.0.1:4443

backend TCP
    server TCP_TLS abns@/var/run/haproxy_tcp.sock send-proxy-v2

frontend TCP_TLS
    mode tcp
    bind abns@/var/run/haproxy_tcp.sock accept-proxy ssl crt /etc/ssl/private/tcp.domain.com.pem
    # 解tls后正常http给web,否则交给v2ray的tcp处理
    use_backend default_web if HTTP
    default_backend v2ray_tcp

# 2333是v2ray的tcp端口

backend v2ray_tcp
    server server_v2ray_tcp     127.0.0.1:2333

backend default_web
    server web                  127.0.0.1:80

ps:mkdir /run/haproxy 要确保这个path存在否则无法启动


提供一个思路而已,有更好的思路欢迎提comment

@ALfheimr-SAO
Copy link
Author

@killgcd4ever
Copy link

server TCP_TLS abns@/var/run/haproxy_tcp.sock send-proxy-v2 这一段什么意思?
send-proxy-v2这个在哪里用到的?

@fefz
Copy link

fefz commented Jun 2, 2020

这种方式配置v2ray不能工作

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment