Compare commits

..
19 Commits
Author SHA1 Message Date
Zach Rice 7b48cadf6d fixing version loading in makefile 2020-01-22 20:42:14 -05:00
Zachary Rice 6eab8a7a0a Update README.md 2020-01-22 20:00:27 -05:00
Zachary Rice c6d14e5b7d Merge pull request #323 from zricethezav/bug/fix-go-module
fixing modules, adding v3 in path
2020-01-22 18:10:23 -05:00
zricethezav ce95cafd54 fixing modules, adding v3 in path 2020-01-22 10:21:00 -05:00
Zachary Rice 4024faceab Merge pull request #322 from zricethezav/exclude-forks
exclude-forks gitlab and github
2020-01-19 12:41:07 -05:00
zricethezav 1afa931248 exclude-forks gitlab and github 2020-01-19 12:35:52 -05:00
Zachary Rice 2474c39311 Merge pull request #321 from zricethezav/depth
reimplementing depth feature
2020-01-19 12:17:42 -05:00
zricethezav f6460a7365 reimplementing depth feature 2020-01-19 12:14:14 -05:00
Zachary Rice b47e00858e Merge pull request #320 from zricethezav/bug/manager-ptr
bug/manager-ptr
2020-01-19 11:56:29 -05:00
zricethezav b200a13c8d bug fix: use manager pointers instead of value for gitleaks hosts... this was causing an issue with metadata logging 2020-01-19 11:51:52 -05:00
Zachary Rice e6fabdbb31 Merge pull request #319 from zricethezav/repo-timeout
Repo timeout
2020-01-19 11:48:57 -05:00
Zachary Rice cdd654eab7 pr template 2020-01-19 10:17:08 -05:00
zricethezav 2f07b96333 adding test, cancelfunc (for go vet) 2020-01-19 10:07:01 -05:00
zricethezav 62e74b2b18 let the repo handle timeouts... better for automating audits anyway 2020-01-19 09:26:06 -05:00
Zachary Rice e75693b131 Update feature_request.md 2020-01-12 12:22:54 -05:00
Zachary Rice 3cd14d4696 Update bug_report.md 2020-01-12 12:22:14 -05:00
Zachary Rice d29cc9892c Update bug_report.md 2020-01-12 12:21:33 -05:00
Zachary Rice d996882f4e Update bug_report.md 2020-01-12 12:20:44 -05:00
Zachary Rice 17b6aa856d Update issue templates 2020-01-12 11:07:45 -05:00
22 changed files with 351 additions and 53 deletions

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Basic Info (please complete the following information):**
- OS:
- Gitleaks Version:
**Additional context**
Add any other context about the problem here.
cc @zricethezav
+22
View File
@@ -0,0 +1,22 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
cc @zricethezav
+8
View File
@@ -0,0 +1,8 @@
### Description:
Explain the purpose of the PR.
### Checklist:
* [ ] Does your PR pass tests?
* [ ] Have you written new tests for your changes?
* [ ] Have you lint your code locally prior to submission?
+1
View File
@@ -7,6 +7,7 @@
*.DS_STORE *.DS_STORE
*.idea *.idea
gitleaks gitleaks
build
# Test binary # Test binary
*.out *.out
+2 -2
View File
@@ -2,8 +2,8 @@
VERSION := `git fetch --tags && git tag | sort -V | tail -1` VERSION := `git fetch --tags && git tag | sort -V | tail -1`
PKG=github.com/zricethezav/gitleaks PKG=github.com/zricethezav/gitleaks
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/version.Version=$(VERSION)" LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v3/version.Version=$(VERSION)"
_LDFLAGS="github.com/zricethezav/gitleaks/version.Version=$(VERSION)" _LDFLAGS="github.com/zricethezav/gitleaks/v3/version.Version=$(VERSION)"
COVER=--cover --coverprofile=cover.out COVER=--cover --coverprofile=cover.out
test-cover: test-cover:
+6 -3
View File
@@ -41,9 +41,9 @@ docker pull zricethezav/gitleaks
``` ```
#### Go #### Go
Ensure `GO111MODULE=on` is set as an env var
```bash ```bash
go get -u github.com/zricethezav/gitleaks go get github.com/zricethezav/gitleaks/v3@latest
``` ```
## Usage ## Usage
@@ -60,7 +60,6 @@ Application Options:
--config= config path --config= config path
--disk Clones repo(s) to disk --disk Clones repo(s) to disk
--version version number --version version number
--timeout= Timeout (s)
--username= Username for git repo --username= Username for git repo
--password= Password for git repo --password= Password for git repo
--access-token= Access token for git repo --access-token= Access token for git repo
@@ -79,11 +78,15 @@ Application Options:
--pretty Pretty print json if leaks are present --pretty Pretty print json if leaks are present
--commit-from= Commit to start audit from --commit-from= Commit to start audit from
--commit-to= Commit to stop audit --commit-to= Commit to stop audit
--timeout= Time allowed per audit. Ex: 10us, 30s, 1m, 1h10m1s
--depth= Number of commits to audit
--host= git hosting service like gitlab or github. Supported hosts include: Github, Gitlab --host= git hosting service like gitlab or github. Supported hosts include: Github, Gitlab
--baseurl= Base URL for API requests. Defaults to the public GitLab or GitHub API, but can be set to a domain endpoint to use with a self hosted server. --baseurl= Base URL for API requests. Defaults to the public GitLab or GitHub API, but can be set to a domain endpoint to use with a self hosted server.
--org= organization to audit --org= organization to audit
--user= user to audit --user= user to audit
--pr= pull/merge request url --pr= pull/merge request url
--exclude-forks audit excludes forks
Help Options: Help Options:
-h, --help Show this help message -h, --help Show this help message
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"path" "path"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
+33 -3
View File
@@ -10,9 +10,9 @@ import (
"sort" "sort"
"testing" "testing"
"github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"github.com/sergi/go-diff/diffmatchpatch" "github.com/sergi/go-diff/diffmatchpatch"
) )
@@ -213,6 +213,36 @@ func TestAudit(t *testing.T) {
}, },
wantEmpty: true, wantEmpty: true,
}, },
{
description: "test local repo one aws leak timeout",
opts: options.Options{
RepoPath: "../test_data/test_repos/test_repo_1",
Report: "../test_data/test_local_repo_one_aws_leak.json.got",
ReportFormat: "json",
Timeout: "10ns",
},
wantEmpty: true,
},
{
description: "test local repo one aws leak long timeout",
opts: options.Options{
RepoPath: "../test_data/test_repos/test_repo_1",
Report: "../test_data/test_local_repo_one_aws_leak.json.got",
ReportFormat: "json",
Timeout: "2m",
},
wantPath: "../test_data/test_local_repo_one_aws_leak.json",
},
{
description: "test owner path depth=2",
opts: options.Options{
OwnerPath: "../test_data/test_repos/",
Report: "../test_data/test_local_owner_aws_leak_depth_2.json.got",
ReportFormat: "json",
Depth: 2,
},
wantPath: "../test_data/test_local_owner_aws_leak_depth_2.json",
},
} }
for _, test := range tests { for _, test := range tests {
+60 -3
View File
@@ -2,6 +2,7 @@ package audit
import ( import (
"bytes" "bytes"
"context"
"crypto/md5" "crypto/md5"
"fmt" "fmt"
"io" "io"
@@ -11,8 +12,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/sergi/go-diff/diffmatchpatch" "github.com/sergi/go-diff/diffmatchpatch"
@@ -39,6 +40,10 @@ type Repo struct {
// for those repo audits. // for those repo audits.
config config.Config config config.Config
// ctx is used to signal timeouts to running goroutines
ctx context.Context
cancel context.CancelFunc
Name string Name string
Manager *manager.Manager Manager *manager.Manager
} }
@@ -48,6 +53,7 @@ func NewRepo(m *manager.Manager) *Repo {
return &Repo{ return &Repo{
Manager: m, Manager: m,
config: m.Config, config: m.Config,
ctx: context.Background(),
} }
} }
@@ -93,6 +99,10 @@ func (repo *Repo) AuditUncommitted() error {
repo.config = cfg repo.config = cfg
} }
if err := repo.setupTimeout(); err != nil {
return err
}
auditTimeStart := time.Now() auditTimeStart := time.Now()
r, err := repo.Head() r, err := repo.Head()
@@ -204,6 +214,10 @@ func (repo *Repo) AuditUncommitted() error {
// git repo. Options that can change the behavior of this function include: --commit, --depth, --branch. // git repo. Options that can change the behavior of this function include: --commit, --depth, --branch.
// See options/options.go for an explanation on these options. // See options/options.go for an explanation on these options.
func (repo *Repo) Audit() error { func (repo *Repo) Audit() error {
if err := repo.setupTimeout(); err != nil {
return err
}
if repo.Repository == nil { if repo.Repository == nil {
return fmt.Errorf("%s repo is empty", repo.Name) return fmt.Errorf("%s repo is empty", repo.Name)
} }
@@ -247,7 +261,8 @@ func (repo *Repo) Audit() error {
semaphore := make(chan bool, howManyThreads(repo.Manager.Opts.Threads)) semaphore := make(chan bool, howManyThreads(repo.Manager.Opts.Threads))
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
err = cIter.ForEach(func(c *object.Commit) error { err = cIter.ForEach(func(c *object.Commit) error {
if c == nil || c.Hash.String() == repo.Manager.Opts.CommitTo { if c == nil || c.Hash.String() == repo.Manager.Opts.CommitTo ||
repo.timeoutReached() || repo.depthReached(cc) {
return storer.ErrStop return storer.ErrStop
} }
@@ -274,6 +289,9 @@ func (repo *Repo) Audit() error {
return return
} }
}() }()
if repo.timeoutReached() {
return nil
}
start := time.Now() start := time.Now()
patch, err := c.Patch(parent) patch, err := c.Patch(parent)
if err != nil { if err != nil {
@@ -344,3 +362,42 @@ func (repo *Repo) loadRepoConfig() (config.Config, error) {
_, err = toml.DecodeReader(f, &tomlLoader) _, err = toml.DecodeReader(f, &tomlLoader)
return tomlLoader.Parse() return tomlLoader.Parse()
} }
// timeoutReached returns true if the timeout deadline has been met. This function should be used
// at the top of loops and before potentially long running goroutines (like checking inefficient regexes)
func (repo *Repo) timeoutReached() bool {
if repo.ctx.Err() == context.DeadlineExceeded {
return true
}
return false
}
// setupTimeout parses the --timeout option and assigns a context with timeout to the manager
// which will exit early if the timeout has been met.
func (repo *Repo) setupTimeout() error {
if repo.Manager.Opts.Timeout == "" {
return nil
}
timeout, err := time.ParseDuration(repo.Manager.Opts.Timeout)
if err != nil {
return err
}
repo.ctx, repo.cancel = context.WithTimeout(context.Background(), timeout)
go func() {
select {
case <-repo.ctx.Done():
log.Warnf("Timeout deadline exceeded: %s", timeout.String())
}
}()
return nil
}
func (repo *Repo) depthReached(i int) bool {
if repo.Manager.Opts.Depth != 0 && repo.Manager.Opts.Depth == i {
log.Warnf("Exceeded depth limit (%d)", i)
return true
}
return false
}
+15 -3
View File
@@ -8,8 +8,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4"
@@ -25,6 +25,9 @@ import (
// After that, file chunks are created which are then inspected by InspectString() // After that, file chunks are created which are then inspected by InspectString()
func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) { func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
for _, f := range patch.FilePatches() { for _, f := range patch.FilePatches() {
if repo.timeoutReached() {
return
}
if f.IsBinary() { if f.IsBinary() {
continue continue
} }
@@ -119,6 +122,9 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
// an optimization would be to switch the regex from FindAllIndex to FindString // an optimization would be to switch the regex from FindAllIndex to FindString
// since we are iterating on the lines if entropy rules exist... // since we are iterating on the lines if entropy rules exist...
for _, line := range strings.Split(content, "\n") { for _, line := range strings.Split(content, "\n") {
if repo.timeoutReached() {
return
}
entropyTripped := trippedEntropy(line, rule) entropyTripped := trippedEntropy(line, rule)
if entropyTripped && !ruleContainRegex(rule) { if entropyTripped && !ruleContainRegex(rule) {
repo.Manager.SendLeaks(manager.Leak{ repo.Manager.SendLeaks(manager.Leak{
@@ -135,6 +141,9 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
File: filename, File: filename,
}) })
} else if entropyTripped { } else if entropyTripped {
if repo.timeoutReached() {
return
}
// entropy has been tripped which means if there is a regex specified in the same // entropy has been tripped which means if there is a regex specified in the same
// rule, we need to inspect the line for a regex match. In otherwords, the current rule has // rule, we need to inspect the line for a regex match. In otherwords, the current rule has
// both entropy and regex set which work in combination. This helps narrow down false positives // both entropy and regex set which work in combination. This helps narrow down false positives
@@ -179,6 +188,9 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
if rule.Regex.String() == "" { if rule.Regex.String() == "" {
continue continue
} }
if repo.timeoutReached() {
return
}
start := time.Now() start := time.Now()
locs := rule.Regex.FindAllIndex([]byte(content), -1) locs := rule.Regex.FindAllIndex([]byte(content), -1)
if len(locs) != 0 { if len(locs) != 0 {
@@ -255,7 +267,7 @@ func inspectCommit(c *object.Commit, repo *Repo) error {
err = fIter.ForEach(func(f *object.File) error { err = fIter.ForEach(func(f *object.File) error {
bin, err := f.IsBinary() bin, err := f.IsBinary()
if bin { if bin || repo.timeoutReached() {
return nil return nil
} else if err != nil { } else if err != nil {
return err return err
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
) )
+1 -1
View File
@@ -2,7 +2,7 @@ package config
import ( import (
"fmt" "fmt"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"regexp" "regexp"
"testing" "testing"
) )
+1 -1
View File
@@ -1,4 +1,4 @@
module github.com/zricethezav/gitleaks module github.com/zricethezav/gitleaks/v3
go 1.13 go 1.13
+16 -8
View File
@@ -6,9 +6,9 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/zricethezav/gitleaks/audit" "github.com/zricethezav/gitleaks/v3/audit"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"github.com/google/go-github/github" "github.com/google/go-github/github"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -21,13 +21,13 @@ import (
// Github wraps a github client and manager. This struct implements what the Host interface defines. // Github wraps a github client and manager. This struct implements what the Host interface defines.
type Github struct { type Github struct {
client *github.Client client *github.Client
manager manager.Manager manager *manager.Manager
wg sync.WaitGroup wg sync.WaitGroup
} }
// NewGithubClient accepts a manager struct and returns a Github host pointer which will be used to // NewGithubClient accepts a manager struct and returns a Github host pointer which will be used to
// perform a github audit on an organization, user, or PR. // perform a github audit on an organization, user, or PR.
func NewGithubClient(m manager.Manager) (*Github, error) { func NewGithubClient(m *manager.Manager) (*Github, error) {
var err error var err error
ctx := context.Background() ctx := context.Background()
token := oauth2.StaticTokenSource( token := oauth2.StaticTokenSource(
@@ -72,7 +72,15 @@ func (g *Github) Audit() {
_githubRepos, resp, err = g.client.Repositories.ListByOrg(ctx, g.manager.Opts.Organization, _githubRepos, resp, err = g.client.Repositories.ListByOrg(ctx, g.manager.Opts.Organization,
&github.RepositoryListByOrgOptions{ListOptions: listOptions}) &github.RepositoryListByOrgOptions{ListOptions: listOptions})
} }
githubRepos = append(githubRepos, _githubRepos...)
for _, r := range _githubRepos {
if g.manager.Opts.ExcludeForks && r.GetFork() {
log.Debugf("excluding forked repo: %s", *r.Name)
continue
}
githubRepos = append(githubRepos, r)
}
if resp == nil { if resp == nil {
break break
@@ -91,7 +99,7 @@ func (g *Github) Audit() {
} }
for _, repo := range githubRepos { for _, repo := range githubRepos {
r := audit.NewRepo(&g.manager) r := audit.NewRepo(g.manager)
r.Name = *repo.Name r.Name = *repo.Name
err := r.Clone(&git.CloneOptions{ err := r.Clone(&git.CloneOptions{
URL: *repo.CloneURL, URL: *repo.CloneURL,
@@ -123,7 +131,7 @@ func (g *Github) AuditPR() {
owner := splits[len(splits)-4] owner := splits[len(splits)-4]
repoName := splits[len(splits)-3] repoName := splits[len(splits)-3]
prNum, err := strconv.Atoi(splits[len(splits)-1]) prNum, err := strconv.Atoi(splits[len(splits)-1])
repo := audit.NewRepo(&g.manager) repo := audit.NewRepo(g.manager)
repo.Name = repoName repo.Name = repoName
log.Infof("auditing pr %s\n", g.manager.Opts.PullRequest) log.Infof("auditing pr %s\n", g.manager.Opts.PullRequest)
+16 -9
View File
@@ -4,9 +4,9 @@ import (
"context" "context"
"sync" "sync"
"github.com/zricethezav/gitleaks/audit" "github.com/zricethezav/gitleaks/v3/audit"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
@@ -15,14 +15,14 @@ import (
// Gitlab wraps a gitlab client and manager. This struct implements what the Host interface defines. // Gitlab wraps a gitlab client and manager. This struct implements what the Host interface defines.
type Gitlab struct { type Gitlab struct {
client *gitlab.Client client *gitlab.Client
manager manager.Manager manager *manager.Manager
ctx context.Context ctx context.Context
wg sync.WaitGroup wg sync.WaitGroup
} }
// NewGitlabClient accepts a manager struct and returns a Gitlab host pointer which will be used to // NewGitlabClient accepts a manager struct and returns a Gitlab host pointer which will be used to
// perform a gitlab audit on an group or user. // perform a gitlab audit on an group or user.
func NewGitlabClient(m manager.Manager) (*Gitlab, error) { func NewGitlabClient(m *manager.Manager) (*Gitlab, error) {
var err error var err error
gitlabClient := &Gitlab{ gitlabClient := &Gitlab{
@@ -57,19 +57,26 @@ func (g *Gitlab) Audit() {
glOpts := &gitlab.ListProjectsOptions{ glOpts := &gitlab.ListProjectsOptions{
ListOptions: listOpts, ListOptions: listOpts,
} }
projects, resp, err = g.client.Projects.ListUserProjects(g.manager.Opts.User, glOpts) _projects, resp, err = g.client.Projects.ListUserProjects(g.manager.Opts.User, glOpts)
} else if g.manager.Opts.Organization != "" { } else if g.manager.Opts.Organization != "" {
glOpts := &gitlab.ListGroupProjectsOptions{ glOpts := &gitlab.ListGroupProjectsOptions{
ListOptions: listOpts, ListOptions: listOpts,
} }
projects, resp, err = g.client.Groups.ListGroupProjects(g.manager.Opts.Organization, glOpts) _projects, resp, err = g.client.Groups.ListGroupProjects(g.manager.Opts.Organization, glOpts)
} }
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
projects = append(projects, _projects...) for _, p := range _projects {
if g.manager.Opts.ExcludeForks && p.ForkedFromProject != nil {
log.Debugf("excluding forked repo: %s", p.Name)
continue
}
projects = append(projects, p)
}
if resp == nil { if resp == nil {
break break
} }
@@ -82,7 +89,7 @@ func (g *Gitlab) Audit() {
// iterate of gitlab projects // iterate of gitlab projects
for _, p := range projects { for _, p := range projects {
r := audit.NewRepo(&g.manager) r := audit.NewRepo(g.manager)
cloneOpts := g.manager.CloneOptions cloneOpts := g.manager.CloneOptions
cloneOpts.URL = p.HTTPURLToRepo cloneOpts.URL = p.HTTPURLToRepo
err := r.Clone(cloneOpts) err := r.Clone(cloneOpts)
+3 -3
View File
@@ -1,7 +1,7 @@
package hosts package hosts
import ( import (
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
"strings" "strings"
) )
@@ -23,9 +23,9 @@ func Run(m *manager.Manager) error {
var err error var err error
switch getHost(m.Opts.Host) { switch getHost(m.Opts.Host) {
case _github: case _github:
host, err = NewGithubClient(*m) host, err = NewGithubClient(m)
case _gitlab: case _gitlab:
host, err = NewGitlabClient(*m) host, err = NewGitlabClient(m)
default: default:
return nil return nil
} }
+3 -3
View File
@@ -3,9 +3,9 @@ package hosts
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"os" "os"
"testing" "testing"
) )
+5 -5
View File
@@ -5,11 +5,11 @@ import (
"os" "os"
"time" "time"
"github.com/zricethezav/gitleaks/audit" "github.com/zricethezav/gitleaks/v3/audit"
"github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/hosts" "github.com/zricethezav/gitleaks/v3/hosts"
"github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"github.com/hako/durafmt" "github.com/hako/durafmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
+2 -2
View File
@@ -13,8 +13,8 @@ import (
"text/tabwriter" "text/tabwriter"
"time" "time"
"github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"github.com/hako/durafmt" "github.com/hako/durafmt"
"github.com/mattn/go-colorable" "github.com/mattn/go-colorable"
+2 -2
View File
@@ -3,8 +3,8 @@ package manager
import ( import (
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/options" "github.com/zricethezav/gitleaks/v3/options"
"io" "io"
"testing" "testing"
) )
+5 -3
View File
@@ -7,7 +7,7 @@ import (
"os/user" "os/user"
"strings" "strings"
"github.com/zricethezav/gitleaks/version" "github.com/zricethezav/gitleaks/v3/version"
"github.com/jessevdk/go-flags" "github.com/jessevdk/go-flags"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -32,7 +32,6 @@ type Options struct {
Config string `long:"config" description:"config path"` Config string `long:"config" description:"config path"`
Disk bool `long:"disk" description:"Clones repo(s) to disk"` Disk bool `long:"disk" description:"Clones repo(s) to disk"`
Version bool `long:"version" description:"version number"` Version bool `long:"version" description:"version number"`
Timeout int `long:"timeout" description:"Timeout (s)"`
Username string `long:"username" description:"Username for git repo"` Username string `long:"username" description:"Username for git repo"`
Password string `long:"password" description:"Password for git repo"` Password string `long:"password" description:"Password for git repo"`
AccessToken string `long:"access-token" description:"Access token for git repo"` AccessToken string `long:"access-token" description:"Access token for git repo"`
@@ -51,13 +50,16 @@ type Options struct {
PrettyPrint bool `long:"pretty" description:"Pretty print json if leaks are present"` PrettyPrint bool `long:"pretty" description:"Pretty print json if leaks are present"`
CommitFrom string `long:"commit-from" description:"Commit to start audit from"` CommitFrom string `long:"commit-from" description:"Commit to start audit from"`
CommitTo string `long:"commit-to" description:"Commit to stop audit"` CommitTo string `long:"commit-to" description:"Commit to stop audit"`
Timeout string `long:"timeout" description:"Time allowed per audit. Ex: 10us, 30s, 1m, 1h10m1s"`
Depth int `long:"depth" description:"Number of commits to audit"`
// Hosts // Hosts
Host string `long:"host" description:"git hosting service like gitlab or github. Supported hosts include: Github, Gitlab"` Host string `long:"host" description:"git hosting service like gitlab or github. Supported hosts include: Github, Gitlab"`
BaseURL string `long:"baseurl" description:"Base URL for API requests. Defaults to the public GitLab or GitHub API, but can be set to a domain endpoint to use with a self hosted server."` BaseURL string `long:"baseurl" description:"Base URL for API requests. Defaults to the public GitLab or GitHub API, but can be set to a domain endpoint to use with a self hosted server."`
Organization string `long:"org" description:"organization to audit"` Organization string `long:"org" description:"organization to audit"`
User string `long:"user" description:"user to audit"` //work User string `long:"user" description:"user to audit"`
PullRequest string `long:"pr" description:"pull/merge request url"` PullRequest string `long:"pr" description:"pull/merge request url"`
ExcludeForks bool `long:"exclude-forks" description:"audit excludes forks"`
} }
// ParseOptions is responsible for parsing options passed in by cli. An Options struct // ParseOptions is responsible for parsing options passed in by cli. An Options struct
@@ -0,0 +1,119 @@
[
{
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
"offender": "AKIAIO5FODNN7EXAMPLE",
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
"repo": "test_repo_1",
"rule": "AWS Manager ID",
"commitMessage": "commit 1 with secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "server.test.py",
"date": "2019-10-24T09:29:27-04:00",
"tags": "key, AWS"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
"offender": "AKIALALEMEL33243OLIB",
"commit": "f61cd8587b7ac1d75a89a0c9af870a2f24c60263",
"repo": "test_repo_2",
"rule": "AWS Manager ID",
"commitMessage": "rm secrets again\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:32-04:00",
"tags": "key, AWS"
},
{
"line": " const AWSSECRET = \"99432bfewaf823ec3294e231\"",
"offender": "SECRET = \"99432bfewaf823ec3294e231\"",
"commit": "f61cd8587b7ac1d75a89a0c9af870a2f24c60263",
"repo": "test_repo_2",
"rule": "Generic Credential",
"commitMessage": "rm secrets again\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:32-04:00",
"tags": "key, API, generic"
},
{
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
"offender": "AKIALALEMEL33243OLIB",
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
"repo": "test_repo_2",
"rule": "AWS Manager ID",
"commitMessage": "adding another one\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, AWS"
},
{
"line": " const AWSSECRET = \"99432bfewaf823ec3294e231\"",
"offender": "SECRET = \"99432bfewaf823ec3294e231\"",
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
"repo": "test_repo_2",
"rule": "Generic Credential",
"commitMessage": "adding another one\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:12:08-04:00",
"tags": "key, API, generic"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
"offender": "AKIALALEMEL33243OLIA",
"commit": "cd5eb8bef855f73c46b97b4c088badffdc40ebe9",
"repo": "test_repo_3",
"rule": "AWS Manager ID",
"commitMessage": "rm secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:26-04:00",
"tags": "key, AWS"
},
{
"line": "const AWSSECRET = \"99432bfewaf823ec3294e231\"",
"offender": "SECRET = \"99432bfewaf823ec3294e231\"",
"commit": "cd5eb8bef855f73c46b97b4c088badffdc40ebe9",
"repo": "test_repo_3",
"rule": "Generic Credential",
"commitMessage": "rm secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:26-04:00",
"tags": "key, API, generic"
},
{
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
"offender": "AKIALALEMEL33243OLIA",
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
"repo": "test_repo_3",
"rule": "AWS Manager ID",
"commitMessage": "more secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:08-04:00",
"tags": "key, AWS"
},
{
"line": "const AWSSECRET = \"99432bfewaf823ec3294e231\"",
"offender": "SECRET = \"99432bfewaf823ec3294e231\"",
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
"repo": "test_repo_3",
"rule": "Generic Credential",
"commitMessage": "more secrets\n",
"author": "zach rice",
"email": "zricer@protonmail.com",
"file": "secrets.md",
"date": "2019-10-25T13:54:08-04:00",
"tags": "key, API, generic"
}
]