forked from P3GLEG/Whaler
-
Notifications
You must be signed in to change notification settings - Fork 3
/
scanner.go
772 lines (765 loc) · 20.3 KB
/
scanner.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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
package main
import (
"regexp"
"encoding/json"
"io"
"github.com/fatih/color"
)
var patterns []Pattern
type Pattern struct {
Description string
SecretType string
Value string
Regex *regexp.Regexp
}
func compileSecretPatterns(){
var temp []Pattern
if err := json.Unmarshal(patternsJson, &temp); err != nil {
panic(err)
}
patterns = temp[:0]
for _, i := range temp{
i.Regex = regexp.MustCompile(i.Value)
patterns = append(patterns, i)
}
}
func scanFilename(filename string, loc string) {
for _, i := range patterns{
if i.SecretType == "Filename" &&i.Regex.MatchString(filename){
color.Green("|Found match %s %s %s %s", filename, i.Description, i.Value, loc)
break
}
}
}
func scanFileContent(reader io.Reader){
/*
for _, i := range patterns{
if i.regex.MatchString(reader){
color.Green("Found match %s", filename)
}
}
*/
}
var patternsJson = []byte(`[
{
"description": "Azure storage standard key format",
"secretType": "FileContent",
"value": "\\b[A-Za-z0-9/+-]{86}\\b"
},
{
"description": "Azure service bus standard key format",
"secretType": "FileContent",
"value": "\\b[A-Za-z0-9/+-]{43}\\b"
},
{
"description": "Azure service configuration file",
"secretType": "Filename",
"value": "\\.cscfg$"
},
{
"description": "Decryption Key",
"secretType": "FileContent",
"value": "CryptDeriveKey"
},
{
"description": "Encryption Key",
"secretType": "FileContent",
"value": "CryptGenKey"
},
{
"description": "Encryption Key",
"secretType": "FileContent",
"value": "HMACSHA1"
},
{
"description": "Machine Key",
"secretType": "FileContent",
"value": "machinekey"
},
{
"description": "Potential MSBuild publish profile",
"secretType": "Filename",
"value": "\\.pubxml(\\.user)?$"
},
{
"description": "RDP file",
"secretType": "Filename",
"value": "\\.rdp$"
},
{
"description": "Private client certificate",
"secretType": "Filename",
"value": "\\.pfx$"
},
{
"description": "Potential cryptographic key bundle",
"secretType": "Filename",
"value": "\\.pkcs12$"
},
{
"description": "Potential cryptographic key bundle",
"secretType": "Filename",
"value": "\\.p12$"
},
{
"description": "Potential cryptographic key bundle",
"secretType": "Filename",
"value": "\\.asc$"
},
{
"description": "Possible public key",
"secretType": "Filename",
"value": "\\.pub$"
},
{
"description": "Potential Jenkins credentials file",
"secretType": "Filename",
"value": "^cred[\\s\\S]*xml"
},
{
"description": "Database file",
"secretType": "Filename",
"value": "\\.mdf$"
},
{
"description": "Database file",
"secretType": "Filename",
"value": "\\.sdf$"
},
{
"description": "Database file",
"secretType": "Filename",
"value": "\\.sql$"
},
{
"description": "Database file",
"secretType": "Filename",
"value": "\\.sqlite$"
},
{
"description": "MySQL client command history file",
"secretType": "Filename",
"value": "^[\\s\\S]*mysql_history"
},
{
"description": "PostgreSQL client command history file",
"secretType": "Filename",
"value": "^[\\s\\S]*psql_history"
},
{
"description": "Ruby On Rails database configuration file",
"secretType": "Filename",
"value": "^database[\\s\\S]*.yml"
},
{
"description": "AWS access key",
"secretType": "FileContent",
"value": "\\b[A-Za-z0-9/+-]{40}\\b"
},
{
"description": "Network traffic capture file",
"secretType": "Filename",
"value": "\\.pcap$"
},
{
"description": "Pidgin chat client account configuration file",
"secretType": "Filename",
"value": "accounts[\\s\\S]*.xml"
},
{
"description": "Wordpress configuration file",
"secretType": "Filename",
"value": "wp-config[\\s\\S]*.php"
},
{
"description": "Hexchat/XChat IRC client server list configuration file",
"secretType": "Filename",
"value": ".?xchat2[\\s\\S]*.conf"
},
{
"description": "S3cmd configuration file",
"secretType": "Filename",
"value": "\\.s3cfg$"
},
{
"description": "T command-line Twitter client configuration file",
"secretType": "Filename",
"value": "\\.trc$"
},
{
"description": "OpenVPN client configuration file",
"secretType": "Filename",
"value": "\\.ovpn$"
},
{
"description": "Ruby On Rails secret token configuration file",
"secretType": "Filename",
"value": "secret_token"
},
{
"description": "OmniAuth configuration file",
"secretType": "Filename",
"value": "\\.omniauth$"
},
{
"description": "Carrierwave configuration file",
"secretType": "Filename",
"value": "carrierwave"
},
{
"description": "Client SSH Config",
"secretType": "Filename",
"value": ".?ssh_config[\\s\\S]*"
},
{
"description": "Server SSH Config",
"secretType": "Filename",
"value": ".?sshd_config[\\s\\S]*"
},
{
"description": "KeePass password manager database file",
"secretType": "Filename",
"value": "\\.kdb$"
},
{
"description": "Contains word: backup",
"secretType": "Filename",
"value": "\\.backup$"
},
{
"description": "Jenkins publish over SSH plugin file",
"secretType": "Filename",
"value": "jenkins.plugins.publish_over_ssh[^ ]*.xml"
},
{
"description": "Potential MediaWiki configuration file",
"secretType": "Filename",
"value": "LocalSettings[^ ]*php"
},
{
"description": "Rubygems credentials file",
"secretType": "Filename",
"value": "\\A\\.?gem/credentials\\z"
},
{
"description": "SSH file",
"secretType": "Filename",
"value": "\\.ssh$"
},
{
"description": "Github Dev API key",
"secretType": "FileContent",
"value": "jekyll_github_token[^ ]*"
},
{
"description": "DHCP server configs",
"secretType": "Filename",
"value": "dhcpd[^ ]*.conf"
},
{
"description": "Heroku Environment Variable",
"secretType": "FileContent",
"value": "heroku config:set"
},
{
"description": "Jupyter Configuration file",
"secretType": "Filename",
"value": "jupyter[^ ]*config[^ ]*.json"
},
{
"description": "bitlocker",
"secretType": "Filename",
"value": "\\.bek$"
},
{
"description": "bitlocker",
"secretType": "Filename",
"value": "\\.tpm$"
},
{
"description": "bitlocker",
"secretType": "Filename",
"value": "\\.fve$"
},
{
"description": "java key store",
"secretType": "Filename",
"value": "\\.jks$"
},
{
"description": "openssl .key, apple .keychain, etc.",
"secretType": "Filename",
"value": "\\.key$"
},
{
"description": "passwordsafe",
"secretType": "Filename",
"value": "\\.psafe3$"
},
{
"description": "PKCS15 tokens",
"secretType": "Filename",
"value": "\\.p15$"
},
{
"description": "mozilla",
"secretType": "Filename",
"value": "cert8.db"
},
{
"description": "sql",
"secretType": "Filename",
"value": "connect.inc"
},
{
"description": "dbman",
"secretType": "Filename",
"value": "default.pass"
},
{
"description": "apache/nginx",
"secretType": "Filename",
"value": "htaccess"
},
{
"description": "openssh",
"secretType": "Filename",
"value": "id_dsa"
},
{
"description": "openssh",
"secretType": "Filename",
"value": "id_ecdsa"
},
{
"description": "openssh",
"secretType": "Filename",
"value": "id_ed25519"
},
{
"description": "openssh",
"secretType": "Filename",
"value": "id_rsa"
},
{
"description": "mozilla",
"secretType": "Filename",
"value": "key3.db"
},
{
"description": "typo3",
"secretType": "Filename",
"value": "localconf"
},
{
"description": "wikimedia",
"secretType": "Filename",
"value": "localsettings"
},
{
"description": "~/.netrc",
"secretType": "Filename",
"value": "\\.netrc$"
},
{
"description": "libpurple otr fingerprints",
"secretType": "Filename",
"value": "otr.fingerprints"
},
{
"description": "pgp",
"secretType": "Filename",
"value": "pgplog"
},
{
"description": "pgp",
"secretType": "Filename",
"value": "pgppolicy.xml"
},
{
"description": "pgp",
"secretType": "Filename",
"value": "pgpprefs.xml"
},
{
"description": "gnupg",
"secretType": "Filename",
"value": "secring\\.gpg"
},
{
"description": "sftp",
"secretType": "Filename",
"value": "sftp-config"
},
{
"description": "freebsd",
"secretType": "Filename",
"value": "spwd.bd"
},
{
"description": ".net",
"secretType": "Filename",
"value": "users.xml"
},
{
"description": "bitcoin",
"secretType": "Filename",
"value": "wallet.dat"
},
{
"description": "Private SSH key",
"secretType": "Filename",
"value": "\\A.*_rsa\\z"
},
{
"description": "Private SSH key",
"secretType": "Filename",
"value": "\\A.*_dsa\\z"
},
{
"description": "Private SSH key",
"secretType": "Filename",
"value": "\\A.*_ed25519\\z"
},
{
"description": "Private SSH key",
"secretType": "Filename",
"value": "\\A.*_ecdsa\\z"
},
{
"description": "SSH configuration file",
"secretType": "Filename",
"value": "\\.?ssh/config\\z"
},
{
"description": "Potential cryptographic private key",
"secretType": "Filename",
"value": "\\Akey(pair)?\\z"
},
{
"description": "Potential cryptographic key bundle",
"secretType": "Filename",
"value": ".pkcs12$"
},
{
"description": "Potential cryptographic key bundle",
"secretType": "Filename",
"value": ".pfx$"
},
{
"description": "Potential cryptographic key bundle",
"secretType": "Filename",
"value": ".p12$"
},
{
"description": "Potential cryptographic key bundle",
"secretType": "Filename",
"value": ".asc$"
},
{
"description": "Pidgin OTR private key",
"secretType": "Filename",
"value": ".otr.private_key"
},
{
"description": "Shell command history file",
"secretType": "Filename",
"value": "\\A\\.?(bash_|zsh_|z)?history\\z"
},
{
"description": "MySQL client command history file",
"secretType": "Filename",
"value": "\\A\\.?mysql_history\\z"
},
{
"description": "PostgreSQL client command history file",
"secretType": "Filename",
"value": "\\A\\.?psql_history\\z"
},
{
"description": "PostgreSQL password file",
"secretType": "Filename",
"value": "\\A\\.?pgpass\\z"
},
{
"description": "Ruby IRB console history file",
"secretType": "Filename",
"value": "\\A\\.?irb_history\\z"
},
{
"description": "Pidgin chat client account configuration file",
"secretType": "Filename",
"value": "\\.?purple\\/accounts\\.xml\\z"
},
{
"description": "Hexchat/XChat IRC client server list configuration file",
"secretType": "Filename",
"value": "\\.?xchat2?\\/servlist_?\\.conf\\z"
},
{
"description": "Irssi IRC client configuration file",
"secretType": "Filename",
"value": "\\.?irssi\\/config\\z"
},
{
"description": "Recon-ng web reconnaissance framework API key database",
"secretType": "Filename",
"value": "\\.?recon-ng\\/keys\\.db\\z"
},
{
"description": "DBeaver SQL database manager configuration file",
"secretType": "Filename",
"value": "\\A\\.?dbeaver-data-sources.xml\\z"
},
{
"description": "Mutt e-mail client configuration file",
"secretType": "Filename",
"value": "\\A\\.?muttrc\\z"
},
{
"description": "S3cmd configuration file",
"secretType": "Filename",
"value": "\\A\\.?s3cfg\\z"
},
{
"description": "AWS CLI credentials file",
"secretType": "Filename",
"value": "\\.?aws/credentials\\z"
},
{
"description": "T command-line Twitter client configuration file",
"secretType": "Filename",
"value": "\\A\\.?trc\\z"
},
{
"description": "OpenVPN client configuration file",
"secretType": "Filename",
"value": "\\.ovpn$"
},
{
"description": "Well, this is awkward... Gitrob configuration file",
"secretType": "Filename",
"value": "\\A\\.?gitrobrc\\z"
},
{
"description": "Shell configuration file",
"secretType": "Filename",
"value": "\\A\\.?(bash|zsh)rc\\z"
},
{
"description": "Shell profile configuration file",
"secretType": "Filename",
"value": "\\A\\.?(bash_|zsh_)?profile\\z"
},
{
"description": "Shell command alias configuration file",
"secretType": "Filename",
"value": "\\A\\.?(bash_|zsh_)?aliases\\z"
},
{
"description": "Potential Ruby On Rails database configuration file",
"secretType": "Filename",
"value": "database.yml"
},
{
"description": "PHP configuration file",
"secretType": "Filename",
"value": "\\A(.*)?config(\\.inc)?\\.php\\z"
},
{
"description": "KeePass password manager database file",
"secretType": "Filename",
"value": "\\.kdb$"
},
{
"description": "1Password password manager database file",
"secretType": "Filename",
"value": "\\.agilekeychain$"
},
{
"description": "Apple Keychain database file",
"secretType": "Filename",
"value": "\\.keychain$"
},
{
"description": "GNOME Keyring database file",
"secretType": "Filename",
"value": "\\Akey(store|ring)\\z"
},
{
"description": "Network traffic capture file",
"secretType": "Filename",
"value": "\\.pcap$"
},
{
"description": "SQL dump file",
"secretType": "Filename",
"value": "\\Asql(dump)?\\z"
},
{
"description": "GnuCash database file",
"secretType": "Filename",
"value": "\\.gnucash$"
},
{
"description": "Jenkins publish over SSH plugin file",
"secretType": "Filename",
"value": "jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin.xml"
},
{
"description": "Potential Jenkins credentials file",
"secretType": "Filename",
"value": "credentials.xml$"
},
{
"description": "Apache htpasswd file",
"secretType": "Filename",
"value": "\\A\\.?htpasswd\\z"
},
{
"description": "Configuration file for auto-login process",
"secretType": "Filename",
"value": "\\A(\\.|_)?netrc\\z"
},
{
"description": "KDE Wallet Manager database file",
"secretType": "Filename",
"value": "\\.kwallet$"
},
{
"description": "Potential MediaWiki configuration file",
"secretType": "Filename",
"value": "LocalSettings.php"
},
{
"description": "Tunnelblick VPN configuration file",
"secretType": "Filename",
"value": "\\.tblk$"
},
{
"description": "Rubygems credentials file",
"secretType": "Filename",
"value": "\\.?gem/credentials\\z"
},
{
"description": "Potential MSBuild publish profile",
"secretType": "Filename",
"value": "\\A*\\.pubxml(\\.user)?\\z"
},
{
"description": "Sequel Pro MySQL database manager bookmark file",
"secretType": "Filename",
"value": "Favorites.plist"
},
{
"description": "Little Snitch firewall configuration file",
"secretType": "Filename",
"value": "configuration.user.xpl"
},
{
"description": "Day One journal file",
"secretType": "Filename",
"value": "\\.dayone$"
},
{
"description": "Tugboat DigitalOcean management tool configuration",
"secretType": "Filename",
"value": "\\A\\.?tugboat\\z"
},
{
"description": "git-credential-store helper credentials file",
"secretType": "Filename",
"value": "\\A\\.?git-credentials\\z"
},
{
"description": "Git configuration file",
"secretType": "Filename",
"value": "\\A\\.?gitconfig\\z"
},
{
"description": "Chef Knife configuration file",
"secretType": "Filename",
"value": "knife.rb"
},
{
"description": "Chef private key",
"secretType": "Filename",
"value": "\\.?chef/(.*)\\.pem\\z"
},
{
"description": "cPanel backup ProFTPd credentials file",
"secretType": "Filename",
"value": "proftpdpasswd"
},
{
"description": "Robomongo MongoDB manager configuration file",
"secretType": "Filename",
"value": "robomongo.json"
},
{
"description": "FileZilla FTP configuration file",
"secretType": "Filename",
"value": "filezilla.xml"
},
{
"description": "FileZilla FTP recent servers file",
"secretType": "Filename",
"value": "recentservers.xml"
},
{
"description": "Ventrilo server configuration file",
"secretType": "Filename",
"value": "ventrilo_srv.ini"
},
{
"description": "Docker configuration file",
"secretType": "Filename",
"value": "\\A\\.?dockercfg\\z"
},
{
"description": "NPM configuration file",
"secretType": "Filename",
"value": "\\A\\.?npmrc\\z"
},
{
"description": "Terraform variable config file",
"secretType": "Filename",
"value": "terraform.tfvars"
},
{
"description": "Environment configuration file",
"secretType": "Filename",
"value": "\\A\\.?env\\z"
},
{
"description": "Secret",
"secretType": "FileContent",
"value": "(\\n[a-z0-9_\\-]+[:;\\|][a-z0-9_\\-]+){10,}"
},
{
"description": "API secret key",
"secretType": "FileContent",
"value": "(api|secret)key\\s*[\\=]+"
},
{
"description": "iCalender",
"secretType": "FileContent",
"value": "BEGIN:VCALENDAR"
},
{
"description": "secret key",
"secretType": "FileContent",
"value": "\\s*[a-z0-9\\-_]*secret[key]+\\s*[:=]+\\s*[\"']\\S+[\"']"
},
{
"description": "HtPasswds",
"secretType": "FileContent",
"value": "^[a-z0-9]+:[a-z0-9]{13}$"
},
{
"description": "Secret finder",
"secretType": "FileContent",
"value": "secret\\s*[\\=]+"
}
]
`)