Compare commits

..
2 Commits
13 changed files with 3004 additions and 44 deletions

No files matched your search

+1 -7
View File
@@ -50,7 +50,6 @@ func main() {
configRules = append(configRules, rules.FlutterwaveSecretKey()) configRules = append(configRules, rules.FlutterwaveSecretKey())
configRules = append(configRules, rules.FlutterwaveSecretKey()) configRules = append(configRules, rules.FlutterwaveSecretKey())
configRules = append(configRules, rules.FrameIO()) configRules = append(configRules, rules.FrameIO())
configRules = append(configRules, rules.GenericCredential())
configRules = append(configRules, rules.GoCardless()) configRules = append(configRules, rules.GoCardless())
// TODO figure out what makes sense for GCP // TODO figure out what makes sense for GCP
// configRules = append(configRules, rules.GCPServiceAccount()) // configRules = append(configRules, rules.GCPServiceAccount())
@@ -101,12 +100,10 @@ func main() {
configRules = append(configRules, rules.TwitchAPIToken()) configRules = append(configRules, rules.TwitchAPIToken())
configRules = append(configRules, rules.Twitter()) configRules = append(configRules, rules.Twitter())
configRules = append(configRules, rules.Typeform()) configRules = append(configRules, rules.Typeform())
configRules = append(configRules, rules.GenericCredential())
config := config.Config{ config := config.Config{
Rules: configRules, Rules: configRules,
Allowlist: config.Allowlist{
StopWords: rules.DefaultStopWords,
},
} }
tmpl, err := template.ParseFiles(templatePath) tmpl, err := template.ParseFiles(templatePath)
if err != nil { if err != nil {
@@ -120,6 +117,3 @@ func main() {
tmpl.Execute(f, config) tmpl.Execute(f, config)
} }
// TODO introduce skiplists:
// https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/wordlist-skipfish.fuzz.txt
+1
View File
@@ -28,6 +28,7 @@ func AsanaClientSecret() *config.Rule {
Description: "Asana Client Secret", Description: "Asana Client Secret",
RuleID: "asana-client-secret", RuleID: "asana-client-secret",
Regex: generateSemiGenericRegex([]string{"asana"}, alphaNumeric("32")), Regex: generateSemiGenericRegex([]string{"asana"}, alphaNumeric("32")),
SecretGroup: 1,
Keywords: []string{"asana"}, Keywords: []string{"asana"},
} }
+13 -4
View File
@@ -16,12 +16,21 @@ paths = [
'''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''', '''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''',
'''(go.mod|go.sum)$''' '''(go.mod|go.sum)$'''
] ]
stopwords = [{{ range $i, $stopword := .Allowlist.StopWords }}
'''{{ $stopword }}''',{{ end }}
]
{{ range $i, $rule := .Rules }}[[rules]] {{ range $i, $rule := .Rules }}[[rules]]
{{ if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}" {{ if and $rule.SecretGroup $rule.Entropy $rule.Allowlist.StopWords }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }}
entropy = {{ $rule.Entropy}}
keywords = [
{{ range $j, $keyword := $rule.Keywords }}"{{$keyword}}",{{end}}
]
[rules.allowlist]
stopwords= [{{ range $j, $stopword := $rule.Allowlist.StopWords }}
"{{$stopword}}",{{end}}
]
{{ else if and $rule.SecretGroup $rule.Entropy }}description = "{{$rule.Description}}"
id = "{{$rule.RuleID}}" id = "{{$rule.RuleID}}"
regex = '''{{$rule.Regex}}''' regex = '''{{$rule.Regex}}'''
secretGroup = {{ $rule.SecretGroup }} secretGroup = {{ $rule.SecretGroup }}
+4 -2
View File
@@ -30,7 +30,10 @@ func GenericCredential() *config.Rule {
"password", "password",
"auth", "auth",
}, },
Entropy: 3.7, Entropy: 3.5,
Allowlist: config.Allowlist{
StopWords: DefaultStopWords,
},
} }
// validate // validate
@@ -39,7 +42,6 @@ func GenericCredential() *config.Rule {
generateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"), generateSampleSecret("generic", "Zf3D0LXCM3EIMbgJpUNnkRtOfOueHznB"),
`"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`, `"client_id" : "0afae57f3ccfd9d7f5767067bc48b30f719e271ba470488056e37ab35d4b6506"`,
`"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`, `"client_secret" : "6da89121079f83b2eb6acccf8219ea982c3d79bccc3e9c6a85856480661f8fde",`,
// TODO add more
} }
fps := []string{ fps := []string{
`client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.client-vpn-endpoint.id`, `client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.client-vpn-endpoint.id`,
+1
View File
@@ -11,6 +11,7 @@ func GoCardless() *config.Rule {
RuleID: "gocardless-api-token", RuleID: "gocardless-api-token",
Description: "GoCardless API token", Description: "GoCardless API token",
Regex: generateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`), Regex: generateSemiGenericRegex([]string{"gocardless"}, `live_(?i)[a-z0-9\-_=]{40}`),
SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"live_", "live_",
"gocardless", "gocardless",
+1
View File
@@ -30,6 +30,7 @@ func LinearClientSecret() *config.Rule {
RuleID: "linear-client-secret", RuleID: "linear-client-secret",
Regex: generateSemiGenericRegex([]string{"linear"}, hex("32")), Regex: generateSemiGenericRegex([]string{"linear"}, hex("32")),
Keywords: []string{"linear"}, Keywords: []string{"linear"},
SecretGroup: 1,
} }
// validate // validate
+2
View File
@@ -11,6 +11,7 @@ func LobPubAPIToken() *config.Rule {
Description: "Lob Publishable API Key", Description: "Lob Publishable API Key",
RuleID: "lob-pub-api-key", RuleID: "lob-pub-api-key",
Regex: generateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`), Regex: generateSemiGenericRegex([]string{"lob"}, `(test|live)_pub_[a-f0-9]{31}`),
SecretGroup: 1,
Keywords: []string{ Keywords: []string{
"test_pub", "test_pub",
"live_pub", "live_pub",
@@ -35,6 +36,7 @@ func LobAPIToken() *config.Rule {
"test_", "test_",
"live_", "live_",
}, },
SecretGroup: 1,
} }
// validate // validate
+1 -12
View File
@@ -28,14 +28,6 @@ const (
secretSuffix = `)(?:['|\"|\n|\r|\s|\x60]|$)` secretSuffix = `)(?:['|\"|\n|\r|\s|\x60]|$)`
) )
var DefaultStopWords = []string{
"client",
"endpoint",
"vpn",
"_ec2_",
"aws_",
}
func generateSemiGenericRegex(identifiers []string, secretRegex string) *regexp.Regexp { func generateSemiGenericRegex(identifiers []string, secretRegex string) *regexp.Regexp {
var sb strings.Builder var sb strings.Builder
sb.WriteString(caseInsensitive) sb.WriteString(caseInsensitive)
@@ -73,13 +65,10 @@ func validate(r config.Rule, truePositives []string, falsePositives []string) *c
d := detect.NewDetector(config.Config{ d := detect.NewDetector(config.Config{
Rules: []*config.Rule{&r}, Rules: []*config.Rule{&r},
Keywords: keywords, Keywords: keywords,
Allowlist: config.Allowlist{
StopWords: DefaultStopWords,
},
}) })
for _, tp := range truePositives { for _, tp := range truePositives {
if len(d.DetectString(tp)) != 1 { if len(d.DetectString(tp)) != 1 {
log.Fatal().Msgf("Failed to validate (tp) %s", r.RuleID) log.Fatal().Msgf("Failed to validate (tp) %s %s", r.RuleID, tp)
} }
} }
for _, fp := range falsePositives { for _, fp := range falsePositives {
+1 -1
View File
@@ -44,7 +44,7 @@ func SlackWebHook() *config.Rule {
// validate // validate
tps := []string{ tps := []string{
"https://hooks.slack.com/services/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", // gitleaks:allow "https://hooks.slack.com/services/" + secrets.NewSecret(alphaNumeric("44")), // gitleaks:allow
} }
return validate(r, tps, nil) return validate(r, tps, nil)
} }
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -50,8 +50,9 @@ func (a *Allowlist) RegexAllowed(s string) bool {
} }
func (a *Allowlist) ContainsStopWord(s string) bool { func (a *Allowlist) ContainsStopWord(s string) bool {
s = strings.ToLower(s)
for _, stopWord := range a.StopWords { for _, stopWord := range a.StopWords {
if strings.Contains(s, stopWord) { if strings.Contains(s, strings.ToLower(stopWord)) {
return true return true
} }
} }
+1489 -17
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -22,6 +22,7 @@ func location(fragment Fragment, matchIndex []int) Location {
end := matchIndex[1] end := matchIndex[1]
for lineNum, pair := range fragment.newlineIndices { for lineNum, pair := range fragment.newlineIndices {
_lineNum = lineNum
newLineByteIndex := pair[0] newLineByteIndex := pair[0]
if prevNewLine <= start && start < newLineByteIndex { if prevNewLine <= start && start < newLineByteIndex {
lineSet = true lineSet = true