Skip to content

Find, verify, and analyze leaked credentials

Add SolarWinds Observability detector (#5199)

Ahsan-Sarbazf9daad8e651c
diff --git a/main.go b/main.go
index 4d62eec96..6513fe5f1 100644
--- a/main.go
+++ b/main.go
@@ -572,6 +572,7 @@ func run(state overseer.State, logSync func() error) {
feature.NewRelicInsightsQueryKeyDetectorEnabled.Store(true)
feature.NewRelicMobileAppTokenDetectorEnabled.Store(true)
feature.MSTeamsWebhookV2DetectorEnabled.Store(true)
+ feature.SolarwindsDetectorEnabled.Store(true)
conf := &config.Config{}
if *configFilename != "" {
diff --git a/pkg/detectors/solarwindsobservability/solarwindsobservability.go b/pkg/detectors/solarwindsobservability/solarwindsobservability.go
new file mode 100644
index 000000000..e81c636d7
--- /dev/null
+++ b/pkg/detectors/solarwindsobservability/solarwindsobservability.go
@@ -0,0 +1,115 @@
+package solarwindsobservability
+
+import (
+ "context"
+ "fmt"
+ "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/detector_typepb"
+)
+
+type Scanner struct {
+ client *http.Client
+}
+
+var _ detectors.Detector = (*Scanner)(nil)
+
+var regions = []string{"na-01", "na-02", "eu-01", "ap-01"}
+
+var (
+ defaultClient = common.SaneHttpClient()
+ keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"solarwinds"}) + `\b([0-9a-zA-Z_-]{71})\b`)
+)
+
+func (s Scanner) Keywords() []string {
+ return []string{"solarwinds"}
+}
+
+func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
+ dataStr := string(data)
+
+ matches := keyPat.FindAllStringSubmatch(dataStr, -1)
+
+ for _, match := range matches {
+ resMatch := strings.TrimSpace(match[1])
+
+ s1 := detectors.Result{
+ DetectorType: detector_typepb.DetectorType_SolarWindsObservability,
+ Raw: []byte(resMatch),
+ SecretParts: map[string]string{"key": resMatch},
+ }
+
+ if verify {
+ client := s.client
+ if client == nil {
+ client = defaultClient
+ }
+ isVerified, region, verificationErr := verifySolarWindsObservability(ctx, client, resMatch)
+ s1.Verified = isVerified
+ s1.SetVerificationError(verificationErr, resMatch)
+ if region != "" {
+ s1.SecretParts["region"] = region
+ s1.ExtraData = map[string]string{"region": region}
+ }
+ }
+
+ results = append(results, s1)
+ }
+
+ return results, nil
+}
+
+// verifySolarWindsObservability tries the token against each regional endpoint and returns the
+// region it verified against, if any.
+func verifySolarWindsObservability(ctx context.Context, client *http.Client, token string) (bool, string, error) {
+ var lastErr error
+ for _, region := range regions {
+ url := fmt.Sprintf("https://api.%s.cloud.solarwinds.com/v1/metrics", region)
+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
+ if err != nil {
+ lastErr = err
+ continue
+ }
+ req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
+
+ res, err := client.Do(req)
+ if err != nil {
+ lastErr = err
+ continue
+ }
+
+ verified, regionErr := func() (bool, error) {
+ defer func() { _ = res.Body.Close() }()
+ switch res.StatusCode {
+ case http.StatusOK:
+ return true, nil
+ case http.StatusUnauthorized:
+ return false, nil
+ default:
+ return false, fmt.Errorf("unexpected HTTP response status %d from region %s", res.StatusCode, region)
+ }
+ }()
+
+ if verified {
+ return true, region, nil
+ }
+ if regionErr != nil {
+ lastErr = regionErr
+ }
+ }
+
+ return false, "", lastErr
+}
+
+func (s Scanner) Type() detector_typepb.DetectorType {
+ return detector_typepb.DetectorType_SolarWindsObservability
+}
+
+func (s Scanner) Description() string {
+ return "SolarWinds Observability is a cloud-based SaaS observability platform (successor to AppOptics). Its API tokens can be used to access and manage monitoring data and configurations."
+}
diff --git a/pkg/detectors/solarwindsobservability/solarwindsobservability_integration_test.go b/pkg/detectors/solarwindsobservability/solarwindsobservability_integration_test.go
new file mode 100644
index 000000000..959526778
--- /dev/null
+++ b/pkg/detectors/solarwindsobservability/solarwindsobservability_integration_test.go
@@ -0,0 +1,167 @@
+//go:build detectors
+// +build detectors
+
+package solarwindsobservability
+
+import (
+ "context"
+ "fmt"
+ "testing"
+ "time"
+
+ "github.com/google/go-cmp/cmp"
+ "github.com/google/go-cmp/cmp/cmpopts"
+
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
+)
+
+func TestSolarWindsObservability_FromChunk(t *testing.T) {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
+ defer cancel()
+ testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors6")
+ if err != nil {
+ t.Fatalf("could not get test secrets from GCP: %s", err)
+ }
+ secret := testSecrets.MustGetField("SOLARWINDSOBSERVABILITY")
+ inactiveSecret := testSecrets.MustGetField("SOLARWINDSOBSERVABILITY_INACTIVE")
+
+ type args struct {
+ ctx context.Context
+ data []byte
+ verify bool
+ }
+ tests := []struct {
+ name string
+ s Scanner
+ args args
+ want []detectors.Result
+ wantErr bool
+ }{
+ {
+ name: "found, verified",
+ s: Scanner{},
+ args: args{
+ ctx: context.Background(),
+ data: []byte(fmt.Sprintf("You can find a solarwinds secret %s within", secret)),
+ verify: true,
+ },
+ want: []detectors.Result{
+ {
+ DetectorType: detector_typepb.DetectorType_SolarWindsObservability,
+ Verified: true,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "found, real secrets, verification error due to timeout",
+ s: Scanner{client: common.SaneHttpClientTimeOut(1 * time.Microsecond)},
+ args: args{
+ ctx: context.Background(),
+ data: []byte(fmt.Sprintf("You can find a solarwinds secret %s within", secret)),
+ verify: true,
+ },
+ want: func() []detectors.Result {
+ r := detectors.Result{
+ DetectorType: detector_typepb.DetectorType_SolarWindsObservability,
+ Verified: false,
+ }
+ r.SetVerificationError(context.DeadlineExceeded)
+ return []detectors.Result{r}
+ }(),
+ wantErr: false,
+ },
+ {
+ name: "found, real secrets, verification error due to unexpected api surface",
+ s: Scanner{client: common.ConstantResponseHttpClient(500, "{}")},
+ args: args{
+ ctx: context.Background(),
+ data: []byte(fmt.Sprintf("You can find a solarwinds secret %s within", secret)),
+ verify: true,
+ },
+ want: func() []detectors.Result {
+ r := detectors.Result{
+ DetectorType: detector_typepb.DetectorType_SolarWindsObservability,
+ Verified: false,
+ }
+ r.SetVerificationError(fmt.Errorf("unexpected HTTP response status 500 from region ap-01"))
+ return []detectors.Result{r}
+ }(),
+ wantErr: false,
+ },
+ {
+ name: "found, unverified",
+ s: Scanner{},
+ args: args{
+ ctx: context.Background(),
+ data: []byte(fmt.Sprintf("You can find a solarwinds secret %s within but not valid", inactiveSecret)),
+ verify: true,
+ },
+ want: []detectors.Result{
+ {
+ DetectorType: detector_typepb.DetectorType_SolarWindsObservability,
+ Verified: false,
+ },
+ },
+ wantErr: false,
+ },
+ {
+ name: "not found",
+ s: Scanner{},
+ args: args{
+ ctx: context.Background(),
+ data: []byte("You cannot find the secret within"),
+ verify: true,
+ },
+ want: nil,
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := tt.s.FromData(tt.args.ctx, tt.args.verify, tt.args.data)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("SolarWindsObservability.FromData() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ for i := range got {
+ if len(got[i].Raw) == 0 {
+ t.Fatalf("no raw secret present: \n %+v", got[i])
+ }
+ gotErr := ""
+ if got[i].VerificationError() != nil {
+ gotErr = got[i].VerificationError().Error()
+ }
+ wantErr := ""
+ if tt.want[i].VerificationError() != nil {
+ wantErr = tt.want[i].VerificationError().Error()
+ }
+ if gotErr != wantErr {
+ t.Fatalf("wantVerificationError = %v, verification error = %v", tt.want[i].VerificationError(), got[i].VerificationError())
+ }
+ }
+ ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "RawV2", "verificationError", "SecretParts", "ExtraData")
+ if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" {
+ t.Errorf("SolarWindsObservability.FromData() %s diff: (-got +want)\n%s", tt.name, diff)
+ }
+ })
+ }
+}
+
+func BenchmarkFromData(benchmark *testing.B) {
+ ctx := context.Background()
+ s := Scanner{}
+ for name, data := range detectors.MustGetBenchmarkData() {
+ benchmark.Run(name, func(b *testing.B) {
+ b.ResetTimer()
+ for n := 0; n < b.N; n++ {
+ _, err := s.FromData(ctx, false, data)
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+ })
+ }
+}
diff --git a/pkg/detectors/solarwindsobservability/solarwindsobservability_test.go b/pkg/detectors/solarwindsobservability/solarwindsobservability_test.go
new file mode 100644
index 000000000..5161d6e74
--- /dev/null
+++ b/pkg/detectors/solarwindsobservability/solarwindsobservability_test.go
@@ -0,0 +1,108 @@
+package solarwindsobservability
+
+import (
+ "context"
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+ "github.com/stretchr/testify/require"
+
+ "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/engine/ahocorasick"
+)
+
+func TestSolarWindsObservability_Pattern(t *testing.T) {
+ d := Scanner{}
+ ahoCorasickCore := ahocorasick.NewAhoCorasickCore([]detectors.Detector{d})
+
+ tests := []struct {
+ name string
+ input string
+ want []string
+ }{
+ {
+ name: "valid pattern",
+ input: `
+ func validateSolarWindsKey() bool {
+ solarwindsKey := "Xwl4ViaAFDLrAmFX9g1blkUVC5dJj2he3a1tzkpJ4-PznQukQruRjqMFbEG73L92LJyBGMZ"
+ log.Println("Checking API key status...")
+
+ if !isActive(solarwindsKey) {
+ log.Println("API key is inactive or invalid.")
+ return false
+ }
+
+ log.Println("API key is valid and active.")
+ return true
+ }`,
+ want: []string{"Xwl4ViaAFDLrAmFX9g1blkUVC5dJj2he3a1tzkpJ4-PznQukQruRjqMFbEG73L92LJyBGMZ"},
+ },
+ {
+ name: "valid pattern - xml",
+ input: `
+ <com.cloudbees.plugins.credentials.impl.StringCredentialsImpl>
+ <scope>GLOBAL</scope>
+ <id>{solarwinds}</id>
+ <secret>{AQAAABAAA zxsb8yzT0RbIJ1TAalB87LOVUcT1b4uEgvT4tXCcSqv_gcmlrx5aQRleHPDFKePjpHFof5J}</secret>
+ <description>configuration for production</description>
+ <creationDate>2023-05-18T14:32:10Z</creationDate>
+ <owner>jenkins-admin</owner>
+ </com.cloudbees.plugins.credentials.impl.StringCredentialsImpl>
+ `,
+ want: []string{"zxsb8yzT0RbIJ1TAalB87LOVUcT1b4uEgvT4tXCcSqv_gcmlrx5aQRleHPDFKePjpHFof5J"},
+ },
+ {
+ name: "invalid pattern",
+ input: `
+ func validateSolarWindsKey() bool {
+ solarwindsKey := "Xwl4ViaAFDLrAmFX9g1blkUVC5dJj2h:3a1tzkpJ43PznQukQruRjqMFbEG73L92LJyBGMZ"
+ log.Println("Checking API key status...")
+
+ if !isActive(solarwindsKey) {
+ log.Println("API key is inactive or invalid.")
+ return false
+ }
+
+ log.Println("API key is valid and active.")
+ return true
+ }`,
+ want: nil,
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ matchedDetectors := ahoCorasickCore.FindDetectorMatches([]byte(test.input))
+ if len(matchedDetectors) == 0 {
+ t.Errorf("test %q failed: expected keywords %v to be found in the input", test.name, d.Keywords())
+ return
+ }
+
+ results, err := d.FromData(context.Background(), false, []byte(test.input))
+ require.NoError(t, err)
+
+ if len(results) != len(test.want) {
+ t.Errorf("mismatch in result count: expected %d, got %d", len(test.want), len(results))
+ return
+ }
+
+ actual := make(map[string]struct{}, len(results))
+ for _, r := range results {
+ if len(r.RawV2) > 0 {
+ actual[string(r.RawV2)] = struct{}{}
+ } else {
+ actual[string(r.Raw)] = struct{}{}
+ }
+ }
+
+ expected := make(map[string]struct{}, len(test.want))
+ for _, v := range test.want {
+ expected[v] = struct{}{}
+ }
+
+ if diff := cmp.Diff(expected, actual); diff != "" {
+ t.Errorf("%s diff: (-want +got)\n%s", test.name, diff)
+ }
+ })
+ }
+}
diff --git a/pkg/engine/defaults/defaults.go b/pkg/engine/defaults/defaults.go
index 9e908807d..75d7b6909 100644
--- a/pkg/engine/defaults/defaults.go
+++ b/pkg/engine/defaults/defaults.go
@@ -728,6 +728,7 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/snipcart"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/snowflake"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/snykkey"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/detectors/solarwindsobservability"
sonarcloudv1 "github.com/trufflesecurity/trufflehog/v3/pkg/detectors/sonarcloud/v1"
sonarcloudv2 "github.com/trufflesecurity/trufflehog/v3/pkg/detectors/sonarcloud/v2"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors/sourcegraph"
@@ -1649,6 +1650,7 @@ func buildDetectorList() []detectors.Detector {
&snipcart.Scanner{},
&snowflake.Scanner{},
&snykkey.Scanner{},
+ &solarwindsobservability.Scanner{},
&sonarcloudv1.Scanner{},
&sonarcloudv2.Scanner{},
&sourcegraph.Scanner{},
@@ -1888,6 +1890,8 @@ func buildDetectorList() []detectors.Detector {
return !feature.NewRelicMobileAppTokenDetectorEnabled.Load()
case *microsoftteamswebhookv2.Scanner:
return !feature.MSTeamsWebhookV2DetectorEnabled.Load()
+ case *solarwindsobservability.Scanner:
+ return !feature.SolarwindsDetectorEnabled.Load()
default:
return false
}
diff --git a/pkg/engine/defaults/defaults_test.go b/pkg/engine/defaults/defaults_test.go
index 523e838df..f64bebfe2 100644
--- a/pkg/engine/defaults/defaults_test.go
+++ b/pkg/engine/defaults/defaults_test.go
@@ -150,6 +150,7 @@ var excludedFromDefaultList = map[detector_typepb.DetectorType]struct{}{
detector_typepb.DetectorType_NewRelicUserKey: {},
detector_typepb.DetectorType_NewRelicInsightsQueryKey: {},
detector_typepb.DetectorType_NewRelicMobileAppToken: {},
+ detector_typepb.DetectorType_SolarWindsObservability: {},
// Reserved / special types.
detector_typepb.DetectorType_CustomRegex: {}, // added dynamically via engine config, not via buildDetectorList()
diff --git a/pkg/feature/feature.go b/pkg/feature/feature.go
index 613b296c2..e9d8e0408 100644
--- a/pkg/feature/feature.go
+++ b/pkg/feature/feature.go
@@ -49,6 +49,7 @@ var (
NewRelicInsightsQueryKeyDetectorEnabled atomic.Bool
NewRelicMobileAppTokenDetectorEnabled atomic.Bool
MSTeamsWebhookV2DetectorEnabled atomic.Bool
+ SolarwindsDetectorEnabled atomic.Bool
)
type AtomicString struct {
diff --git a/pkg/pb/detector_typepb/detector_type.pb.go b/pkg/pb/detector_typepb/detector_type.pb.go
index d2f83c1d7..640c779a3 100644
--- a/pkg/pb/detector_typepb/detector_type.pb.go
+++ b/pkg/pb/detector_typepb/detector_type.pb.go
@@ -1124,6 +1124,7 @@ const (
DetectorType_NewRelicUserKey DetectorType = 1066
DetectorType_NewRelicInsightsQueryKey DetectorType = 1067
DetectorType_NewRelicMobileAppToken DetectorType = 1068
+ DetectorType_SolarWindsObservability DetectorType = 1069
)
// Enum value maps for DetectorType.
@@ -2194,6 +2195,7 @@ var (
1066: "NewRelicUserKey",
1067: "NewRelicInsightsQueryKey",
1068: "NewRelicMobileAppToken",
+ 1069: "SolarWindsObservability",
}
DetectorType_value = map[string]int32{
"Alibaba": 0,
@@ -3261,6 +3263,7 @@ var (
"NewRelicUserKey": 1066,
"NewRelicInsightsQueryKey": 1067,
"NewRelicMobileAppToken": 1068,
+ "SolarWindsObservability": 1069,
}
)
@@ -3296,7 +3299,7 @@ var File_detector_type_proto protoreflect.FileDescriptor
var file_detector_type_proto_rawDesc = []byte{
0x0a, 0x13, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0d, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x5f,
- 0x74, 0x79, 0x70, 0x65, 0x2a, 0xd5, 0x8b, 0x01, 0x0a, 0x0c, 0x44, 0x65, 0x74, 0x65, 0x63, 0x74,
+ 0x74, 0x79, 0x70, 0x65, 0x2a, 0xf3, 0x8b, 0x01, 0x0a, 0x0c, 0x44, 0x65, 0x74, 0x65, 0x63, 0x74,
0x6f, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x41, 0x6c, 0x69, 0x62, 0x61, 0x62,
0x61, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x4d, 0x51, 0x50, 0x10, 0x01, 0x12, 0x07, 0x0a,
0x03, 0x41, 0x57, 0x53, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x7a, 0x75, 0x72, 0x65, 0x10,
@@ -4413,12 +4416,14 @@ var file_detector_type_proto_rawDesc = []byte{
0x08, 0x12, 0x1d, 0x0a, 0x18, 0x4e, 0x65, 0x77, 0x52, 0x65, 0x6c, 0x69, 0x63, 0x49, 0x6e, 0x73,
0x69, 0x67, 0x68, 0x74, 0x73, 0x51, 0x75, 0x65, 0x72, 0x79, 0x4b, 0x65, 0x79, 0x10, 0xab, 0x08,
0x12, 0x1b, 0x0a, 0x16, 0x4e, 0x65, 0x77, 0x52, 0x65, 0x6c, 0x69, 0x63, 0x4d, 0x6f, 0x62, 0x69,
- 0x6c, 0x65, 0x41, 0x70, 0x70, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x10, 0xac, 0x08, 0x42, 0x41, 0x5a,
- 0x3f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x72, 0x75, 0x66,
- 0x66, 0x6c, 0x65, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2f, 0x74, 0x72, 0x75, 0x66,
- 0x66, 0x6c, 0x65, 0x68, 0x6f, 0x67, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x62,
- 0x2f, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x70, 0x62,
- 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+ 0x6c, 0x65, 0x41, 0x70, 0x70, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x10, 0xac, 0x08, 0x12, 0x1c, 0x0a,
+ 0x17, 0x53, 0x6f, 0x6c, 0x61, 0x72, 0x57, 0x69, 0x6e, 0x64, 0x73, 0x4f, 0x62, 0x73, 0x65, 0x72,
+ 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x10, 0xad, 0x08, 0x42, 0x41, 0x5a, 0x3f, 0x67,
+ 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x72, 0x75, 0x66, 0x66, 0x6c,
+ 0x65, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2f, 0x74, 0x72, 0x75, 0x66, 0x66, 0x6c,
+ 0x65, 0x68, 0x6f, 0x67, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x62, 0x2f, 0x64,
+ 0x65, 0x74, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x70, 0x62, 0x62, 0x06,
+ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
diff --git a/proto/detector_type.proto b/proto/detector_type.proto
index dd1a33fb7..2982e7056 100644
--- a/proto/detector_type.proto
+++ b/proto/detector_type.proto
@@ -1070,4 +1070,5 @@ enum DetectorType {
NewRelicUserKey = 1066;
NewRelicInsightsQueryKey = 1067;
NewRelicMobileAppToken = 1068;
+ SolarWindsObservability = 1069;
}