Compare commits

..
6 Commits
Author SHA1 Message Date
zricethezav 3e760d7fed updating help message 2020-03-02 20:24:22 -05:00
Noel Algora 679f00dc9c Scan files at latest commit (#348)
* Inspect files at latest commit

Added option to scan files at latest commit

* Files at latest commit test
2020-03-02 20:22:14 -05:00
Zachary Rice dae5c142d7 Fix host clone auth (#350)
* trying auth fix

* fixing github private user auth and donate msg

* formatting

* go fmt...
2020-02-29 13:30:08 -05:00
Zachary Rice 8e8873286e Update leaky-repo.toml 2020-02-29 13:19:55 -05:00
Zachary Rice 6693cbdde3 Update README.md 2020-02-27 09:29:52 -05:00
Zachary Rice 8b3ce2cb1e forgot to bump in code... (#347) 2020-02-26 20:41:54 -05:00
19 changed files with 134 additions and 60 deletions

No files matched your search

+2 -2
View File
@@ -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/v3/version.Version=$(VERSION)"
_LDFLAGS="github.com/zricethezav/gitleaks/v3/version.Version=$(VERSION)"
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v4/version.Version=$(VERSION)"
_LDFLAGS="github.com/zricethezav/gitleaks/v4/version.Version=$(VERSION)"
COVER=--cover --coverprofile=cover.out
test-cover:
+5 -2
View File
@@ -5,6 +5,9 @@
</p>
</p>
### [Gitleaks Action](https://github.com/marketplace/actions/gitleaks) now available for your workflows!
Audit git repos for secrets. Gitleaks provides a way for you to find unencrypted secrets and other unwanted data types in git repositories. As part of its core functionality, it provides:
* Audits for uncommitted changes
@@ -43,7 +46,7 @@ docker pull zricethezav/gitleaks
#### Go
Ensure `GO111MODULE=on` is set as an env var
```bash
go get github.com/zricethezav/gitleaks/v3@latest
go get github.com/zricethezav/gitleaks/v4@latest
```
## Usage
@@ -64,7 +67,7 @@ Application Options:
--password= Password for git repo
--access-token= Access token for git repo
--commit= sha of commit to audit
--files-at-commit= sha of commit to audit all files at commit
--files-at-commit= sha of commit to audit all files at commit or "latest" to scan the last commit of the repository
--threads= Maximum number of threads gitleaks spawns
--ssh-key= path to ssh key used for auth
--uncommitted run gitleaks on uncommitted code
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"io/ioutil"
"path"
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v4/manager"
log "github.com/sirupsen/logrus"
)
+13 -3
View File
@@ -10,9 +10,9 @@ import (
"sort"
"testing"
"github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/config"
"github.com/zricethezav/gitleaks/v4/manager"
"github.com/zricethezav/gitleaks/v4/options"
"github.com/sergi/go-diff/diffmatchpatch"
)
@@ -243,6 +243,16 @@ func TestAudit(t *testing.T) {
},
wantPath: "../test_data/test_local_repo_five_files_at_commit.json",
},
{
description: "test local repo five files at latest commit",
opts: options.Options{
RepoPath: "../test_data/test_repos/test_repo_5",
Report: "../test_data/test_local_repo_five_files_at_latest_commit.json.got",
FilesAtCommit: "latest",
ReportFormat: "json",
},
wantPath: "../test_data/test_local_repo_five_files_at_commit.json",
},
{
description: "test local repo five at commit",
opts: options.Options{
+11 -2
View File
@@ -12,8 +12,8 @@ import (
"sync"
"time"
"github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v4/config"
"github.com/zricethezav/gitleaks/v4/manager"
"github.com/BurntSushi/toml"
"github.com/sergi/go-diff/diffmatchpatch"
@@ -224,6 +224,15 @@ func (repo *Repo) Audit() error {
if repo.Manager.Opts.Commit != "" {
return inspectCommit(repo.Manager.Opts.Commit, repo, inspectCommitPatches)
} else if repo.Manager.Opts.FilesAtCommit != "" {
if repo.Manager.Opts.FilesAtCommit == "latest" {
// Getting the latest commit on the current branch
// ... retrieving the branch being pointed by HEAD
ref, err := repo.Repository.Head()
if err != nil {
return err
}
return inspectCommit(ref.Hash().String(), repo, inspectFilesAtCommit)
}
return inspectCommit(repo.Manager.Opts.FilesAtCommit, repo, inspectFilesAtCommit)
}
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"strings"
"time"
"github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v4/config"
"github.com/zricethezav/gitleaks/v4/manager"
log "github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4"
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"regexp"
"strconv"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/options"
"github.com/BurntSushi/toml"
)
+1 -1
View File
@@ -2,7 +2,7 @@ package config
import (
"fmt"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/options"
"regexp"
"testing"
)
+51 -18
View File
@@ -124,45 +124,78 @@ title = "gitleaks config"
[[rules]]
description = "Env Var"
regex = '''(?i)(api_key|apikey|secret|key|api|password|pw|host)=[0-9a-zA-Z-_{}]{4,120}'''
regex = '''(?i)(apikey|secret|key|api|password|pass|pw|host)=[0-9a-zA-Z-_.{}]{4,120}'''
[[rules]]
description = "Port"
regex = '''(?i)port(.{0,4})?[0-9]{1,10}'''
[[rules.whitelist]]
regex = '''(?i)port '''
description = "ignore export "
[[rules]]
description = "Email"
regex = '''[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}'''
tags = ["email"]
[[rules.whitelist]]
file = '''(?i)bashrc'''
description = "ignore bashrc emails"
[[rules]]
description = "Generic Credential"
regex = '''(?i)(dbpasswd|dbuser|dbname|dbhost|api_key|apikey|secret|key|api|password|user|guid|hostname|pw|auth)(.{0,20})?['|"][0-9a-zA-Z-_!{}/=]{4,120}['|"]'''
regex = '''(?i)(dbpasswd|dbuser|dbname|dbhost|api_key|apikey|secret|key|api|password|user|guid|hostname|pw|auth)(.{0,20})?['|"]([0-9a-zA-Z-_\/+!{}/=]{4,120})['|"]'''
tags = ["key", "API", "generic"]
# ignore leaks with specific identifiers like slack and aws
[[rules.whitelist]]
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})'''
description = "ignore slack"
[[rules.whitelist]]
description = "MailChimp API key"
regex = '''(?i)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
[[rules.whitelist]]
description = "AWS Manager ID"
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
#[[rules]]
# description = "s3config"
# regex = '''(?i)(dbpasswd|dbuser|dbname|dbhost|api_key|apikey|key|api|password|user|guid|hostname|pw|auth)(.{0,3})?([0-9a-zA-Z-_\/+!{}=]{4,120})'''
# fileNameRegex = '''(?i)s3cfg$'''
[[rules]]
description = "High Entropy"
regex = '''[0-9a-zA-Z-_!{}/=]{4,120}'''
fileNameRegex = '''(?i)(dump.sql|high-entropy-misc.txt)$'''
tags = ["entropy"]
[[rules.Entropies]]
Min = "4.3"
Max = "7.0"
[[rules.whitelist]]
description = "ignore ssh key and pems"
file = '''(pem|ppk|env)$'''
path = '''(.*)?ssh'''
[[rules]]
description = "Potential bash var"
regex='''(?i)(=)([0-9a-zA-Z-_!{}=]{4,120})'''
tags = ["key", "bash", "API", "generic"]
[[rules.Entropies]]
Min = "3.5"
Max = "4.5"
Group = "1"
[[rules]]
description = "WP-Config"
regex='''define(.{0,20})?(DB_CHARSET|NONCE_SALT|LOGGED_IN_SALT|AUTH_SALT|NONCE_KEY|DB_HOST|DB_PASSWORD|AUTH_KEY|SECURE_AUTH_KEY|LOGGED_IN_KEY|DB_NAME|DB_USER)(.{0,20})?['|"].{10,120}['|"]'''
tags = ["key", "API", "generic"]
[[rules]]
description = "Pure Entropy"
regex = '''['|"][0-9a-zA-Z-._{}$\/=]{40,120}['|"]'''
[[rules.Entropies]]
Min = "5.0"
Max = "5.6"
[[rules]]
description = "Entropy plus Generic Credential"
regex = '''(?i)(api_key|apikey|secret|key|api|password|pw)'''
[[rules.Entropies]]
Min = "5.2"
Max = "5.5"
[[rules]]
description = "Files with keys and credentials"
file = '''(?i)(id_rsa|passwd|id_rsa.pub|pgpass|pem|key|shadow)'''
fileNameRegex = '''(?i)(id_rsa|passwd|id_rsa.pub|pgpass|pem|key|shadow)'''
[whitelist]
description = "image whitelists"
+2 -2
View File
@@ -1,11 +1,11 @@
module github.com/zricethezav/gitleaks/v3
module github.com/zricethezav/gitleaks/v4
go 1.13
require (
github.com/BurntSushi/toml v0.3.1
github.com/google/go-cmp v0.4.0 // indirect
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-github/v29 v29.0.3
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4
github.com/jessevdk/go-flags v1.4.0
github.com/mattn/go-colorable v0.1.2
+7 -2
View File
@@ -19,12 +19,14 @@ github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-github/v29 v29.0.3 h1:IktKCTwU//aFHnpA+2SLIi7Oo9uhAzgsdZNbcAqhgdc=
github.com/google/go-github/v29 v29.0.3/go.mod h1:CHKiKKPHJ0REzfwc14QMklvtHwCveD0PxlMjLlzAM5E=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4 h1:60gBOooTSmNtrqNaRvrDbi8VAne0REaek2agjnITKSw=
@@ -81,10 +83,12 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -107,6 +111,7 @@ golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a h1:mEQZbbaBjWyLNy0tmZmgEuQ
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+18 -6
View File
@@ -6,16 +6,17 @@ import (
"strings"
"sync"
"github.com/zricethezav/gitleaks/v3/audit"
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/audit"
"github.com/zricethezav/gitleaks/v4/manager"
"github.com/zricethezav/gitleaks/v4/options"
"github.com/google/go-github/github"
"github.com/google/go-github/v29/github"
log "github.com/sirupsen/logrus"
"golang.org/x/oauth2"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
)
// Github wraps a github client and manager. This struct implements what the Host interface defines.
@@ -57,7 +58,10 @@ func (g *Github) Audit() {
Page: 1,
}
var githubRepos []*github.Repository
var (
githubRepos []*github.Repository
auth transport.AuthMethod
)
for {
var (
@@ -71,6 +75,9 @@ func (g *Github) Audit() {
} else if g.manager.Opts.Organization != "" {
_githubRepos, resp, err = g.client.Repositories.ListByOrg(ctx, g.manager.Opts.Organization,
&github.RepositoryListByOrgOptions{ListOptions: listOptions})
} else {
_githubRepos, resp, err = g.client.Repositories.List(ctx, "",
&github.RepositoryListOptions{ListOptions: listOptions})
}
for _, r := range _githubRepos {
@@ -99,8 +106,13 @@ func (g *Github) Audit() {
for _, repo := range githubRepos {
r := audit.NewRepo(g.manager)
if g.manager.CloneOptions != nil {
auth = g.manager.CloneOptions.Auth
}
err := r.Clone(&git.CloneOptions{
URL: *repo.CloneURL,
URL: *repo.CloneURL,
Auth: auth,
})
r.Name = *repo.Name
if err != nil {
+3 -3
View File
@@ -4,9 +4,9 @@ import (
"context"
"sync"
"github.com/zricethezav/gitleaks/v3/audit"
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/audit"
"github.com/zricethezav/gitleaks/v4/manager"
"github.com/zricethezav/gitleaks/v4/options"
log "github.com/sirupsen/logrus"
"github.com/xanzy/go-gitlab"
+1 -1
View File
@@ -1,7 +1,7 @@
package hosts
import (
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v4/manager"
"strings"
)
+3 -3
View File
@@ -3,9 +3,9 @@ package hosts
import (
"flag"
"fmt"
"github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/v3/manager"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/config"
"github.com/zricethezav/gitleaks/v4/manager"
"github.com/zricethezav/gitleaks/v4/options"
"os"
"testing"
)
+5 -5
View File
@@ -5,11 +5,11 @@ import (
"os"
"time"
"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/zricethezav/gitleaks/v4/audit"
"github.com/zricethezav/gitleaks/v4/config"
"github.com/zricethezav/gitleaks/v4/hosts"
"github.com/zricethezav/gitleaks/v4/manager"
"github.com/zricethezav/gitleaks/v4/options"
"github.com/hako/durafmt"
log "github.com/sirupsen/logrus"
+2 -2
View File
@@ -13,8 +13,8 @@ import (
"text/tabwriter"
"time"
"github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/config"
"github.com/zricethezav/gitleaks/v4/options"
"github.com/hako/durafmt"
"github.com/mattn/go-colorable"
+2 -2
View File
@@ -3,8 +3,8 @@ package manager
import (
"crypto/rand"
"fmt"
"github.com/zricethezav/gitleaks/v3/config"
"github.com/zricethezav/gitleaks/v3/options"
"github.com/zricethezav/gitleaks/v4/config"
"github.com/zricethezav/gitleaks/v4/options"
"io"
"testing"
)
+4 -2
View File
@@ -7,7 +7,7 @@ import (
"os/user"
"strings"
"github.com/zricethezav/gitleaks/v3/version"
"github.com/zricethezav/gitleaks/v4/version"
"github.com/jessevdk/go-flags"
log "github.com/sirupsen/logrus"
@@ -23,6 +23,7 @@ const (
Success = 0
LeaksPresent = 1
ErrorEncountered = 2
donateMessage = "👋 maintaining gitleaks takes a lot of work so consider sponsoring me or donating a little something\n❤️ https://github.com/sponsors/zricethezav\n💸 https://www.paypal.me/zricethezav\n₿ btc:3GndEzRZa6rJ8ZpkLureUcc5TDHMYfpDxn"
)
// Options stores values of command line options
@@ -35,7 +36,7 @@ type Options struct {
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"`
Commit string `long:"commit" description:"sha of commit to audit"`
Commit string `long:"commit" description:"sha of commit to audit or \"latest\" to scan the last commit of the repository"`
FilesAtCommit string `long:"files-at-commit" description:"sha of commit to audit all files at commit"`
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
SSH string `long:"ssh-key" description:"path to ssh key used for auth"`
@@ -76,6 +77,7 @@ func ParseOptions() (Options, error) {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
parser.WriteHelp(os.Stdout)
}
fmt.Println(donateMessage)
os.Exit(0)
}