forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigration.go
197 lines (168 loc) · 5.83 KB
/
migration.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package config
import (
"crypto/sha256"
"encoding/hex"
"regexp"
"strings"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/logging"
)
func deprecated(config_obj *config_proto.Config, name string) {
logging.Prelog("Config contains deprecated field %v", name)
}
// Migrate from pre 0.4.2 config files.
func migrate_0_4_2(config_obj *config_proto.Config) {
if config_obj.Frontend != nil && config_obj.AutocertDomain != "" {
deprecated(config_obj, "autocert_domain")
config_obj.Frontend.Hostname = config_obj.AutocertDomain
config_obj.AutocertDomain = ""
}
if config_obj.ServerType != "" {
config_obj.ServerType = "linux"
}
if config_obj.Client != nil {
local_buffer := config_obj.Client.LocalBuffer
if local_buffer != nil && local_buffer.Filename != "" {
deprecated(config_obj, "Client.local_buffer.filename")
local_buffer.Filename = ""
}
}
if config_obj.Frontend != nil &&
config_obj.Frontend.Certificate != "" {
if config_obj.Frontend.PublicPath != "" {
deprecated(config_obj, "Frontend.public_path")
config_obj.Frontend.PublicPath = ""
}
if config_obj.Frontend.DynDns != nil {
if config_obj.Frontend.DynDns.Hostname != "" {
deprecated(config_obj, "config_obj.Frontend.dyn_dns.hostname")
config_obj.Frontend.Hostname = config_obj.Frontend.DynDns.Hostname
config_obj.Frontend.DynDns.Hostname = ""
}
}
if config_obj.Frontend.Hostname == "" {
logging.Prelog("Invalid config: New field Frontend.hostname is missing!")
if config_obj.Client != nil {
for _, url := range config_obj.Client.ServerUrls {
re := regexp.MustCompile(`https://([^:/]+)`)
matches := re.FindStringSubmatch(url)
if len(matches) > 1 {
config_obj.Frontend.Hostname = matches[1]
}
}
}
if config_obj.Frontend.Hostname == "" {
panic("Unable to deduce the Frontend.hostname")
}
logging.Prelog("Guessing Frontend.hostname from Client.server_urls: %v",
config_obj.Frontend.Hostname)
}
if config_obj.ObfuscationNonce == "" {
sha_sum := sha256.New()
_, _ = sha_sum.Write([]byte(config_obj.Frontend.PrivateKey))
config_obj.ObfuscationNonce = hex.EncodeToString(sha_sum.Sum(nil))
}
}
}
func migrate_0_4_6(config_obj *config_proto.Config) {
// We need to migrate old authentication information into an
// authenticator protobuf.
if config_obj.GUI != nil &&
config_obj.GUI.Authenticator == nil {
gui := config_obj.GUI
auther := &config_proto.Authenticator{Type: "Basic"}
if config_obj.GUI.GoogleOauthClientId != "" {
auther.Type = "Google"
auther.OauthClientId = gui.GoogleOauthClientId
auther.OauthClientSecret = gui.GoogleOauthClientSecret
// Clear the old values
gui.GoogleOauthClientId = ""
gui.GoogleOauthClientSecret = ""
} else if config_obj.GUI.SamlCertificate != "" {
auther.Type = "SAML"
auther.SamlCertificate = gui.SamlCertificate
auther.SamlPrivateKey = gui.SamlPrivateKey
auther.SamlIdpMetadataUrl = gui.SamlIdpMetadataUrl
auther.SamlRootUrl = gui.SamlRootUrl
auther.SamlUserAttribute = gui.SamlUserAttribute
// Clear the old values
gui.SamlCertificate = ""
gui.SamlPrivateKey = ""
gui.SamlIdpMetadataUrl = ""
gui.SamlRootUrl = ""
gui.SamlUserAttribute = ""
}
config_obj.GUI.Authenticator = auther
}
if config_obj.Datastore != nil {
if config_obj.Datastore.Implementation == "FileBaseDataStore" &&
config_obj.Datastore.Location == "" {
config_obj.Datastore.Location = config_obj.Datastore.FilestoreDirectory
}
}
}
func migrate_0_5_6(config_obj *config_proto.Config) {
if config_obj.Logging != nil {
default_rotator := &config_proto.LoggingRetentionConfig{
RotationTime: config_obj.Logging.RotationTime,
MaxAge: config_obj.Logging.MaxAge,
}
if config_obj.Logging.Debug == nil {
config_obj.Logging.Debug = default_rotator
}
if config_obj.Logging.Info == nil {
config_obj.Logging.Debug = default_rotator
}
if config_obj.Logging.Error == nil {
config_obj.Logging.Debug = default_rotator
}
}
if config_obj.Frontend != nil {
if config_obj.Frontend.Resources == nil {
config_obj.Frontend.Resources = &config_proto.FrontendResourceControl{
Concurrency: config_obj.Frontend.Concurrency,
MaxUploadSize: config_obj.Frontend.MaxUploadSize,
ExpectedClients: config_obj.Frontend.ExpectedClients,
PerClientUploadRate: config_obj.Frontend.PerClientUploadRate,
GlobalUploadRate: config_obj.Frontend.GlobalUploadRate,
ClientEventMaxWait: config_obj.Frontend.ClientEventMaxWait,
}
config_obj.Frontend.Concurrency = 0
config_obj.Frontend.MaxUploadSize = 0
config_obj.Frontend.ExpectedClients = 0
config_obj.Frontend.PerClientUploadRate = 0
config_obj.Frontend.GlobalUploadRate = 0
config_obj.Frontend.ClientEventMaxWait = 0
}
// Update all the extra frontends to use the same resources.
for _, fe := range config_obj.ExtraFrontends {
fe.Resources = config_obj.Frontend.Resources
}
}
}
func migrate_0_6_1(config_obj *config_proto.Config) {
// We require the datastore location to have no trailing path
// separators.
if config_obj.Datastore != nil {
config_obj.Datastore.Location = strings.TrimSuffix(
config_obj.Datastore.Location, "\\")
config_obj.Datastore.Location = strings.TrimSuffix(
config_obj.Datastore.Location, "/")
config_obj.Datastore.FilestoreDirectory = strings.TrimSuffix(
config_obj.Datastore.FilestoreDirectory, "\\")
config_obj.Datastore.FilestoreDirectory = strings.TrimSuffix(
config_obj.Datastore.FilestoreDirectory, "/")
}
if config_obj.Defaults == nil {
config_obj.Defaults = &config_proto.Defaults{
HuntExpiryHours: 24 * 7,
NotebookCellTimeoutMin: 10,
}
}
}
func migrate(config_obj *config_proto.Config) {
migrate_0_4_2(config_obj)
migrate_0_4_6(config_obj)
migrate_0_5_6(config_obj)
migrate_0_6_1(config_obj)
}