forked from pagpeter/TrackMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
executable file
·157 lines (138 loc) · 3.92 KB
/
structs.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
149
150
151
152
153
154
155
156
157
package main
import (
"encoding/json"
"fmt"
"log"
)
type TLSDetails struct {
Ciphers []string `json:"ciphers"`
Extensions []interface{} `json:"extensions"`
RecordVersion string `json:"tls_version_record"`
NegotiatedVesion string `json:"tls_version_negotiated"`
JA3 string `json:"ja3"`
JA3Hash string `json:"ja3_hash"`
PeetPrint string `json:"peetprint (WIP)"`
PeetPrintHash string `json:"peetprint_hash (WIP)"`
ClientRandom string `json:"client_random"`
SessionID string `json:"session_id"`
}
type Http1Details struct {
Headers []string `json:"headers"`
}
type Http2Details struct {
AkamaiFingerprint string `json:"akamai_fingerprint"`
AkamaiFingerprintHash string `json:"akamai_fingerprint_hash"`
SendFrames []ParsedFrame `json:"sent_frames"`
}
type Response struct {
// Donate string `json:"donate"`
IP string `json:"ip"`
HTTPVersion string `json:"http_version"`
path string `json:"-"`
Method string `json:"method"`
UserAgent string `json:"user_agent,omitempty"`
TLS TLSDetails `json:"tls"`
Http1 *Http1Details `json:"http1,omitempty"`
Http2 *Http2Details `json:"http2,omitempty"`
}
func (res Response) ToJson() string {
j, err := json.MarshalIndent(res, "", " ")
if err != nil {
log.Println("Error marshalling response", err)
return ""
}
return string(j)
}
type SmallResponse struct {
JA3 string `json:"ja3"`
JA3Hash string `json:"ja3_hash"`
Akamai string `json:"akamai"`
AkamaiHash string `json:"akamai_hash"`
}
func (res SmallResponse) ToJson() string {
j, err := json.MarshalIndent(res, "", " ")
if err != nil {
log.Println("Error marshalling response", err)
return ""
}
return string(j)
}
type Priority struct {
Weight int `json:"weight"`
DependsOn int `json:"depends_on"`
Exclusive int `json:"exclusive"`
}
type GoAway struct {
LastStreamID uint32
ErrCode uint32
DebugData []byte
}
type ParsedFrame struct {
Type string `json:"frame_type,omitempty"`
Stream uint32 `json:"stream_id,omitempty"`
Length uint32 `json:"length,omitempty"`
Payload []byte `json:"payload,omitempty"`
Headers []string `json:"headers,omitempty"`
Settings []string `json:"settings,omitempty"`
Increment uint32 `json:"increment,omitempty"`
Flags []string `json:"flags,omitempty"`
Priority *Priority `json:"priority,omitempty"`
GoAway *GoAway `json:"goaway,omitempty"`
}
type Config struct {
LogToDB bool `json:"log_to_db"`
TLSPort string `json:"tls_port"`
HTTPPort string `json:"http_port"`
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
Host string `json:"host"`
MongoURL string `json:"mongoURL"`
Collection string `json:"mongo_collection"`
DB string `json:"mongo_database"`
LogIPs bool `json:"mongo_log_ips"`
}
func (c *Config) LoadFromFile() error {
data, err := ReadFile("config.json")
fmt.Println(string(data))
if err != nil {
fmt.Println("No config file found: generating one", err)
c.MakeDefault()
return c.WriteToFile("config.json")
}
var tmp Config
err = json.Unmarshal(data, &tmp)
if err != nil {
return err
}
c.LogToDB = tmp.LogToDB
c.Host = tmp.Host
c.TLSPort = tmp.TLSPort
c.HTTPPort = tmp.HTTPPort
c.CertFile = tmp.CertFile
c.KeyFile = tmp.KeyFile
c.MongoURL = tmp.MongoURL
c.Collection = tmp.Collection
c.DB = tmp.DB
c.LogIPs = tmp.LogIPs
return nil
}
func (c *Config) WriteToFile(file string) error {
j, err := json.MarshalIndent(c, "", " ")
if err != nil {
log.Println("Error marshalling config", err)
return err
}
return WriteToFile(file, j)
}
func (c *Config) MakeDefault() {
c.LogToDB = true
c.Host = ""
c.TLSPort = "443"
c.HTTPPort = "80"
c.CertFile = "certs/chain.pem"
c.KeyFile = "certs/key.pem"
c.MongoURL = ""
c.Collection = "requests"
c.DB = "TrackMe"
c.LogIPs = false
}