forked from pagpeter/TrackMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
144 lines (131 loc) · 4.2 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
package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
"strings"
)
func staticFile(file string) func(Response, url.Values) ([]byte, string) {
return func(Response, url.Values) ([]byte, string) {
b, _ := ReadFile(file)
return b, "text/html"
}
}
func apiAll(res Response, _ url.Values) ([]byte, string) {
return []byte(res.ToJson()), "application/json"
}
func apiTLS(res Response, _ url.Values) ([]byte, string) {
return []byte(Response{
TLS: res.TLS,
}.ToJson()), "application/json"
}
func apiClean(res Response, _ url.Values) ([]byte, string) {
akamai := "-"
hash := "-"
if res.HTTPVersion == "h2" {
akamai = res.Http2.AkamaiFingerprint
hash = GetMD5Hash(res.Http2.AkamaiFingerprint)
}
return []byte(SmallResponse{
JA3: res.TLS.JA3,
JA3Hash: res.TLS.JA3Hash,
Akamai: akamai,
AkamaiHash: hash,
PeetPrint: res.TLS.PeetPrint,
PeetPrintHash: res.TLS.PeetPrintHash,
}.ToJson()), "application/json"
}
func apiRequestCount(_ Response, _ url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
return []byte(fmt.Sprintf(`{"total_requests": %v}`, GetTotalRequestCount())), "application/json"
}
func apiSearchJA3(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByJa3(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func apiSearchH2(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByH2(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func apiSearchPeetPrint(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByPeetPrint(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func apiSearchUserAgent(_ Response, u url.Values) ([]byte, string) {
if !connectedToDB {
return []byte("{\"error\": \"Not connected to database.\"}"), "application/json"
}
by := getParam("by", u)
if by == "" {
return []byte("{\"error\": \"No 'by' param present\"}"), "application/json"
}
res := GetByUserAgent(by)
j, _ := json.MarshalIndent(res, "", "\t")
return j, "application/json"
}
func index(r Response, v url.Values) ([]byte, string) {
res, ct := staticFile("static/index.html")(r, v)
data, _ := json.Marshal(r)
return []byte(strings.ReplaceAll(string(res), "/*DATA*/", string(data))), ct
}
// write all to log/db and return an empty pixel
func apiEmptyGif(res Response, _ url.Values) ([]byte, string) {
// Define the byte slice for a 1x1 transparent GIF
var emptyGif = []byte{
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00,
0x01, 0x00, 0x80, 0xff, 0x00, 0xc0, 0xc0, 0xc0,
0x00, 0xff, 0xff, 0xff, 0x21, 0xf9, 0x04, 0x01,
0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02,
0x44, 0x01, 0x00, 0x3b,
}
data, err := json.Marshal(res)
if err != nil {
log.Fatalf("Error occurred during marshaling. Error: %s", err.Error())
} else {
Log(string(data))
}
return emptyGif, "image/gif"
}
func getAllPaths() map[string]func(Response, url.Values) ([]byte, string) {
return map[string]func(Response, url.Values) ([]byte, string){
"/": index,
"/explore": staticFile("static/explore.html"),
"/api/all": apiAll,
"/api/tls": apiTLS,
"/api/clean": apiClean,
"/api/request-count": apiRequestCount,
"/api/search-ja3": apiSearchJA3,
"/api/search-h2": apiSearchH2,
"/api/search-peetprint": apiSearchPeetPrint,
"/api/search-useragent": apiSearchUserAgent,
"/pixel.gif": apiEmptyGif,
}
}