This commit is contained in:
zricethezav committed 2018-02-04 14:40:22 -06:00
1 parent 493f45ed8c
commit d533d5a273
3 files changed
+10 -21

No files matched your search

+1
View File
@@ -21,3 +21,4 @@ This will clone the target `{git url}` and run a diff on all commits. A report w
- Specify a target branch - Specify a target branch
- Support for custom regex - Support for custom regex
- Filter regex - Filter regex
- Modify entropy cutoff
+8 -20
View File
@@ -14,14 +14,9 @@ import (
"syscall" "syscall"
) )
type ReportElem struct { type LeakElem struct {
Lines []string `json:"lines"` Line string `json:"line"`
Commit string `json:"commit"` Commit string `json:"commit"`
}
type GitLeak struct {
leaks []string
commit string
} }
func start(opts *Options, repoUrl string) { func start(opts *Options, repoUrl string) {
@@ -49,7 +44,6 @@ func start(opts *Options, repoUrl string) {
err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJson, 0644) err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJson, 0644)
} }
// cleanup changes to app root and recursive rms target repo
func cleanup(repoName string) { func cleanup(repoName string) {
if err := os.Chdir(appRoot); err != nil { if err := os.Chdir(appRoot); err != nil {
log.Fatalf("failed cleaning up repo. Does the repo exist? %v", err) log.Fatalf("failed cleaning up repo. Does the repo exist? %v", err)
@@ -60,15 +54,14 @@ func cleanup(repoName string) {
} }
} }
// audit parses git branch --all func getLeaks(repoName string) []LeakElem {
func getLeaks(repoName string) []ReportElem {
var ( var (
out []byte out []byte
err error err error
wg sync.WaitGroup wg sync.WaitGroup
concurrent = 100 concurrent = 100
semaphoreChan = make(chan struct{}, concurrent) semaphoreChan = make(chan struct{}, concurrent)
gitLeaks = make(chan GitLeak) gitLeaks = make(chan LeakElem)
) )
out, err = exec.Command("git", "rev-list", "--all", "--remotes", "--topo-order").Output() out, err = exec.Command("git", "rev-list", "--all", "--remotes", "--topo-order").Output()
@@ -87,7 +80,6 @@ func getLeaks(repoName string) []ReportElem {
go func(currCommit string, repoName string) { go func(currCommit string, repoName string) {
defer wg.Done() defer wg.Done()
var leakPrs bool var leakPrs bool
var leaks []string
if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repoName)); err != nil { if err := os.Chdir(fmt.Sprintf("%s/%s", appRoot, repoName)); err != nil {
log.Fatal(err) log.Fatal(err)
@@ -109,20 +101,16 @@ func getLeaks(repoName string) []ReportElem {
for _, line := range lines { for _, line := range lines {
leakPrs = checkEntropy(line) leakPrs = checkEntropy(line)
if leakPrs { if leakPrs {
leaks = append(leaks, line) gitLeaks <- LeakElem{line, currCommit}
} }
} }
gitLeaks <- GitLeak{leaks, currCommit}
}(currCommit, repoName) }(currCommit, repoName)
} }
go func() { go func() {
for gitLeak := range gitLeaks { for gitLeak := range gitLeaks {
if len(gitLeak.leaks) != 0 { fmt.Println(gitLeak)
fmt.Println(gitLeak.leaks) report = append(report, gitLeak)
report = append(report, ReportElem{gitLeak.leaks, gitLeak.commit})
}
} }
}() }()
wg.Wait() wg.Wait()
+1 -1
View File
@@ -9,7 +9,7 @@ var (
appRoot string appRoot string
regexes map[string]*regexp.Regexp regexes map[string]*regexp.Regexp
assignRegex *regexp.Regexp assignRegex *regexp.Regexp
report []ReportElem report []LeakElem
) )
func init() { func init() {