forked from Skyuzii/SpoofingTlsFingerprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
124 lines (108 loc) · 3.24 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"Golang/Request"
"Golang/Response"
"compress/gzip"
"encoding/json"
"fmt"
"github.com/Skyuzii/CycleTLS/cycletls"
"github.com/gorilla/mux"
"io/ioutil"
"log"
"net/http"
"net/http/cookiejar"
url2 "net/url"
"os"
"strings"
)
func main() {
port := "8000"
if len(os.Args) > 1 {
port = os.Args[1]
}
err := os.Setenv("tls13", "1")
if err != nil {
log.Println(err.Error())
}
router := mux.NewRouter()
router.HandleFunc("/check-status", CheckStatus).Methods("GET")
router.HandleFunc("/handle", Handle).Methods("POST")
fmt.Println("The proxy server is running")
log.Fatal(http.ListenAndServe(":"+port, router))
}
func CheckStatus(responseWriter http.ResponseWriter, request *http.Request) {
responseWriter.Header().Set("Content-Type", "application/json")
json.NewEncoder(responseWriter).Encode("good")
}
func Handle(responseWriter http.ResponseWriter, request *http.Request) {
responseWriter.Header().Set("Content-Type", "application/json")
var handleRequest Request.HandleRequest
json.NewDecoder(request.Body).Decode(&handleRequest)
client := cycletls.Init()
var cookies []*http.Cookie
for _, cookie := range handleRequest.Cookies {
cookies = append(cookies, &http.Cookie{
Name: cookie.Name,
Value: cookie.Value,
Path: cookie.Path,
Domain: cookie.Domain,
Expires: cookie.Expires,
MaxAge: cookie.MaxAge,
Secure: cookie.Secure,
HttpOnly: cookie.HTTPOnly,
})
}
cookiesJar, _ := cookiejar.New(nil)
requestUrl, _ := url2.Parse(handleRequest.Url)
cookiesJar.SetCookies(requestUrl, cookies)
resp, err := client.Do(handleRequest.Url, cycletls.Options{
CookiesJar: cookiesJar,
InsecureSkipVerify: handleRequest.InsecureSkipVerify,
Body: handleRequest.Body,
Proxy: handleRequest.Proxy,
Timeout: handleRequest.Timeout,
Headers: handleRequest.Headers,
Ja3: handleRequest.Ja3,
UserAgent: handleRequest.UserAgent,
DisableRedirect: handleRequest.DisableRedirect,
}, handleRequest.Method)
var handleResponse Response.HandleResponse
if err != nil {
fmt.Println(err)
handleResponse.Success = false
handleResponse.Error = err.Error()
json.NewEncoder(responseWriter).Encode(handleResponse)
return
}
handleResponse.Success = true
handleResponse.Payload = &Response.HandleResponsePayload{
Text: DecodeResponse(&resp),
Headers: resp.Response.Headers,
Status: resp.Response.Status,
Url: resp.Response.Url,
}
for _, cookie := range cookiesJar.Cookies(requestUrl) {
handleResponse.Payload.Cookies = append(handleResponse.Payload.Cookies, &cycletls.Cookie{
Name: cookie.Name,
Value: cookie.Value,
Path: cookie.Path,
Domain: cookie.Domain,
Expires: cookie.Expires,
MaxAge: cookie.MaxAge,
Secure: cookie.Secure,
HTTPOnly: cookie.HttpOnly,
})
}
json.NewEncoder(responseWriter).Encode(handleResponse)
}
func DecodeResponse(response *cycletls.Response) string {
switch response.Response.Headers["Content-Encoding"] {
case "gzip":
reader, _ := gzip.NewReader(strings.NewReader(response.Response.Body))
defer reader.Close()
readerResponse, _ := ioutil.ReadAll(reader)
return string(readerResponse)
default:
return response.Response.Body
}
}