Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Added support for indeterminate verification for letter Z detectors (#4165)
Kashif Khan3bba2773e004
diff --git a/pkg/detectors/zapierwebhook/zapierwebhook.go b/pkg/detectors/zapierwebhook/zapierwebhook.goindex bd0a7f3d1..204fc20d7 100644--- a/pkg/detectors/zapierwebhook/zapierwebhook.go+++ b/pkg/detectors/zapierwebhook/zapierwebhook.go@@ -2,6 +2,8 @@ package zapierwebhookimport ("context"+ "fmt"+ "io""net/http""strings"@@ -44,17 +46,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "POST", "https://hooks.zapier.com/hooks/catch/"+resMatch, nil)- if err != nil {- continue- }- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZapierWebhook(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -70,3 +64,29 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zapier is an automation tool that connects your apps and services. Zapier webhooks can be used to automate workflows by sending HTTP requests to a unique URL."}++func verifyZapierWebhook(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://hooks.zapier.com/hooks/catch/"+key, http.NoBody)+ if err != nil {+ return false, err+ }++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zendeskapi/zendeskapi.go b/pkg/detectors/zendeskapi/zendeskapi.goindex 30b1357b3..e1efe925a 100644--- a/pkg/detectors/zendeskapi/zendeskapi.go+++ b/pkg/detectors/zendeskapi/zendeskapi.go@@ -2,10 +2,9 @@ package zendeskapiimport ("context"- b64 "encoding/base64""fmt"+ "io""net/http"- "strings"regexp "github.com/wasilibs/go-re2"@@ -13,7 +12,7 @@ import ("github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb")-type Scanner struct{+type Scanner struct {detectors.DefaultMultiPartCredentialProvider}@@ -25,7 +24,7 @@ var (token = regexp.MustCompile(detectors.PrefixRegex([]string{"zendesk"}) + `([A-Za-z0-9_-]{40})`)email = regexp.MustCompile(`\b([a-zA-Z-0-9-]{5,16}\@[a-zA-Z-0-9]{4,16}\.[a-zA-Z-0-9]{3,6})\b`)- domain = regexp.MustCompile(`\b([a-zA-Z-0-9]{3,16}\.zendesk\.com)\b`)+ domain = regexp.MustCompile(`\b([a-zA-Z-0-9]{3,25}\.zendesk\.com)\b`))// Keywords are used for efficiently pre-filtering chunks.@@ -38,40 +37,32 @@ func (s Scanner) Keywords() []string {func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {dataStr := string(data)- tokens := token.FindAllStringSubmatch(dataStr, -1)- domains := domain.FindAllStringSubmatch(dataStr, -1)- emails := email.FindAllStringSubmatch(dataStr, -1)+ var uniqueEmails, uniqueTokens, uniqueDomains = make(map[string]struct{}), make(map[string]struct{}), make(map[string]struct{})- for _, token := range tokens {- resMatch := strings.TrimSpace(token[1])+ for _, match := range email.FindAllStringSubmatch(dataStr, -1) {+ uniqueEmails[match[1]] = struct{}{}+ }- var resDomain string- for _, domain := range domains {- resDomain = strings.TrimSpace(domain[1])+ for _, match := range token.FindAllStringSubmatch(dataStr, -1) {+ uniqueTokens[match[1]] = struct{}{}+ }- for _, email := range emails {- resEmail := strings.TrimSpace(email[1])+ for _, match := range domain.FindAllStringSubmatch(dataStr, -1) {+ uniqueDomains[match[1]] = struct{}{}+ }+ for token := range uniqueTokens {+ for email := range uniqueEmails {+ for domain := range uniqueDomains {s1 := detectors.Result{DetectorType: detectorspb.DetectorType_ZendeskApi,- Raw: []byte(resMatch),+ Raw: []byte(token),}if verify {- data := fmt.Sprintf("%s/token:%s", resEmail, resMatch)- sEnc := b64.StdEncoding.EncodeToString([]byte(data))- req, err := http.NewRequestWithContext(ctx, "GET", "https://"+resDomain+"/api/v2/users.json", nil)- if err != nil {- continue- }- req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc))- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZendesk(ctx, client, email, token, domain)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, token)}results = append(results, s1)@@ -91,3 +82,31 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zendesk is a customer service platform. Zendesk API tokens can be used to access and modify customer service data."}++func verifyZendesk(ctx context.Context, client *http.Client, email, token, domain string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://"+domain+"/api/v2/users.json", http.NoBody)+ if err != nil {+ return false, err+ }++ // docs: https://developer.zendesk.com/api-reference/introduction/security-and-auth/+ req.SetBasicAuth(email+"/token", token)+ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized, http.StatusNotFound:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zenkitapi/zenkitapi.go b/pkg/detectors/zenkitapi/zenkitapi.goindex 8c5c6e6d7..3b3450b7a 100644--- a/pkg/detectors/zenkitapi/zenkitapi.go+++ b/pkg/detectors/zenkitapi/zenkitapi.go@@ -2,10 +2,13 @@ package zenkitapiimport ("context"- regexp "github.com/wasilibs/go-re2"+ "fmt"+ "io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -44,18 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", "https://base.zenkit.com/api/v1/users/me", nil)- if err != nil {- continue- }- req.Header.Add("Zenkit-API-Key", resMatch)- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZenkitKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -71,3 +65,31 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zenkit is a collaborative SaaS platform for project management, database building, and more. Zenkit API keys can be used to access and interact with Zenkit's services programmatically."}++func verifyZenkitKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://base.zenkit.com/api/v1/users/me", http.NoBody)+ if err != nil {+ return false, err+ }++ req.Header.Add("Zenkit-API-Key", key)++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zenrows/zenrows.go b/pkg/detectors/zenrows/zenrows.goindex e7be3b50d..3ceb3c8f6 100644--- a/pkg/detectors/zenrows/zenrows.go+++ b/pkg/detectors/zenrows/zenrows.go@@ -3,10 +3,12 @@ package zenrowsimport ("context""fmt"- regexp "github.com/wasilibs/go-re2"+ "io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -45,17 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.zenrows.com/v1/?apikey=%s&url=https://httpbin.org/anything", resMatch), nil)- if err != nil {- continue- }- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZenrowsKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -71,3 +65,29 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "ZenRows is a web scraping API service that allows users to extract data from websites. ZenRows API keys can be used to access and scrape web data."}++func verifyZenrowsKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://api.zenrows.com/v1/?apikey=%s&url=https://httpbin.org/anything", key), http.NoBody)+ if err != nil {+ return false, err+ }++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized, http.StatusPaymentRequired: // docs: https://docs.zenrows.com/api-error-codes#402-payment-required+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zenscrape/zenscrape.go b/pkg/detectors/zenscrape/zenscrape.goindex c66b4d446..363455879 100644--- a/pkg/detectors/zenscrape/zenscrape.go+++ b/pkg/detectors/zenscrape/zenscrape.go@@ -2,6 +2,8 @@ package zenscrapeimport ("context"+ "fmt"+ "io""net/http""strings"@@ -45,18 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", "https://app.zenscrape.com/api/v1/status", nil)- if err != nil {- continue- }- req.Header.Add("apikey", resMatch)- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if (res.StatusCode >= 200 && res.StatusCode < 300) || res.StatusCode == 429 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZenScrapeKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -72,3 +65,31 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zenscrape is a web scraping service that provides an API to extract data from websites. Zenscrape API keys can be used to access and scrape data from web pages."}++func verifyZenScrapeKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://app.zenscrape.com/api/v1/status", http.NoBody)+ if err != nil {+ return false, err+ }++ req.Header.Add("apikey", key)++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK, http.StatusTooManyRequests:+ return true, nil+ case http.StatusUnauthorized, http.StatusForbidden:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zenserp/zenserp.go b/pkg/detectors/zenserp/zenserp.goindex 3b3504aca..19d66704c 100644--- a/pkg/detectors/zenserp/zenserp.go+++ b/pkg/detectors/zenserp/zenserp.go@@ -2,12 +2,14 @@ package zenserpimport ("context"- regexp "github.com/wasilibs/go-re2"+ "fmt""io""net/http""strings""time"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -45,22 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", `https://app.zenserp.com/api/v2/search?q="test"&apikey=`+resMatch, nil)- if err != nil {- continue- }- 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 strings.Contains(body, "query") {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZenSerpKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -76,3 +65,39 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zenserp is a service that provides SERP (Search Engine Results Page) API. Zenserp API keys can be used to access search engine data programmatically."}++func verifyZenSerpKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, `https://app.zenserp.com/api/v2/search?q="test"&apikey=`+key, http.NoBody)+ if err != nil {+ return false, err+ }++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ bodyBytes, err := io.ReadAll(resp.Body)+ if err != nil {+ return false, err+ }++ body := string(bodyBytes)+ if strings.Contains(body, "query") {+ return true, nil+ }++ return false, nil+ case http.StatusUnauthorized, http.StatusForbidden:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zeplin/zeplin.go b/pkg/detectors/zeplin/zeplin.goindex 2f731c40c..feb516c59 100644--- a/pkg/detectors/zeplin/zeplin.go+++ b/pkg/detectors/zeplin/zeplin.go@@ -3,10 +3,12 @@ package zeplinimport ("context""fmt"- regexp "github.com/wasilibs/go-re2"+ "io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -45,18 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", "https://api.zeplin.dev/v1/users/me", nil)- if err != nil {- continue- }- req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch))- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZeplinKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -72,3 +65,31 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zeplin is a collaboration app for UI designers and front-end developers. Zeplin API keys can be used to access and modify project data."}++func verifyZeplinKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.zeplin.dev/v1/users/me", http.NoBody)+ if err != nil {+ return false, err+ }++ req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", key))++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zerobounce/zerobounce.go b/pkg/detectors/zerobounce/zerobounce.goindex 42902753e..727297048 100644--- a/pkg/detectors/zerobounce/zerobounce.go+++ b/pkg/detectors/zerobounce/zerobounce.go@@ -2,11 +2,13 @@ package zerobounceimport ("context"- regexp "github.com/wasilibs/go-re2"+ "fmt""io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -45,23 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", "https://api.zerobounce.net/v1/[email protected]&api_key="+resMatch, nil)- if err != nil {- continue- }- 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 strings.Contains(body, "found") {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZeroBounceKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -77,3 +65,38 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zerobounce is an email validation and verification service. Zerobounce API keys can be used to access and utilize this service."}++func verifyZeroBounceKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.zerobounce.net/v2/[email protected]&api_key="+key, http.NoBody)+ if err != nil {+ return false, err+ }++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ bodyBytes, err := io.ReadAll(resp.Body)+ if err != nil {+ return false, err+ }++ if strings.Contains(string(bodyBytes), "found") {+ return true, nil+ }++ return false, nil+ case http.StatusUnauthorized, http.StatusNotFound:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zerotier/zerotier.go b/pkg/detectors/zerotier/zerotier.goindex 51296922d..a227be6d5 100644--- a/pkg/detectors/zerotier/zerotier.go+++ b/pkg/detectors/zerotier/zerotier.go@@ -3,10 +3,12 @@ package zerotierimport ("context""fmt"- regexp "github.com/wasilibs/go-re2"+ "io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -46,30 +48,14 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- // API docs: https://docs.zerotier.com/central/v1/client := s.clientif client == nil {client = defaultClient}- req, err := http.NewRequestWithContext(ctx, "GET", "https://api.zerotier.com/api/v1/network", nil)- if err != nil {- continue- }- req.Header.Add("Authorization", fmt.Sprintf("token %s", 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 res.StatusCode == 401 {- // The secret is determinately not verified (nothing to do)- } else {- err = fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)- s1.SetVerificationError(err, resMatch)- }- } else {- s1.SetVerificationError(err, resMatch)- }++ isVerified, verificationErr := verifyZerotierKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -85,3 +71,31 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "ZeroTier is a network virtualization technology that provides secure and flexible network connections. ZeroTier API keys can be used to manage and control these network connections."}++// API docs: https://docs.zerotier.com/central/v1/+func verifyZerotierKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.zerotier.com/api/v1/network", http.NoBody)+ if err != nil {+ return false, err+ }++ req.Header.Add("Authorization", fmt.Sprintf("token %s", key))+ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zerotier/zerotier_integration_test.go b/pkg/detectors/zerotier/zerotier_integration_test.goindex e770ca68f..24c37dcfe 100644--- a/pkg/detectors/zerotier/zerotier_integration_test.go+++ b/pkg/detectors/zerotier/zerotier_integration_test.go@@ -102,7 +102,7 @@ func TestZerotier_FromChunk(t *testing.T) {t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError())}}- ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError")+ ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError", "primarySecret")if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" {t.Errorf("Zerotier.FromData() %s diff: (-got +want)\n%s", tt.name, diff)}diff --git a/pkg/detectors/zipapi/zipapi.go b/pkg/detectors/zipapi/zipapi.goindex e95dce05a..c4e4c716f 100644--- a/pkg/detectors/zipapi/zipapi.go+++ b/pkg/detectors/zipapi/zipapi.go@@ -2,8 +2,8 @@ package zipapiimport ("context"- b64 "encoding/base64""fmt"+ "io""net/http""strings"@@ -25,7 +25,7 @@ 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{"zipapi"}) + `\b([0-9a-z]{32})\b`)+ keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"zipapi"}) + `\b([A-Z0-9a-z]{32})\b`)emailPat = regexp.MustCompile(common.EmailPattern)pwordPat = regexp.MustCompile(detectors.PrefixRegex([]string{"zipapi"}) + `\b([a-zA-Z0-9!=@#$%^]{7,})`))@@ -62,21 +62,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- data := fmt.Sprintf("%s:%s", emailMatch, passMatch)- sEnc := b64.StdEncoding.EncodeToString([]byte(data))- req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://service.zipapi.us/zipcode/90210/?X-API-KEY=%s", keyMatch), nil)- if err != nil {- continue- }- req.Header.Add("Content-Type", "application/json")- req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc))- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZipAPI(ctx, client, emailMatch, keyMatch, passMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, keyMatch)}results = append(results, s1)@@ -94,3 +82,32 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "ZipAPI is a service used to retrieve ZIP code information. ZipAPI keys can be used to access and retrieve this information from their API."}++func verifyZipAPI(ctx context.Context, client *http.Client, email, key, password string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://service.zipapi.us/zipcode/90210/?X-API-KEY=%s", key), http.NoBody)+ if err != nil {+ return false, err+ }++ req.Header.Add("Content-Type", "application/json")+ req.SetBasicAuth(email, password)++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized, http.StatusForbidden:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zipbooks/zipbooks.go b/pkg/detectors/zipbooks/zipbooks.goindex 9fc5fb9a8..d67ef9bda 100644--- a/pkg/detectors/zipbooks/zipbooks.go+++ b/pkg/detectors/zipbooks/zipbooks.go@@ -3,6 +3,7 @@ package zipbooksimport ("context""fmt"+ "io""net/http""strings"@@ -55,19 +56,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- payload := strings.NewReader(fmt.Sprintf(`{"email": "%s", "password": "%s"}`, emailMatch, resPword))- req, err := http.NewRequestWithContext(ctx, "POST", "https://api.zipbooks.com/v2/auth/login", payload)- if err != nil {- continue- }- req.Header.Add("Content-Type", "application/json")- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZipBooksCredentials(ctx, client, emailMatch, resPword)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, emailMatch)}results = append(results, s1)@@ -83,3 +74,32 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "ZipBooks is an accounting software service that allows businesses to manage their finances online. The credentials can be used to access and manage financial data."}++func verifyZipBooksCredentials(ctx context.Context, client *http.Client, email, password string) (bool, error) {+ payload := strings.NewReader(fmt.Sprintf(`{"email": "%s", "password": "%s"}`, email, password))+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.zipbooks.com/v2/auth/login", payload)+ if err != nil {+ return false, err+ }++ req.Header.Add("Content-Type", "application/json")++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized, http.StatusNotFound: // username or password not found+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zipcodeapi/zipcodeapi.go b/pkg/detectors/zipcodeapi/zipcodeapi.goindex 406f7ce45..b8b0083a6 100644--- a/pkg/detectors/zipcodeapi/zipcodeapi.go+++ b/pkg/detectors/zipcodeapi/zipcodeapi.go@@ -3,10 +3,12 @@ package zipcodeapiimport ("context""fmt"- regexp "github.com/wasilibs/go-re2"+ "io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -45,17 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://www.zipcodeapi.com/rest/%s/distance.json/71601/72959/mile", resMatch), nil)- if err != nil {- continue- }- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZipCodeAPIKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -71,3 +65,29 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "ZipCodeAPI provides a service for retrieving zip code information and calculating distances between zip codes. ZipCodeAPI keys can be used to access these services."}++func verifyZipCodeAPIKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://www.zipcodeapi.com/rest/%s/distance.json/71601/72959/mile", key), http.NoBody)+ if err != nil {+ return false, err+ }++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zipcodebase/zipcodebase.go b/pkg/detectors/zipcodebase/zipcodebase.goindex c176e033f..ebcdf18bd 100644--- a/pkg/detectors/zipcodebase/zipcodebase.go+++ b/pkg/detectors/zipcodebase/zipcodebase.go@@ -2,6 +2,8 @@ package zipcodebaseimport ("context"+ "fmt"+ "io""net/http""strings"@@ -45,19 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", "https://app.zipcodebase.com/api/v1/search?codes=10005,10006", nil)- if err != nil {- continue- }- req.Header.Add("Accept", "application/vnd.zipcodebase+json; version=3")- req.Header.Add("apikey", resMatch)- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZipCodeBaseKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr)}results = append(results, s1)@@ -73,3 +65,32 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "Zipcodebase is a service that provides access to a database of postal codes. The API keys can be used to query this database for information related to postal codes."}++func verifyZipCodeBaseKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://app.zipcodebase.com/api/v1/search?codes=10005,10006", http.NoBody)+ if err != nil {+ return false, err+ }++ req.Header.Add("Accept", "application/vnd.zipcodebase+json; version=3")+ req.Header.Add("apikey", key)++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized, http.StatusForbidden:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zohocrm/zohocrm.go b/pkg/detectors/zohocrm/zohocrm.goindex 0ede84e42..bab3e9423 100644--- a/pkg/detectors/zohocrm/zohocrm.go+++ b/pkg/detectors/zohocrm/zohocrm.go@@ -73,7 +73,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (resultfunc verifyMatch(ctx context.Context, client *http.Client, token string) (bool, error) {endpoint := "https://www.zohoapis.com/crm/v7/Leads?fields=Email&per_page=1"- req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, http.NoBody)if err != nil {return false, err}diff --git a/pkg/detectors/zonkafeedback/zonkafeedback.go b/pkg/detectors/zonkafeedback/zonkafeedback.goindex 287b939b0..bee7d6ce5 100644--- a/pkg/detectors/zonkafeedback/zonkafeedback.go+++ b/pkg/detectors/zonkafeedback/zonkafeedback.go@@ -2,10 +2,13 @@ package zonkafeedbackimport ("context"- regexp "github.com/wasilibs/go-re2"+ "fmt"+ "io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -44,18 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", "https://app-us1.zonkafeedback.com/responses?page=1&limit=25&startDate=2020-05-02&endDate=2020-05-09", nil)- if err != nil {- continue- }- req.Header.Add("Z-API-TOKEN", resMatch)- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {- s1.Verified = true- }- }+ isVerified, verificationErr := verifyZonkaFeedbackKey(ctx, client, resMatch)+ s1.Verified = isVerified+ s1.SetVerificationError(verificationErr, resMatch)}results = append(results, s1)@@ -71,3 +65,32 @@ func (s Scanner) Type() detectorspb.DetectorType {func (s Scanner) Description() string {return "ZonkaFeedback is a platform for collecting and analyzing customer feedback. The API token can be used to access and manage feedback data."}++func verifyZonkaFeedbackKey(ctx context.Context, client *http.Client, key string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet,+ "https://app-us1.zonkafeedback.com/responses?page=1&limit=25&startDate=2020-05-02&endDate=2020-05-09", http.NoBody)+ if err != nil {+ return false, err+ }++ req.Header.Add("Z-API-TOKEN", key)++ resp, err := client.Do(req)+ if err != nil {+ return false, err+ }++ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ switch resp.StatusCode {+ case http.StatusOK:+ return true, nil+ case http.StatusUnauthorized:+ return false, nil+ default:+ return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)+ }+}diff --git a/pkg/detectors/zulipchat/zulipchat.go b/pkg/detectors/zulipchat/zulipchat.goindex 7388e96a9..bdd5da149 100644--- a/pkg/detectors/zulipchat/zulipchat.go+++ b/pkg/detectors/zulipchat/zulipchat.go@@ -86,7 +86,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}func verifyResult(ctx context.Context, client *http.Client, domain, id, key string) (bool, error) {- req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://%s/api/v1/users", domain), nil)+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://%s/api/v1/users", domain), http.NoBody)if err != nil {return false, err}