This repository was archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 832
/
Copy pathsignatures.go
710 lines (687 loc) · 20.6 KB
/
signatures.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
package core
import (
"crypto/sha1"
"fmt"
"io"
"path/filepath"
"regexp"
"strings"
)
const (
TypeSimple = "simple"
TypePattern = "pattern"
PartExtension = "extension"
PartFilename = "filename"
PartPath = "path"
)
var skippableExtensions = []string{".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".tif", ".psd", ".xcf"}
var skippablePathIndicators = []string{"node_modules/", "vendor/bundle", "vendor/cache"}
type MatchFile struct {
Path string
Filename string
Extension string
}
func (f *MatchFile) IsSkippable() bool {
ext := strings.ToLower(f.Extension)
path := strings.ToLower(f.Path)
for _, skippableExt := range skippableExtensions {
if ext == skippableExt {
return true
}
}
for _, skippablePathIndicator := range skippablePathIndicators {
if strings.Contains(path, skippablePathIndicator) {
return true
}
}
return false
}
type Finding struct {
Id string
FilePath string
Action string
Description string
Comment string
RepositoryOwner string
RepositoryName string
CommitHash string
CommitMessage string
CommitAuthor string
FileUrl string
CommitUrl string
RepositoryUrl string
}
func (f *Finding) setupUrls() {
f.RepositoryUrl = fmt.Sprintf("https://github.com/%s/%s", f.RepositoryOwner, f.RepositoryName)
f.FileUrl = fmt.Sprintf("%s/blob/%s/%s", f.RepositoryUrl, f.CommitHash, f.FilePath)
f.CommitUrl = fmt.Sprintf("%s/commit/%s", f.RepositoryUrl, f.CommitHash)
}
func (f *Finding) generateID() {
h := sha1.New()
io.WriteString(h, f.FilePath)
io.WriteString(h, f.Action)
io.WriteString(h, f.RepositoryOwner)
io.WriteString(h, f.RepositoryName)
io.WriteString(h, f.CommitHash)
io.WriteString(h, f.CommitMessage)
io.WriteString(h, f.CommitAuthor)
f.Id = fmt.Sprintf("%x", h.Sum(nil))
}
func (f *Finding) Initialize() {
f.setupUrls()
f.generateID()
}
type Signature interface {
Match(file MatchFile) bool
Description() string
Comment() string
}
type SimpleSignature struct {
part string
match string
description string
comment string
}
type PatternSignature struct {
part string
match *regexp.Regexp
description string
comment string
}
func (s SimpleSignature) Match(file MatchFile) bool {
var haystack *string
switch s.part {
case PartPath:
haystack = &file.Path
case PartFilename:
haystack = &file.Filename
case PartExtension:
haystack = &file.Extension
default:
return false
}
return (s.match == *haystack)
}
func (s SimpleSignature) Description() string {
return s.description
}
func (s SimpleSignature) Comment() string {
return s.comment
}
func (s PatternSignature) Match(file MatchFile) bool {
var haystack *string
switch s.part {
case PartPath:
haystack = &file.Path
case PartFilename:
haystack = &file.Filename
case PartExtension:
haystack = &file.Extension
default:
return false
}
return s.match.MatchString(*haystack)
}
func (s PatternSignature) Description() string {
return s.description
}
func (s PatternSignature) Comment() string {
return s.comment
}
func NewMatchFile(path string) MatchFile {
_, filename := filepath.Split(path)
extension := filepath.Ext(path)
return MatchFile{
Path: path,
Filename: filename,
Extension: extension,
}
}
var Signatures = []Signature{
SimpleSignature{
part: PartExtension,
match: ".pem",
description: "Potential cryptographic private key",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".log",
description: "Log file",
comment: "Log files can contain secret HTTP endpoints, session IDs, API keys and other goodies",
},
SimpleSignature{
part: PartExtension,
match: ".pkcs12",
description: "Potential cryptographic key bundle",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".p12",
description: "Potential cryptographic key bundle",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".pfx",
description: "Potential cryptographic key bundle",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".asc",
description: "Potential cryptographic key bundle",
comment: "",
},
SimpleSignature{
part: PartFilename,
match: "otr.private_key",
description: "Pidgin OTR private key",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".ovpn",
description: "OpenVPN client configuration file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".cscfg",
description: "Azure service configuration schema file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".rdp",
description: "Remote Desktop connection file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".mdf",
description: "Microsoft SQL database file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".sdf",
description: "Microsoft SQL server compact database file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".sqlite",
description: "SQLite database file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".bek",
description: "Microsoft BitLocker recovery key file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".tpm",
description: "Microsoft BitLocker Trusted Platform Module password file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".fve",
description: "Windows BitLocker full volume encrypted data file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".jks",
description: "Java keystore file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".psafe3",
description: "Password Safe database file",
comment: "",
},
SimpleSignature{
part: PartFilename,
match: "secret_token.rb",
description: "Ruby On Rails secret token configuration file",
comment: "If the Rails secret token is known, it can allow for remote code execution (http://www.exploit-db.com/exploits/27527/)",
},
SimpleSignature{
part: PartFilename,
match: "carrierwave.rb",
description: "Carrierwave configuration file",
comment: "Can contain credentials for cloud storage systems such as Amazon S3 and Google Storage",
},
SimpleSignature{
part: PartFilename,
match: "database.yml",
description: "Potential Ruby On Rails database configuration file",
comment: "Can contain database credentials",
},
SimpleSignature{
part: PartFilename,
match: "omniauth.rb",
description: "OmniAuth configuration file",
comment: "The OmniAuth configuration file can contain client application secrets",
},
SimpleSignature{
part: PartFilename,
match: "settings.py",
description: "Django configuration file",
comment: "Can contain database credentials, cloud storage system credentials, and other secrets",
},
SimpleSignature{
part: PartExtension,
match: ".agilekeychain",
description: "1Password password manager database file",
comment: "Feed it to Hashcat and see if you're lucky",
},
SimpleSignature{
part: PartExtension,
match: ".keychain",
description: "Apple Keychain database file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".pcap",
description: "Network traffic capture file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".gnucash",
description: "GnuCash database file",
comment: "",
},
SimpleSignature{
part: PartFilename,
match: "jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin.xml",
description: "Jenkins publish over SSH plugin file",
comment: "",
},
SimpleSignature{
part: PartFilename,
match: "credentials.xml",
description: "Potential Jenkins credentials file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".kwallet",
description: "KDE Wallet Manager database file",
comment: "",
},
SimpleSignature{
part: PartFilename,
match: "LocalSettings.php",
description: "Potential MediaWiki configuration file",
comment: "",
},
SimpleSignature{
part: PartExtension,
match: ".tblk",
description: "Tunnelblick VPN configuration file",
comment: "",
},
SimpleSignature{
part: PartFilename,
match: "Favorites.plist",
description: "Sequel Pro MySQL database manager bookmark file",
comment: "",
},
SimpleSignature{
part: PartFilename,
match: "configuration.user.xpl",
description: "Little Snitch firewall configuration file",
comment: "Contains traffic rules for applications",
},
SimpleSignature{
part: PartExtension,
match: ".dayone",
description: "Day One journal file",
comment: "Now it's getting creepy...",
},
SimpleSignature{
part: PartFilename,
match: "journal.txt",
description: "Potential jrnl journal file",
comment: "Now it's getting creepy...",
},
SimpleSignature{
part: PartFilename,
match: "knife.rb",
description: "Chef Knife configuration file",
comment: "Can contain references to Chef servers",
},
SimpleSignature{
part: PartFilename,
match: "proftpdpasswd",
description: "cPanel backup ProFTPd credentials file",
comment: "Contains usernames and password hashes for FTP accounts",
},
SimpleSignature{
part: PartFilename,
match: "robomongo.json",
description: "Robomongo MongoDB manager configuration file",
comment: "Can contain credentials for MongoDB databases",
},
SimpleSignature{
part: PartFilename,
match: "filezilla.xml",
description: "FileZilla FTP configuration file",
comment: "Can contain credentials for FTP servers",
},
SimpleSignature{
part: PartFilename,
match: "recentservers.xml",
description: "FileZilla FTP recent servers file",
comment: "Can contain credentials for FTP servers",
},
SimpleSignature{
part: PartFilename,
match: "ventrilo_srv.ini",
description: "Ventrilo server configuration file",
comment: "Can contain passwords",
},
SimpleSignature{
part: PartFilename,
match: "terraform.tfvars",
description: "Terraform variable config file",
comment: "Can contain credentials for terraform providers",
},
SimpleSignature{
part: PartFilename,
match: ".exports",
description: "Shell configuration file",
comment: "Shell configuration files can contain passwords, API keys, hostnames and other goodies",
},
SimpleSignature{
part: PartFilename,
match: ".functions",
description: "Shell configuration file",
comment: "Shell configuration files can contain passwords, API keys, hostnames and other goodies",
},
SimpleSignature{
part: PartFilename,
match: ".extra",
description: "Shell configuration file",
comment: "Shell configuration files can contain passwords, API keys, hostnames and other goodies",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^.*_rsa$`),
description: "Private SSH key",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^.*_dsa$`),
description: "Private SSH key",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^.*_ed25519$`),
description: "Private SSH key",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^.*_ecdsa$`),
description: "Private SSH key",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?ssh/config$`),
description: "SSH configuration file",
comment: "",
},
PatternSignature{
part: PartExtension,
match: regexp.MustCompile(`^key(pair)?$`),
description: "Potential cryptographic private key",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?(bash_|zsh_|sh_|z)?history$`),
description: "Shell command history file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?mysql_history$`),
description: "MySQL client command history file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?psql_history$`),
description: "PostgreSQL client command history file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?pgpass$`),
description: "PostgreSQL password file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?irb_history$`),
description: "Ruby IRB console history file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?purple/accounts\.xml$`),
description: "Pidgin chat client account configuration file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?xchat2?/servlist_?\.conf$`),
description: "Hexchat/XChat IRC client server list configuration file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?irssi/config$`),
description: "Irssi IRC client configuration file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?recon-ng/keys\.db$`),
description: "Recon-ng web reconnaissance framework API key database",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?dbeaver-data-sources.xml$`),
description: "DBeaver SQL database manager configuration file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?muttrc$`),
description: "Mutt e-mail client configuration file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?s3cfg$`),
description: "S3cmd configuration file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?aws/credentials$`),
description: "AWS CLI credentials file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^sftp-config(\.json)?$`),
description: "SFTP connection configuration file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?trc$`),
description: "T command-line Twitter client configuration file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?gitrobrc$`),
description: "Well, this is awkward... Gitrob configuration file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?(bash|zsh|csh)rc$`),
description: "Shell configuration file",
comment: "Shell configuration files can contain passwords, API keys, hostnames and other goodies",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?(bash_|zsh_)?profile$`),
description: "Shell profile configuration file",
comment: "Shell configuration files can contain passwords, API keys, hostnames and other goodies",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?(bash_|zsh_)?aliases$`),
description: "Shell command alias configuration file",
comment: "Shell configuration files can contain passwords, API keys, hostnames and other goodies",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`config(\.inc)?\.php$`),
description: "PHP configuration file",
comment: "",
},
PatternSignature{
part: PartExtension,
match: regexp.MustCompile(`^key(store|ring)$`),
description: "GNOME Keyring database file",
comment: "",
},
PatternSignature{
part: PartExtension,
match: regexp.MustCompile(`^kdbx?$`),
description: "KeePass password manager database file",
comment: "Feed it to Hashcat and see if you're lucky",
},
PatternSignature{
part: PartExtension,
match: regexp.MustCompile(`^sql(dump)?$`),
description: "SQL dump file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?htpasswd$`),
description: "Apache htpasswd file",
comment: "",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^(\.|_)?netrc$`),
description: "Configuration file for auto-login process",
comment: "Can contain username and password",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?gem/credentials$`),
description: "Rubygems credentials file",
comment: "Can contain API key for a rubygems.org account",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?tugboat$`),
description: "Tugboat DigitalOcean management tool configuration",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`doctl/config.yaml$`),
description: "DigitalOcean doctl command-line client configuration file",
comment: "Contains DigitalOcean API key and other information",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?git-credentials$`),
description: "git-credential-store helper credentials file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`config/hub$`),
description: "GitHub Hub command-line client configuration file",
comment: "Can contain GitHub API access token",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?gitconfig$`),
description: "Git configuration file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`\.?chef/(.*)\.pem$`),
description: "Chef private key",
comment: "Can be used to authenticate against Chef servers",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`etc/shadow$`),
description: "Potential Linux shadow file",
comment: "Contains hashed passwords for system users",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`etc/passwd$`),
description: "Potential Linux passwd file",
comment: "Contains system user information",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?dockercfg$`),
description: "Docker configuration file",
comment: "Can contain credentials for public or private Docker registries",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?npmrc$`),
description: "NPM configuration file",
comment: "Can contain credentials for NPM registries",
},
PatternSignature{
part: PartFilename,
match: regexp.MustCompile(`^\.?env$`),
description: "Environment configuration file",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`credential`),
description: "Contains word: credential",
comment: "",
},
PatternSignature{
part: PartPath,
match: regexp.MustCompile(`password`),
description: "Contains word: password",
comment: "",
},
}