From b3555f54192ace20533f2f86f5bb072c8a3f95d6 Mon Sep 17 00:00:00 2001 From: Dylan Ayrey Date: Mon, 2 Oct 2023 13:45:17 -0700 Subject: [PATCH] Adding Howtorotate Guides to TruffleHog (#1839) * adding how to rotate guides * Adding project ID to metadata * update key name, remove comments, and ensure always present --------- Co-authored-by: counter Co-authored-by: Dustin Decker --- .../airbrakeprojectkey/airbrakeprojectkey.go | 3 +++ .../airbrakeuserkey/airbrakeuserkey.go | 3 +++ pkg/detectors/aws/aws.go | 12 +++++++----- pkg/detectors/azure/azure.go | 4 ++++ pkg/detectors/gcp/gcp.go | 5 +++++ pkg/detectors/github/github.go | 17 +++++++++-------- pkg/detectors/github_oauth2/github_oauth2.go | 3 +++ pkg/detectors/github_old/github_old.go | 3 +++ pkg/detectors/githubapp/githubapp.go | 3 +++ pkg/detectors/gitlab/gitlab.go | 3 +++ pkg/detectors/gitlabv2/gitlab_v2.go | 3 +++ pkg/detectors/jiratoken/jiratoken.go | 3 +++ pkg/detectors/mailchimp/mailchimp.go | 3 +++ .../microsoftteamswebhook.go | 3 +++ pkg/detectors/mongodb/mongodb.go | 7 +++++-- pkg/detectors/netlify/netlify.go | 3 +++ pkg/detectors/npmtoken/npmtoken.go | 3 +++ pkg/detectors/npmtokenv2/npmtokenv2.go | 3 +++ pkg/detectors/sendbird/sendbird.go | 3 +++ pkg/detectors/sendgrid/sendgrid.go | 3 +++ pkg/detectors/slack/slack.go | 3 +++ pkg/detectors/slackwebhook/slackwebhook.go | 3 +++ pkg/detectors/square/square.go | 3 +++ pkg/detectors/stripe/stripe.go | 3 +++ pkg/detectors/twilio/twilio.go | 4 ++++ 25 files changed, 91 insertions(+), 15 deletions(-) diff --git a/pkg/detectors/airbrakeprojectkey/airbrakeprojectkey.go b/pkg/detectors/airbrakeprojectkey/airbrakeprojectkey.go index ac9eeeb5..97342081 100644 --- a/pkg/detectors/airbrakeprojectkey/airbrakeprojectkey.go +++ b/pkg/detectors/airbrakeprojectkey/airbrakeprojectkey.go @@ -55,6 +55,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result Raw: []byte(resMatch), RawV2: []byte(resMatch + resIdMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/airbrake/", + } if verify { payload := strings.NewReader(`{"environment":"production","username":"john","email":"john@smith.com","repository":"https://github.com/airbrake/airbrake","revision":"38748467ea579e7ae64f7815452307c9d05e05c5","version":"v2.0"}`) diff --git a/pkg/detectors/airbrakeuserkey/airbrakeuserkey.go b/pkg/detectors/airbrakeuserkey/airbrakeuserkey.go index 8718b311..06e26069 100644 --- a/pkg/detectors/airbrakeuserkey/airbrakeuserkey.go +++ b/pkg/detectors/airbrakeuserkey/airbrakeuserkey.go @@ -45,6 +45,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_AirbrakeUserKey, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/airbrake/", + } if verify { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.airbrake.io/api/v4/projects?key="+resMatch, nil) diff --git a/pkg/detectors/aws/aws.go b/pkg/detectors/aws/aws.go index ab0a3a93..0047f761 100644 --- a/pkg/detectors/aws/aws.go +++ b/pkg/detectors/aws/aws.go @@ -206,6 +206,10 @@ func (s scanner) verifyMatch(ctx context.Context, resIDMatch, resSecretMatch str client = defaultVerificationClient } + extraData := map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/aws/", + } + res, err := client.Do(req) if err == nil { defer res.Body.Close() @@ -213,11 +217,9 @@ func (s scanner) verifyMatch(ctx context.Context, resIDMatch, resSecretMatch str identityInfo := identityRes{} err := json.NewDecoder(res.Body).Decode(&identityInfo) if err == nil { - extraData := map[string]string{ - "account": identityInfo.GetCallerIdentityResponse.GetCallerIdentityResult.Account, - "user_id": identityInfo.GetCallerIdentityResponse.GetCallerIdentityResult.UserID, - "arn": identityInfo.GetCallerIdentityResponse.GetCallerIdentityResult.Arn, - } + extraData["account"] = identityInfo.GetCallerIdentityResponse.GetCallerIdentityResult.Account + extraData["user_id"] = identityInfo.GetCallerIdentityResponse.GetCallerIdentityResult.UserID + extraData["arn"] = identityInfo.GetCallerIdentityResponse.GetCallerIdentityResult.Arn return true, extraData, nil } else { return false, nil, err diff --git a/pkg/detectors/azure/azure.go b/pkg/detectors/azure/azure.go index 57868cb5..67a54e37 100644 --- a/pkg/detectors/azure/azure.go +++ b/pkg/detectors/azure/azure.go @@ -57,6 +57,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result RawV2: []byte(clientID[2] + clientSecret[2] + tenantID[2]), Redacted: clientID[2], } + // Set the RotationGuideURL in the ExtraData + s.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/azure/", + } if verify { cred := auth.NewClientCredentialsConfig(clientID[2], clientSecret[2], tenantID[2]) diff --git a/pkg/detectors/gcp/gcp.go b/pkg/detectors/gcp/gcp.go index 5ec70a94..8771fc25 100644 --- a/pkg/detectors/gcp/gcp.go +++ b/pkg/detectors/gcp/gcp.go @@ -87,6 +87,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result RawV2: credBytes, Redacted: creds.ClientEmail, } + // Set the RotationGuideURL in the ExtraData + s.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/gcp/", + "project": creds.ProjectID, + } if verify { credentials, err := google.CredentialsFromJSON(ctx, credBytes, "https://www.googleapis.com/auth/cloud-platform") diff --git a/pkg/detectors/github/github.go b/pkg/detectors/github/github.go index 82036681..804f90c1 100644 --- a/pkg/detectors/github/github.go +++ b/pkg/detectors/github/github.go @@ -68,6 +68,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result s1 := detectors.Result{ DetectorType: detectorspb.DetectorType_Github, Raw: []byte(token), + ExtraData: map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/github/", + }, } if verify { @@ -88,14 +91,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res.Body.Close() if err == nil { s1.Verified = true - s1.ExtraData = map[string]string{ - "username": userResponse.Login, - "url": userResponse.UserURL, - "account_type": userResponse.Type, - "site_admin": fmt.Sprintf("%t", userResponse.SiteAdmin), - "name": userResponse.Name, - "company": userResponse.Company, - } + s1.ExtraData["username"] = userResponse.Login + s1.ExtraData["url"] = userResponse.UserURL + s1.ExtraData["account_type"] = userResponse.Type + s1.ExtraData["site_admin"] = fmt.Sprintf("%t", userResponse.SiteAdmin) + s1.ExtraData["name"] = userResponse.Name + s1.ExtraData["company"] = userResponse.Company } } } diff --git a/pkg/detectors/github_oauth2/github_oauth2.go b/pkg/detectors/github_oauth2/github_oauth2.go index 6cd6f27e..a3678a39 100644 --- a/pkg/detectors/github_oauth2/github_oauth2.go +++ b/pkg/detectors/github_oauth2/github_oauth2.go @@ -54,6 +54,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result Raw: []byte(idMatch[1]), RawV2: []byte(idMatch[1] + secretMatch[1]), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/github/", + } config := &clientcredentials.Config{ ClientID: idMatch[1], diff --git a/pkg/detectors/github_old/github_old.go b/pkg/detectors/github_old/github_old.go index 21a4d040..57dbeae7 100644 --- a/pkg/detectors/github_old/github_old.go +++ b/pkg/detectors/github_old/github_old.go @@ -69,6 +69,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Github, Raw: []byte(token), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/github/", + } if verify { client := common.SaneHttpClient() diff --git a/pkg/detectors/githubapp/githubapp.go b/pkg/detectors/githubapp/githubapp.go index b99bd91a..ec1c0758 100644 --- a/pkg/detectors/githubapp/githubapp.go +++ b/pkg/detectors/githubapp/githubapp.go @@ -57,6 +57,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_GitHubApp, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/github/", + } if verify { signKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(resMatch)) diff --git a/pkg/detectors/gitlab/gitlab.go b/pkg/detectors/gitlab/gitlab.go index bf2aac0a..1188f3df 100644 --- a/pkg/detectors/gitlab/gitlab.go +++ b/pkg/detectors/gitlab/gitlab.go @@ -55,6 +55,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Gitlab, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/gitlab/", + } if verify { isVerified, verificationErr := s.verifyGitlab(ctx, resMatch) diff --git a/pkg/detectors/gitlabv2/gitlab_v2.go b/pkg/detectors/gitlabv2/gitlab_v2.go index dc8b237b..3084efa6 100644 --- a/pkg/detectors/gitlabv2/gitlab_v2.go +++ b/pkg/detectors/gitlabv2/gitlab_v2.go @@ -51,6 +51,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Gitlab, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/gitlab/", + } if verify { isVerified, verificationErr := s.verifyGitlab(ctx, resMatch) diff --git a/pkg/detectors/jiratoken/jiratoken.go b/pkg/detectors/jiratoken/jiratoken.go index 4c547251..3e495773 100644 --- a/pkg/detectors/jiratoken/jiratoken.go +++ b/pkg/detectors/jiratoken/jiratoken.go @@ -73,6 +73,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result Raw: []byte(resToken), RawV2: []byte(fmt.Sprintf("%s:%s:%s", resEmail, resToken, resDomain)), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/atlassian/", + } if verify { client := s.getClient() diff --git a/pkg/detectors/mailchimp/mailchimp.go b/pkg/detectors/mailchimp/mailchimp.go index 2535a15b..a206b070 100644 --- a/pkg/detectors/mailchimp/mailchimp.go +++ b/pkg/detectors/mailchimp/mailchimp.go @@ -42,6 +42,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Mailchimp, Raw: []byte(match), } + s.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/mailchimp/", + } if verify { datacenter := strings.Split(match, "-")[1] diff --git a/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go b/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go index d9deb9f9..5047d0bb 100644 --- a/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go +++ b/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go @@ -50,6 +50,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_MicrosoftTeamsWebhook, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/microsoftteams/", + } if verify { client := s.client diff --git a/pkg/detectors/mongodb/mongodb.go b/pkg/detectors/mongodb/mongodb.go index a9832123..a98d4dbf 100644 --- a/pkg/detectors/mongodb/mongodb.go +++ b/pkg/detectors/mongodb/mongodb.go @@ -2,8 +2,6 @@ package mongodb import ( "context" - "go.mongodb.org/mongo-driver/x/mongo/driver/auth" - "go.mongodb.org/mongo-driver/x/mongo/driver/topology" "regexp" "strings" "time" @@ -11,6 +9,8 @@ import ( "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/readpref" + "go.mongodb.org/mongo-driver/x/mongo/driver/auth" + "go.mongodb.org/mongo-driver/x/mongo/driver/topology" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" @@ -49,6 +49,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_MongoDB, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/mongo/", + } if verify { timeout := s.timeout diff --git a/pkg/detectors/netlify/netlify.go b/pkg/detectors/netlify/netlify.go index 7530501f..a0c75a46 100644 --- a/pkg/detectors/netlify/netlify.go +++ b/pkg/detectors/netlify/netlify.go @@ -45,6 +45,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Netlify, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/netlify/", + } if verify { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.netlify.com/api/v1/sites", nil) diff --git a/pkg/detectors/npmtoken/npmtoken.go b/pkg/detectors/npmtoken/npmtoken.go index 12bcad23..2a624045 100644 --- a/pkg/detectors/npmtoken/npmtoken.go +++ b/pkg/detectors/npmtoken/npmtoken.go @@ -47,6 +47,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_NpmToken, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/npm/", + } if verify { req, err := http.NewRequestWithContext(ctx, "GET", "https://registry.npmjs.org/-/whoami", nil) diff --git a/pkg/detectors/npmtokenv2/npmtokenv2.go b/pkg/detectors/npmtokenv2/npmtokenv2.go index 40e2fdf6..56b2ef03 100644 --- a/pkg/detectors/npmtokenv2/npmtokenv2.go +++ b/pkg/detectors/npmtokenv2/npmtokenv2.go @@ -48,6 +48,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_NpmToken, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/npm/", + } if verify { req, err := http.NewRequestWithContext(ctx, "GET", "https://registry.npmjs.org/-/whoami", nil) diff --git a/pkg/detectors/sendbird/sendbird.go b/pkg/detectors/sendbird/sendbird.go index 4963469c..f632083a 100644 --- a/pkg/detectors/sendbird/sendbird.go +++ b/pkg/detectors/sendbird/sendbird.go @@ -61,6 +61,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Sendbird, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/sendbird/", + } if verify { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api-%s.sendbird.com/v3/users", resAppIdMatch), nil) diff --git a/pkg/detectors/sendgrid/sendgrid.go b/pkg/detectors/sendgrid/sendgrid.go index 0a4045b7..9760cffe 100644 --- a/pkg/detectors/sendgrid/sendgrid.go +++ b/pkg/detectors/sendgrid/sendgrid.go @@ -48,6 +48,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_SendGrid, Raw: []byte(res), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/sendgrid/", + } if verify { // there are a few endpoints we can check, but templates seems the least sensitive. diff --git a/pkg/detectors/slack/slack.go b/pkg/detectors/slack/slack.go index 2f03cc35..9e105bb8 100644 --- a/pkg/detectors/slack/slack.go +++ b/pkg/detectors/slack/slack.go @@ -60,6 +60,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Slack, Raw: []byte(token), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/slack/", + } if verify { client := s.client if s.client == nil { diff --git a/pkg/detectors/slackwebhook/slackwebhook.go b/pkg/detectors/slackwebhook/slackwebhook.go index ed05c6d1..16bf24f0 100644 --- a/pkg/detectors/slackwebhook/slackwebhook.go +++ b/pkg/detectors/slackwebhook/slackwebhook.go @@ -49,6 +49,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_SlackWebhook, Raw: []byte(resMatch), } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/slack-webhook/", + } if verify { diff --git a/pkg/detectors/square/square.go b/pkg/detectors/square/square.go index f1ca436a..481ddb9f 100644 --- a/pkg/detectors/square/square.go +++ b/pkg/detectors/square/square.go @@ -49,6 +49,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Square, Raw: []byte(res), } + s.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/square/", + } if verify { // there are a few endpoints we can check, but templates seems the least sensitive. diff --git a/pkg/detectors/stripe/stripe.go b/pkg/detectors/stripe/stripe.go index 753ffad5..98c3a768 100644 --- a/pkg/detectors/stripe/stripe.go +++ b/pkg/detectors/stripe/stripe.go @@ -40,6 +40,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detectorspb.DetectorType_Stripe, Raw: []byte(match), } + s.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/stripe/", + } if verify { diff --git a/pkg/detectors/twilio/twilio.go b/pkg/detectors/twilio/twilio.go index 06236493..7a18c678 100644 --- a/pkg/detectors/twilio/twilio.go +++ b/pkg/detectors/twilio/twilio.go @@ -54,6 +54,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result Redacted: sid, } + s1.ExtraData = map[string]string{ + "rotation_guide": "https://howtorotate.com/docs/tutorials/twilio/", + } + if verify { client = s.client if client == nil {