Skip to content

Commit aea9374

Browse files
Detector improvements (#125)
* New tokens and endpoints (#115) Co-authored-by: dmarquero <[email protected]>
1 parent 1182759 commit aea9374

File tree

62 files changed

+309
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+309
-162
lines changed

pkg/common/http.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,11 @@ func SaneHttpClient() *http.Client {
127127
httpClient.Transport = NewCustomTransport(nil)
128128
return httpClient
129129
}
130+
131+
//custom timeout for some scanners
132+
func SaneHttpClientTimeOut(timeOutSeconds int64) *http.Client {
133+
httpClient := &http.Client{}
134+
httpClient.Timeout = time.Second * time.Duration(timeOutSeconds)
135+
httpClient.Transport = NewCustomTransport(nil)
136+
return httpClient
137+
}

pkg/detectors/allsports/allsports.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5858
res, err := client.Do(req)
5959
if err == nil {
6060
defer res.Body.Close()
61-
bodyBytes, _ := ioutil.ReadAll(res.Body)
61+
bodyBytes, err := ioutil.ReadAll(res.Body)
62+
if err != nil {
63+
continue
64+
}
6265
body := string(bodyBytes)
6366

6467
if strings.Contains(body, "success") {

pkg/detectors/amadeus/amadeus.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6565
res, err := client.Do(req)
6666
if err == nil {
6767
defer res.Body.Close()
68-
bodyBytes, _ := ioutil.ReadAll(res.Body)
68+
bodyBytes, err := ioutil.ReadAll(res.Body)
69+
if err != nil {
70+
continue
71+
}
6972
body := string(bodyBytes)
7073
if (res.StatusCode >= 200 && res.StatusCode < 300) && strings.Contains(body, "access_token") {
7174
s1.Verified = true

pkg/detectors/auth0oauth/auth0oauth.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
9090
res, err := client.Do(req)
9191
if err == nil {
9292
defer res.Body.Close()
93-
bodyBytes, _ := ioutil.ReadAll(res.Body)
93+
bodyBytes, err := ioutil.ReadAll(res.Body)
94+
if err != nil {
95+
continue
96+
}
9497
body := string(bodyBytes)
9598

9699
// if client_id and client_secret is valid -> 403 {"error":"invalid_grant","error_description":"Invalid authorization code"}

pkg/detectors/baseapiio/baseapiio.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5757
res, err := client.Do(req)
5858
if err == nil {
5959
defer res.Body.Close()
60-
bodyBytes, _ := ioutil.ReadAll(res.Body)
60+
bodyBytes, err := ioutil.ReadAll(res.Body)
61+
if err != nil {
62+
continue
63+
}
6164
body := string(bodyBytes)
6265

6366
if strings.Contains(body, "items") {

pkg/detectors/besttime/besttime.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5555
res, err := client.Do(req)
5656
if err == nil {
5757
defer res.Body.Close()
58-
bodyBytes, _ := ioutil.ReadAll(res.Body)
58+
bodyBytes, err := ioutil.ReadAll(res.Body)
59+
if err != nil {
60+
continue
61+
}
5962
body := string(bodyBytes)
6063

6164
if strings.Contains(body, `"status": "OK"`) {

pkg/detectors/borgbase/borgbase.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6464
bodyBytes, err := ioutil.ReadAll(res.Body)
6565
if err == nil {
6666
bodyString := string(bodyBytes)
67-
errCode := strings.Contains(bodyString, `"errors"`)
67+
validResponse := strings.Contains(bodyString, `"sshList":[]`)
6868
defer res.Body.Close()
6969
if res.StatusCode >= 200 && res.StatusCode < 300 {
70-
if errCode {
71-
s1.Verified = false
72-
} else {
70+
if validResponse {
7371
s1.Verified = true
72+
} else {
73+
s1.Verified = false
7474
}
7575
} else {
7676
//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

pkg/detectors/bulbul/bulbul.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5555
}
5656
res, err := client.Do(req)
5757
if err == nil {
58-
bodyBytes, _ := ioutil.ReadAll(res.Body)
58+
bodyBytes, err := ioutil.ReadAll(res.Body)
59+
60+
if err != nil {
61+
continue
62+
}
5963

6064
bodyString := string(bodyBytes)
6165
validResponse := strings.Contains(bodyString, `"message":"Successful",`)

pkg/detectors/cexio/cexio.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,19 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
9292
defer res.Body.Close()
9393

9494
body, err := ioutil.ReadAll(res.Body)
95+
if err != nil {
96+
continue
97+
}
98+
bodyString := string(body)
99+
validResponse := strings.Contains(bodyString, `timestamp`)
95100
if err != nil {
96101
fmt.Print(err.Error())
97102
}
98103

99104
var responseObject Response
100105
json.Unmarshal(body, &responseObject)
101106

102-
if res.StatusCode >= 200 && res.StatusCode < 300 && responseObject.Error == "" {
107+
if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse {
103108
s1.Verified = true
104109
} else {
105110
//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

pkg/detectors/coinlayer/coinlayer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
4949
}
5050

5151
if verify {
52-
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.coinlayer.com/api/live?access_key=%s", resMatch), nil)
52+
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.coinlayer.com/api/livelive?access_key=%s", resMatch), nil)
5353
if err != nil {
5454
continue
5555
}
@@ -58,13 +58,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5858
bodyBytes, err := ioutil.ReadAll(res.Body)
5959
if err == nil {
6060
bodyString := string(bodyBytes)
61-
errCode := strings.Contains(bodyString, `"code":101`)
61+
validResponse := strings.Contains(bodyString, `"success": true`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`)
6262
defer res.Body.Close()
6363
if res.StatusCode >= 200 && res.StatusCode < 300 {
64-
if errCode {
65-
s1.Verified = false
66-
} else {
64+
if validResponse {
6765
s1.Verified = true
66+
} else {
67+
s1.Verified = false
6868
}
6969
} else {
7070
//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

0 commit comments

Comments
 (0)