Skip to content

Commit

Permalink
Detector improvements (trufflesecurity#125)
Browse files Browse the repository at this point in the history
* New tokens and endpoints  (trufflesecurity#115)

Co-authored-by: dmarquero <[email protected]>
  • Loading branch information
dustin-decker and dmarquero authored Apr 3, 2022
1 parent 1182759 commit aea9374
Show file tree
Hide file tree
Showing 62 changed files with 309 additions and 162 deletions.
8 changes: 8 additions & 0 deletions pkg/common/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,11 @@ func SaneHttpClient() *http.Client {
httpClient.Transport = NewCustomTransport(nil)
return httpClient
}

//custom timeout for some scanners
func SaneHttpClientTimeOut(timeOutSeconds int64) *http.Client {
httpClient := &http.Client{}
httpClient.Timeout = time.Second * time.Duration(timeOutSeconds)
httpClient.Transport = NewCustomTransport(nil)
return httpClient
}
5 changes: 4 additions & 1 deletion pkg/detectors/allsports/allsports.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)

if strings.Contains(body, "success") {
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/amadeus/amadeus.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)
if (res.StatusCode >= 200 && res.StatusCode < 300) && strings.Contains(body, "access_token") {
s1.Verified = true
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/auth0oauth/auth0oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)

// if client_id and client_secret is valid -> 403 {"error":"invalid_grant","error_description":"Invalid authorization code"}
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/baseapiio/baseapiio.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)

if strings.Contains(body, "items") {
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/besttime/besttime.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)

if strings.Contains(body, `"status": "OK"`) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/detectors/borgbase/borgbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
bodyBytes, err := ioutil.ReadAll(res.Body)
if err == nil {
bodyString := string(bodyBytes)
errCode := strings.Contains(bodyString, `"errors"`)
validResponse := strings.Contains(bodyString, `"sshList":[]`)
defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
if errCode {
s1.Verified = false
} else {
if validResponse {
s1.Verified = true
} else {
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
Expand Down
6 changes: 5 additions & 1 deletion pkg/detectors/bulbul/bulbul.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
res, err := client.Do(req)
if err == nil {
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)

if err != nil {
continue
}

bodyString := string(bodyBytes)
validResponse := strings.Contains(bodyString, `"message":"Successful",`)
Expand Down
7 changes: 6 additions & 1 deletion pkg/detectors/cexio/cexio.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,19 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
bodyString := string(body)
validResponse := strings.Contains(bodyString, `timestamp`)
if err != nil {
fmt.Print(err.Error())
}

var responseObject Response
json.Unmarshal(body, &responseObject)

if res.StatusCode >= 200 && res.StatusCode < 300 && responseObject.Error == "" {
if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse {
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
Expand Down
10 changes: 5 additions & 5 deletions pkg/detectors/coinlayer/coinlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.coinlayer.com/api/live?access_key=%s", resMatch), nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.coinlayer.com/api/livelive?access_key=%s", resMatch), nil)
if err != nil {
continue
}
Expand All @@ -58,13 +58,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
bodyBytes, err := ioutil.ReadAll(res.Body)
if err == nil {
bodyString := string(bodyBytes)
errCode := strings.Contains(bodyString, `"code":101`)
validResponse := strings.Contains(bodyString, `"success": true`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`)
defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
if errCode {
s1.Verified = false
} else {
if validResponse {
s1.Verified = true
} else {
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
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/currencycloud/currencycloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)
if strings.Contains(body, "auth_token") {
s1.Verified = true
Expand Down
8 changes: 4 additions & 4 deletions pkg/detectors/currencylayer/currencylayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
bodyBytes, err2 := ioutil.ReadAll(res.Body)
if err2 == nil {
bodyString := string(bodyBytes)
errCode := strings.Contains(bodyString, `"code":101`)
validResponse := strings.Contains(bodyString, `"success": true`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`)
defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
if errCode {
s1.Verified = false
} else {
if validResponse {
s1.Verified = true
} else {
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
Expand Down
8 changes: 6 additions & 2 deletions pkg/detectors/dyspatch/dyspatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)
validResponse := strings.Contains(body, "limited_usage") || strings.Contains(body, "data")

if !strings.Contains(body, "unauthenticated") {
if validResponse {
s1.Verified = true
} else {
if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/elasticemail/elasticemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}

defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
data, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
continue
}
var ResVar struct {
Expand Down
7 changes: 5 additions & 2 deletions pkg/detectors/fetchrss/fetchrss.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}

if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://fetchrss.com/api/v1/feed/create?auth="+resMatch, nil)
req, err := http.NewRequestWithContext(ctx, "GET", "https://fetchrss.com/api/v1/feed/list?auth="+resMatch, nil)
if err != nil {
continue
}
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)

if !strings.Contains(body, "Not authorised") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/detectors/fetchrss/fetchrss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestFetchrss_FromChunk(t *testing.T) {
if err != nil {
t.Fatalf("could not get test secrets from GCP: %s", err)
}
secret := testSecrets.MustGetField("FETCHRSS")
secret := testSecrets.MustGetField("FETCHRSS_TOKEN")
inactiveSecret := testSecrets.MustGetField("FETCHRSS_INACTIVE")

type args struct {
Expand Down
12 changes: 7 additions & 5 deletions pkg/detectors/financialmodelingprep/financialmodelingprep.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyString := string(bodyBytes)
if err == nil {
bodyString := string(bodyBytes)
errCode := strings.Contains(bodyString, `"Error Message"`)
// valid response should be an array of currencies
// error response is in json
validResponse := strings.Contains(bodyString, `[ "`)

defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
if errCode {
s1.Verified = false
} else {
if validResponse {
s1.Verified = true
} else {
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
Expand Down
10 changes: 8 additions & 2 deletions pkg/detectors/fixerio/fixerio.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)

// if client_id and client_secret is valid -> 403 {"error":"invalid_grant","error_description":"Invalid authorization code"}
// if invalid -> 401 {"error":"access_denied","error_description":"Unauthorized"}
// ingenious!

if !strings.Contains(body, "invalid_access_key") {
validResponse := strings.Contains(body, `"success": true`) || strings.Contains(body, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`)
defer res.Body.Close()

if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse {
s1.Verified = true
} else {
if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/flickr/flickr.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)
if (res.StatusCode >= 200 && res.StatusCode < 300) && strings.Contains(body, "owner=") {
s1.Verified = true
Expand Down
8 changes: 6 additions & 2 deletions pkg/detectors/flightstats/flightstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, _ := ioutil.ReadAll(res.Body)
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
continue
}
body := string(bodyBytes)
if (res.StatusCode >= 200 && res.StatusCode < 300) || (res.StatusCode == 403 && strings.Contains(body, "application is not active")) {
validResponse := (res.StatusCode >= 200 && res.StatusCode < 300 && strings.Contains(body, "id")) || (res.StatusCode == 403 && strings.Contains(body, "application is not active"))
if validResponse {
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
Expand Down
Loading

0 comments on commit aea9374

Please sign in to comment.