From 9bc725786d1874bf7d468e492c6e150f49739e1e Mon Sep 17 00:00:00 2001 From: San Tran Date: Thu, 17 Apr 2025 05:10:47 +0800 Subject: [PATCH] Adding clickhouse scanner (#1826) * Adding clickhouse scanner * removing mention of aws as i used it as template --- cmd/generate/config/main.go | 4 +++- cmd/generate/config/rules/clickhouse.go | 30 +++++++++++++++++++++++++ config/gitleaks.toml | 7 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 cmd/generate/config/rules/clickhouse.go diff --git a/cmd/generate/config/main.go b/cmd/generate/config/main.go index 7a654e64..65464f64 100644 --- a/cmd/generate/config/main.go +++ b/cmd/generate/config/main.go @@ -1,10 +1,11 @@ package main import ( - "golang.org/x/exp/slices" "os" "text/template" + "golang.org/x/exp/slices" + "github.com/zricethezav/gitleaks/v8/cmd/generate/config/base" "github.com/zricethezav/gitleaks/v8/cmd/generate/config/rules" "github.com/zricethezav/gitleaks/v8/config" @@ -47,6 +48,7 @@ func main() { rules.Beamer(), rules.CodecovAccessToken(), rules.CoinbaseAccessToken(), + rules.ClickHouseCloud(), rules.Clojars(), rules.CloudflareAPIKey(), rules.CloudflareGlobalAPIKey(), diff --git a/cmd/generate/config/rules/clickhouse.go b/cmd/generate/config/rules/clickhouse.go new file mode 100644 index 00000000..190c1e0c --- /dev/null +++ b/cmd/generate/config/rules/clickhouse.go @@ -0,0 +1,30 @@ +package rules + +import ( + "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils" + "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets" + "github.com/zricethezav/gitleaks/v8/config" + "github.com/zricethezav/gitleaks/v8/regexp" +) + +func ClickHouseCloud() *config.Rule { + // define rule + r := config.Rule{ + RuleID: "clickhouse-cloud-api-secret-key", + Description: "Identified a pattern that may indicate clickhouse cloud API secret key, risking unauthorized clickhouse cloud api access and data breaches on ClickHouse Cloud platforms.", + Regex: regexp.MustCompile(`\b(4b1d[A-Za-z0-9]{38})\b`), + Entropy: 3, + Keywords: []string{ + "4b1d", // Prefix + }, + } + + // validate + tps := utils.GenerateSampleSecrets("ClickHouse", "4b1dbRdW3rOcB7xLthrM4BTBGK1qPLkHigpN1bXD6z") + tps = append(tps, utils.GenerateSampleSecrets("ClickHouse", "4b1d"+secrets.NewSecret("[A-Za-z0-9]{38}"))...) + fps := []string{ + `key = 4b1dXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`, // Low entropy + `key = adf4b1dbRdW3rOcB7xLthrM4BTBGK1qPLkHigpN1bXD6z`, // Not start of a word + } + return utils.Validate(r, tps, fps) +} diff --git a/config/gitleaks.toml b/config/gitleaks.toml index c95cb97b..dc3e8229 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -217,6 +217,13 @@ regex = '''[\w.-]{0,50}?(?i:[\w.-]{0,50}?(?:(?-i:[Mm]eraki|MERAKI))(?:[ \t\w.-]{ entropy = 3 keywords = ["meraki"] +[[rules]] +id = "clickhouse-cloud-api-secret-key" +description = "Identified a pattern that may indicate clickhouse cloud API secret key, risking unauthorized clickhouse cloud api access and data breaches on ClickHouse Cloud platforms." +regex = '''\b(4b1d[A-Za-z0-9]{38})\b''' +entropy = 3 +keywords = ["4b1d"] + [[rules]] id = "clojars-api-token" description = "Uncovered a possible Clojars API token, risking unauthorized access to Clojure libraries and potential code manipulation."