feat(raw search)!: Use utls to mimic chrome TLS clienthello fingerprint

This commit is contained in:
Pachakutiq
2025-08-28 16:43:39 +08:00
parent c35c5f134d
commit 81fc057c83
3 changed files with 81 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
package baidu
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"strings"
@@ -12,6 +14,8 @@ import (
"github.com/corpix/uarand"
"github.com/karust/openserp/core"
"github.com/sirupsen/logrus"
utls "github.com/refraction-networking/utls"
)
func baiduRequest(searchURL string, query core.Query) (*http.Response, error) {
@@ -30,6 +34,29 @@ func baiduRequest(searchURL string, query core.Query) (*http.Response, error) {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
transport.DialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{}
rawConn, err := dialer.DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
hostname := strings.Split(addr, ":")[0]
config := &utls.Config{
ServerName: hostname,
InsecureSkipVerify: query.Insecure,
}
uconn := utls.UClient(rawConn, config, utls.HelloChrome_Auto)
if err := uconn.Handshake(); err != nil {
rawConn.Close()
return nil, err
}
return uconn, nil
}
baseClient := &http.Client{
Transport: transport,
Timeout: time.Second * 10,

View File

@@ -1,7 +1,9 @@
package google
import (
"context"
"crypto/tls"
"net"
"net/http"
"net/url"
"strings"
@@ -11,6 +13,8 @@ import (
"github.com/corpix/uarand"
"github.com/karust/openserp/core"
"github.com/sirupsen/logrus"
utls "github.com/refraction-networking/utls"
)
func googleRequest(searchURL string, query core.Query) (*http.Response, error) {
@@ -29,6 +33,29 @@ func googleRequest(searchURL string, query core.Query) (*http.Response, error) {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
transport.DialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{}
rawConn, err := dialer.DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
hostname := strings.Split(addr, ":")[0]
config := &utls.Config{
ServerName: hostname,
InsecureSkipVerify: query.Insecure,
}
uconn := utls.UClient(rawConn, config, utls.HelloChrome_Auto)
if err := uconn.Handshake(); err != nil {
rawConn.Close()
return nil, err
}
return uconn, nil
}
baseClient := &http.Client{
Transport: transport,
Timeout: time.Second * 10,

View File

@@ -1,7 +1,9 @@
package yandex
import (
"context"
"crypto/tls"
"net"
"net/http"
"net/url"
"strings"
@@ -11,6 +13,8 @@ import (
"github.com/corpix/uarand"
"github.com/karust/openserp/core"
"github.com/sirupsen/logrus"
utls "github.com/refraction-networking/utls"
)
func yandexRequest(searchURL string, query core.Query) (*http.Response, error) {
@@ -29,6 +33,29 @@ func yandexRequest(searchURL string, query core.Query) (*http.Response, error) {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
transport.DialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{}
rawConn, err := dialer.DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
hostname := strings.Split(addr, ":")[0]
config := &utls.Config{
ServerName: hostname,
InsecureSkipVerify: query.Insecure,
}
uconn := utls.UClient(rawConn, config, utls.HelloChrome_Auto)
if err := uconn.Handshake(); err != nil {
rawConn.Close()
return nil, err
}
return uconn, nil
}
baseClient := &http.Client{
Transport: transport,
Timeout: time.Second * 10,