utls icon indicating copy to clipboard operation
utls copied to clipboard

Applypreset is doing something wrong during Handshake, which leads the request getting blocked from anti bots!

Open kawacode opened this issue 3 years ago • 0 comments

package cipher

import (
   "bufio"
   "github.com/refraction-networking/utls"
   "net"
   "net/http"
)

func get(addr string) (*http.Response, error) {
   req, err := http.NewRequest("GET", addr, nil)
   if err != nil {
      return nil, err
   }
   dial, err := net.Dial("tcp", req.URL.Host + ":" + req.URL.Scheme)
   if err != nil {
      return nil, err
   }
   cfg := tls.Config{ServerName: req.URL.Host}
   client := tls.UClient(dial, &cfg, tls.HelloCustom)
   spec := tls.ClientHelloSpec{
      CipherSuites: []uint16{
         0x1302, // TLS_AES_256_GCM_SHA384
         0xC02C ,// TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
      },
      Extensions: []tls.TLSExtension{
         &tls.SupportedCurvesExtension{
            []tls.CurveID{tls.X25519},
         },
         &tls.SupportedPointsExtension{
            SupportedPoints: []byte{0},
         },
      },
   }
   client.ApplyPreset(&spec) <--- Error is here
   client.Handshake() <--- Error is here too 
   req.Write(client)
   return http.ReadResponse(bufio.NewReader(client), req)
}
Wireshark: 
![image](https://user-images.githubusercontent.com/93525229/174451757-8cf3d91e-36b3-4a2f-bc56-87dca0140239.png)
Error 403 Blocks my request, because of certificate i dont know :/

What is should look like image

This Code is working fine, Handshake and everything is fine!!!

func get(addr string) (*http.Response, error) {
   req, err := http.NewRequest("GET", addr, nil)
   if err != nil {
      return nil, err
   }
   dial, err := net.Dial("tcp", req.URL.Host + ":" + req.URL.Scheme)
   if err != nil {
      return nil, err
   }
   cfg := tls.Config{ServerName: req.URL.Host} // Here i can change random chipersuites and there is no error
   client := tls.UClient(dial, &cfg, tls.HelloChrome)
   req.Write(client)
   return http.ReadResponse(bufio.NewReader(client), req)
}

kawacode avatar Jun 18 '22 18:06 kawacode