-
Notifications
You must be signed in to change notification settings - Fork 17
/
consts.go
336 lines (305 loc) · 6.5 KB
/
consts.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*************************************************************************
* Copyright 2018 Gravwell, Inc. All rights reserved.
* Contact: <legal@gravwell.io>
*
* This software may be modified and distributed under the terms of the
* BSD 2-clause license. See the LICENSE file for details.
**************************************************************************/
package main
import (
"log"
"math"
"math/rand"
"net"
"strings"
rd "github.com/Pallinder/go-randomdata"
"github.com/gravwell/gravwell/v3/generators/ipgen"
)
const (
maxGroups int = 64
maxUsers int = 1024 * 1024
hcount int = 32
appcount int = 2048
tsFormat string = `2006-01-02T15:04:05.999999Z07:00`
)
// this is all Zeek stuff:
var (
protos = []string{"icmp", "tcp", "udp"}
alphabet = []byte("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
services = map[string][]string{
"icmp": []string{"-"},
"tcp": []string{"-", "http", "ssl", "ssh"},
"udp": []string{"-", "dns", "dhcp", "krb", "dtls"},
}
states = []string{
"OTH",
"SF",
"S0",
"SH",
"SHR",
"RSTR",
"S1",
"RSTO",
"RSTRH",
"S3",
}
histories = []string{
"Dc",
"ShADadFf",
"-",
"Dd",
"C",
"D",
"HcADF",
"ShADadfF",
"CC",
"S",
"ShADadFRfR",
"DadA",
"^dDa",
"ShADad",
"ShADadfFr",
"ShADadR",
"HcAD",
"ShADadFfR",
"Cd",
"^d",
"ShADdaFf",
"DFdfR",
"ShR",
"^dADa",
"Sh",
"ShADadfR",
"^dDaA",
"ShADadtFf",
"ShADadf",
"ShADadfFR",
"ShAFf",
"ShADadFfrrr",
"DFafA",
"ShADadtfFrr",
"ShADadFRf",
"ShADadr",
"^dfADFr",
"ShADdaFfR",
"DFdfrR",
"ShADdFaf",
"ShADadtFfR",
"ShADadfr",
"ShADadttttFf",
"ShADadFfrr",
"ShADadtttFf",
"ShADaFdRfR",
"ShADadFfT",
"ShADadFfRRR",
"ShADFadRfR",
"ShADadtfRrr",
"ShADadtfF",
"ShADFadfR",
"DFr",
"DadAt",
"DFdrrR",
"DadAf",
"^dfA",
"ShADFadRf",
"Fr",
"ShADadtR",
"ShADadFfRR",
"ShADdfFa",
"ShADadtfFR",
"ShADadftR",
"DFdrR",
"DFadfR",
"ShADadttf",
"SW",
"ShADadTtfFrr",
"^r",
"ShADadFTfR",
}
)
var (
groups []string
users []Account
complexGroups []ComplexGroup
hosts []string
apps []string
v4gen *ipgen.V4Gen
v6gen *ipgen.V6Gen
serverIPs []net.IP
serverIP6s []net.IP
)
func init() {
var err error
v4gen, err = ipgen.RandomWeightedV4Generator(40)
if err != nil {
log.Fatalf("Failed to instantiate v4 generator: %v", err)
}
v6gen, err = ipgen.RandomWeightedV6Generator(30)
if err != nil {
log.Fatalf("Failed to instantiate v6 generator: %v\n", err)
}
for i := 0; i < 4; i++ {
serverIPs = append(serverIPs, v4gen.IP())
}
for i := 0; i < 4; i++ {
serverIP6s = append(serverIP6s, v6gen.IP())
}
for i := 0; i < hcount; i++ {
hosts = append(hosts, rd.Noun())
}
for i := 0; i < appcount; i++ {
apps = append(apps, rd.Adjective())
}
}
type Account struct {
User string `json:"user" xml:"user,attr"`
Name string `json:"name" xml:"name,attr"`
Email string `json:"email" xml:"email,attr"`
Phone string `json:"phone" xml:"phone,attr"`
Address string `json:"address"`
State string `json:"state"`
Country string `json:"country"`
}
type ComplexGroup struct {
ID int `json:"gid" xml:"gid,attr"`
Name string `json:"name" xml:"name,attr"`
Division string `json:"division" xml:"division,attr"`
Attributes []string `json:"attributes,omitempty" xml:"attributes,attr"`
Locations []ComplexLocation `json:"location" xml:"location,attr"`
}
type ComplexLocation struct {
Lat float64 `json:"lat" xml:"lat,attr"`
Long float64 `json:"long" xml:"long,attr"`
Country string `json:"country" xml:"country,attr"`
State string `json:"state" xml:"state,attr"`
}
func seedUsers(usercount, gcount int) {
if usercount > maxUsers {
usercount = maxUsers
}
if gcount > maxGroups {
gcount = maxGroups
}
for i := 0; i < gcount; i++ {
name := rd.Noun()
groups = append(groups, name)
complexGroups = append(complexGroups, ComplexGroup{
ID: i,
Name: name,
Division: rd.FirstName(rd.RandomGender),
Attributes: randAttributes(4),
Locations: randLocations(2),
})
}
for i := 0; i < usercount; i++ {
email := rd.Email()
user := strings.Split(email, "@")[0]
a := Account{
User: user,
Name: rd.FullName(i & 1),
Email: email,
Phone: rd.PhoneNumber(),
Address: rd.Address(),
State: rd.State(rd.Small),
Country: rd.Country(rd.FullCountry),
}
users = append(users, a)
}
}
func getUser() Account {
return users[rand.Intn(len(users))]
}
func getGroup() string {
return groups[rand.Intn(len(groups))]
}
func getComplexGroup() ComplexGroup {
return complexGroups[rand.Intn(len(complexGroups))]
}
func getGroups() (r []string) {
if cnt := rand.Intn(3); cnt > 0 {
r = make([]string, cnt)
for i := range r {
r[i] = getGroup()
}
}
return
}
func getComplexGroups() (r []ComplexGroup) {
if cnt := rand.Intn(3); cnt > 0 {
r = make([]ComplexGroup, cnt)
for i := range r {
r[i] = getComplexGroup()
}
}
return
}
func getHost() string {
return hosts[rand.Intn(len(hosts))]
}
func getApp() string {
return apps[rand.Intn(len(apps))]
}
func ips() (string, string) {
if (rand.Int() & 3) == 0 {
//more IPv4 than 6
return v6gen.IP().String(), v6gen.IP().String()
}
return v4gen.IP().String(), v4gen.IP().String()
}
func ports() (int, int) {
var orig_port, resp_port int
if rand.Int()%2 == 0 {
orig_port = 1 + rand.Intn(2048)
resp_port = 2048 + rand.Intn(0xffff-2048)
} else {
orig_port = 2048 + rand.Intn(0xffff-2048)
resp_port = 1 + rand.Intn(2048)
}
return orig_port, resp_port
}
func randomBase62(l int) string {
r := make([]byte, l)
for i := 0; i < l; i++ {
r[i] = alphabet[rand.Intn(len(alphabet))]
}
return string(r)
}
func randAttributes(max int) (r []string) {
n := rand.Intn(max) + 1
p := strings.Fields(rd.Paragraph())
if len(p) < n {
r = p
} else {
r = p[0:n]
}
return
}
func randLocations(max int) (r []ComplexLocation) {
n := rand.Intn(max) + 1
r = make([]ComplexLocation, 0, n)
for i := 0; i < n; i++ {
r = append(r, ComplexLocation{
Country: rd.Country(rd.FullCountry),
State: rd.Locale(),
Lat: randLatLong(),
Long: randLatLong(),
})
}
return
}
func randLatLong() float64 {
v := rand.Float64()
negative := v < 0
if negative {
v = v * -1
}
v = math.Mod(v, 180.0)
if negative {
v = v * -1
}
return roundFloat(v, 4)
}
func roundFloat(val float64, precision uint) float64 {
ratio := math.Pow(10, float64(precision))
return float64(math.Round(val*ratio) / ratio)
}