Skip to content

Commit b0dabf4

Browse files
committed
feat: add flag to disable ssl verify
1 parent ef3a714 commit b0dabf4

File tree

49 files changed

+300
-238
lines changed

Some content is hidden

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

49 files changed

+300
-238
lines changed

main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var (
7878
includeDetectors = cli.Flag("include-detectors", "Comma separated list of detector types to include. Protobuf name or IDs may be used, as well as ranges.").Default("all").String()
7979
excludeDetectors = cli.Flag("exclude-detectors", "Comma separated list of detector types to exclude. Protobuf name or IDs may be used, as well as ranges. IDs defined here take precedence over the include list.").String()
8080
jobReportFile = cli.Flag("output-report", "Write a scan report to the provided path.").Hidden().OpenFile(os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
81+
SslVerify = cli.Flag("ssl-verify", "Whether to verify the SSL certificates when making requests.").Default("true").Bool()
8182

8283
noVerificationCache = cli.Flag("no-verification-cache", "Disable verification caching").Bool()
8384

@@ -297,7 +298,7 @@ func init() {
297298

298299
cmd = kingpin.MustParse(cli.Parse(os.Args[1:]))
299300

300-
// Configure logging.
301+
// Configure log level.
301302
switch {
302303
case *trace:
303304
log.SetLevel(5)
@@ -318,6 +319,11 @@ func init() {
318319
log.SetLevel(l)
319320
}
320321
}
322+
323+
// Disable certificate validation, if specified.
324+
if !*SslVerify {
325+
feature.NoVerifySsl.Store(true)
326+
}
321327
}
322328

323329
func main() {

pkg/common/http.go

+23-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/hashicorp/go-retryablehttp"
13+
1314
"github.com/trufflesecurity/trufflehog/v3/pkg/feature"
1415
)
1516

@@ -204,23 +205,31 @@ func RetryableHTTPClientTimeout(timeOutSeconds int64, opts ...ClientOption) *htt
204205

205206
const DefaultResponseTimeout = 5 * time.Second
206207

207-
var saneTransport = &http.Transport{
208-
Proxy: http.ProxyFromEnvironment,
209-
DialContext: (&net.Dialer{
210-
Timeout: 2 * time.Second,
211-
KeepAlive: 5 * time.Second,
212-
}).DialContext,
213-
MaxIdleConns: 5,
214-
IdleConnTimeout: 5 * time.Second,
215-
TLSHandshakeTimeout: 3 * time.Second,
216-
ExpectContinueTimeout: 1 * time.Second,
208+
func saneTransport() *http.Transport {
209+
t := &http.Transport{
210+
Proxy: http.ProxyFromEnvironment,
211+
DialContext: (&net.Dialer{
212+
Timeout: 2 * time.Second,
213+
KeepAlive: 5 * time.Second,
214+
}).DialContext,
215+
MaxIdleConns: 5,
216+
IdleConnTimeout: 5 * time.Second,
217+
TLSHandshakeTimeout: 3 * time.Second,
218+
ExpectContinueTimeout: 1 * time.Second,
219+
}
220+
221+
// Disable TLS certificate validation.
222+
if feature.NoVerifySsl.Load() {
223+
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
224+
}
225+
return t
217226
}
218227

219228
func SaneHttpClient() *http.Client {
220-
httpClient := &http.Client{}
221-
httpClient.Timeout = DefaultResponseTimeout
222-
httpClient.Transport = NewCustomTransport(saneTransport)
223-
return httpClient
229+
client := &http.Client{}
230+
client.Timeout = DefaultResponseTimeout
231+
client.Transport = NewCustomTransport(saneTransport())
232+
return client
224233
}
225234

226235
// SaneHttpClientTimeOut adds a custom timeout for some scanners

pkg/detectors/aha/aha.go

+4-11
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ var (
2121
// Ensure the Scanner satisfies the interface at compile time.
2222
_ detectors.Detector = (*Scanner)(nil)
2323

24-
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
25-
2624
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2725
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"aha"}) + `\b([0-9a-f]{64})\b`)
2826
URLPat = regexp.MustCompile(`\b([A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])\.aha\.io)`)
@@ -34,13 +32,6 @@ func (s Scanner) Keywords() []string {
3432
return []string{"aha.io"}
3533
}
3634

37-
func (s Scanner) getClient() *http.Client {
38-
if s.client != nil {
39-
return s.client
40-
}
41-
return defaultClient
42-
}
43-
4435
// FromData will find and optionally verify Aha secrets in a given set of bytes.
4536
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
4637
dataStr := string(data)
@@ -61,8 +52,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6152
}
6253

6354
if verify {
64-
client := s.getClient()
65-
isVerified, verificationErr := verifyAha(ctx, client, resMatch, resURLMatch)
55+
if s.client == nil {
56+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
57+
}
58+
isVerified, verificationErr := verifyAha(ctx, s.client, resMatch, resURLMatch)
6659
s1.Verified = isVerified
6760
s1.SetVerificationError(verificationErr, resMatch)
6861
}

pkg/detectors/apiflash/apiflash.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ import (
1414
)
1515

1616
type Scanner struct {
17+
client *http.Client
1718
detectors.DefaultMultiPartCredentialProvider
1819
}
1920

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

2324
var (
24-
client = detectors.DetectorHttpClientWithNoLocalAddresses
25-
2625
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2726
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"apiflash"}) + `\b([a-z0-9]{32})\b`)
2827

@@ -51,7 +50,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5150
}
5251

5352
if verify {
54-
isVerified, verificationErr := verifyAPIFlash(ctx, client, key)
53+
if s.client == nil {
54+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
55+
}
56+
isVerified, verificationErr := verifyAPIFlash(ctx, s.client, key)
5557
s1.Verified = isVerified
5658
s1.SetVerificationError(verificationErr, key)
5759
}

pkg/detectors/artifactory/artifactory.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ var (
2323
_ detectors.Detector = (*Scanner)(nil)
2424
_ detectors.EndpointCustomizer = (*Scanner)(nil)
2525

26-
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
27-
2826
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2927
keyPat = regexp.MustCompile(`\b([a-zA-Z0-9]{73}|\b[a-zA-Z0-9]{64})`)
3028
URLPat = regexp.MustCompile(`\b([A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])\.jfrog\.io)`)
@@ -36,13 +34,6 @@ func (s Scanner) Keywords() []string {
3634
return []string{"artifactory"}
3735
}
3836

39-
func (s Scanner) getClient() *http.Client {
40-
if s.client != nil {
41-
return s.client
42-
}
43-
return defaultClient
44-
}
45-
4637
// FromData will find and optionally verify Artifactory secrets in a given set of bytes.
4738
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
4839
dataStr := string(data)
@@ -57,8 +48,6 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5748
for _, match := range matches {
5849
resMatch := strings.TrimSpace(match[1])
5950

60-
client := s.getClient()
61-
6251
for _, URL := range s.Endpoints(resURLMatch) {
6352
s1 := detectors.Result{
6453
DetectorType: detectorspb.DetectorType_ArtifactoryAccessToken,
@@ -67,7 +56,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6756
}
6857

6958
if verify {
70-
isVerified, verificationErr := verifyArtifactory(ctx, client, URL, resMatch)
59+
if s.client == nil {
60+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
61+
}
62+
63+
isVerified, verificationErr := verifyArtifactory(ctx, s.client, URL, resMatch)
7164
s1.Verified = isVerified
7265
s1.SetVerificationError(verificationErr, resMatch)
7366
}

pkg/detectors/auth0managementapitoken/auth0managementapitoken.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
type Scanner struct {
16+
client *http.Client
1617
detectors.DefaultMultiPartCredentialProvider
1718
}
1819

@@ -21,8 +22,6 @@ var _ detectors.Detector = (*Scanner)(nil)
2122
var _ detectors.MaxSecretSizeProvider = (*Scanner)(nil)
2223

2324
var (
24-
client = detectors.DetectorHttpClientWithLocalAddresses
25-
2625
// long jwt token but note this is default 8640000 seconds = 24 hours but could be set to maximum 2592000 seconds = 720 hours = 30 days
2726
// at https://manage.auth0.com/dashboard/us/dev-63memjo3/apis/management/explorer
2827
managementAPITokenPat = regexp.MustCompile(`\b(ey[a-zA-Z0-9._-]+)\b`)
@@ -61,6 +60,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6160
}
6261

6362
if verify {
63+
if s.client == nil {
64+
s.client = detectors.GetHttpClientWithLocalAddresses()
65+
}
6466
/*
6567
curl -H "Authorization: Bearer $token" https://domain/api/v2/users
6668
*/
@@ -70,7 +72,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
7072
continue
7173
}
7274
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", managementAPITokenRes))
73-
res, err := client.Do(req)
75+
res, err := s.client.Do(req)
7476
if err == nil {
7577
defer res.Body.Close()
7678
if res.StatusCode >= 200 && res.StatusCode < 300 {

pkg/detectors/azure_batch/azurebatch.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var _ detectors.Detector = (*Scanner)(nil)
2626
var _ detectors.CustomFalsePositiveChecker = (*Scanner)(nil)
2727

2828
var (
29-
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
3029
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
3130
urlPat = regexp.MustCompile(`https://(.{1,50})\.(.{1,50})\.batch\.azure\.com`)
3231
secretPat = regexp.MustCompile(`[A-Za-z0-9+/=]{88}`)
@@ -61,9 +60,8 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6160
}
6261

6362
if verify {
64-
client := s.client
65-
if client == nil {
66-
client = defaultClient
63+
if s.client == nil {
64+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
6765
}
6866
url := fmt.Sprintf("%s/applications?api-version=2020-09-01.12.0", endpoint)
6967
date := time.Now().UTC().Format(http.TimeFormat)
@@ -84,7 +82,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
8482
req.Header.Set("Content-Type", "application/json")
8583
req.Header.Set("Authorization", fmt.Sprintf("SharedKey %s:%s", accountName, signature))
8684
req.Header.Set("Date", date)
87-
resp, err := client.Do(req)
85+
resp, err := s.client.Do(req)
8886
if err != nil {
8987
continue
9088
}

pkg/detectors/azure_storage/storage.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ type Scanner struct {
2626
var _ detectors.Detector = (*Scanner)(nil)
2727

2828
var (
29-
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
30-
3129
namePat = regexp.MustCompile(`(?i:Account[_.-]?Name|Storage[_.-]?(?:Account|Name))(?:.|\s){0,20}?\b([a-z0-9]{3,24})\b|([a-z0-9]{3,24})(?i:\.blob\.core\.windows\.net)`) // Names can only be lowercase alphanumeric.
3230
keyPat = regexp.MustCompile(`(?i:(?:Access|Account|Storage)[_.-]?Key)(?:.|\s){0,25}?([a-zA-Z0-9+\/-]{86,88}={0,2})`)
3331

@@ -105,12 +103,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
105103
}
106104

107105
if verify {
108-
client := s.client
109-
if client == nil {
110-
client = defaultClient
106+
if s.client == nil {
107+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
111108
}
112109

113-
isVerified, verificationErr := s.verifyMatch(ctx, client, name, key, s1.ExtraData)
110+
isVerified, verificationErr := s.verifyMatch(ctx, s.client, name, key, s1.ExtraData)
114111
s1.Verified = isVerified
115112
s1.SetVerificationError(verificationErr, key)
116113
}

pkg/detectors/azuresearchquerykey/azuresearchquerykey.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type Scanner struct {
2121
var _ detectors.Detector = (*Scanner)(nil)
2222

2323
var (
24-
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
2524
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2625
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"azure"}) + `\b([0-9a-zA-Z]{52})\b`)
2726
urlPat = regexp.MustCompile(detectors.PrefixRegex([]string{"azure"}) + `https:\/\/([0-9a-z]{5,40})\.search\.windows\.net\/indexes\/([0-9a-z]{5,40})\b`)
@@ -53,17 +52,16 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5352
RawV2: []byte(resMatch + resUrlMatch),
5453
}
5554
if verify {
56-
client := s.client
57-
if client == nil {
58-
client = defaultClient
55+
if s.client == nil {
56+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
5957
}
6058
req, err := http.NewRequestWithContext(ctx, "GET", resUrlMatch+"/docs/$count?api-version=2023-10-01-Preview", nil)
6159
if err != nil {
6260
continue
6361
}
6462
req.Header.Add("api-key", resMatch)
6563

66-
res, err := client.Do(req)
64+
res, err := s.client.Do(req)
6765
if err == nil {
6866
defer res.Body.Close()
6967
if res.StatusCode >= 200 && res.StatusCode < 300 {

pkg/detectors/caspio/caspio.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import (
1313
)
1414

1515
type Scanner struct {
16+
client *http.Client
1617
detectors.DefaultMultiPartCredentialProvider
1718
}
1819

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

2223
var (
23-
client = detectors.DetectorHttpClientWithNoLocalAddresses
24-
2524
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2625
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"caspio"}) + `\b([a-z0-9]{50})\b`)
2726
idPat = regexp.MustCompile(detectors.PrefixRegex([]string{"caspio"}) + `\b([a-z0-9]{50})\b`)
@@ -60,13 +59,17 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6059
}
6160

6261
if verify {
62+
if s.client == nil {
63+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
64+
}
65+
6366
payload := strings.NewReader(fmt.Sprintf(`grant_type=client_credentials&client_id=%s&client_secret=%s`, resIdMatch, resMatch))
6467
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("https://%s.caspio.com/oauth/token", resDomainMatch), payload)
6568
if err != nil {
6669
continue
6770
}
6871
req.Header.Add("Content-Type", "text/plain")
69-
res, err := client.Do(req)
72+
res, err := s.client.Do(req)
7073
if err == nil {
7174
defer res.Body.Close()
7275
if res.StatusCode >= 200 && res.StatusCode < 300 {

pkg/detectors/databrickstoken/databrickstoken.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ type Scanner struct {
2121
var _ detectors.Detector = (*Scanner)(nil)
2222

2323
var (
24-
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
25-
2624
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2725
domain = regexp.MustCompile(`\b([a-z0-9-]+(?:\.[a-z0-9-]+)*\.(cloud\.databricks\.com|gcp\.databricks\.com|azuredatabricks\.net))\b`)
2826
keyPat = regexp.MustCompile(`\b(dapi[0-9a-f]{32}(-\d)?)\b`)
@@ -54,16 +52,15 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5452
}
5553

5654
if verify {
57-
client := s.client
58-
if client == nil {
59-
client = defaultClient
55+
if s.client == nil {
56+
s.client = detectors.GetHttpClientWithNoLocalAddresses()
6057
}
6158
req, err := http.NewRequestWithContext(ctx, "GET", "https://"+resDomainMatch+"/api/2.0/clusters/list", nil)
6259
if err != nil {
6360
continue
6461
}
6562
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch))
66-
res, err := client.Do(req)
63+
res, err := s.client.Do(req)
6764
if err == nil {
6865
defer res.Body.Close()
6966
if res.StatusCode >= 200 && res.StatusCode < 300 {

0 commit comments

Comments
 (0)