Skip to content

Sniffing TLS serverName with tproxy tcp not work #1537

Description

@avengermsoft

What version of Xray are you using?

Version 1.7.2

What's your scenario of using Xray?

dokodemo-door(tproxy(tcp,udp)) -> vmess-wss

What problems have you encountered?

Sniffing TLS serverName with tproxy tcp not work. HTTP with tproxy, sock work.

Please attach your configuration here

Client configuration:

{
	"log": {
		"loglevel": "debug"
	},
	"inbounds": [
		{
			"listen": "::",
			"port": 1082,
			"protocol": "socks",
			"settings": {
				"network": "tcp",
				"auth": "noauth"
			},
			"sniffing": {
				"enabled": true,
				"destOverride": [
					"http",
					"tls",
					"quic"
				]
			},
			"tag": "socks"
		},
		{
			"listen": "127.0.0.1",
			"port": 9171,
			"protocol": "dokodemo-door",
			"settings": {
				"network": "tcp,udp",
				"followRedirect": true
			},
			"streamSettings": {
				"sockopt": {
					"tproxy": "tproxy"
				}
			},
			"sniffing": {
				"enabled": true,
				"destOverride": [
					"http",
					"tls",
					"quic"
				]
			},
			"tag": "tproxy4"
		}
	],
	"outbounds": [
		{
			"protocol": "vmess",
			"settings": {
				"vnext": [
					{
						"address": "a.myserver.xyz",
						"port": 443,
						"users": [
							{
								"id": "b95c7f",
								"alterId": 0,
								"security": "chacha20-poly1305"
							}
						]
					}
				]
			},
			"streamSettings": {
				"sockopt": {
					"mark": 9012
				},
				"network": "ws",
				"wsSettings": {
					"path": "/test",
					"connectionReuse": true
				},
				"security": "tls",
				"tlsSettings": {
					"serverName": "a.myserver.xyz",
					"allowInsecure": false
				},
				"mux": {
					"enabled": false
				}
			},
			"tag": "proxy-vmess"
		}
	],
	"routing": {
		"rules": [
			{
				"type": "field",
				"inboundTag": [
					"tproxy4"
				],
				"outboundTag": "proxy-vmess"
			}
		]
	}
}
ipset create unblock4-ssp hash:net timeout 86400 family inet -exist
ip -4 route add local default dev lo table 233 2>/dev/null
ip -4 rule add fwmark 0x2333 table 233 priority 233 2>/dev/null
iptables -N SSREDIR -t mangle 2>/dev/null
#iptables -F SSREDIR -t mangle 2>/dev/null

# connection-mark -> packet-mark
iptables -A SSREDIR -t mangle -m set ! --match-set unblock4-ssp dst -j RETURN
iptables -A SSREDIR -t mangle -m mark --mark 0x2334 -j RETURN
iptables -A SSREDIR -t mangle -d 0.0.0.0/8 -j RETURN
iptables -A SSREDIR -t mangle -d 10.0.0.0/8 -j RETURN
iptables -A SSREDIR -t mangle -d 127.0.0.0/8 -j RETURN
iptables -A SSREDIR -t mangle -d 169.254.0.0/16 -j RETURN
iptables -A SSREDIR -t mangle -d 172.16.0.0/12 -j RETURN
iptables -A SSREDIR -t mangle -d 192.168.0.0/16 -j RETURN
iptables -A SSREDIR -t mangle -d 224.0.0.0/4 -j RETURN
iptables -A SSREDIR -t mangle -d 240.0.0.0/4 -j RETURN
iptables -A SSREDIR -t mangle -j CONNMARK --restore-mark
iptables -A SSREDIR -t mangle -m mark --mark 0x2333 -j RETURN
iptables -A SSREDIR -t mangle -p tcp --syn -j MARK --set-mark 0x2333
iptables -A SSREDIR -t mangle -p udp -m conntrack --ctstate NEW -j MARK --set-mark 0x2333
iptables -A SSREDIR -t mangle -j CONNMARK --save-mark

iptables -A PREROUTING -t mangle -p tcp -m set --match-set unblock4-ssp dst -j SSREDIR
iptables -A PREROUTING -t mangle -p udp -m set --match-set unblock4-ssp dst -j SSREDIR
iptables -A OUTPUT     -t mangle -p tcp -m set --match-set unblock4-ssp dst -j SSREDIR
iptables -A OUTPUT     -t mangle -p udp -m set --match-set unblock4-ssp dst -j SSREDIR

iptables -A PREROUTING -t mangle -p tcp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 9171
iptables -A PREROUTING -t mangle -p udp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 9171

Test scenario from client

ipset -exist add unblock4-ssp 45.79.77.20
curl -4 -vk "https://www.jsonip.com" --resolve www.jsonip.com:443:45.79.77.20

Please attach error logs here

Client error log with HTTPS: - !!!Not Work

curl -4 -vk "https://www.jsonip.com" --resolve www.jsonip.com:443:45.79.77.20

2023/01/17 10:52:47 [Debug] [1631894061] proxy/dokodemo: processing connection from: 192.168.97.123:61082
2023/01/17 10:52:47 [Info] [1631894061] proxy/dokodemo: received request for 192.168.97.123:61082
2023/01/17 10:52:47 [Info] [1631894061] app/dispatcher: taking detour [proxy-vmess] for [tcp:45.79.77.20:443]
2023/01/17 10:52:47 192.168.97.123:61082 accepted tcp:45.79.77.20:443 [proxy-vmess]
2023/01/17 10:52:47 [Info] [1631894061] transport/internet/websocket: creating connection to tcp:a.myserver.xyz:443
2023/01/17 10:52:48 [Info] [1631894061] proxy/vmess/outbound: tunneling request to tcp:45.79.77.20:443 via a.myserver.xyz:443
2023/01/17 10:53:48 [Info] [1631894061] app/proxyman/outbound: failed to process outbound traffic > proxy/vmess/outbound: connection ends > proxy/vmess/outbound: failed to read header > common/drain: common/drain: unable to drain connection > websocket: close 1006 (abnormal closure): unexpected EOF > proxy/vmess/encoding: Unable to Read Header Len > websocket: close 1006 (abnormal closure): unexpected EOF
2023/01/17 10:53:48 [Info] [1631894061] app/proxyman/inbound: connection ends > proxy/dokodemo: connection ends > proxy/dokodemo: failed to transport response > io: read/write on closed pipe

Client error log with HTTP - !!!Work:

curl -4 -vk "http://www.jsonip.com" --resolve www.jsonip.com:80:45.79.77.20

2023/01/17 10:51:45 [Debug] [1651629936] proxy/dokodemo: processing connection from: 192.168.97.123:61078
2023/01/17 10:51:45 [Info] [1651629936] proxy/dokodemo: received request for 192.168.97.123:61078
2023/01/17 10:51:45 [Info] [1651629936] app/dispatcher: sniffed domain: www.jsonip.com
2023/01/17 10:51:45 [Info] [1651629936] app/dispatcher: taking detour [proxy-vmess] for [tcp:www.jsonip.com:80]
2023/01/17 10:51:45 192.168.97.123:61078 accepted tcp:45.79.77.20:80 [proxy-vmess]
2023/01/17 10:51:45 [Info] [1651629936] transport/internet/websocket: creating connection to tcp:a.myserver.xyz:443
2023/01/17 10:51:45 [Info] [1651629936] proxy/vmess/outbound: tunneling request to tcp:www.jsonip.com:80 via a.myserver.xyz:443
2023/01/17 10:51:48 [Info] [1651629936] app/proxyman/inbound: connection ends > proxy/dokodemo: connection ends > context canceled
2023/01/17 10:51:48 [Info] [1651629936] app/proxyman/outbound: failed to process outbound traffic > proxy/vmess/outbound: connection ends > context canceled

Client error log with Sock - !!!Work:

curl -4 -v -x "socks5://zyavenger:1082" "https://www.jsonip.com" --resolve www.jsonip.com:443:45.79.77.20

2023/01/17 10:57:32 [Info] [3847910039] proxy/socks: TCP Connect request to tcp:45.79.77.20:443
2023/01/17 10:57:32 [Info] [3847910039] app/dispatcher: sniffed domain: www.jsonip.com
2023/01/17 10:57:32 tcp:192.168.97.123:61108 accepted tcp:45.79.77.20:443 [proxy-vmess]
2023/01/17 10:57:32 [Info] [3847910039] app/dispatcher: taking detour [proxy-vmess] for [tcp:www.jsonip.com:443]
2023/01/17 10:57:32 [Info] [3847910039] transport/internet/websocket: creating connection to tcp:a.myserver.xyz:443
2023/01/17 10:57:33 [Info] [3847910039] proxy/vmess/outbound: tunneling request to tcp:www.jsonip.com:443 via a.myserver.xyz:443

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions