Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bytify all detectors #1572

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions pkg/detectors/abbysale/abbysale.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package abbysale

import (
"bytes"
"context"
"net/http"
"regexp"
"strings"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
Expand All @@ -25,40 +25,37 @@ 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{"abbysale"}
func (s Scanner) Keywords() [][]byte {
return [][]byte{[]byte("abbysale")}
}

// FromData will find and optionally verify Abbysale 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_Abbysale,
Raw: []byte(resMatch),
Raw: resMatch,
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.abyssale.com/ready", nil)
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
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/detectors/abstract/abstract.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package abstract

import (
"bytes"
"context"
"fmt"
"net/http"
"regexp"
"strings"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
Expand All @@ -15,7 +15,7 @@
type Scanner struct{}

// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)

Check failure on line 18 in pkg/detectors/abstract/abstract.go

View workflow job for this annotation

GitHub Actions / test-detectors

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

var (
client = common.SaneHttpClient()
Expand All @@ -32,23 +32,21 @@

// FromData will find and optionally verify Abstract 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_Abstract,
Raw: []byte(resMatch),
Raw: resMatch,
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://exchange-rates.abstractapi.com/v1/live/?api_key=%s&base=USD", resMatch), nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://exchange-rates.abstractapi.com/v1/live/?api_key=%s&base=USD", string(resMatch)), nil)
if err != nil {
continue
}
Expand All @@ -59,7 +57,6 @@
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
}
Expand Down
18 changes: 7 additions & 11 deletions pkg/detectors/abuseipdb/abuseipdb.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package abuseipdb

Check failure on line 1 in pkg/detectors/abuseipdb/abuseipdb.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/trufflesecurity/trufflehog/v3/pkg/detectors/abuseipdb

import (
"bytes"
"context"
"io"
"net/http"
// "log"
"regexp"
"strings"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
Expand All @@ -16,7 +16,7 @@
type Scanner struct{}

// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)

Check failure on line 19 in pkg/detectors/abuseipdb/abuseipdb.go

View workflow job for this annotation

GitHub Actions / test-detectors

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 19 in pkg/detectors/abuseipdb/abuseipdb.go

View workflow job for this annotation

GitHub Actions / speed

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 19 in pkg/detectors/abuseipdb/abuseipdb.go

View workflow job for this annotation

GitHub Actions / smoke

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 19 in pkg/detectors/abuseipdb/abuseipdb.go

View workflow job for this annotation

GitHub Actions / test

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 19 in pkg/detectors/abuseipdb/abuseipdb.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

var (
client = common.SaneHttpClient()
Expand All @@ -33,34 +33,30 @@

// FromData will find and optionally verify AbuseIPDB 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_AbuseIPDB,
Raw: []byte(resMatch),
Raw: resMatch,
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.abuseipdb.com/api/v2/check?ipAddress=118.25.6.39", nil)
if err != nil {
continue
}
req.Header.Add("Key", resMatch)
req.Header.Add("Key", string(resMatch))
res, err := client.Do(req)
if err == nil {
bodyBytes, err := io.ReadAll(res.Body)
if err == nil {
bodyString := string(bodyBytes)
validResponse := strings.Contains(bodyString, `ipAddress`)
// errCode := strings.Contains(bodyString, `AbuseIPDB APIv2 Server.`)
validResponse := bytes.Contains(bodyBytes, []byte(`ipAddress`))

defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
Expand All @@ -70,14 +66,14 @@
s1.Verified = false
}
} 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)
}

Expand Down
13 changes: 5 additions & 8 deletions pkg/detectors/accuweather/accuweather.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package accuweather

Check failure on line 1 in pkg/detectors/accuweather/accuweather.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/trufflesecurity/trufflehog/v3/pkg/detectors/accuweather

import (
"bytes"
"context"
"net/http"
"regexp"
"strings"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
Expand All @@ -14,7 +14,7 @@
type Scanner struct{}

// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)

Check failure on line 17 in pkg/detectors/accuweather/accuweather.go

View workflow job for this annotation

GitHub Actions / test-detectors

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/accuweather/accuweather.go

View workflow job for this annotation

GitHub Actions / speed

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/accuweather/accuweather.go

View workflow job for this annotation

GitHub Actions / smoke

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/accuweather/accuweather.go

View workflow job for this annotation

GitHub Actions / test

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/accuweather/accuweather.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

var (
client = common.SaneHttpClient()
Expand All @@ -31,23 +31,21 @@

// FromData will find and optionally verify Accuweather 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_Accuweather,
Raw: []byte(resMatch),
Raw: resMatch,
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://dataservice.accuweather.com/locations/v1/cities/autocomplete?apikey="+resMatch+"&q=----&language=en-us", nil)
req, err := http.NewRequestWithContext(ctx, "GET", "https://dataservice.accuweather.com/locations/v1/cities/autocomplete?apikey="+string(resMatch)+"&q=----&language=en-us", nil)
if err != nil {
continue
}
Expand All @@ -57,7 +55,6 @@
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
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/detectors/adafruitio/adafruitio.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package adafruitio

Check failure on line 1 in pkg/detectors/adafruitio/adafruitio.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/trufflesecurity/trufflehog/v3/pkg/detectors/adafruitio

import (
"bytes"
"context"
"net/http"
"regexp"
"strings"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
Expand All @@ -14,7 +14,7 @@
type Scanner struct{}

// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)

Check failure on line 17 in pkg/detectors/adafruitio/adafruitio.go

View workflow job for this annotation

GitHub Actions / test-detectors

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/adafruitio/adafruitio.go

View workflow job for this annotation

GitHub Actions / speed

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/adafruitio/adafruitio.go

View workflow job for this annotation

GitHub Actions / smoke

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/adafruitio/adafruitio.go

View workflow job for this annotation

GitHub Actions / test

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

Check failure on line 17 in pkg/detectors/adafruitio/adafruitio.go

View workflow job for this annotation

GitHub Actions / lint

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

var (
client = common.SaneHttpClient()
Expand All @@ -31,23 +31,21 @@

// FromData will find and optionally verify AdafruitIO 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_AdafruitIO,
Raw: []byte(resMatch),
Raw: resMatch,
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://io.adafruit.com/api/v2/ladybugtest/feeds/?x-aio-key="+resMatch, nil)
req, err := http.NewRequestWithContext(ctx, "GET", "https://io.adafruit.com/api/v2/ladybugtest/feeds/?x-aio-key="+string(resMatch), nil)
if err != nil {
continue
}
Expand All @@ -57,7 +55,6 @@
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
}
Expand Down
22 changes: 10 additions & 12 deletions pkg/detectors/adobeio/adobeio.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package adobeio

import (
"bytes"
"context"
"net/http"
"regexp"
"strings"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
Expand All @@ -14,7 +14,7 @@
type Scanner struct{}

// Ensure the Scanner satisfies the interface at compile time.
var _ detectors.Detector = (*Scanner)(nil)

Check failure on line 17 in pkg/detectors/adobeio/adobeio.go

View workflow job for this annotation

GitHub Actions / test-detectors

cannot use (*Scanner)(nil) (value of type *Scanner) as detectors.Detector value in variable declaration: *Scanner does not implement detectors.Detector (wrong type for method Keywords)

var (
client = common.SaneHttpClient()
Expand All @@ -31,43 +31,41 @@
}

// FromData will find and optionally verify AdobeIO 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)
idMatches := idPat.FindAllStringSubmatch(dataStr, -1)
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
matches := keyPat.FindAllSubmatch(data, -1)
idMatches := idPat.FindAllSubmatch(data, -1)

for _, match := range matches {
if len(match) != 2 {
continue
}
resMatch := strings.TrimSpace(match[1])
resMatch := bytes.TrimSpace(match[1])
for _, idMatch := range idMatches {
if len(idMatch) != 2 {
continue
}
resIdMatch := strings.TrimSpace(idMatch[1])
resIdMatch := bytes.TrimSpace(idMatch[1])

s1 := detectors.Result{
DetectorType: detectorspb.DetectorType_AdobeIO,
Raw: []byte(resMatch),
RawV2: []byte(resMatch + resIdMatch),
Raw: resMatch,
RawV2: append(resMatch, resIdMatch...),
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://stock.adobe.io/Rest/Media/1/Search/Files?locale=en_US%2526search_parameters%255Bwords%255D=kittens", nil)
if err != nil {
continue
}
req.Header.Add("x-api-key", resMatch)
req.Header.Add("x-product", resIdMatch)
req.Header.Add("x-api-key", string(resMatch))
req.Header.Add("x-product", string(resIdMatch))
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
}
Expand Down
Loading
Loading