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

Rule (regex) identify MSSQL credentials in code analysis #1395

Open
fhverga opened this issue Apr 19, 2024 · 0 comments
Open

Rule (regex) identify MSSQL credentials in code analysis #1395

fhverga opened this issue Apr 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@fhverga
Copy link

fhverga commented Apr 19, 2024

Hello, I had created a local .yml rule to identify these types of mssql "connection" password exposure. Because originally running gitleaks on pip it was not identified. And when manually reviewing via code-review I caught this type of scenario. With that I made the regex to automate and try to contribute so that if this type of exposure comes again, gitleaks will be able to catch it and alert me.

Below is an example of the manual test.

image

yml (example)

rules:
  - id: mssql_database_credentials
    regex: "Password=[^;]+"
    description: Detects exposure of MSSQL database credentials.
    tags: ["database", "MSSQL", "credentials"]
or  

go (example)

package rules

import (
	"regexp"

	"github.com/zricethezav/gitleaks/v8/config"
)

// MSSQLDatabaseCredentials generates a rule for detecting exposure of MSSQL database credentials.
func MSSQLDatabaseCredentials() *config.Rule {
	// Define Rule
	r := config.Rule{
		// Human readable description of the rule
		Description: "Detects exposure of MSSQL database credentials",

		// Unique ID for the rule
		RuleID: "mssql-database-credentials",

		// Regex used for detecting secrets
		Regex: regexp.MustCompile(
			`Password=[^;]+`),

		// Keywords used for string matching on fragments (pre-filter)
		Keywords: []string{"MSSQL", "credentials"},
	}

	// Validate rule
	tps := []string{
		// Example secrets that match the rule
		"Password=mySecurePassword123;",
	}
	return validate(r, tps, nil)
}
@fhverga fhverga added the enhancement New feature or request label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant