-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
subject.go
402 lines (381 loc) · 8.58 KB
/
subject.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
package certs
/*
Sliver Implant Framework
Copyright (C) 2021 Bishop Fox
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import (
"crypto/x509/pkix"
"fmt"
insecureRand "math/rand"
"strings"
"github.com/bishopfox/sliver/server/codenames"
)
var (
// Finally found a good use for Github Co-Pilot!
// Country -> State -> Localities -> Street Addresses
subjects = map[string]map[string]map[string][]string{
"US": {
"": {
"": {
"",
},
},
"Arizona": {
"Phoenix": {""},
"Mesa": {""},
"Scottsdale": {""},
"Chandler": {""},
},
"California": {
"San Francisco": {"", "", "Golden Gate"},
"Oakland": {""},
"Berkeley": {""},
"Palo Alto": {""},
"Los Angeles": {""},
"San Diego": {""},
"San Jose": {""},
"Sunnyvale": {""},
"Santa Clara": {""},
"Mountain View": {""},
"San Mateo": {""},
"Redwood City": {""},
"Menlo Park": {""},
"San Bruno": {""},
"San Carlos": {""},
"San Leandro": {""},
"San Rafael": {""},
"San Ramon": {""},
"Santa Monica": {""},
"Santa Rosa": {""},
"South San Francisco": {
"",
},
},
"Colorado": {
"Denver": {""},
"Boulder": {""},
"Aurora": {""},
"Fort Collins": {""},
},
"Connecticut": {
"New Haven": {""},
"Bridgeport": {""},
"Stamford": {""},
"Norwalk": {""},
},
"Washington": {
"Seattle": {""},
"Tacoma": {""},
"Olympia": {""},
"Spokane": {""},
},
"Florida": {
"Miami": {""},
"Orlando": {""},
"Tampa": {""},
"Jacksonville": {""},
},
"Illinois": {
"Chicago": {""},
"Aurora": {""},
"Naperville": {""},
"Peoria": {""},
},
"Indiana": {
"Indianapolis": {""},
"Fort Wayne": {""},
"Evansville": {""},
"South Bend": {""},
},
"Massachusetts": {
"Boston": {""},
"Worcester": {
"",
"Polytechnic Institute",
},
"Springfield": {""},
"Lowell": {""},
},
"Michigan": {
"Detroit": {""},
"Grand Rapids": {
"",
"State University",
},
"Warren": {""},
"Sterling Heights": {
"",
"Community College",
},
},
"Minnesota": {
"Minneapolis": {""},
"Saint Paul": {""},
"Bloomington": {""},
"Plymouth": {""},
},
"New Jersey": {
"Newark": {""},
"Jersey City": {
"",
"Institute of Technology",
},
"Paterson": {""},
"Elizabeth": {
"",
"Princeton",
},
},
"New York": {
"New York": {""},
"Buffalo": {""},
"Rochester": {
"",
"University",
},
"Yonkers": {""},
},
"North Carolina": {
"Charlotte": {""},
"Raleigh": {""},
"Greensboro": {
"",
"University",
},
"Winston-Salem": {""},
},
"Ohio": {
"Columbus": {""},
"Cleveland": {
"",
"State University",
},
"Cincinnati": {""},
"Toledo": {""},
},
},
"CA": {
"": {
"": {
"",
},
},
"Alberta": {
"Calgary": {""},
"Edmonton": {
"",
"University",
},
"Red Deer": {""},
"Fort McMurray": {
"",
"University",
},
},
"British Columbia": {
"Vancouver": {""},
"Victoria": {""},
"Kelowna": {""},
"Richmond": {""},
},
"Manitoba": {
"Winnipeg": {""},
"Brandon": {""},
"Thompson": {""},
"Portage la Prairie": {
"",
"University",
},
},
"New Brunswick": {
"Fredericton": {""},
"Moncton": {""},
"Saint John": {""},
"Dieppe": {""},
},
"Newfoundland and Labrador": {
"St. John's": {""},
"Mount Pearl": {
"",
"College",
},
"Conception Bay South": {""},
"Paradise": {
"",
"College",
},
},
},
"JP": {
"": {
"": {
"",
},
},
"Aichi": {
"Nagoya": {""},
"Kasugai": {
"",
"University",
},
"Okazaki": {""},
"Handa": {""},
},
"Chiba": {
"Chiba": {""},
"Kashiwa": {
"",
"University",
},
"Funabashi": {""},
"Kimitsu": {""},
},
},
}
)
func randomSubject(commonName string) *pkix.Name {
country, province, locale, street := randomProvinceLocalityStreetAddress()
return &pkix.Name{
Organization: randomOrganization(),
Country: country,
Province: province,
Locality: locale,
StreetAddress: street,
PostalCode: randomPostalCode(country),
CommonName: commonName,
}
}
func randomPostalCode(country []string) []string {
// 1 in `n` will include a postal code
// From my cursory view of a few TLS certs it seems uncommon to include this
// in the distinguished name so right now it's set to 1/5
const postalProbability = 5
if len(country) == 0 {
return []string{}
}
switch country[0] {
case "US":
// American postal codes are 5 digits
switch insecureRand.Intn(postalProbability) {
case 0:
return []string{fmt.Sprintf("%05d", insecureRand.Intn(90000)+1000)}
default:
return []string{}
}
case "CA":
// Canadian postal codes are weird and include letter/number combo's
letters := "ABHLMNKGJPRSTVYX"
switch insecureRand.Intn(postalProbability) {
case 0:
letter1 := string(letters[insecureRand.Intn(len(letters))])
letter2 := string(letters[insecureRand.Intn(len(letters))])
if insecureRand.Intn(2) == 0 {
letter1 = strings.ToLower(letter1)
letter2 = strings.ToLower(letter2)
}
return []string{
fmt.Sprintf("%s%d%s", letter1, insecureRand.Intn(9), letter2),
}
default:
return []string{}
}
}
return []string{}
}
func randomProvinceLocalityStreetAddress() ([]string, []string, []string, []string) {
country := randomCountry()
state := randomState(country)
locality := randomLocality(country, state)
streetAddress := randomStreetAddress(country, state, locality)
return []string{country}, []string{state}, []string{locality}, []string{streetAddress}
}
func randomCountry() string {
keys := make([]string, 0, len(subjects))
for k := range subjects {
keys = append(keys, k)
}
return keys[insecureRand.Intn(len(keys))]
}
func randomState(country string) string {
keys := make([]string, 0, len(subjects[country]))
for k := range subjects[country] {
keys = append(keys, k)
}
return keys[insecureRand.Intn(len(keys))]
}
func randomLocality(country string, state string) string {
locales := subjects[country][state]
keys := make([]string, 0, len(locales))
for k := range locales {
keys = append(keys, k)
}
return keys[insecureRand.Intn(len(keys))]
}
func randomStreetAddress(country string, state string, locality string) string {
addresses := subjects[country][state][locality]
return addresses[insecureRand.Intn(len(addresses))]
}
var (
orgSuffixes = []string{
"",
"",
"co",
"llc",
"inc",
"corp",
"ltd",
"plc",
"inc.",
"corp.",
"ltd.",
"plc.",
"co.",
"llc.",
"incorporated",
"limited",
"corporation",
"company",
"incorporated",
"limited",
"corporation",
"company",
}
)
func randomOrganization() []string {
adjective, _ := codenames.RandomAdjective()
noun, _ := codenames.RandomNoun()
suffix := orgSuffixes[insecureRand.Intn(len(orgSuffixes))]
var orgName string
switch insecureRand.Intn(8) {
case 0:
orgName = strings.TrimSpace(fmt.Sprintf("%s %s, %s", adjective, noun, suffix))
case 1:
orgName = strings.TrimSpace(strings.ToLower(fmt.Sprintf("%s %s, %s", adjective, noun, suffix)))
case 2:
orgName = strings.TrimSpace(fmt.Sprintf("%s, %s", noun, suffix))
case 3:
orgName = strings.TrimSpace(strings.Title(fmt.Sprintf("%s %s, %s", adjective, noun, suffix)))
case 4:
orgName = strings.TrimSpace(strings.Title(fmt.Sprintf("%s %s", adjective, noun)))
case 5:
orgName = strings.TrimSpace(strings.ToLower(fmt.Sprintf("%s %s", adjective, noun)))
case 6:
orgName = strings.TrimSpace(strings.Title(fmt.Sprintf("%s", noun)))
case 7:
noun2, _ := codenames.RandomNoun()
orgName = strings.TrimSpace(strings.ToLower(fmt.Sprintf("%s-%s", noun, noun2)))
default:
orgName = ""
}
return []string{orgName}
}