mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-26 19:30:55 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b48cadf6d | ||
|
|
6eab8a7a0a | ||
|
|
c6d14e5b7d | ||
|
|
ce95cafd54 | ||
|
|
4024faceab | ||
|
|
1afa931248 | ||
|
|
2474c39311 | ||
|
|
f6460a7365 | ||
|
|
b47e00858e | ||
|
|
b200a13c8d | ||
|
|
e6fabdbb31 | ||
|
|
cdd654eab7 | ||
|
|
2f07b96333 | ||
|
|
62e74b2b18 | ||
|
|
e75693b131 | ||
|
|
3cd14d4696 | ||
|
|
d29cc9892c | ||
|
|
d996882f4e | ||
|
|
17b6aa856d |
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
@@ -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?
|
||||
@@ -7,6 +7,7 @@
|
||||
*.DS_STORE
|
||||
*.idea
|
||||
gitleaks
|
||||
build
|
||||
|
||||
# Test binary
|
||||
*.out
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
VERSION := `git fetch --tags && git tag | sort -V | tail -1`
|
||||
PKG=github.com/zricethezav/gitleaks
|
||||
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/version.Version=$(VERSION)"
|
||||
_LDFLAGS="github.com/zricethezav/gitleaks/version.Version=$(VERSION)"
|
||||
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v3/version.Version=$(VERSION)"
|
||||
_LDFLAGS="github.com/zricethezav/gitleaks/v3/version.Version=$(VERSION)"
|
||||
COVER=--cover --coverprofile=cover.out
|
||||
|
||||
test-cover:
|
||||
|
||||
@@ -41,9 +41,9 @@ docker pull zricethezav/gitleaks
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
Ensure `GO111MODULE=on` is set as an env var
|
||||
```bash
|
||||
go get -u github.com/zricethezav/gitleaks
|
||||
go get github.com/zricethezav/gitleaks/v3@latest
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -60,7 +60,6 @@ Application Options:
|
||||
--config= config path
|
||||
--disk Clones repo(s) to disk
|
||||
--version version number
|
||||
--timeout= Timeout (s)
|
||||
--username= Username for git repo
|
||||
--password= Password for git repo
|
||||
--access-token= Access token for git repo
|
||||
@@ -79,11 +78,15 @@ Application Options:
|
||||
--pretty Pretty print json if leaks are present
|
||||
--commit-from= Commit to start audit from
|
||||
--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
|
||||
--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
|
||||
--user= user to audit
|
||||
--pr= pull/merge request url
|
||||
--exclude-forks audit excludes forks
|
||||
|
||||
Help Options:
|
||||
-h, --help Show this help message
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"path"
|
||||
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
+33
-3
@@ -10,9 +10,9 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/zricethezav/gitleaks/config"
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/config"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
)
|
||||
@@ -213,6 +213,36 @@ func TestAudit(t *testing.T) {
|
||||
},
|
||||
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 {
|
||||
|
||||
+60
-3
@@ -2,6 +2,7 @@ package audit
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -11,8 +12,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/config"
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/config"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
@@ -39,6 +40,10 @@ type Repo struct {
|
||||
// for those repo audits.
|
||||
config config.Config
|
||||
|
||||
// ctx is used to signal timeouts to running goroutines
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
|
||||
Name string
|
||||
Manager *manager.Manager
|
||||
}
|
||||
@@ -48,6 +53,7 @@ func NewRepo(m *manager.Manager) *Repo {
|
||||
return &Repo{
|
||||
Manager: m,
|
||||
config: m.Config,
|
||||
ctx: context.Background(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +99,10 @@ func (repo *Repo) AuditUncommitted() error {
|
||||
repo.config = cfg
|
||||
}
|
||||
|
||||
if err := repo.setupTimeout(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
auditTimeStart := time.Now()
|
||||
|
||||
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.
|
||||
// See options/options.go for an explanation on these options.
|
||||
func (repo *Repo) Audit() error {
|
||||
if err := repo.setupTimeout(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if repo.Repository == nil {
|
||||
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))
|
||||
wg := sync.WaitGroup{}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -274,6 +289,9 @@ func (repo *Repo) Audit() error {
|
||||
return
|
||||
}
|
||||
}()
|
||||
if repo.timeoutReached() {
|
||||
return nil
|
||||
}
|
||||
start := time.Now()
|
||||
patch, err := c.Patch(parent)
|
||||
if err != nil {
|
||||
@@ -344,3 +362,42 @@ func (repo *Repo) loadRepoConfig() (config.Config, error) {
|
||||
_, err = toml.DecodeReader(f, &tomlLoader)
|
||||
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
@@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/config"
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/config"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/src-d/go-git.v4"
|
||||
@@ -25,6 +25,9 @@ import (
|
||||
// After that, file chunks are created which are then inspected by InspectString()
|
||||
func inspectPatch(patch *object.Patch, c *object.Commit, repo *Repo) {
|
||||
for _, f := range patch.FilePatches() {
|
||||
if repo.timeoutReached() {
|
||||
return
|
||||
}
|
||||
if f.IsBinary() {
|
||||
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
|
||||
// since we are iterating on the lines if entropy rules exist...
|
||||
for _, line := range strings.Split(content, "\n") {
|
||||
if repo.timeoutReached() {
|
||||
return
|
||||
}
|
||||
entropyTripped := trippedEntropy(line, rule)
|
||||
if entropyTripped && !ruleContainRegex(rule) {
|
||||
repo.Manager.SendLeaks(manager.Leak{
|
||||
@@ -135,6 +141,9 @@ func InspectString(content string, c *object.Commit, repo *Repo, filename string
|
||||
File: filename,
|
||||
})
|
||||
} else if entropyTripped {
|
||||
if repo.timeoutReached() {
|
||||
return
|
||||
}
|
||||
// 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
|
||||
// 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() == "" {
|
||||
continue
|
||||
}
|
||||
if repo.timeoutReached() {
|
||||
return
|
||||
}
|
||||
start := time.Now()
|
||||
locs := rule.Regex.FindAllIndex([]byte(content), -1)
|
||||
if len(locs) != 0 {
|
||||
@@ -255,7 +267,7 @@ func inspectCommit(c *object.Commit, repo *Repo) error {
|
||||
|
||||
err = fIter.ForEach(func(f *object.File) error {
|
||||
bin, err := f.IsBinary()
|
||||
if bin {
|
||||
if bin || repo.timeoutReached() {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return err
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module github.com/zricethezav/gitleaks
|
||||
module github.com/zricethezav/gitleaks/v3
|
||||
|
||||
go 1.13
|
||||
|
||||
|
||||
+16
-8
@@ -6,9 +6,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/zricethezav/gitleaks/audit"
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/audit"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
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.
|
||||
type Github struct {
|
||||
client *github.Client
|
||||
manager manager.Manager
|
||||
manager *manager.Manager
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// 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.
|
||||
func NewGithubClient(m manager.Manager) (*Github, error) {
|
||||
func NewGithubClient(m *manager.Manager) (*Github, error) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
token := oauth2.StaticTokenSource(
|
||||
@@ -72,7 +72,15 @@ func (g *Github) Audit() {
|
||||
_githubRepos, resp, err = g.client.Repositories.ListByOrg(ctx, g.manager.Opts.Organization,
|
||||
&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 {
|
||||
break
|
||||
@@ -91,7 +99,7 @@ func (g *Github) Audit() {
|
||||
}
|
||||
|
||||
for _, repo := range githubRepos {
|
||||
r := audit.NewRepo(&g.manager)
|
||||
r := audit.NewRepo(g.manager)
|
||||
r.Name = *repo.Name
|
||||
err := r.Clone(&git.CloneOptions{
|
||||
URL: *repo.CloneURL,
|
||||
@@ -123,7 +131,7 @@ func (g *Github) AuditPR() {
|
||||
owner := splits[len(splits)-4]
|
||||
repoName := splits[len(splits)-3]
|
||||
prNum, err := strconv.Atoi(splits[len(splits)-1])
|
||||
repo := audit.NewRepo(&g.manager)
|
||||
repo := audit.NewRepo(g.manager)
|
||||
repo.Name = repoName
|
||||
log.Infof("auditing pr %s\n", g.manager.Opts.PullRequest)
|
||||
|
||||
|
||||
+16
-9
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/zricethezav/gitleaks/audit"
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/audit"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"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.
|
||||
type Gitlab struct {
|
||||
client *gitlab.Client
|
||||
manager manager.Manager
|
||||
manager *manager.Manager
|
||||
ctx context.Context
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// 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.
|
||||
func NewGitlabClient(m manager.Manager) (*Gitlab, error) {
|
||||
func NewGitlabClient(m *manager.Manager) (*Gitlab, error) {
|
||||
var err error
|
||||
|
||||
gitlabClient := &Gitlab{
|
||||
@@ -57,19 +57,26 @@ func (g *Gitlab) Audit() {
|
||||
glOpts := &gitlab.ListProjectsOptions{
|
||||
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 != "" {
|
||||
glOpts := &gitlab.ListGroupProjectsOptions{
|
||||
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 {
|
||||
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 {
|
||||
break
|
||||
}
|
||||
@@ -82,7 +89,7 @@ func (g *Gitlab) Audit() {
|
||||
|
||||
// iterate of gitlab projects
|
||||
for _, p := range projects {
|
||||
r := audit.NewRepo(&g.manager)
|
||||
r := audit.NewRepo(g.manager)
|
||||
cloneOpts := g.manager.CloneOptions
|
||||
cloneOpts.URL = p.HTTPURLToRepo
|
||||
err := r.Clone(cloneOpts)
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package hosts
|
||||
|
||||
import (
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -23,9 +23,9 @@ func Run(m *manager.Manager) error {
|
||||
var err error
|
||||
switch getHost(m.Opts.Host) {
|
||||
case _github:
|
||||
host, err = NewGithubClient(*m)
|
||||
host, err = NewGithubClient(m)
|
||||
case _gitlab:
|
||||
host, err = NewGitlabClient(*m)
|
||||
host, err = NewGitlabClient(m)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,9 +3,9 @@ package hosts
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/zricethezav/gitleaks/config"
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/config"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/audit"
|
||||
"github.com/zricethezav/gitleaks/config"
|
||||
"github.com/zricethezav/gitleaks/hosts"
|
||||
"github.com/zricethezav/gitleaks/manager"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/audit"
|
||||
"github.com/zricethezav/gitleaks/v3/config"
|
||||
"github.com/zricethezav/gitleaks/v3/hosts"
|
||||
"github.com/zricethezav/gitleaks/v3/manager"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ import (
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/config"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/config"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
"github.com/mattn/go-colorable"
|
||||
|
||||
@@ -3,8 +3,8 @@ package manager
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"github.com/zricethezav/gitleaks/config"
|
||||
"github.com/zricethezav/gitleaks/options"
|
||||
"github.com/zricethezav/gitleaks/v3/config"
|
||||
"github.com/zricethezav/gitleaks/v3/options"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
||||
+5
-3
@@ -7,7 +7,7 @@ import (
|
||||
"os/user"
|
||||
"strings"
|
||||
|
||||
"github.com/zricethezav/gitleaks/version"
|
||||
"github.com/zricethezav/gitleaks/v3/version"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -32,7 +32,6 @@ type Options struct {
|
||||
Config string `long:"config" description:"config path"`
|
||||
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
||||
Version bool `long:"version" description:"version number"`
|
||||
Timeout int `long:"timeout" description:"Timeout (s)"`
|
||||
Username string `long:"username" description:"Username for git repo"`
|
||||
Password string `long:"password" description:"Password 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"`
|
||||
CommitFrom string `long:"commit-from" description:"Commit to start audit from"`
|
||||
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
|
||||
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."`
|
||||
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"`
|
||||
ExcludeForks bool `long:"exclude-forks" description:"audit excludes forks"`
|
||||
}
|
||||
|
||||
// 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"
|
||||
}
|
||||
]
|
||||
Reference in new issue
Block a user