From 9be7d77441ae423963d2bf505df4801aaed9ea4a Mon Sep 17 00:00:00 2001 From: Ahrav Dutta Date: Fri, 25 Aug 2023 21:41:39 -0700 Subject: [PATCH] PR 37 of 40 --- pkg/detectors/userflow/userflow.go | 23 ++----- pkg/detectors/userstack/userstack.go | 26 +++---- pkg/detectors/vatlayer/vatlayer.go | 24 +++---- pkg/detectors/vbout/vbout.go | 16 ++--- pkg/detectors/vercel/vercel.go | 22 ++---- pkg/detectors/verifier/verifier.go | 31 +++------ pkg/detectors/verimail/verimail.go | 22 ++---- pkg/detectors/veriphone/veriphone.go | 21 ++---- pkg/detectors/versioneye/versioneye.go | 17 ++--- pkg/detectors/viewneo/viewneo.go | 17 ++--- pkg/detectors/virustotal/virustotal.go | 69 ++++++++++--------- .../visualcrossing/visualcrossing.go | 20 ++---- pkg/detectors/voicegain/voicegain.go | 29 +++----- pkg/detectors/voodoosms/voodoosms.go | 18 +++-- pkg/detectors/vouchery/vouchery.go | 29 +++----- pkg/detectors/vpnapi/vpnapi.go | 17 ++--- pkg/detectors/vultrapikey/vultrapikey.go | 20 ++---- pkg/detectors/vyte/vyte.go | 22 ++---- pkg/detectors/walkscore/walkscore.go | 24 +++---- pkg/detectors/weatherbit/weatherbit.go | 21 +++--- 20 files changed, 184 insertions(+), 304 deletions(-) diff --git a/pkg/detectors/userflow/userflow.go b/pkg/detectors/userflow/userflow.go index b0ba9111..1c54bc6e 100644 --- a/pkg/detectors/userflow/userflow.go +++ b/pkg/detectors/userflow/userflow.go @@ -1,11 +1,11 @@ package userflow import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -14,37 +14,29 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"userflow"}) + `\b([0-9a-z_]{29})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"userflow"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("userflow")} } -// FromData will find and optionally verify Userflow secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Userflow, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -53,14 +45,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } req.Header.Add("Accept", "application/vnd.userflow+json; version=3") - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", string(resMatch))) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/userstack/userstack.go b/pkg/detectors/userstack/userstack.go index d8662ee3..2e06347a 100644 --- a/pkg/detectors/userstack/userstack.go +++ b/pkg/detectors/userstack/userstack.go @@ -1,12 +1,12 @@ package userstack import ( + "bytes" "context" "fmt" "io" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -15,41 +15,33 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"userstack"}) + `\b([a-z0-9]{32})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"userstack"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("userstack")} } -// FromData will find and optionally verify UserStack secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_UserStack, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.userstack.com/detect?access_key=%s&ua=Mozilla/5.0", resMatch), nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.userstack.com/detect?access_key=%s&ua=Mozilla/5.0", string(resMatch)), nil) if err != nil { continue } @@ -57,14 +49,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyBytes, err := io.ReadAll(res.Body) if err == nil { - bodyString := string(bodyBytes) - valid := strings.Contains(bodyString, `is_mobile_device`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) + valid := bytes.Contains(bodyBytes, []byte(`is_mobile_device`)) || bytes.Contains(bodyBytes, []byte(`"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`)) defer res.Body.Close() if valid { s1.Verified = true } else { s1.Verified = false - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/vatlayer/vatlayer.go b/pkg/detectors/vatlayer/vatlayer.go index bd0155c5..840ce144 100644 --- a/pkg/detectors/vatlayer/vatlayer.go +++ b/pkg/detectors/vatlayer/vatlayer.go @@ -1,12 +1,12 @@ package vatlayer import ( + "bytes" "context" "fmt" "io" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -15,41 +15,35 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"vatlayer"}) + `\b([a-z0-9]{32})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"vatlayer"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("vatlayer")} } -// FromData will find and optionally verify VatLayer secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_VatLayer, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://www.apilayer.net/api/validate?access_key=%s&vat_number=LU26375245&format=1", resMatch), nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://www.apilayer.net/api/validate?access_key=%s&vat_number=LU26375245&format=1", string(resMatch)), nil) if err != nil { continue } @@ -57,9 +51,8 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyBytes, err := io.ReadAll(res.Body) if err == nil { - bodyString := string(bodyBytes) - validResponse := strings.Contains(bodyString, `vat_number`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) defer res.Body.Close() + validResponse := bytes.Contains(bodyBytes, []byte(`vat_number`)) || bytes.Contains(bodyBytes, []byte(`"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`)) if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true @@ -67,7 +60,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result s1.Verified = false } } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/vbout/vbout.go b/pkg/detectors/vbout/vbout.go index 04df4949..ba40f7eb 100644 --- a/pkg/detectors/vbout/vbout.go +++ b/pkg/detectors/vbout/vbout.go @@ -1,11 +1,11 @@ package vbout import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -25,26 +25,23 @@ var ( ) // Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"vbout"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("vbout")} } // FromData will find and optionally verify Vbout secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Vbout, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -58,7 +55,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/vercel/vercel.go b/pkg/detectors/vercel/vercel.go index 55d6f23e..6f861a9f 100644 --- a/pkg/detectors/vercel/vercel.go +++ b/pkg/detectors/vercel/vercel.go @@ -1,11 +1,11 @@ package vercel import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -14,37 +14,30 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"vercel"}) + `\b([a-zA-Z0-9]{24})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"vercel"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("vercel")} } -// FromData will find and optionally verify Vercel secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Vercel, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -52,14 +45,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", string(resMatch))) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/verifier/verifier.go b/pkg/detectors/verifier/verifier.go index 324f76a1..10d0e040 100644 --- a/pkg/detectors/verifier/verifier.go +++ b/pkg/detectors/verifier/verifier.go @@ -1,11 +1,11 @@ package verifier import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -14,49 +14,40 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"verifier"}) + `\b([a-z0-9]{96})\b`) - emailPat = regexp.MustCompile(detectors.PrefixRegex([]string{"verifier"}) + `\b([a-zA-Z-0-9-]{5,16}\@[a-zA-Z-0-9]{4,16}\.[a-zA-Z-0-9]{3,6})\b`) + emailPat = regexp.MustCompile(detectors.PrefixRegex([]string{"verifier"}) + `\b([a-zA-Z-0-9]{5,16}@[-a-zA-Z-0-9]{4,16}\.[a-zA-Z-0-9]{3,6})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"verifier"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("verifier")} } -// FromData will find and optionally verify Verifier secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) - idMatches := emailPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) + idMatches := emailPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) for _, idMatch := range idMatches { if len(idMatch) != 2 { continue } - - userPatMatch := strings.TrimSpace(idMatch[1]) - + userPatMatch := bytes.TrimSpace(idMatch[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Verifier, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://verifier.meetchopra.com/verify/%s?token=%s", userPatMatch, resMatch), nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://verifier.meetchopra.com/verify/%s?token=%s", string(userPatMatch), string(resMatch)), nil) if err != nil { continue } @@ -66,7 +57,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } @@ -77,6 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result results = append(results, s1) } } + return results, nil } diff --git a/pkg/detectors/verimail/verimail.go b/pkg/detectors/verimail/verimail.go index 19345aed..db456d48 100644 --- a/pkg/detectors/verimail/verimail.go +++ b/pkg/detectors/verimail/verimail.go @@ -1,10 +1,10 @@ package verimail import ( + "bytes" "context" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -13,41 +13,34 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"verimail"}) + `\b([A-Z0-9]{32})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"verimail"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("verimail")} } -// FromData will find and optionally verify Verimail secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Verimail, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", "https://api.verimail.io/v3/verify?key="+resMatch, nil) + req, err := http.NewRequestWithContext(ctx, "GET", "https://api.verimail.io/v3/verify?key="+string(resMatch), nil) if err != nil { continue } @@ -57,7 +50,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/veriphone/veriphone.go b/pkg/detectors/veriphone/veriphone.go index 6b4f4300..5cae0c72 100644 --- a/pkg/detectors/veriphone/veriphone.go +++ b/pkg/detectors/veriphone/veriphone.go @@ -1,10 +1,10 @@ package veriphone import ( + "bytes" "context" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -13,41 +13,35 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"veriphone"}) + `\b([0-9A-Z]{32})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"veriphone"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("veriphone")} } -// FromData will find and optionally verify Veriphone secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Veriphone, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", "https://api.veriphone.io/v2/verify?phone=%252B49-15123577723&key="+resMatch, nil) + req, err := http.NewRequestWithContext(ctx, "GET", "https://api.veriphone.io/v2/verify?phone=%252B49-15123577723&key="+string(resMatch), nil) if err != nil { continue } @@ -57,7 +51,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/versioneye/versioneye.go b/pkg/detectors/versioneye/versioneye.go index 5148a99d..4197c08f 100644 --- a/pkg/detectors/versioneye/versioneye.go +++ b/pkg/detectors/versioneye/versioneye.go @@ -1,10 +1,10 @@ package versioneye import ( + "bytes" "context" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -25,25 +25,23 @@ var ( // Keywords are used for efficiently pre-filtering chunks. // Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"versioneye"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("versioneye")} } // FromData will find and optionally verify VersionEye secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_VersionEye, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -51,14 +49,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - req.Header.Add("apiKey", resMatch) + req.Header.Add("apiKey", string(resMatch)) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/viewneo/viewneo.go b/pkg/detectors/viewneo/viewneo.go index fa35a063..83799f41 100644 --- a/pkg/detectors/viewneo/viewneo.go +++ b/pkg/detectors/viewneo/viewneo.go @@ -1,11 +1,11 @@ package viewneo import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -26,24 +26,22 @@ var ( // Keywords are used for efficiently pre-filtering chunks. // Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"viewneo"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("viewneo")} } // FromData will find and optionally verify Viewneo secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Viewneo, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -52,14 +50,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } req.Header.Add("Accept", "application/json") - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", string(resMatch))) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/virustotal/virustotal.go b/pkg/detectors/virustotal/virustotal.go index 465b1c06..2c4245db 100644 --- a/pkg/detectors/virustotal/virustotal.go +++ b/pkg/detectors/virustotal/virustotal.go @@ -1,10 +1,12 @@ package virustotal import ( + "bytes" "context" + "io" + "mime/multipart" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -13,70 +15,69 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"virustotal"}) + `\b([a-f0-9]{64})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"virustotal"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("virustotal")} } -// FromData will find and optionally verify VirusTotal secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_VirusTotal, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - s1.Verified = verifyToken(ctx, client, resMatch) - if !s1.Verified && detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { + body := &bytes.Buffer{} + writer := multipart.NewWriter(body) + fw, err := writer.CreateFormField("url") + if err != nil { continue } + _, err = io.Copy(fw, bytes.NewBufferString("https://www.amazon.com")) + if err != nil { + continue + } + writer.Close() + req, err := http.NewRequestWithContext(ctx, "POST", "https://www.virustotal.com/api/v3/urls", body) + if err != nil { + continue + } + req.Header.Add("Content-Type", writer.FormDataContentType()) + req.Header.Add("x-apikey", string(resMatch)) + res, err := client.Do(req) + if err == nil { + defer res.Body.Close() + if res.StatusCode >= 200 && res.StatusCode < 300 { + s1.Verified = true + } else { + if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { + continue + } + } + } } + results = append(results, s1) } return results, nil } -func verifyToken(ctx context.Context, client *http.Client, token string) bool { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://www.virustotal.com/api/v3/metadata", nil) - if err != nil { - return false - } - req.Header.Add("x-apikey", token) - - res, err := client.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - - if res.StatusCode < 200 || res.StatusCode >= 300 { - return false - } - return true -} - func (s Scanner) Type() detectorspb.DetectorType { return detectorspb.DetectorType_VirusTotal } diff --git a/pkg/detectors/visualcrossing/visualcrossing.go b/pkg/detectors/visualcrossing/visualcrossing.go index ea9dd249..472a5815 100644 --- a/pkg/detectors/visualcrossing/visualcrossing.go +++ b/pkg/detectors/visualcrossing/visualcrossing.go @@ -1,11 +1,11 @@ package visualcrossing import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -24,31 +24,26 @@ var ( keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"visualcrossing"}) + `\b([0-9A-Z]{25})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"visualcrossing"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("visualcrossing")} } -// FromData will find and optionally verify Visualcrossing secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_VisualCrossing, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/LA?key=%s", resMatch), nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/LA?key=%s", string(resMatch)), nil) if err != nil { continue } @@ -59,7 +54,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/voicegain/voicegain.go b/pkg/detectors/voicegain/voicegain.go index 67741e25..32ece920 100644 --- a/pkg/detectors/voicegain/voicegain.go +++ b/pkg/detectors/voicegain/voicegain.go @@ -1,11 +1,11 @@ package voicegain import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -14,37 +14,31 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. - keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"voicegain"}) + `\b(ey[0-9a-zA-Z_-]{34}.ey[0-9a-zA-Z_-]{108}.[0-9a-zA-Z_-]{43})\b`) + keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"voicegain"}) + + `\b(ey[0-9a-zA-Z_-]{34}.ey[0-9a-zA-Z_-]{108}.[0-9a-zA-Z_-]{43})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"voicegain"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("voicegain")} } -// FromData will find and optionally verify Voicegain secrets in a given set of bytes. -func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) +func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) ([]detectors.Result, error) { + matches := keyPat.FindAllSubmatch(data, -1) + var results []detectors.Result for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Voicegain, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -53,14 +47,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } req.Header.Add("Content-Type", "application/json") - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", string(resMatch))) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/voodoosms/voodoosms.go b/pkg/detectors/voodoosms/voodoosms.go index c382d093..aab578a5 100644 --- a/pkg/detectors/voodoosms/voodoosms.go +++ b/pkg/detectors/voodoosms/voodoosms.go @@ -1,11 +1,11 @@ package voodoosms import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -26,25 +26,24 @@ var ( // Keywords are used for efficiently pre-filtering chunks. // Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"voodoosms"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("voodoosms")} } // FromData will find and optionally verify VoodooSMS secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_VoodooSMS, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -53,14 +52,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } req.Header.Add("Content-Type'", "application/json") - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", string(resMatch))) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/vouchery/vouchery.go b/pkg/detectors/vouchery/vouchery.go index ec917e56..5966555a 100644 --- a/pkg/detectors/vouchery/vouchery.go +++ b/pkg/detectors/vouchery/vouchery.go @@ -1,11 +1,11 @@ package vouchery import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -20,56 +20,49 @@ var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"vouchery"}) + `\b([a-z0-9-]{36})\b`) subPat = regexp.MustCompile(detectors.PrefixRegex([]string{"vouchery"}) + `\b([a-zA-Z0-9-\S]{2,20})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"vouchery"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("vouchery")} } -// FromData will find and optionally verify Vouchery secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) - subMatches := subPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) + subMatches := subPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) for _, subMatch := range subMatches { if len(subMatch) != 2 { continue } - subMatch := strings.TrimSpace(subMatch[1]) + subMatchTrim := bytes.TrimSpace(subMatch[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Vouchery, - Raw: []byte(resMatch), - RawV2: []byte(resMatch + subMatch), + Raw: resMatch, + RawV2: append(resMatch, subMatchTrim...), } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s.vouchery.io/api/v2.0/users", subMatch), nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s.vouchery.io/api/v2.0/users", string(subMatchTrim)), nil) if err != nil { continue } - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", string(resMatch))) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/vpnapi/vpnapi.go b/pkg/detectors/vpnapi/vpnapi.go index 5593e0d4..64184a4a 100644 --- a/pkg/detectors/vpnapi/vpnapi.go +++ b/pkg/detectors/vpnapi/vpnapi.go @@ -1,10 +1,10 @@ package vpnapi import ( + "bytes" "context" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -25,29 +25,27 @@ var ( // Keywords are used for efficiently pre-filtering chunks. // Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"vpnapi"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("vpnapi")} } // FromData will find and optionally verify Vpnapi secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Vpnapi, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", "https://vpnapi.io/api/8.8.8.8?key="+resMatch, nil) + req, err := http.NewRequestWithContext(ctx, "GET", "https://vpnapi.io/api/8.8.8.8?key="+string(resMatch), nil) if err != nil { continue } @@ -57,7 +55,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/vultrapikey/vultrapikey.go b/pkg/detectors/vultrapikey/vultrapikey.go index 536a27c9..6a4ccfe0 100644 --- a/pkg/detectors/vultrapikey/vultrapikey.go +++ b/pkg/detectors/vultrapikey/vultrapikey.go @@ -1,11 +1,11 @@ package vultrapikey import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -24,27 +24,22 @@ var ( keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"vultr"}) + ` \b([A-Z0-9]{36})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"vultr"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("vultr")} } -// FromData will find and optionally verify VultrApiKey secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_VultrApiKey, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -52,14 +47,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", string(resMatch))) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/vyte/vyte.go b/pkg/detectors/vyte/vyte.go index 0671be79..7442ec95 100644 --- a/pkg/detectors/vyte/vyte.go +++ b/pkg/detectors/vyte/vyte.go @@ -1,10 +1,10 @@ package vyte import ( + "bytes" "context" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -13,37 +13,30 @@ import ( type Scanner struct{} -// Ensure the Scanner satisfies the interface at compile time. var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"vyte"}) + `\b([0-9a-z]{50})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"vyte"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("vyte")} } -// FromData will find and optionally verify Vyte secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Vyte, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -52,14 +45,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } req.Header.Add("Accept", "application/vnd.vyte+json; version=3") - req.Header.Add("Authorization", resMatch) + req.Header.Add("Authorization", string(resMatch)) res, err := client.Do(req) if err == nil { defer res.Body.Close() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/walkscore/walkscore.go b/pkg/detectors/walkscore/walkscore.go index 4400afaa..0f1e0abd 100644 --- a/pkg/detectors/walkscore/walkscore.go +++ b/pkg/detectors/walkscore/walkscore.go @@ -1,12 +1,11 @@ package walkscore import ( + "bytes" "context" "fmt" - "io" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -27,29 +26,28 @@ var ( // Keywords are used for efficiently pre-filtering chunks. // Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"walkscore"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("walkscore")} } // FromData will find and optionally verify Walkscore secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_WalkScore, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { - req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://transit.walkscore.com/transit/search/stops/?lat=47.6101359&lon=-122.3420567&wsapikey=%s", resMatch), nil) + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://transit.walkscore.com/transit/search/stops/?lat=47.6101359&lon=-122.3420567&wsapikey=%s", string(resMatch)), nil) if err != nil { continue } @@ -57,15 +55,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { defer res.Body.Close() - bodyBytes, err := io.ReadAll(res.Body) - if err != nil { - continue - } - body := string(bodyBytes) - if (res.StatusCode >= 200 && res.StatusCode < 300) && strings.Contains(body, `distance`) { + if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue } diff --git a/pkg/detectors/weatherbit/weatherbit.go b/pkg/detectors/weatherbit/weatherbit.go index 04a8ebad..a5931297 100644 --- a/pkg/detectors/weatherbit/weatherbit.go +++ b/pkg/detectors/weatherbit/weatherbit.go @@ -1,11 +1,11 @@ package weatherbit import ( + "bytes" "context" "fmt" "net/http" "regexp" - "strings" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" @@ -20,31 +20,26 @@ var _ detectors.Detector = (*Scanner)(nil) var ( client = common.SaneHttpClient() - // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"weatherbit"}) + `\b([0-9a-z]{32})\b`) ) -// Keywords are used for efficiently pre-filtering chunks. -// Use identifiers in the secret preferably, or the provider name. -func (s Scanner) Keywords() []string { - return []string{"weatherbit"} +func (s Scanner) Keywords() [][]byte { + return [][]byte{[]byte("weatherbit")} } -// FromData will find and optionally verify Weatherbit secrets in a given set of bytes. func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { - dataStr := string(data) - - matches := keyPat.FindAllStringSubmatch(dataStr, -1) + matches := keyPat.FindAllSubmatch(data, -1) for _, match := range matches { if len(match) != 2 { continue } - resMatch := strings.TrimSpace(match[1]) + + resMatch := bytes.TrimSpace(match[1]) s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_WeatherBit, - Raw: []byte(resMatch), + Raw: resMatch, } if verify { @@ -52,6 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } + req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { @@ -59,7 +55,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { - // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key. if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { continue }