From 7a0ce07f99d6aec1c3d17bb7b789baa5f6499e74 Mon Sep 17 00:00:00 2001 From: zricethezav Date: Fri, 23 Feb 2018 17:58:02 -0600 Subject: [PATCH 1/3] --since sh-sh-sha --- leaks.go | 18 ++++++++++-------- options.go | 29 ++++++++++++++++++----------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/leaks.go b/leaks.go index 796793f9..0e3c7011 100644 --- a/leaks.go +++ b/leaks.go @@ -27,13 +27,13 @@ func start(opts *Options) { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM) - fmt.Printf("Cloning \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) + // fmt.Printf("Cloning \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) err := exec.Command("git", "clone", opts.RepoURL).Run() if err != nil { log.Printf("failed to clone repo %v", err) return } - fmt.Printf("Evaluating \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) + // fmt.Printf("Evaluating \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) repoName := getLocalRepoName(opts.RepoURL) if err = os.Chdir(repoName); err != nil { log.Fatal(err) @@ -46,7 +46,7 @@ func start(opts *Options) { report := getLeaks(repoName, opts) if len(report) == 0 { - fmt.Printf("No Leaks detected for \x1b[35;2m%s\x1b[0m...\n\n", opts.RepoURL) + // fmt.Printf("No Leaks detected for \x1b[35;2m%s\x1b[0m...\n\n", opts.RepoURL) } cleanup(repoName) reportJSON, _ := json.MarshalIndent(report, "", "\t") @@ -108,19 +108,21 @@ func getLeaks(repoName string, opts *Options) []LeakElem { } commits := bytes.Split(out, []byte("\n")) - commitWG.Add(len(commits)) for _, currCommitB := range commits { currCommit := string(currCommitB) + if currCommit == "" { + continue + } + if currCommit == opts.SinceCommit { + break + } + commitWG.Add(1) go func(currCommit string, repoName string, commitWG *sync.WaitGroup, gitLeakReceiverWG *sync.WaitGroup) { defer commitWG.Done() - if currCommit == "" { - return - } - if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repoName)); err != nil { log.Fatal(err) } diff --git a/options.go b/options.go index 4c8feb2c..611dacf9 100644 --- a/options.go +++ b/options.go @@ -9,15 +9,16 @@ import ( const usage = `usage: gitleaks [options] Options: - -c Concurrency factor (default is 10) - -u --user Git user url - -r --repo Git repo url - -o --org Git organization url - -s --strict Strict mode uses stopwords in config.yml - -b --b64Entropy Base64 entropy cutoff (default is 70) - -x --hexEntropy Hex entropy cutoff (default is 40) - -e --entropy Enable entropy - -h --help Display this message + -c Concurrency factor (default is 10) + -u --user Git user url + -r --repo Git repo url + -o --org Git organization url + -s --since Commit to stop at + -b --b64Entropy Base64 entropy cutoff (default is 70) + -x --hexEntropy Hex entropy cutoff (default is 40) + -e --entropy Enable entropy + -h --help Display this message + --strict Enables stopwords ` // Options for gitleaks @@ -30,6 +31,7 @@ type Options struct { RepoURL string Strict bool Entropy bool + SinceCommit string } // help prints the usage string and exits @@ -73,10 +75,16 @@ func parseOptions(args []string) *Options { Entropy: false, } + if len(args) == 0 { + help() + } + for i := 0; i < len(args); i++ { arg := args[i] switch arg { - case "-s", "--strict": + case "-s", "--since": + opts.SinceCommit = optionsNextString(args, &i) + case "--strict": opts.Strict = true case "-b", "--b64Entropy": opts.B64EntropyCutoff = optionsNextInt(args, &i) @@ -102,7 +110,6 @@ func parseOptions(args []string) *Options { } else { fmt.Printf("Uknown option %s\n\n", arg) help() - return nil } } } From 801254f97e233b2db39dc9fa4aece51c6d69fe21 Mon Sep 17 00:00:00 2001 From: zricethezav Date: Fri, 23 Feb 2018 18:02:29 -0600 Subject: [PATCH 2/3] messages go back in, will add reporting support s00n --- leaks.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/leaks.go b/leaks.go index 0e3c7011..9dc225da 100644 --- a/leaks.go +++ b/leaks.go @@ -27,13 +27,13 @@ func start(opts *Options) { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM) - // fmt.Printf("Cloning \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) + fmt.Printf("Cloning \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) err := exec.Command("git", "clone", opts.RepoURL).Run() if err != nil { log.Printf("failed to clone repo %v", err) return } - // fmt.Printf("Evaluating \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) + fmt.Printf("Evaluating \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL) repoName := getLocalRepoName(opts.RepoURL) if err = os.Chdir(repoName); err != nil { log.Fatal(err) @@ -46,7 +46,7 @@ func start(opts *Options) { report := getLeaks(repoName, opts) if len(report) == 0 { - // fmt.Printf("No Leaks detected for \x1b[35;2m%s\x1b[0m...\n\n", opts.RepoURL) + fmt.Printf("No Leaks detected for \x1b[35;2m%s\x1b[0m...\n\n", opts.RepoURL) } cleanup(repoName) reportJSON, _ := json.MarshalIndent(report, "", "\t") From c11171f47d82a443b190413ecb026dcca4809ffd Mon Sep 17 00:00:00 2001 From: zricethezav Date: Fri, 23 Feb 2018 18:06:19 -0600 Subject: [PATCH 3/3] the damned README --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 11606f96..e0428ea9 100644 --- a/README.md +++ b/README.md @@ -38,18 +38,19 @@ Gitleaks scans all lines of all commits and checks if there are any regular expr #### Help ``` -usage: gitleaks [options] +usage: gitleaks [options] Options: - -c Concurrency factor (default is 10) - -u --user Git user url - -r --repo Git repo url - -o --org Git organization url - -s --strict Strict mode uses stopwords in config.yml - -b --b64Entropy Base64 entropy cutoff (default is 70) - -x --hexEntropy Hex entropy cutoff (default is 40) - -e --entropy Enable entropy - -h --help Display this message + -c Concurrency factor (default is 10) + -u --user Git user url + -r --repo Git repo url + -o --org Git organization url + -s --since Scan until this commit (SHA) + -b --b64Entropy Base64 entropy cutoff (default is 70) + -x --hexEntropy Hex entropy cutoff (default is 40) + -e --entropy Enable entropy + --strict Enables stopwords + -h --help Display this message ``` NOTE: your mileage may vary so if you aren't getting the results you expected try updating the regexes to fit your needs or try tweaking the entropy cutoffs and stopwords. Entropy cutoff for base64 alphabets seemed to give good results around 70 and hex alphabets seemed to give good results around 40. Entropy is calculated using [Shannon entropy](http://www.bearcave.com/misl/misl_tech/wavelets/compression/shannon.html).