-
Notifications
You must be signed in to change notification settings - Fork 18
/
response.go
77 lines (62 loc) · 1.74 KB
/
response.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
package main
import (
"log"
"github.com/dreadl0ck/tlsx"
"github.com/wi1dcard/fingerproxy/pkg/ja3"
"github.com/wi1dcard/fingerproxy/pkg/ja4"
"github.com/wi1dcard/fingerproxy/pkg/metadata"
)
// echoResponse is the HTTP response struct of this echo server
type echoResponse struct {
Detail *detailResponse `json:"detail,omitempty"`
JA3 string `json:"ja3"`
JA4 string `json:"ja4"`
HTTP2 string `json:"http2"`
log *log.Logger
}
type detailResponse struct {
Metadata *metadata.Metadata `json:"metadata"`
UserAgent string `json:"user_agent"`
JA3 *ja3Detail `json:"ja3"`
JA3Raw string `json:"ja3_raw"`
JA4 *ja4Detail `json:"ja4"`
}
func (r *echoResponse) fingerprintJA3() error {
fp := &tlsx.ClientHelloBasic{}
rd := r.Detail
err := fp.Unmarshal(rd.Metadata.ClientHelloRecord)
if err != nil {
return err
}
ja3Raw := ja3.Bare(fp)
rd.JA3 = (*ja3Detail)(fp)
rd.JA3Raw = string(ja3Raw)
r.JA3 = ja3.BareToDigestHex(ja3Raw)
r.logf("ja3: %s", r.JA3)
return nil
}
func (r *echoResponse) fingerprintJA4() error {
fp := &ja4.JA4Fingerprint{}
err := fp.UnmarshalBytes(r.Detail.Metadata.ClientHelloRecord, 't')
if err != nil {
return err
}
r.Detail.JA4 = (*ja4Detail)(fp)
r.JA4 = fp.String()
r.logf("ja4: %s", r.JA4)
return nil
}
func (r *echoResponse) fingerrpintHTTP2() {
protocol := r.Detail.Metadata.ConnectionState.NegotiatedProtocol
if protocol == "h2" {
r.HTTP2 = r.Detail.Metadata.HTTP2Frames.String()
r.logf("http2: %s", r.HTTP2)
} else if *flagVerbose {
r.logf("protocol is %s, skipping HTTP2 fingerprinting", protocol)
}
}
func (r *echoResponse) logf(format string, args ...any) {
if !*flagQuiet {
r.log.Printf(format, args...)
}
}