mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
6 files changed
+30
-29
No files matched your search
@@ -1,5 +1,8 @@
|
|||||||
# GitLeaks
|
# GitLeaks
|
||||||
|
|
||||||
|
[](http://godoc.org/github.com/zricethezav/gitleaks)
|
||||||
|
[](https://golangci.com)
|
||||||
|
|
||||||
## Check git repos for secrets and keys
|
## Check git repos for secrets and keys
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nbutton23/zxcvbn-go"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nbutton23/zxcvbn-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// check each line of a diff and see if there are any potential secrets
|
// check each line of a diff and see if there are any potential secrets
|
||||||
@@ -38,7 +39,7 @@ func checkEntropy(target string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO check for stop words here
|
// TODO check for stop words here
|
||||||
target = strings.Trim(target[index[1]:len(target)], " ")
|
target = strings.Trim(target[index[1]:], " ")
|
||||||
|
|
||||||
if len(target) > 70 {
|
if len(target) > 70 {
|
||||||
return false
|
return false
|
||||||
@@ -47,8 +48,5 @@ func checkEntropy(target string) bool {
|
|||||||
entropy := zxcvbn.PasswordStrength(target, nil).Entropy
|
entropy := zxcvbn.PasswordStrength(target, nil).Entropy
|
||||||
|
|
||||||
// tune this/make option
|
// tune this/make option
|
||||||
if entropy > 70 {
|
return entropy > 70
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
@@ -19,16 +19,16 @@ type LeakElem struct {
|
|||||||
Commit string `json:"commit"`
|
Commit string `json:"commit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(opts *Options, repoUrl string) {
|
func start(_ *Options, repoURL string) {
|
||||||
c := make(chan os.Signal, 2)
|
c := make(chan os.Signal, 2)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
err := exec.Command("git", "clone", repoUrl).Run()
|
err := exec.Command("git", "clone", repoURL).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to clone repo %v", err)
|
log.Fatalf("failed to clone repo %v", err)
|
||||||
}
|
}
|
||||||
repoName := getLocalRepoName(repoUrl)
|
repoName := getLocalRepoName(repoURL)
|
||||||
if err := os.Chdir(repoName); err != nil {
|
if err = os.Chdir(repoName); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
@@ -39,8 +39,11 @@ func start(opts *Options, repoUrl string) {
|
|||||||
|
|
||||||
report := getLeaks(repoName)
|
report := getLeaks(repoName)
|
||||||
cleanup(repoName)
|
cleanup(repoName)
|
||||||
reportJson, _ := json.MarshalIndent(report, "", "\t")
|
reportJSON, _ := json.MarshalIndent(report, "", "\t")
|
||||||
err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJson, 0644)
|
err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJSON, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Can't write to file: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLocalRepoName generates the name of the local clone folder based on the given URL
|
// getLocalRepoName generates the name of the local clone folder based on the given URL
|
||||||
|
|||||||
+3
-3
@@ -3,9 +3,9 @@ package main
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestGetLocalRepoName(t *testing.T) {
|
func TestGetLocalRepoName(t *testing.T) {
|
||||||
cases := []struct{
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
@@ -12,7 +13,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
appRoot, _ = os.Getwd()
|
var err error
|
||||||
|
appRoot, err = os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Can't get working dir: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO update regex to look for things like:
|
// TODO update regex to look for things like:
|
||||||
// TODO ability to add/filter regex
|
// TODO ability to add/filter regex
|
||||||
// client("AKAI32fJ334...",
|
// client("AKAI32fJ334...",
|
||||||
@@ -30,7 +36,7 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
args := os.Args[2:]
|
args := os.Args[2:]
|
||||||
repoUrl := os.Args[1]
|
repoURL := os.Args[1]
|
||||||
opts := parseOptions(args, repoUrl)
|
opts := parseOptions(args)
|
||||||
start(opts, repoUrl)
|
start(opts, repoURL)
|
||||||
}
|
}
|
||||||
+1
-10
@@ -39,16 +39,7 @@ func optionsNextInt(args []string, i *int) int {
|
|||||||
return argInt
|
return argInt
|
||||||
}
|
}
|
||||||
|
|
||||||
func optionsNextString(args []string, i *int) string {
|
func parseOptions(args []string) *Options {
|
||||||
if len(args) > *i+1 {
|
|
||||||
*i++
|
|
||||||
} else {
|
|
||||||
help()
|
|
||||||
}
|
|
||||||
return args[*i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseOptions(args []string, repoUrl string) *Options {
|
|
||||||
opts := &Options{}
|
opts := &Options{}
|
||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
|
|||||||
Reference in new issue
Block a user