-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.go
148 lines (125 loc) · 3.58 KB
/
routes.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
http "github.com/Noooste/fhttp"
"strconv"
"time"
)
func redirect(path string, res http.ResponseWriter, req *http.Request) {
res.Header().Add("Location", path)
res.WriteHeader(302)
_, _ = res.Write([]byte("302 Moved Temporarily"))
}
func sendUnknown(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(404)
res.Write([]byte("Page not found !"))
}
func showTLS(res http.ResponseWriter, req *http.Request) {
var response = Information{
Type: req.Proto,
Method: req.Method,
Path: req.URL.Path,
}
if req.TLS != nil {
clientHello := req.TLSConn.ClientHello
eString, eValue := getExtensionsString(clientHello.Raw)
response.TLS = &TLSInformation{
Ciphers: getCiphersString(clientHello.CipherSuites),
Extensions: eString,
Schemes: getAlgoString(clientHello.SupportedSignatureAlgorithms),
ALPN: clientHello.AlpnProtocols,
Versions: getVersionsValues(clientHello.SupportedVersions),
Curves: getCurvesValues(clientHello.SupportedCurves),
Points: getPointsValues(clientHello.SupportedPoints),
}
response.TLS.JA3 = getJA3(req.TLS.Version, clientHello.CipherSuites, eValue, clientHello.SupportedCurves, clientHello.SupportedPoints)
hash := md5.Sum([]byte(response.TLS.JA3))
response.TLS.JA3Hash = hex.EncodeToString(hash[:])
response.Ip = req.TLSConn.RemoteAddr().String()
} else {
response.Ip = req.RemoteAddr
}
switch req.Proto {
case "HTTP/2.0":
frames, af := parseHTTP2Frames(req)
hash := md5.Sum([]byte(af))
afh := hex.EncodeToString(hash[:])
response.HTTP = &HTTP2Information{
Frames: frames,
AF: af,
AFH: afh,
}
default:
response.HTTP = &HTTP1Information{
Header: getHTTP1Headers(req),
}
}
h := res.Header()
h.Add("content-type", "application/json")
h.Add("Access-Control-Allow-Origin", "*")
h.Add("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
if result, err := json.MarshalIndent(response, "", " "); err == nil {
res.Write(result)
} else {
res.Write([]byte("error"))
}
}
func redirectNTimes(res http.ResponseWriter, req *http.Request) {
var r = numberReg.FindStringSubmatch(req.URL.Path)
if len(r) == 2 {
value, _ := strconv.Atoi(r[1])
if value > 1 {
redirect("/redirect/"+strconv.Itoa(value-1), res, req)
} else if value == 1 {
redirect("/get", res, req)
} else {
sendUnknown(res, req)
}
} else {
sendUnknown(res, req)
}
}
func delayResponse(res http.ResponseWriter, req *http.Request) {
var r = numberReg.FindStringSubmatch(req.URL.Path)
if len(r) == 2 {
value, _ := strconv.Atoi(r[1])
time.Sleep(time.Duration(value) * time.Second)
showTLS(res, req)
} else {
sendUnknown(res, req)
}
}
func wrongValue(valueName, in string, res http.ResponseWriter, req *http.Request) {
res.Write([]byte("wrong value in " + in + " : " + valueName))
res.WriteHeader(400)
}
func getCookie(res http.ResponseWriter, req *http.Request) {
query := req.URL.Query()
cookie := &http.Cookie{}
if v := query.Get("name"); v != "" {
cookie.Name = v
} else {
cookie.Name = "test-cookie"
}
if v := query.Get("value"); v != "" {
cookie.Value = v
} else {
cookie.Value = "aaaa"
}
if v := query.Get("max-age"); v != "" {
var l, err = strconv.Atoi(v)
if err != nil {
wrongValue("max-age", "query", res, req)
return
}
cookie.MaxAge = l
}
cookie.Path = query.Get("path")
cookie.Secure = query.Get("secure") == "true"
cookie.Domain = query.Get("domain")
cookie.HttpOnly = query.Get("http-only") == "true"
cookie.Origin = query.Get("origin")
res.Header().Set("set-cookie", (cookie).String())
}