Compare commits

...

1 Commits

Author SHA1 Message Date
Ahrav Dutta 6f298a2b24 PR 26 of 40 2023-08-25 21:41:06 -07:00
20 changed files with 167 additions and 262 deletions
+8 -10
View File
@@ -1,11 +1,11 @@
package podio
import (
"bytes"
"context"
"fmt"
"net/http"
"regexp"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -21,30 +21,28 @@ 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{"podio"}) + `\b([[0-9a-z]{32})\b`)
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"podio"}) + `\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{"podio"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("podio")}
}
// FromData will find and optionally verify Podio 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_Podio,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -52,7 +50,7 @@ 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()
+7 -16
View File
@@ -1,10 +1,10 @@
package pollsapi
import (
"bytes"
"context"
"net/http"
"regexp"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -13,37 +13,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{"pollsapi"}) + `\b([A-Z0-9]{28})\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{"pollsapi"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("pollsapi")}
}
// FromData will find and optionally verify PollsAPI 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_PollsAPI,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -51,14 +43,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if err != nil {
continue
}
req.Header.Add("api-key", resMatch)
req.Header.Add("api-key", 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
}
+12 -18
View File
@@ -1,6 +1,7 @@
package poloniex
import (
"bytes"
"context"
"crypto/hmac"
"crypto/sha512"
@@ -9,7 +10,6 @@ import (
"net/url"
"regexp"
"strconv"
"strings"
"time"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
@@ -25,40 +25,35 @@ 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{"poloniex"}) + `\b([0-9A-Z]{8}-[0-9A-Z]{8}-[0-9A-Z]{8}-[0-9A-Z]{8})\b`)
secretPat = regexp.MustCompile(detectors.PrefixRegex([]string{"poloniex"}) + `\b([0-9a-f]{128})\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{"poloniex"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("poloniex")}
}
// FromData will find and optionally verify Poloniex 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)
secretMatches := secretPat.FindAllStringSubmatch(dataStr, -1)
matches := keyPat.FindAllSubmatch(data, -1)
secretMatches := secretPat.FindAllSubmatch(data, -1)
for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])
resMatch := bytes.TrimSpace(match[1])
for _, secretMatch := range secretMatches {
if len(secretMatch) != 2 {
continue
}
resSecretMatch := strings.TrimSpace(secretMatch[1])
resSecretMatch := bytes.TrimSpace(secretMatch[1])
s1 := detectors.Result{
DetectorType: detectorspb.DetectorType_Poloniex,
Raw: []byte(resSecretMatch),
RawV2: []byte(resMatch + resSecretMatch),
Raw: resSecretMatch,
RawV2: append(resMatch, resSecretMatch...),
}
if verify {
@@ -69,14 +64,14 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
payload.Add("command", "returnBalances")
payload.Add("nonce", timestamp)
signature := getPoloniexSignature(resSecretMatch, payload.Encode())
signature := getPoloniexSignature(string(resSecretMatch), payload.Encode())
req, err := http.NewRequestWithContext(ctx, "POST", "https://poloniex.com/tradingApi", strings.NewReader(payload.Encode()))
req, err := http.NewRequestWithContext(ctx, "POST", "https://poloniex.com/tradingApi", bytes.NewBufferString(payload.Encode()))
if err != nil {
continue
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Key", resMatch)
req.Header.Add("Key", string(resMatch))
req.Header.Add("Sign", signature)
res, err := client.Do(req)
if err == nil {
@@ -84,7 +79,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
}
+8 -10
View File
@@ -1,10 +1,11 @@
package polygon
import (
"bytes"
"context"
"fmt"
"net/http"
"regexp"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -25,29 +26,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{"polygon"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("polygon")}
}
// FromData will find and optionally verify Polygon 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_Polygon,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.polygon.io/v2/reference/locales?apiKey="+resMatch, nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.polygon.io/v2/reference/locales?apiKey=%s", string(resMatch)), nil)
if err != nil {
continue
}
@@ -58,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
}
+6 -14
View File
@@ -1,11 +1,11 @@
package positionstack
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{"positionstack"}) + `\b([a-zA-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{"positionstack"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("positionstack")}
}
// FromData will find and optionally verify PositionStack 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_PositionStack,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -58,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
}
+7 -10
View File
@@ -1,10 +1,10 @@
package postageapp
import (
"bytes"
"context"
"net/http"
"regexp"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -25,29 +25,26 @@ 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{"postageapp"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("postageapp")}
}
// FromData will find and optionally verify PostageApp 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_PostageApp,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.postageapp.com/v.1.0/get_account_info.json?api_key="+resMatch, nil)
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.postageapp.com/v.1.0/get_account_info.json?api_key="+string(resMatch), nil)
if err != nil {
continue
}
+9 -20
View File
@@ -1,11 +1,10 @@
package postbacks
import (
"bytes"
"context"
"net/http"
"regexp"
"strings"
"time"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -14,56 +13,46 @@ 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{"postbacks"}) + `\b([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\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{"postbacks"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("postbacks")}
}
// FromData will find and optionally verify Postbacks 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_Postbacks,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
timeout := 10 * time.Second
client.Timeout = timeout
payload := strings.NewReader(`{"url": "https://foo.com/bar","send_at": 1579049877,"body_string": "{ \"email_id\":\"123456789\" }"}`)
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.postbacks.io/v1/requestPostback", payload)
reqBody := bytes.NewBufferString(`{"url": "https://foo.com/bar","send_at": 1579049877,"body_string": "{ \"email_id\":\"123456789\" }"}`)
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.postbacks.io/v1/requestPostback", reqBody)
if err != nil {
continue
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Postbacks-Authorization", resMatch)
req.Header.Add("Postbacks-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
}
+12 -12
View File
@@ -1,10 +1,11 @@
package posthog
import (
"bytes"
"context"
"fmt"
"net/http"
"regexp"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -25,33 +26,32 @@ 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{"phc_"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("phc_")}
}
// FromData will find and optionally verify AppPosthog 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_PosthogApp,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
payload := strings.NewReader(` {
"api_key": "` + resMatch + `",
payload := fmt.Sprintf(` {
"api_key": "%s",
"distinct_id": "1234"
}`)
req, err := http.NewRequestWithContext(ctx, "POST", "https://app.posthog.com/decide/", payload)
}`, string(resMatch))
req, err := http.NewRequestWithContext(ctx, "POST", "https://app.posthog.com/decide/", bytes.NewBufferString(payload))
if err != nil {
continue
}
+7 -11
View File
@@ -1,10 +1,10 @@
package postman
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{"PMAK-"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("PMAK-")}
}
// FromData will find and optionally verify Postman 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_Postman,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -51,21 +49,19 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if err != nil {
continue
}
req.Header.Add("x-api-key", resMatch)
req.Header.Add("x-api-key", 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
}
}
}
}
results = append(results, s1)
}
+7 -12
View File
@@ -1,10 +1,10 @@
package postmark
import (
"bytes"
"context"
"net/http"
"regexp"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -22,27 +22,22 @@ var (
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"postmark"}) + `\b([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})\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{"postmark"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("postmark")}
}
// FromData will find and optionally verify Postmark 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_Postmark,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -52,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-Postmark-Server-Token", resMatch)
req.Header.Add("X-Postmark-Server-Token", string(resMatch))
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
+7 -16
View File
@@ -1,11 +1,11 @@
package powrbot
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{"powrbot"}) + `\b([a-z0-9A-Z]{40})\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{"powrbot"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("powrbot")}
}
// FromData will find and optionally verify Powrbot 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_Powrbot,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -52,14 +44,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if err != nil {
continue
}
req.Header.Add("Authorization", fmt.Sprintf("secret-key %s", resMatch))
req.Header.Add("Authorization", fmt.Sprintf("secret-key %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
}
+7 -16
View File
@@ -1,11 +1,11 @@
package prefect
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(`\b(pnu_[a-zA-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{"pnu_"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("pnu_")}
}
// FromData will find and optionally verify Prefect 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_Prefect,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -52,14 +44,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
}
+1 -1
View File
@@ -18,7 +18,7 @@ func init() {
}
var (
ErrUncrackable = errors.New("unable to crack encryption")
ErrUncrackable = errors.New(string([]byte("unable to crack encryption")))
)
func crack(in []byte) (interface{}, error) {
+10 -11
View File
@@ -1,6 +1,7 @@
package privatekey
import (
"bytes"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
@@ -8,7 +9,6 @@ import (
"crypto/x509"
"encoding/hex"
"errors"
"strings"
"golang.org/x/crypto/ssh"
)
@@ -16,17 +16,19 @@ import (
var (
ErrNotSupported = errors.New("key type not supported")
ErrEncryptedKey = errors.New("key is encrypted")
protectedKeyErrMsg = []byte("private key is passphrase protected")
)
func FingerprintPEMKey(in []byte) (string, error) {
func FingerprintPEMKey(in []byte) ([]byte, error) {
parsedKey, err := ssh.ParseRawPrivateKey(in)
if err != nil && strings.Contains(err.Error(), "private key is passphrase protected") {
if err != nil && bytes.Contains([]byte(err.Error()), protectedKeyErrMsg) {
parsedKey, err = crack(in)
if err != nil {
return "", err
return nil, err
}
} else if err != nil {
return "", err
return nil, err
}
var pubKey interface{}
@@ -37,19 +39,16 @@ func FingerprintPEMKey(in []byte) (string, error) {
pubKey = &privateKey.PublicKey
case *ed25519.PrivateKey:
pubKey = privateKey.Public()
// No fingerprinting support for DSA
// case *dsa.PrivateKey:
// pubKey = privateKey.PublicKey
default:
return "", ErrNotSupported
return nil, ErrNotSupported
}
publickeyBytes, err := x509.MarshalPKIXPublicKey(pubKey)
if err != nil {
return "", err
return nil, err
}
publicKeyFingerprint := sha1.Sum(publickeyBytes)
publicKeyFingerprintInHex := hex.EncodeToString(publicKeyFingerprint[:])
return publicKeyFingerprintInHex, nil
return []byte(publicKeyFingerprintInHex), nil
}
+23 -22
View File
@@ -1,31 +1,32 @@
package privatekey
import (
"strings"
"bytes"
)
func normalize(in string) string {
in = strings.ReplaceAll(in, `"`, "")
in = strings.ReplaceAll(in, `'`, "")
in = strings.ReplaceAll(in, "\t", "")
in = strings.ReplaceAll(in, `\t`, "")
in = strings.ReplaceAll(in, `\\t`, "")
in = strings.ReplaceAll(in, `\n`, "\n")
in = strings.ReplaceAll(in, `\\r\\n`, "\n")
in = strings.ReplaceAll(in, `\r\n`, "\n")
in = strings.ReplaceAll(in, "\r\n", "\n")
in = strings.ReplaceAll(in, `\\r`, "\n")
in = strings.ReplaceAll(in, "\r", "\n")
in = strings.ReplaceAll(in, `\r`, "\n")
in = strings.ReplaceAll(in, `\\n`, "\n")
in = strings.ReplaceAll(in, `\n\n`, "\n")
in = strings.ReplaceAll(in, "\n\n", "\n")
in = strings.ReplaceAll(in, `\\`, "\n")
func normalize(in []byte) []byte {
in = bytes.ReplaceAll(in, []byte(`"`), []byte(""))
in = bytes.ReplaceAll(in, []byte(`'`), []byte(""))
in = bytes.ReplaceAll(in, []byte("\t"), []byte(""))
in = bytes.ReplaceAll(in, []byte(`\t`), []byte(""))
in = bytes.ReplaceAll(in, []byte(`\\t`), []byte(""))
in = bytes.ReplaceAll(in, []byte(`\n`), []byte("\n"))
in = bytes.ReplaceAll(in, []byte(`\\r\\n`), []byte("\n"))
in = bytes.ReplaceAll(in, []byte(`\r\n`), []byte("\n"))
in = bytes.ReplaceAll(in, []byte("\r\n"), []byte("\n"))
in = bytes.ReplaceAll(in, []byte(`\\r`), []byte("\n"))
in = bytes.ReplaceAll(in, []byte("\r"), []byte("\n"))
in = bytes.ReplaceAll(in, []byte(`\r`), []byte("\n"))
in = bytes.ReplaceAll(in, []byte(`\\n`), []byte("\n"))
in = bytes.ReplaceAll(in, []byte(`\n\n`), []byte("\n"))
in = bytes.ReplaceAll(in, []byte("\n\n"), []byte("\n"))
in = bytes.ReplaceAll(in, []byte(`\\`), []byte("\n"))
cleaned := strings.Builder{}
parts := strings.Split(in, "\n")
cleaned := bytes.Buffer{}
parts := bytes.Split(in, []byte("\n"))
for _, line := range parts {
cleaned.WriteString(strings.TrimSpace(line) + "\n")
cleaned.Write(bytes.TrimSpace(line))
cleaned.WriteByte('\n')
}
return cleaned.String()
return cleaned.Bytes()
}
+7 -14
View File
@@ -17,30 +17,23 @@ type Scanner struct {
IncludeExpired bool
}
// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)
var (
// TODO: add base64 encoded key support
client = common.RetryableHttpClient()
keyPat = regexp.MustCompile(`(?i)-----\s*?BEGIN[ A-Z0-9_-]*?PRIVATE KEY\s*?-----[\s\S]*?----\s*?END[ A-Z0-9_-]*? PRIVATE KEY\s*?-----`)
)
// 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{"private key"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("private key")}
}
// FromData will find and optionally verify Privatekey secrets in a given set of bytes.
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) ([]detectors.Result, error) {
results := []detectors.Result{}
dataStr := string(data)
matches := keyPat.FindAllString(dataStr, -1)
matches := keyPat.FindAll(data, -1)
for _, match := range matches {
token := normalize(match)
if len(token) < 64 {
@@ -49,8 +42,8 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) ([]dete
secret := detectors.Result{
DetectorType: detectorspb.DetectorType_PrivateKey,
Raw: []byte(token),
Redacted: token[0:64],
Raw: token,
Redacted: string(token[0:64]),
}
fingerprint, err := FingerprintPEMKey([]byte(token))
@@ -59,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) ([]dete
}
if verify {
data, err := lookupFingerprint(fingerprint, s.IncludeExpired)
data, err := lookupFingerprint(string(fingerprint), s.IncludeExpired)
if err == nil {
secret.StructuredData = data
if data != nil {
@@ -91,7 +84,7 @@ func lookupFingerprint(publicKeyFingerprintInHex string, includeExpired bool) (d
return
}
seen := map[string]struct{}{}
seen := make(map[string]struct{})
for _, r := range results.CertificateResults {
if _, ok := seen[r.CertificateFingerprint]; ok {
continue
+7 -9
View File
@@ -1,11 +1,11 @@
package prodpad
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,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{"prodpad"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("prodpad")}
}
// FromData will find and optionally verify Prodpad 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_Prodpad,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -53,7 +51,7 @@ 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()
+7 -15
View File
@@ -1,11 +1,11 @@
package prospectcrm
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{"prospect"}) + `\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{"prospectcrm"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("prospectcrm")}
}
// FromData will find and optionally verify ProspectCRM 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_ProspectCRM,
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
}
+8 -15
View File
@@ -1,10 +1,10 @@
package prospectio
import (
"bytes"
"context"
"net/http"
"regexp"
"strings"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -13,37 +13,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{"prospect"}) + `\b([a-z0-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{"prospect"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("prospect")}
}
// FromData will find and optionally verify ProspectIO 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_ProspectIO,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -51,7 +45,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if err != nil {
continue
}
req.Header.Add("Authorization", resMatch)
req.Header.Add("Authorization", string(resMatch))
req.Header.Add("Content-Type", "application/vnd.api+json; charset=utf-8")
res, err := client.Do(req)
if err == nil {
@@ -59,8 +53,7 @@ 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) {
if detectors.IsKnownFalsePositive([]byte(resMatch), detectors.DefaultFalsePositives, true) {
continue
}
}
+7 -10
View File
@@ -1,11 +1,11 @@
package protocolsio
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,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{"protocols"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("protocols")}
}
// FromData will find and optionally verify ProtocolsIO 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_ProtocolsIO,
Raw: []byte(resMatch),
Raw: resMatch,
}
if verify {
@@ -52,14 +50,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
}