Skip to content

Find, verify, and analyze leaked credentials

MaxMind detector uses the right endpoint (#2577)

faktas272fb2b9deb99
diff --git a/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2.go b/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2.go
index 4815a8565..e6209a0d1 100644
--- a/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2.go
+++ b/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
+ "net/url"
"regexp"
"strings"
@@ -20,7 +21,6 @@ var _ detectors.Detector = (*Scanner)(nil)
var (
client = common.SaneHttpClient()
- idPat = regexp.MustCompile(detectors.PrefixRegex([]string{"maxmind", "geoip"}) + `\b([0-9]{2,7})\b`)
keyPat = regexp.MustCompile(`\b([0-9A-Za-z]{6}_[0-9A-Za-z]{29}_mmk)\b`)
)
@@ -37,49 +37,43 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
dataStr := string(data)
keyMatches := keyPat.FindAllStringSubmatch(dataStr, -1)
- idMatches := idPat.FindAllStringSubmatch(dataStr, -1)
for _, keyMatch := range keyMatches {
- keyRes := strings.TrimSpace(keyMatch[1])
+ keyRes := keyMatch[1]
+
+ r := detectors.Result{
+ DetectorType: detectorspb.DetectorType_MaxMindLicense,
+ Raw: []byte(keyRes),
+ ExtraData: map[string]string{
+ "rotation_guide": "https://howtorotate.com/docs/tutorials/maxmind/",
+ "version": fmt.Sprintf("%d", s.Version()),
+ },
+ }
- for _, idMatch := range idMatches {
- if len(idMatch) != 2 {
+ if verify {
+ data := url.Values{}
+ data.Add("license_key", keyRes)
+ req, err := http.NewRequestWithContext(
+ ctx, "POST", "https://secret-scanning.maxmind.com/secrets/validate-license-key",
+ strings.NewReader(data.Encode()))
+ if err != nil {
+ r.SetVerificationError(err)
+ results = append(results, r)
continue
}
- idRes := strings.TrimSpace(idMatch[1])
-
- s := detectors.Result{
- DetectorType: detectorspb.DetectorType_MaxMindLicense,
- Redacted: idRes,
- Raw: []byte(keyRes),
- RawV2: []byte(keyRes + idRes),
- ExtraData: map[string]string{
- "rotation_guide": "https://howtorotate.com/docs/tutorials/maxmind/",
- "version": fmt.Sprintf("%d", s.Version()),
- },
- }
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
- if verify {
- req, err := http.NewRequestWithContext(ctx, "GET", "https://geoip.maxmind.com/geoip/v2.1/country/8.8.8.8", nil)
- if err != nil {
- continue
- }
- req.SetBasicAuth(idRes, keyRes)
- res, err := client.Do(req)
- if err == nil {
- defer res.Body.Close()
- if res.StatusCode >= 200 && res.StatusCode < 300 {
- s.Verified = true
- } else {
- if detectors.IsKnownFalsePositive(keyRes, detectors.DefaultFalsePositives, true) {
- continue
- }
- }
- }
+ res, err := client.Do(req)
+ if err != nil {
+ r.SetVerificationError(err)
+ }
+ defer res.Body.Close()
+ if err == nil && res.StatusCode >= 200 && res.StatusCode < 300 {
+ r.Verified = true
}
-
- results = append(results, s)
}
+
+ results = append(results, r)
}
return results, nil
diff --git a/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2_test.go b/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2_test.go
index e47ce4f1d..60c375440 100644
--- a/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2_test.go
+++ b/pkg/detectors/maxmindlicense/v2/maxmindlicense_v2_test.go
@@ -16,16 +16,15 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
)
-func TestMaxMindLicense_FromChunk(t *testing.T) {
+func TestMaxMindLicense(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors3")
if err != nil {
t.Fatalf("could not get test secrets from GCP: %s", err)
}
- secret := testSecrets.MustGetField("MAXMIND_LICENSE")
- user := testSecrets.MustGetField("MAXMIND_USER")
- inactiveSecret := testSecrets.MustGetField("MAXMIND_LICENSE_INACTIVE")
+ secret := testSecrets.MustGetField("MAXMIND_LICENSE_V2")
+ inactiveSecret := testSecrets.MustGetField("MAXMIND_LICENSE_INACTIVE_V2")
type args struct {
ctx context.Context
@@ -44,13 +43,12 @@ func TestMaxMindLicense_FromChunk(t *testing.T) {
s: Scanner{},
args: args{
ctx: context.Background(),
- data: []byte(fmt.Sprintf("You can find a geoip secret %s within with maxmind user %s", secret, user)),
+ data: []byte(fmt.Sprintf("You can find a geoip secret %s", secret)),
verify: true,
},
want: []detectors.Result{
{
DetectorType: detectorspb.DetectorType_MaxMindLicense,
- Redacted: "662034",
Verified: true,
ExtraData: map[string]string{
"rotation_guide": "https://howtorotate.com/docs/tutorials/maxmind/",
@@ -65,13 +63,12 @@ func TestMaxMindLicense_FromChunk(t *testing.T) {
s: Scanner{},
args: args{
ctx: context.Background(),
- data: []byte(fmt.Sprintf("You can find a maxmind secret %s within with maxmind user %s", inactiveSecret, user)),
+ data: []byte(fmt.Sprintf("You can find a maxmind secret %s", inactiveSecret)),
verify: true,
},
want: []detectors.Result{
{
DetectorType: detectorspb.DetectorType_MaxMindLicense,
- Redacted: "662034",
Verified: false,
ExtraData: map[string]string{
"rotation_guide": "https://howtorotate.com/docs/tutorials/maxmind/",