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使用部分SSH软件连接目标主机 #3459

Open
2 tasks done
islercn opened this issue Jun 20, 2024 · 13 comments
Open
2 tasks done

无法通过xray使用部分SSH软件连接目标主机 #3459

islercn opened this issue Jun 20, 2024 · 13 comments
Labels
can't reproduce The issue can't provide full reproduction process. Without further information, the issue may closed

Comments

@islercn
Copy link

islercn commented Jun 20, 2024

完整性要求

  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我搜索了issues,没有发现已提出的类似问题。

版本

1.8.15

描述

有一个带密码的上游https代理,我把它转成了透明代理,用iptables转发。在测试中,上网、远程桌面什么的都没问题,但是用xshell之类的软件通过ssh连代理后的服务器,直接没反应(提示连接,然后就卡在那了),且:
1.kill掉xray,起ss的透明代理(其他都不变),秒连(意味着iptables转发没有问题)
2.用putty,秒连;用MobaXterm,连不上,和xshell一样(ss下可连)
3.将这个https代理用goproxy转成socks5,然后xshell下ssh设置这个socks5代理,秒连,但是xray连socks5也不行

防火墙配置:
iptables -t nat -A work -p tcp -m set --match-set worklist dst -j REDIRECT --to-ports 123

抓包的数据上看,除了xshell的包长度超过1500,putty没超,别的地方似乎没有任何区别了。

也可以看goproxy的这个issue

1
2

重现方式

把上游https代理转成透明代理,xshell等软件无法通过代理连接目标服务器(SSH)

客户端配置

{
"log": {
"error": "/root/proxy/xray/error.log",
"loglevel": "debug"
},
"inbounds": [
{
"port": 321,
"protocol": "socks",
"settings": {
"udp": true
}
},
{
"port": 123,
"protocol": "dokodemo-door",
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"network": "tcp,udp",
"followRedirect": true
},
"streamSettings": {
"sockopt": {
"tproxy": "redirect"
}
}
}
],
"outbounds": [
{
"protocol": "http",
"settings": {
"servers": [
{
"address": "proxy.com",
"port": 12345,
"users": [
{
"user": "username",
"pass": "password"
}
]
}
]
},
"streamSettings": {
"security": "tls",
"tlsSettings": {
"allowInsecure": false
}
}
}
]
}

服务端配置

上级是https代理,无配置

客户端日志

只记录到这么多,xxx.com和10.1.1.2对应同一台机器):

透明代理日志:
2024/06/20 12:38:01 [Debug] [1299392023] proxy/dokodemo: processing connection from: 192.168.11.101:63925
2024/06/20 12:38:01 [Info] [1299392023] proxy/dokodemo: received request for 192.168.11.101:63925
2024/06/20 12:38:02 [Info] [1299392023] app/dispatcher: default route for tcp:10.1.1.2:22

SOCKS代理日志:
2024/06/20 12:25:43 [Info] [1352458977] proxy/socks: TCP Connect request to tcp:xxx.com:22
2024/06/20 12:25:43 [Info] [1352458977] app/dispatcher: default route for tcp:xxx.com:22

服务端日志

上级是https代理,无日志

@Fangliding
Copy link
Member

完整日志

@islercn
Copy link
Author

islercn commented Jun 21, 2024

使用透明代理尝试连接一次,连不上关掉窗口,然后日志就这么多:

2024/06/21 03:52:45 [Debug] app/log: Logger started
2024/06/21 03:52:45 [Debug] app/proxyman/inbound: creating stream worker on 0.0.0.0:321
2024/06/21 03:52:45 [Debug] app/proxyman/inbound: creating stream worker on 0.0.0.0:123
2024/06/21 03:52:45 [Info] transport/internet/tcp: listening TCP on 0.0.0.0:321
2024/06/21 03:52:45 [Info] transport/internet/udp: listening UDP on 0.0.0.0:321
2024/06/21 03:52:45 [Info] transport/internet/tcp: listening TCP on 0.0.0.0:123
2024/06/21 03:52:45 [Info] transport/internet/udp: listening UDP on 0.0.0.0:123
2024/06/21 03:52:45 [Warning] core: Xray 1.8.15 started
2024/06/21 03:52:47 [Debug] [2681177714] proxy/dokodemo: processing connection from: 192.168.11.101:51528
2024/06/21 03:52:47 [Info] [2681177714] proxy/dokodemo: received request for 192.168.11.101:51528
2024/06/21 03:52:48 [Info] [2681177714] app/dispatcher: default route for tcp:10.1.1.2:22
2024/06/21 03:53:08 [Info] [2681177714] transport/internet/tcp: dialing TCP to tcp:proxy.com:12345
2024/06/21 03:53:08 [Debug] transport/internet: dialing to tcp:proxy.com:12345
2024/06/21 03:53:10 [Info] [2681177714] app/proxyman/inbound: connection ends > proxy/dokodemo: connection ends > context canceled

@islercn
Copy link
Author

islercn commented Jun 21, 2024

使用socks5尝试一次,也是一样的,只是协议变成了socks,地址变成了域名(目标服务器是通过域名连接的):
2024/06/21 03:55:27 [Debug] app/log: Logger started
2024/06/21 03:55:27 [Debug] app/proxyman/inbound: creating stream worker on 0.0.0.0:321
2024/06/21 03:55:27 [Debug] app/proxyman/inbound: creating stream worker on 0.0.0.0:123
2024/06/21 03:55:27 [Info] transport/internet/tcp: listening TCP on 0.0.0.0:321
2024/06/21 03:55:27 [Info] transport/internet/udp: listening UDP on 0.0.0.0:321
2024/06/21 03:55:27 [Info] transport/internet/tcp: listening TCP on 0.0.0.0:123
2024/06/21 03:55:27 [Info] transport/internet/udp: listening UDP on 0.0.0.0:123
2024/06/21 03:55:27 [Warning] core: Xray 1.8.15 started
2024/06/21 03:55:29 [Info] [3817245398] proxy/socks: TCP Connect request to tcp:xxx.com:22
2024/06/21 03:55:29 [Info] [3817245398] app/dispatcher: default route for tcp:xxx.com:22
2024/06/21 03:55:32 [Info] [3817245398] transport/internet/tcp: dialing TCP to tcp:proxy.com:12345
2024/06/21 03:55:32 [Debug] transport/internet: dialing to tcp:proxy.com:12345
2024/06/21 03:55:34 [Info] [3817245398] app/proxyman/inbound: connection ends > proxy/socks: connection ends > context canceled

@Fangliding
Copy link
Member

Fangliding commented Jun 21, 2024

如果不使用透明代理 直接用任意门映射一个ssh端口 再尝试连接这个端口 试试能不能用?(理论上处理流程是一样的)
再看看使用putty时候的日志

@islercn
Copy link
Author

islercn commented Jun 21, 2024

就是没有日志才奇怪,xshell窗口直接是卡死的,ctrl+c没用,只能手动关掉标签页,看起来就像发送请求给xray,xray一直没接。

putty的日志是类似的,看上去没有任何的区别,但是可以连上:
2024/06/21 04:46:35 [Debug] app/log: Logger started
2024/06/21 04:46:35 [Debug] app/proxyman/inbound: creating stream worker on 0.0.0.0:321
2024/06/21 04:46:35 [Debug] app/proxyman/inbound: creating stream worker on 0.0.0.0:123
2024/06/21 04:46:35 [Info] transport/internet/tcp: listening TCP on 0.0.0.0:321
2024/06/21 04:46:35 [Info] transport/internet/udp: listening UDP on 0.0.0.0:321
2024/06/21 04:46:35 [Info] transport/internet/tcp: listening TCP on 0.0.0.0:123
2024/06/21 04:46:35 [Info] transport/internet/udp: listening UDP on 0.0.0.0:123
2024/06/21 04:46:35 [Warning] core: Xray 1.8.15 started
2024/06/21 04:46:38 [Debug] [260256817] proxy/dokodemo: processing connection from: 192.168.11.101:53901
2024/06/21 04:46:38 [Info] [260256817] proxy/dokodemo: received request for 192.168.11.101:53901
2024/06/21 04:46:38 [Info] [260256817] app/dispatcher: default route for tcp:10.1.1.2:22
2024/06/21 04:46:38 [Info] [260256817] transport/internet/tcp: dialing TCP to tcp:proxy.com:12345
2024/06/21 04:46:38 [Debug] transport/internet: dialing to tcp:proxy.com:12345

非要说能看出来点啥,那就是超过1500的包,透明代理下,xray和goproxy不能正常处理(直接丢弃了?),gost可以正常处理;socks代理下,xray还是不能正常处理,goproxy和gost可以正常处理。gost在这块表现最好,但是它的透明代理不支持ipv6,所以这三个都不完美,不过可惜xray在这个场景下表现是最差的。。

@Fangliding
Copy link
Member

如果不使用透明代理 直接用任意门映射一个ssh端口 再尝试连接这个端口 试试能不能用?(理论上处理流程是一样的)

^

@islercn
Copy link
Author

islercn commented Jun 21, 2024

如果你是下面这个意思,那日志什么的是一样的,也是xshell不能连,putty可以连

{
"port": 22222,
"protocol": "dokodemo-door",
"settings": {
"address": "10.1.1.2",
"port": 22,
"network": "tcp",
"timeout": 0,
"followRedirect": false,
"userLevel": 0
}
},

多余启动的日志就不贴了,后面还是只有这三条,显示的不是任意门的端口
2024/06/21 05:10:29 [Debug] app/proxyman/inbound: creating stream worker on 0.0.0.0:22222
2024/06/21 05:10:29 [Info] transport/internet/tcp: listening TCP on 0.0.0.0:22222
2024/06/21 05:10:32 [Debug] [700452900] proxy/dokodemo: processing connection from: 192.168.11.101:62346
2024/06/21 05:10:32 [Info] [700452900] proxy/dokodemo: received request for 192.168.11.101:62346
2024/06/21 05:10:32 [Info] [700452900] app/dispatcher: default route for tcp:10.1.1.2:22

连接过程如下图所示,上面是xshell,一直卡连接,下面是putty,秒连。需要再指出的一点是,如果后台开着xray,xshell就一直卡在“Connection established.”,等很久也不会断,ctrl+c也不行,只能手动关掉窗口,但这时如果后台杀掉xray,连接就会断开了,提示:

Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(192.168.11.1-2222) at 13:21:34.

123

@Fangliding
Copy link
Member

我自己试了下nc监听端口 写程序发送2000字节的包 可以被任意门正常处理
自己电脑上的xshell也可以正常连 复现不了

@islercn
Copy link
Author

islercn commented Jun 21, 2024

我用刚发布的1.8.16,同一个配置,直接在windows下运行,然后连接127.0.0.1:22222,还是卡连接

也许和上级代理有关系,但是转透明代理的话gost是没问题的,转socks代理gost和goproxy都没问题,xray都有问题。

于是再换一个配置,直接把22222端口转发到openwrt的SSH端口,这回和上游代理完全没关系了,结果还是卡。。。

{
"port": 22222,
"protocol": "dokodemo-door",
"settings": {
"address": "192.168.11.1",
"port": @2345,
"network": "tcp",
"timeout": 0,
"followRedirect": false,
"userLevel": 0
},
},

然后我在服务器所在的内网下,用windows的xray把22222转发到一台服务器上,这回也和上游代理没关系,结果还是卡。。。

所以说,我换了客户机(两台win10),换了目标服务器(ubuntu主机/x86和x64的openwrt),换了代理开关(是否使用上级代理),换了客户端软件(xshell,mobaxterm,都是默认设置),都是xray不行(试了几个不同版本的xray都不行),gost或者goproxy可以,那么还可以怎么测试证明不是xray的问题呢?

windows下命令行窗口会有一条额外的日志,但是依然卡着不继续连接,putty还是秒连
2024/06/21 15:08:06 127.0.0.1:61184 accepted tcp:10.1.1.2:22

1234

@dyhkwong
Copy link
Contributor

尝试 "metadataOnly": true

以及:v2fly/v2ray-core@17d8526

@islercn islercn changed the title 协议转换后透明代理不能转发所有流量 无法通过xray使用部分SSH软件连接目标主机 Jun 21, 2024
@islercn
Copy link
Author

islercn commented Jun 21, 2024

inbounds增加如下配置无效:

"sniffing":{
"enabled":true,
"metadataOnly":true
}

@dyhkwong
Copy link
Contributor

那就并且 cherry-pick 下那个 commit

@islercn
Copy link
Author

islercn commented Jun 21, 2024

用v2ray似乎是一样的结果

@Fangliding Fangliding added the can't reproduce The issue can't provide full reproduction process. Without further information, the issue may closed label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce The issue can't provide full reproduction process. Without further information, the issue may closed
Projects
None yet
Development

No branches or pull requests

3 participants