replace cycletls with bogdanfinn/tls-client for better tls fingerprint spoofing reliability

This commit is contained in:
Kevin Pham
2023-11-28 12:33:53 -06:00
parent 9d31f7eb59
commit 31200cf9e2
10 changed files with 147 additions and 451 deletions

View File

@@ -4,9 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
http "github.com/bogdanfinn/fhttp"
"net"
//"net/http"
http "github.com/Danny-Dasilva/fhttp"
/*
tls_client "github.com/bogdanfinn/tls-client"
//"net/http"
*/
"time"
"ladder/proxychain"
@@ -38,45 +42,53 @@ func resolveWithGoogleDoH(host string) (string, error) {
return "", fmt.Errorf("no DoH DNS record found for %s", host)
}
type CustomDialer struct {
*net.Dialer
}
func NewCustomDialer(timeout, keepAlive time.Duration) *CustomDialer {
return &CustomDialer{
Dialer: &net.Dialer{
Timeout: timeout,
KeepAlive: keepAlive,
},
}
}
func (cd *CustomDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
port = "443"
}
resolvedHost, err := resolveWithGoogleDoH(host)
if err != nil {
return nil, err
}
return cd.Dialer.DialContext(ctx, network, net.JoinHostPort(resolvedHost, port))
}
// ResolveWithGoogleDoH modifies a ProxyChain's client to make the request by resolving the URL
// using Google's DNS over HTTPs service
func ResolveWithGoogleDoH() proxychain.RequestModification {
return func(px *proxychain.ProxyChain) error {
client := &http.Client{
Timeout: px.Client.Timeout,
}
dialer := &net.Dialer{
Timeout: 5 * time.Second,
KeepAlive: 5 * time.Second,
}
customDialContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
// If the addr doesn't include a port, determine it based on the URL scheme
if px.Request.URL.Scheme == "https" {
port = "443"
} else {
port = "80"
}
host = addr // assume the entire addr is the host
///customDialer := NewCustomDialer(10*time.Second, 10*time.Second)
return func(chain *proxychain.ProxyChain) error {
/*
options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(30),
tls_client.WithRandomTLSExtensionOrder(),
tls_client.WithDialer(*customDialer.Dialer),
//tls_client.WithClientProfile(profiles.Chrome_105),
}
resolvedHost, err := resolveWithGoogleDoH(host)
client, err := tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)
if err != nil {
return nil, err
return err
}
return dialer.DialContext(ctx, network, net.JoinHostPort(resolvedHost, port))
}
patchedTransportWithDoH := &http.Transport{
DialContext: customDialContext,
}
client.Transport = patchedTransportWithDoH
px.Client = client // Assign the modified client to the ProxyChain
chain.SetOnceHTTPClient(client)
*/
return nil
}
}