Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
T
tls-forward
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangmingming
tls-forward
Commits
7acaa64b
Commit
7acaa64b
authored
Dec 13, 2023
by
wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
111
parent
600ee9a4
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
54 deletions
+122
-54
go.mod
go.mod
+21
-4
go.sum
go.sum
+67
-0
client.go
tls/client.go
+34
-50
No files found.
go.mod
View file @
7acaa64b
...
...
@@ -17,27 +17,44 @@ require (
github.com/bogdanfinn/utls v1.5.16 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cloudflare/circl v1.3.6 // indirect
github.com/gaukas/godicttls v0.0.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20231212022811-ec68065c825e // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imroc/req/v3 v3.42.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.
2
// indirect
github.com/klauspost/compress v1.17.
4
// indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo/v2 v2.13.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
github.com/quic-go/quic-go v0.40.1 // indirect
github.com/refraction-networking/utls v1.5.4 // indirect
github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
go.uber.org/mock v0.3.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
...
...
go.sum
View file @
7acaa64b
This diff is collapsed.
Click to expand it.
tls/client.go
View file @
7acaa64b
...
...
@@ -8,30 +8,31 @@ import (
"encoding/binary"
"errors"
"github.com/andybalholm/brotli"
http
"github.com/bogdanfinn/fhttp"
tls_client
"github.com/bogdanfinn/tls-client"
"github.com/bogdanfinn/tls-client/profiles"
"github.com/imroc/req/v3"
"github.com/sirupsen/logrus"
utls
"github.com/refraction-networking/utls"
"io/ioutil"
"math/big"
"net/http"
"net/url"
"strings"
)
type
Client
struct
{
Client
tls_client
.
Http
Client
Client
*
req
.
Client
Jar
tls_client
.
CookieJar
Item
ForwardItem
Response
*
http
.
Response
Response
*
req
.
Response
uri
*
url
.
URL
TlsVersion
string
}
func
(
c
*
Client
)
Start
()
error
{
var
req
*
http
.
Request
var
err
error
uri
,
err
:=
url
.
Parse
(
c
.
Item
.
Url
)
c
.
uri
=
uri
request
:=
c
.
Client
.
R
()
cookie
:=
c
.
Item
.
Headers
[
"cookie"
]
delete
(
c
.
Item
.
Headers
,
"cookie"
)
...
...
@@ -56,24 +57,25 @@ func (c *Client) Start() error {
Value
:
strings
.
ReplaceAll
(
strings
.
Join
(
t
[
1
:
],
"="
),
";"
,
""
),
})
}
c
.
Jar
.
SetCookies
(
uri
,
cookies
)
if
err
!=
nil
{
re
turn
err
request
.
SetCookies
(
cookies
...
)
for
k
,
v
:=
range
c
.
Item
.
Headers
{
re
quest
.
SetHeader
(
k
,
v
)
}
if
strings
.
ToUpper
(
c
.
Item
.
Method
)
==
"GET"
{
req
,
err
=
http
.
NewRequest
(
http
.
MethodGet
,
c
.
Item
.
Url
,
nil
)
var
resp
*
req
.
Response
var
err
error
if
strings
.
ToUpper
(
c
.
Item
.
Method
)
==
"POST"
{
request
.
SetBodyString
(
c
.
Item
.
Data
)
resp
,
err
=
request
.
Post
(
c
.
Item
.
Url
)
}
else
{
re
q
,
err
=
http
.
NewRequest
(
http
.
MethodPost
,
c
.
Item
.
Url
,
strings
.
NewReader
(
c
.
Item
.
Data
)
)
re
sp
,
err
=
request
.
Get
(
c
.
Item
.
Url
)
}
if
err
!=
nil
{
logrus
.
Error
(
"url初始化失败 "
,
err
.
Error
())
return
err
}
for
k
,
v
:=
range
c
.
Item
.
Headers
{
req
.
Header
.
Set
(
k
,
v
)
}
//c.Client.SetProxy("http://user-unifflcc-region-us:q39CEBTs5A5YQXor@pr.roxlabs.cn:4600")
resp
,
err
:=
c
.
Client
.
Do
(
req
)
if
err
!=
nil
{
logrus
.
Error
(
"请求失败 "
,
err
.
Error
())
return
err
...
...
@@ -92,7 +94,7 @@ func (c *Client) GetResponseHeaders() map[string]string {
func
(
c
*
Client
)
GetSessionCookies
()
map
[
string
]
string
{
res
:=
make
(
map
[
string
]
string
)
cks
:=
c
.
Jar
.
Cookies
(
c
.
uri
)
cks
:=
c
.
Client
.
Cookies
for
_
,
ck
:=
range
cks
{
res
[
ck
.
Name
]
=
ck
.
Value
}
...
...
@@ -100,19 +102,19 @@ func (c *Client) GetSessionCookies() map[string]string {
}
func
(
c
*
Client
)
GetText
()
string
{
defer
c
.
Response
.
Body
.
Close
()
//http.DecompressBody(c.Response)
//rb, _ := io.ReadAll(c.Response.Body)
content
,
_
:=
ioutil
.
ReadAll
(
c
.
Response
.
Body
)
encoding
:=
c
.
Response
.
Header
.
Get
(
"Content-Encoding"
)
DecompressBody
(
&
content
,
encoding
)
return
string
(
content
)
//
defer c.Response.Body.Close()
//
//
http.DecompressBody(c.Response)
//
//
rb, _ := io.ReadAll(c.Response.Body)
//
content, _ := ioutil.ReadAll(c.Response.Body)
//
encoding := c.Response.Header.Get("Content-Encoding")
//
DecompressBody(&content, encoding)
return
c
.
Response
.
String
(
)
}
func
(
c
*
Client
)
GetRespUrl
()
string
{
location
,
err
:=
c
.
Response
.
Location
()
if
err
!=
nil
{
return
c
.
uri
.
String
()
return
c
.
Response
.
Request
.
URL
.
String
()
}
return
location
.
RequestURI
()
...
...
@@ -138,33 +140,15 @@ func RandRandom(a int64) int64 {
return
res
.
Int64
()
}
func
NewClient
(
forWard
ForwardItem
,
ios
bool
)
(
Client
,
error
)
{
jar
:=
tls_client
.
NewCookieJar
()
tlsVersion
:=
chromes
[
RandRandom
(
int64
(
len
(
chromes
)))]
if
ios
{
tlsVersion
=
profiles
.
Safari_IOS_16_0
}
options
:=
[]
tls_client
.
HttpClientOption
{
tls_client
.
WithTimeoutSeconds
(
forWard
.
Timeout
),
tls_client
.
WithClientProfile
(
tlsVersion
),
tls_client
.
WithProxyUrl
(
forWard
.
Proxy
),
//tls_client.WithForceHttp1(),
tls_client
.
WithCookieJar
(
jar
),
tls_client
.
WithRandomTLSExtensionOrder
(),
//tls_client.WithProxyUrl("http://user:pass@host:port"),
tls_client
.
WithInsecureSkipVerify
(),
}
logger
:=
tls_client
.
NewNoopLogger
()
client
:=
req
.
C
()
.
SetUserAgent
(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
)
.
SetTLSFingerprintChrome
()
client
.
SetTLSFingerprint
(
utls
.
HelloChrome_115_PQ_PSK
)
if
forWard
.
Debug
{
logger
=
tls_client
.
NewDebugLogger
(
tls_client
.
NewDebugLogger
(
tls_client
.
NewLogger
()))
}
client
,
err
:=
tls_client
.
NewHttpClient
(
logger
,
options
...
)
client
.
SetFollowRedirect
(
forWard
.
AllowRedirects
)
if
err
!=
nil
{
return
Client
{},
err
client
=
client
.
EnableDumpAll
()
}
return
Client
{
Client
:
client
,
Item
:
forWard
,
Jar
:
jar
,
TlsVersion
:
tlsVersion
.
GetClientHelloStr
()
},
nil
return
Client
{
Client
:
client
,
Item
:
forWard
},
nil
}
// 解码Body数据
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment