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

fix websocket alpn correctly on utls #590

Closed
wants to merge 43 commits into from
Closed

fix websocket alpn correctly on utls #590

wants to merge 43 commits into from

Conversation

sJJdGG
Copy link

@sJJdGG sJJdGG commented May 4, 2023

based on PR XTLS/Xray-core#1256

please read the origin PR for complete description.

credits: @HirbodBehnam

Fixes utls not setting alpn correctly when using utls.

Could be a major filtering hazard.

Also without this fix connection is not established when using CDN (as alpn is not set correctly).

Logs are based on using CF as CDN.

client config:

{
  "log": {
    "level": "info",
    "timestamp": true
  },
  "route": {
    "geoip": {
      "path": "geoip.db",
      "download_url": "https://github.com/soffchen/sing-geoip/releases/latest/download/geoip.db"
    },
    "geosite": {
      "path": "geosite.db",
      "download_url": "https://github.com/soffchen/sing-geosite/releases/latest/download/geosite.db"
    },
    "rules": [
      {
        "geosite": ["cn", "private"],
        "outbound": "direct"
      },
      {
        "geoip": ["cn", "private"],
        "outbound": "direct"
      }
    ]
  },
  "inbounds": [
    {
      "type": "mixed",
      "tag": "mixed-in",
      "listen": "::",
      "listen_port": 10000,
      "domain_strategy": "ipv4_only",
      "tcp_fast_open": true,
      "sniff": true,
      "sniff_override_destination": true
    }
  ],
  "outbounds": [
    {
      "type": "vless",
      "tag": "proxy",
      "server": "sudbdomain.domain.tld",
      "server_port": 443,
      "uuid": "c74ffa38-ea77-11ed-9c46-d7588d9ee022",
      "flow": "",
      "network": "tcp",
      "tls": {
        "enabled": true,
        "server_name": "sudbdomain.domain.tld",
        "utls": {
          "enabled": true,
          "fingerprint": "chrome"
        }
      },
      "packet_encoding": "xudp",
      "transport": {
        "type": "ws",
        "path": "/testing",
        "early_data_header_name": "Sec-WebSocket-Protocol",
        "headers": {
          "Host": "sudbdomain.domain.tld"
        }
      }
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    }
  ]
}

without setting utls object in client config:

sjjd@GG:~/code/sing/sing-box/cmd/sing-box$ ./sing-box run -c config_client.json 
+0330 2023-05-04 15:53:07 INFO router: using vless[proxy] as default outbound for connection
+0330 2023-05-04 15:53:07 INFO router: using direct[direct] as default outbound for packet connection
+0330 2023-05-04 15:53:07 WARN router: geoip database not exists: geoip.db
+0330 2023-05-04 15:53:07 INFO router: downloading geoip database
+0330 2023-05-04 15:53:07 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:53:08 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:53:09 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:53:10 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:53:23 INFO router: loaded geoip database: 259 codes
+0330 2023-05-04 15:53:23 WARN router: geosite database not exists: geosite.db
+0330 2023-05-04 15:53:23 INFO router: downloading geosite database
+0330 2023-05-04 15:53:23 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:53:24 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:53:25 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:53:25 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:53:30 INFO router: loaded geosite database: 1385 codes
+0330 2023-05-04 15:53:31 INFO inbound/mixed[mixed-in]: tcp server started at [::]:10000
+0330 2023-05-04 15:53:31 INFO sing-box started (23.422s)

With utls, without this fix:

sjjd@GG:~/code/sing/sing-box/cmd/sing-box$ ./sing-box run -c config_client.json 
+0330 2023-05-04 15:19:25 INFO router: using vless[proxy] as default outbound for connection
+0330 2023-05-04 15:19:25 INFO router: using direct[direct] as default outbound for packet connection
+0330 2023-05-04 15:19:25 WARN router: geoip database not exists: geoip.db
+0330 2023-05-04 15:19:25 INFO router: downloading geoip database
+0330 2023-05-04 15:19:25 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:19:26 ERROR router: download geoip database: Get "https://github.com/soffchen/sing-geoip/releases/latest/download/geoip.db": malformed HTTP response "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x01\x00\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\b\x00\x00\x00\x00\x00\x7f\xff\x00\x00\x00\x00\b\a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
+0330 2023-05-04 15:19:26 INFO router: downloading geoip database
+0330 2023-05-04 15:19:26 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:19:27 ERROR router: download geoip database: Get "https://github.com/soffchen/sing-geoip/releases/latest/download/geoip.db": malformed HTTP response "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x01\x00\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\b\x00\x00\x00\x00\x00\x7f\xff\x00\x00\x00\x00\b\a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
+0330 2023-05-04 15:19:27 INFO router: downloading geoip database
+0330 2023-05-04 15:19:27 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:19:28 ERROR router: download geoip database: Get "https://github.com/soffchen/sing-geoip/releases/latest/download/geoip.db": malformed HTTP response "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x01\x00\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\b\x00\x00\x00\x00\x00\x7f\xff\x00\x00\x00\x00\b\a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
FATAL[0002] start service: Get "https://github.com/soffchen/sing-geoip/releases/latest/download/geoip.db": malformed HTTP response "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x01\x00\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\b\x00\x00\x00\x00\x00\x7f\xff\x00\x00\x00\x00\b\a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
sjjd@GG:~/code/sing/sing-box/cmd/sing-box$ 

with utls, with this fix:

sjjd@GG:~/code/sing/sing-box/cmd/sing-box$ ./sing-box run -c config_client.json 
+0330 2023-05-04 15:46:58 INFO router: using vless[proxy] as default outbound for connection
+0330 2023-05-04 15:46:58 INFO router: using direct[direct] as default outbound for packet connection
+0330 2023-05-04 15:46:58 WARN router: geoip database not exists: geoip.db
+0330 2023-05-04 15:46:58 INFO router: downloading geoip database
+0330 2023-05-04 15:46:58 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:46:59 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:47:00 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:47:00 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:47:04 INFO router: loaded geoip database: 259 codes
+0330 2023-05-04 15:47:04 WARN router: geosite database not exists: geosite.db
+0330 2023-05-04 15:47:04 INFO router: downloading geosite database
+0330 2023-05-04 15:47:04 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:47:05 INFO outbound/vless[proxy]: outbound connection to github.com:443
+0330 2023-05-04 15:47:06 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:47:06 INFO outbound/vless[proxy]: outbound connection to objects.githubusercontent.com:443
+0330 2023-05-04 15:47:09 INFO router: loaded geosite database: 1385 codes
+0330 2023-05-04 15:47:11 INFO inbound/mixed[mixed-in]: tcp server started at [::]:10000
+0330 2023-05-04 15:47:11 INFO sing-box started (12.322s)

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

Successfully merging this pull request may close these issues.

None yet

7 participants