Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xray VLESS-TCP-Reality + xtls-rprx-vision +nginx stream 443 sni 分流端口复用 + Proxy Protocol 访客IP是127.0.0.1 #1697

Closed
heygo1345678 opened this issue Feb 23, 2023 · 23 comments

Comments

@heygo1345678
Copy link

heygo1345678 commented Feb 23, 2023

日志:2023/02/23 01:52:46 127.0.0.1:52556 accepted tcp:github.githubassets.com:443 [VLESS-TCP-Reality >> direct]
nginx stream 配置:

map $ssl_preread_server_name $stream_map {

xtls.test vless;
www.microsoft.com real;

}

upstream vless {
server 127.0.0.1:8443;
}

upstream real {
server 127.0.0.1:44443 ;

}

stream模块监听443端口,并进行端口复用

server {
listen 443 reuseport ;
listen [::]:443 reuseport ;
proxy_pass $stream_map;
ssl_preread on;
proxy_protocol on; # 开启Proxy protocol

}

}

reality版本:

xray version

Xray 1.7.5 (Xray, Penetrates Everything.) 4d5c319 (go1.20.1 linux/amd64)
A unified platform for anti-censorship.

reality服务器配置文件:
{
"log": {
"loglevel": "warning"
},

"inbounds": [
    {

"tag": "VLESS-TCP-Reality",
"listen": "0.0.0.0",
"port": 44443, //服务器监听端口号,可以不是443,防火墙打开或者vps面板操作:iptables -I INPUT -p tcp --dport 8443 -j ACCEPT
"protocol": "vless",
"settings": {
"clients": [
{
"id": "",
"flow": "xtls-rprx-vision" //解决tls in tls流量特征
}
],
"decryption": "none"
},
"streamSettings": {

"tcpSettings": {
          "acceptProxyProtocol": true
        },
"network": "tcp",
"security": "reality",      //魔改的tls协议 reality
"realitySettings": {
  
  
  "show": false,
  "privateKey": "",        //使用上面生成的私钥
  "shortIds": [
    ""
  ],
  "Dest": "61.147.219.124:443",     //这个是sni白名单网站www.microsoft.com的cdn IP和 https网站端口号
  "type": "tcp",
  "serverNames": [
    "www.microsoft.com"
  ]
}

}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
}
]
}

客户端配置:
{
"log": {
"loglevel": "warning"
},

"inbounds": [
     {
       // "listen": "127.0.0.1",
        "port": 10000, // 本地监听端口
        "protocol": "socks",
        "settings": {
            "udp": true
        },
        "sniffing": {
            "enabled": true,
            "destOverride": [
                "http",
                "tls"
            ]
        }
    }
	
	
	
	
	
	
],
"outbounds": [
     {
"tag": "VLESS-TCP-Reality",
"protocol": "vless",
"settings": {
  "vnext": [
    {
      
      "address": "1.2.3.4",        //这里是vps服务器节点IP
      "port": 443,  		 //vps服务器节点端口号
      "users": [
        {
          "id": "",
          "encryption": "none",
          "flow": "xtls-rprx-vision"              //解决tls in tls流量特征
        }
      ]
    }
  ]
},
"streamSettings": {
  "network": "tcp",
  "security": "reality",                   //魔改的tls协议 reality
  "realitySettings": {
    "publicKey": "",                 //公钥验证,用于验证服务器预防中间人攻击
    "shortId": "",
    "serverName": "www.microsoft.com",          //客户端向sni白名单的境外网站 偷证书发起假装的连接,糊弄gfw,
    "fingerprint": "chrome",       //模拟uTLS指纹,糊弄gfw以为是浏览器访问
    "spiderX": "/"
  }
}

}
]

}
相同的action build版本,用老的xtls是可以获取访客IP的:
2023/02/23 01:51:52 [Warning] infra/conf: You are using an old version of XTLS, which is deprecated now and will be removed soon. Please use flow "xtls-rprx-vision" with "tls & tlsSettings" instead.
2023/02/23 01:51:52 [Warning] transport/internet/websocket: accepting PROXY protocol
2023/02/23 01:51:52 [Warning] core: Xray 1.7.5 started
2023/02/23 01:51:53 234.12.31.12:38640 accepted tcp:149.12.1.100:80
nginx stream配置同上;
xray配置文件:
{
"log": {

"loglevel": "warning"

},
"inbounds": [
{
"port": 8443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "",
"flow": "xtls-rprx-direct"
}
],
"decryption": "none",
"fallbacks": [
{
"dest": 60000,
"alpn": "",
"xver": 1
},
{
"dest": 60001,
"alpn": "h2",
"xver": 1
},
{
"dest": 60002,
"path": "/9d/",
"xver": 1
},
{
"name": "",
"dest": 5003,
"xver": 1
},
{
"name": "",
"alpn": "h2",
"dest": 5004,
"xver": 1
},
{
"alpn": "http/1.1",
"dest": 800
},
{
"alpn": "h2",
"dest": 801
}

    ]
  },
  "streamSettings": {
    "network": "tcp",
    "security": "xtls",
	"tcpSettings": {
          "acceptProxyProtocol": true
        },
    "xtlsSettings": {
      "minVersion": "1.2",
      "certificates": [
        {
          "certificateFile": "/root/ecc/fullchain.cer",
          "keyFile": "/root/ecc/top.key"
        }
        
      ]
    }
  },
  "sniffing": {
    "enabled": true,
    "destOverride": [
      "http",
      "tls"
    ]
  }
},
{
  "port": 60002,
  "listen": "127.0.0.1",
  "protocol": "vless",
  "settings": {
    "clients": [
      {
        "id": ""
      }
    ],
    "decryption": "none"
  },
  "streamSettings": {
    "network": "ws",
    "security": "none",
    "wsSettings": {
      "acceptProxyProtocol": true,
      "path": "/970c/"
    }
  }
},
{
  
   "port": 60003,
  "listen": "127.0.0.1",
  "protocol": "vless",
  "settings": {
    "clients": [
      {
        "id": ""
      }
    ],
    "decryption": "none"
  },
  "streamSettings": {
    "network": "grpc",
    "security": "none",
    "grpcSettings": {
      "serviceName": "enjoy"
    }
  }
}

],
"outbounds": [
{
"protocol": "freedom"
}
]
}

@RPRX
Copy link
Member

RPRX commented Feb 23, 2023

你的注释中存在很多错误,别让 ChatGPT 学去了然后胡说八道

@chika0801
Copy link
Contributor

chika0801 commented Feb 23, 2023

发下nginx 完整配置,猜是

log_format main 里面的 $remote_addr或写成$proxy_protocol_addr

另外排版弄好点吧

@RPRX
Copy link
Member

RPRX commented Feb 23, 2023

客户端用 Client Hello 中 key_share 对应的私钥和配置中的 publicKey 算出一个共享密钥,再 HKDF 生成“临时认证密钥”,用它对版本号、时间戳、Short ID 进行 AEAD 认证加密,附加数据为整个握手,结果填充至 session ID,以供服务端验证请求。

服务端用配置中的 privateKey 和 Client Hello 中的 key_share 算出一个相同的共享密钥,再 HKDF 生成相同的“临时认证密钥”,用它解密、验证客户端的请求,然后生成一个 Ed25519 “临时可信证书”,签名为“临时认证密钥”对其中的公钥的 HMAC。

以上就是配置中 publicKeyprivateKey 的作用。

@heygo1345678
Copy link
Author

客户端用 Client Hello 中 key_share 对应的私钥和配置中的 publicKey 算出一个共享密钥,再 HKDF 生成“临时认证密钥”,用它对版本号、时间戳、Short ID 进行 AEAD 认证加密,附加数据为整个握手,结果填充至 session ID,以供服务端验证请求。

服务端用配置中的 privateKey 和 Client Hello 中的 key_share 算出一个相同的共享密钥,再 HKDF 生成相同的“临时认证密钥”,用它解密、验证客户端的请求,然后生成一个 Ed25519 “临时可信证书”,签名为“临时认证密钥”对其中的公钥的 HMAC。

以上就是配置中 publicKeyprivateKey 的作用。

好的,多谢大佬指点,我不是搞开发的,对publicKey 的理解只剩下验证阻止中间人攻击了,这个配置是没有出官方模板前群里套用的,可能有的地方理解有误

@chika0801
Copy link
Contributor

学到了,Short ID 我还是要填下了

@heygo1345678
Copy link
Author

发下nginx 完整配置,猜是

log_format main 里面的 $remote_addr或写成$proxy_protocol_addr

另外排版弄好点吧

nginx.conf配置文件,不过我上面有提及,相同配置老的xtls是可以获取访客IP的:

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;

include /etc/nginx/conf.d/*.conf;

}

stream模块设置

stream {

log_format proxy '$proxy_protocol_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

access_log /var/log/nginx/tcp-access.log proxy ;
open_log_file_cache off;
include /etc/nginx/conf.d/*.stream;

map $ssl_preread_server_name $stream_map {

xtls.test vless;
www.microsoft.com real;

}

upstream vless {
server 127.0.0.1:8443;
}

upstream real {
server 127.0.0.1:44443 ;

}

stream模块监听443端口,并进行端口复用

server {
listen 443 reuseport ;
listen [::]:443 reuseport ;
proxy_pass $stream_map;
ssl_preread on;
proxy_protocol on; # 开启Proxy protocol

}

}

@chika0801
Copy link
Contributor

你的问题是nginx日志还是xray日志,哪个不能得到访问者的ip?

@chika0801
Copy link
Contributor

chika0801 commented Feb 23, 2023

"tcpSettings": {
"acceptProxyProtocol": true
},
不确定这个它生效没有

如果是xray日志报访问者127.0.0.1
盲猜你试试改配置

"sockopt": {

"acceptProxyProtocol": true,

}

你去文档搜下加上面的参数

@heygo1345678
Copy link
Author

xray reality服务器端日志访客IP是127.0.0.1,用老的xtls搭建服务器有访客真实IP;
不过我的nginx的两个日志只有http块的/var/log/nginx/access.log 是正常的,cf反代ws,grpc,网站都有访客日志,因为有设置set real ip from
/var/log/nginx/tcp-access.log这个日志里面全是127.0.0.1,老的xtls节点和reality节点在里面日志分别为:

  • [23/Feb/2023:01:47:04 +0000] TCP 200 3559 435 1.797 "127.0.0.1:8443" "768" "3559" "0.000"
  • [23/Feb/2023:04:06:51 +0000] TCP 200 6296 216 2.790 "127.0.0.1:44443" "783" "6296" "0.000"
  • 虽然/var/log/nginx/tcp-access.log这个日志里面老的xtls节点是127.0.0.1,
  • 但是xray服务器端日志却是有真实访客IP的,
  • 所以我觉得reality节点在处理"acceptProxyProtocol": true的时候不一样

@heygo1345678
Copy link
Author

"tcpSettings": { "acceptProxyProtocol": true }, 不确定这个它生效没有

如果是xray日志报访问者127.0.0.1 盲猜你试试改配置

"sockopt": {

"acceptProxyProtocol": true,

}

你去文档搜下加上面的参数

测试了你说的:
"streamSettings": {

"sockopt": {

"tcpcongestion": "bbr",
"acceptProxyProtocol": true
}}
不过日志还是127.0.0.1:

2023/02/23 05:20:09 127.0.0.1:47288 accepted tcp:update.googleapis.com:443 [VLESS-TCP-Reality -> block]
2023/02/23 05:20:07 127.0.0.1:40106 accepted tcp:8.8.4.4:53 [VLESS-TCP-Reality >> direct]
2023/02/23 05:24:51 127.0.0.1:51940 accepted tcp:github.com:443 [VLESS-TCP-Reality >> direct]
2023/02/23 05:24:06 127.0.0.1:36702 accepted tcp:alive.github.com:443 [VLESS-TCP-Reality >> direct]
2023/02/23 05:23:59 [Warning] transport/internet/tcp: accepting PROXY protocol
Xray 1.7.5 (Xray, Penetrates Everything.) 4d5c319 (go1.20.1 linux/amd64)
A unified platform for anti-censorship.
2023/02/23 05:23:59 [Info] infra/conf/serial: Reading config: /etc/xray/config.json
2023/02/23 05:23:59 [Warning] core: Xray 1.7.5 started
2023/02/23 05:24:00 127.0.0.1:36530 accepted tcp:xxxx:80 [VLESS-TCP-Reality >> direct]
2023/02/23 05:24:00 127.0.0.1:36546 accepted tcp:xxxx:443 [VLESS-TCP-Reality >> direct]
2023/02/23 05:24:00 127.0.0.1:36522 accepted tcp:xxxx:443 [VLESS-TCP-Reality >> direct]

@chika0801
Copy link
Contributor

chika0801 commented Feb 23, 2023

你说清楚 xray日志 的 127.0.0.1 ,那你等开发者试试。我不用SNI分流,没测试过。

建议你把 nginx 和 xray 的配置 完整的,整理好,发上来,方便开发者定位复现别人测试,注意下排版

@RPRX
Copy link
Member

RPRX commented Feb 23, 2023

还有,REALITY 的原理不是“偷证书”,TLSv1.3 把 Server Hello 后的消息全加密了,中间人看不到证书,想象力需要再丰富些

REALITY 服务端只偷了目标网站的 Server Hello,和后续握手消息的长度特征,还有超时特征等是 TODO

@RPRX
Copy link
Member

RPRX commented Feb 23, 2023

仔细看了一下这个 issue,有可能是 REALITY 服务端代码的问题,你开一下服务端的 show 看看有没有真实 IP

@heygo1345678
Copy link
Author

仔细看了一下这个 issue,有可能是 REALITY 服务端代码的问题,你开一下服务端的 show 看看有没有真实 IP
测试了,确实可以看到访客IP了,我xxxx脱敏了

Xray 1.7.5 (Xray, Penetrates Everything.) 4d5c319 (go1.20.1 linux/amd64)
A unified platform for anti-censorship.
2023/02/23 06:19:32 [Info] infra/conf/serial: Reading config: /etc/xray/config.json
2023/02/23 06:19:33 [Warning] transport/internet/tcp: accepting PROXY protocol
2023/02/23 06:19:33 [Warning] core: Xray 1.7.5 started
REALITY remoteAddr: xxxxx:40380
REALITY remoteAddr: xxxx:40383
REALITY remoteAddr: xxxxx:40380 hs.clientHello.sessionId: [207 10 49 87 145 57 61]

@debiansid
Copy link

debiansid commented Feb 23, 2023 via email

@RPRX
Copy link
Member

RPRX commented Feb 23, 2023

@heygo1345678 OK,那我猜对了,v1.8.0 前会修复

@RPRX RPRX closed this as completed in bdbca33 Feb 26, 2023
@RPRX
Copy link
Member

RPRX commented Feb 26, 2023

已修复,请测试 bdbca33

@lxhao61
Copy link

lxhao61 commented Feb 26, 2023

已修复,请测试 bdbca33

大佬,SNI分流问题没有完美解决。使用此版本后反而不能使用SNI分流+Proxy Protocol了,必须去除Proxy Protocol才能正常使用。

@RPRX
Copy link
Member

RPRX commented Feb 26, 2023

已修复,请测试 bdbca33

大佬,SNI分流问题没有解决,使用此版本后反而不能使用SNI分流+Proxy Protocol了,必须去除Proxy Protocol才能正常使用。

#1712 (comment)

@lxhao61
Copy link

lxhao61 commented Feb 26, 2023

已修复,请测试 bdbca33

大佬,SNI分流问题没有解决,使用此版本后反而不能使用SNI分流+Proxy Protocol了,必须去除Proxy Protocol才能正常使用。

#1712 (comment)

感谢大佬,新更新完美修复了。

@debiansid
Copy link

debiansid commented Feb 26, 2023 via email

@guigeng
Copy link

guigeng commented Feb 27, 2023

已修复,请测试 bdbca33

大佬,SNI分流问题没有解决,使用此版本后反而不能使用SNI分流+Proxy Protocol了,必须去除Proxy Protocol才能正常使用。

#1712 (comment)

感谢大佬,新更新完美修复了。

等你更新配置大全

@iwoomi
Copy link

iwoomi commented May 28, 2023

问题吐槽

虽然这是一个已经关闭的issue,但我刚好看到了,我实在是看不过去这种提问格式,因为我已经看到过n次这种直接粘配置上来不整理格式的情况了。

我真的难以想象一个能搭建出“ xray VLESS-TCP-Reality + xtls-rprx-vision +nginx stream 443 sni 分流端口复用”的人,竟然连三个反引号引住代码区块都不会(又或者是懒?),粘出来的配置文件格式💩一样的难看,我要是rprx,看到这种回复我都不想回答,整理一下格式很难吗?

不敢说让你们去折叠代码了,就连基本的用一对```括住配置文件都不会吗:创建和突显代码块

所以我写了这个教程,如果有人再遇到这样直接把配置文件粘上来不整理格式的,先把我这个教程给他看,让他重新编辑好格式再来问。

配置文件格式化教学

1、如果你的配置文件写的时候就格式不整齐,首先要格式化一下,可以在网上找格式化工具:json格式化网站
2、但网上的格式化网站几乎都是有以下两个缺点:

  • 1)当json的值为数字时,不能不加引号(不加的话,一格式化就会报错,而xray的端口号一般不加引号的);
  • 2)不支持在json中使用双斜杠添加注释//(添加了注释的话,一格式化就会报错,或者会被去除)

基于以上两个原因,所以我推荐用编辑器来格式化,我推荐用Visual Studio Code(平时简称vscode)编辑器
3、vscode编辑器格式化json代码示例

  • 1)在vscode中新建一个文件:File→New Text File (也可以直接在vscode中按control+N,macOS按command+N)
  • 2)选择“select a language” → 搜索json,选择“json with comments”
  • 3)把xray配置文件内容粘贴进去,一般来说自动就格式化了,如果没有,则全选后→右击→“Format Document”
    以下是用vscode格式化xray配置文件演示
    使用vscode格式化json

2、然后在gihub issue区域先敲一对三反引号(```),如下所示,最后把你格式化后的配置粘贴到里面去

```
// 在这里放置你的配置文件
```

3、写完后,点击左上角的“Preview”预览一下再发,预览格式没问题再发,有问题继续修改
image

我们来看看格式化后的配置文件,多清晰

{
    "log": {
        "loglevel": "warning"
    },
    "inbounds": [{
        "tag": "VLESS-TCP-Reality",
        "listen": "0.0.0.0",
        "port": 44443, //服务器监听端口号,可以不是443,防火墙打开或者vps面板操作:iptables -I INPUT -p tcp --dport 8443 -j ACCEPT
        "protocol": "vless",
        "settings": {
            "clients": [{
                "id": "",
                "flow": "xtls-rprx-vision" //解决tls in tls流量特征
            }],
            "decryption": "none"
        },
        "streamSettings": {
            "tcpSettings": {
                "acceptProxyProtocol": true
            },
            "network": "tcp",
            "security": "reality", //魔改的tls协议 reality
            "realitySettings": {
                "show": false,
                "privateKey": "", //使用上面生成的私钥
                "shortIds": [""],
                "Dest": "61.147.219.124:443", //这个是sni白名单网站www.microsoft.com的cdn IP和 https网站端口号
                "type": "tcp",
                "serverNames": ["www.microsoft.com"]
            }
        }
    }],
    "outbounds": [{
        "protocol": "freedom",
        "tag": "direct"
    }]
}

再看看原来没有格式化的截图,看看像什么样?
image

折叠过长配置文件或日志

当配置文件或粘贴上来的日志过长时,如果不折叠,看起来比较麻烦,此时你可以使用github markdown独有的折叠功能。

折叠的语法如下,你只需要把这个粘贴到你的issue中,然后把你要折叠的内容放在下面的内容区域,内容本身如果是配置文件,还是要加```来括住

<details>
<summary>这是自定义按钮</summary>

这是要被折叠的内容第1行
这是要被折叠的内容第2行
这是要被折叠的内容第3行

</details>

我们来试试,把以下内容粘贴到issue中,然后点击“Preview”按钮预览一下

<details>
<summary>server端配置</summary>

```json
{
    "log": {
        "loglevel": "warning"
    },
    "inbounds": [{
        "tag": "VLESS-TCP-Reality",
        "listen": "0.0.0.0",
        "port": 44443, //服务器监听端口号,可以不是443,防火墙打开或者vps面板操作:iptables -I INPUT -p tcp --dport 8443 -j ACCEPT
        "protocol": "vless",
        "settings": {
            "clients": [{
                "id": "",
                "flow": "xtls-rprx-vision" //解决tls in tls流量特征
            }],
            "decryption": "none"
        },
        "streamSettings": {
            "tcpSettings": {
                "acceptProxyProtocol": true
            },
            "network": "tcp",
            "security": "reality", //魔改的tls协议 reality
            "realitySettings": {
                "show": false,
                "privateKey": "", //使用上面生成的私钥
                "shortIds": [""],
                "Dest": "61.147.219.124:443", //这个是sni白名单网站www.microsoft.com的cdn IP和 https网站端口号
                "type": "tcp",
                "serverNames": ["www.microsoft.com"]
            }
        }
    }],
    "outbounds": [{
        "protocol": "freedom",
        "tag": "direct"
    }]
}
```

</details>

如下所示,可以看到虽然我们的配置文件内容挺长,但实际显示时就显示成一个按钮了,我们可以点击它来展开查看,看完又可以收起,这样可以让我们看issue时结构分明,等要看具体配置的时候才展开来看

server端配置
{
    "log": {
        "loglevel": "warning"
    },
    "inbounds": [{
        "tag": "VLESS-TCP-Reality",
        "listen": "0.0.0.0",
        "port": 44443, //服务器监听端口号,可以不是443,防火墙打开或者vps面板操作:iptables -I INPUT -p tcp --dport 8443 -j ACCEPT
        "protocol": "vless",
        "settings": {
            "clients": [{
                "id": "",
                "flow": "xtls-rprx-vision" //解决tls in tls流量特征
            }],
            "decryption": "none"
        },
        "streamSettings": {
            "tcpSettings": {
                "acceptProxyProtocol": true
            },
            "network": "tcp",
            "security": "reality", //魔改的tls协议 reality
            "realitySettings": {
                "show": false,
                "privateKey": "", //使用上面生成的私钥
                "shortIds": [""],
                "Dest": "61.147.219.124:443", //这个是sni白名单网站www.microsoft.com的cdn IP和 https网站端口号
                "type": "tcp",
                "serverNames": ["www.microsoft.com"]
            }
        }
    }],
    "outbounds": [{
        "protocol": "freedom",
        "tag": "direct"
    }]
}

希望大家提issue都能这么提,不求全部用折叠,但至少用一对```括住配置文件,开发者本来就很辛苦了,不要增加他们的工作难度,提的issue格式良好才能让人有更好的心情去回复大家的问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants