mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60267523e9 | ||
|
|
8153da6e9c | ||
|
|
5f6fb388ec | ||
|
|
ba49396755 | ||
|
|
40240cb5ee | ||
|
|
bba926693e | ||
|
|
9103834503 | ||
|
|
7e3c740592 | ||
|
|
35a59746df | ||
|
|
23b5ce3264 | ||
|
|
03c53d2978 | ||
|
|
695449d73d | ||
|
|
6bad1e7194 | ||
|
|
77dec1461b | ||
|
|
14d77f59d4 | ||
|
|
afb598cf15 | ||
|
|
b4c6fe92e0 | ||
|
|
f50577be1c | ||
|
|
c358ae9310 | ||
|
|
9554258d02 | ||
|
|
95ee2cc30e | ||
|
|
79a35f0c27 | ||
|
|
7a021cda9e | ||
|
|
447f7a04cb | ||
|
|
e5b62cbc7c | ||
|
|
6739a34f74 | ||
|
|
e502bf29de | ||
|
|
51b504bf99 | ||
|
|
107d582e7b | ||
|
|
ea42ed406f | ||
|
|
c869812875 | ||
|
|
4f7ce9c195 | ||
|
|
847687a637 | ||
|
|
94389137e8 | ||
|
|
98e6ba9378 | ||
|
|
e288db29a8 | ||
|
|
98aeee9b1d | ||
|
|
45a2aa8495 | ||
|
|
4b350987a1 | ||
|
|
3b2b754fe5 | ||
|
|
64e7afea98 | ||
|
|
16765c19cf |
No files matched your search
+38
-4
@@ -1,6 +1,40 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.19.1
|
||||||
|
----
|
||||||
|
- mistakenly removed default whitelist files
|
||||||
|
|
||||||
|
1.19.0
|
||||||
|
----
|
||||||
|
- removed `--all-refs`. By default gitleaks now scans all branches, remote and local.
|
||||||
|
- added commit memoizer to prevent duplicate commit audits
|
||||||
|
- removed branch whitelist
|
||||||
|
- removed branch from report as a commit is an object independent of branch
|
||||||
|
- Better regexes for facebook, github, twitter (no more unbounded wildcards)
|
||||||
|
|
||||||
|
1.18.0
|
||||||
|
----
|
||||||
|
- fixing slack token
|
||||||
|
- defaulting to single thread process
|
||||||
|
- `--max-go=` --> `--threads=`
|
||||||
|
- guarding `--threads=` > max threads available (you aint gettin any more performance)
|
||||||
|
|
||||||
|
1.17.0
|
||||||
|
----
|
||||||
|
- Default regex added to search: slack, telegram.
|
||||||
|
- Default whitelisting: bin, doc, jpeg, gif
|
||||||
|
|
||||||
|
1.16.1
|
||||||
|
----
|
||||||
|
- Fixing default ssh auth logic
|
||||||
|
|
||||||
|
1.16.0
|
||||||
|
----
|
||||||
|
- Better commit coverage. Now iterates through each commit in git log and generates a patch with each commit's parent.
|
||||||
|
- Removing the need for --private/-p option. Instead gitleaks will determine if the repo is private or not.
|
||||||
|
|
||||||
|
|
||||||
1.15.0
|
1.15.0
|
||||||
----
|
----
|
||||||
- Whitelist repos use regex now
|
- Whitelist repos use regex now
|
||||||
@@ -72,14 +106,14 @@ CHANGELOG
|
|||||||
|
|
||||||
1.6.0
|
1.6.0
|
||||||
-----
|
-----
|
||||||
- Default maximum goroutines spawned is number of cores your cpu run with. See benchmarks in wiki.
|
- Default maximum goroutines spawned is number of cores your CPU run with. See benchmarks in wiki.
|
||||||
- Cleanup after each repo audit for organizations rather than waiting for the entire organization to complete. Eliminates risk of running out of disk space.
|
- Cleanup after each repo audit for organizations rather than waiting for the entire organization to complete. Eliminates the risk of running out of disk space.
|
||||||
|
|
||||||
|
|
||||||
1.5.0
|
1.5.0
|
||||||
-----
|
-----
|
||||||
- Support for CSV reporting
|
- Support for CSV reporting
|
||||||
- Refactoring github user/owner audits
|
- Refactoring Github user/owner audits
|
||||||
|
|
||||||
1.4.0
|
1.4.0
|
||||||
-----
|
-----
|
||||||
@@ -96,7 +130,7 @@ CHANGELOG
|
|||||||
|
|
||||||
1.2.0
|
1.2.0
|
||||||
-----
|
-----
|
||||||
- Added support for providing an alternate GitHub URL to support scanning GitHub Enteprise repositories
|
- Added support for providing an alternate GitHub URL to support scanning GitHub Enterprise repositories
|
||||||
|
|
||||||
1.1.2
|
1.1.2
|
||||||
-----
|
-----
|
||||||
|
|||||||
+3
-3
@@ -5,14 +5,14 @@ contributions via GitHub pull requests.
|
|||||||
|
|
||||||
## How to Contribute
|
## How to Contribute
|
||||||
|
|
||||||
Open a PR. Give the PR a descriptive title. Add some comments describing whats the purpose of the PR.
|
Open a PR. Give the PR a descriptive title. Add some comments describing what is the purpose of the PR.
|
||||||
|
|
||||||
__BUT before you do that!__
|
__BUT before you do that!__
|
||||||
|
|
||||||
Make sure you pass this list of requirements.
|
Make sure you pass this list of requirements.
|
||||||
|
|
||||||
- You've ran `go fmt`.
|
- You've run `go fmt`.
|
||||||
- You've ran `golint`.
|
- You've run `golint`.
|
||||||
- Your Go changes are confined to `gitleaks_test.go` and `main.go`. This is subject to change as the project evolves. Stylistically, I like having a single go file considering the size of this project (its tiny).
|
- Your Go changes are confined to `gitleaks_test.go` and `main.go`. This is subject to change as the project evolves. Stylistically, I like having a single go file considering the size of this project (its tiny).
|
||||||
- You've added test cases for your changes.
|
- You've added test cases for your changes.
|
||||||
- You've updated [the changelog](CHANGELOG.md).
|
- You've updated [the changelog](CHANGELOG.md).
|
||||||
|
|||||||
@@ -68,15 +68,12 @@ Application Options:
|
|||||||
--github-org= Github organization to audit
|
--github-org= Github organization to audit
|
||||||
--github-url= GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/ (default: https://api.github.com/)
|
--github-url= GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/ (default: https://api.github.com/)
|
||||||
--github-pr= Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set
|
--github-pr= Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set
|
||||||
-p, --private Include private repos in audit
|
|
||||||
-b, --branch= branch name to audit (defaults to HEAD)
|
|
||||||
-c, --commit= sha of commit to stop at
|
-c, --commit= sha of commit to stop at
|
||||||
--depth= maximum commit depth
|
--depth= maximum commit depth
|
||||||
--repo-path= Path to repo
|
--repo-path= Path to repo
|
||||||
--owner-path= Path to owner directory (repos discovered)
|
--owner-path= Path to owner directory (repos discovered)
|
||||||
--max-go= Maximum number of concurrent go-routines gitleaks spawns
|
--threads= Maximum number of threads gitleaks spawns
|
||||||
--disk Clones repo(s) to disk
|
--disk Clones repo(s) to disk
|
||||||
--all-refs run audit on all refs
|
|
||||||
--single-search= single regular expression to search for
|
--single-search= single regular expression to search for
|
||||||
--config= path to gitleaks config
|
--config= path to gitleaks config
|
||||||
--ssh-key= path to ssh key
|
--ssh-key= path to ssh key
|
||||||
@@ -94,7 +91,7 @@ Help Options:
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### Exit Codes
|
#### Exit Codes
|
||||||
Gitleaks provides consisten exist codes to assist in automation workflows such as CICD platforms and bulk scanning.
|
Gitleaks provides consistent exist codes to assist in automation workflows such as CICD platforms and bulk scanning.
|
||||||
|
|
||||||
These can be effectively used in conjunction with the report output file to detect and return meaningful data back to the user or external system about if leaks have been detected, and where they reside.
|
These can be effectively used in conjunction with the report output file to detect and return meaningful data back to the user or external system about if leaks have been detected, and where they reside.
|
||||||
|
|
||||||
@@ -114,10 +111,10 @@ The code return codes are:
|
|||||||
* [Rewrite git history with the BFG (theguardian.com)](https://www.theguardian.com/info/developer-blog/2013/apr/29/rewrite-git-history-with-the-bfg)
|
* [Rewrite git history with the BFG (theguardian.com)](https://www.theguardian.com/info/developer-blog/2013/apr/29/rewrite-git-history-with-the-bfg)
|
||||||
* [Auditing Bitbucket Server Data for Credentials in AWS (sourcedgroup.com)](https://www.sourcedgroup.com/blog/auditing-bitbucket-server-data-credentials-in-aws)
|
* [Auditing Bitbucket Server Data for Credentials in AWS (sourcedgroup.com)](https://www.sourcedgroup.com/blog/auditing-bitbucket-server-data-credentials-in-aws)
|
||||||
|
|
||||||
This blog post details how gitleaks was used to audit data in Atlassian Bitbucket server when hosted on AWS, and visualise the results in a compliance dashboard using Splunk.
|
This blog post details how gitleaks was used to audit data in Atlassian Bitbucket server when hosted on AWS and visualise the results in a compliance dashboard using Splunk.
|
||||||
|
|
||||||
* How does gitleaks differ to github token scanning ?
|
* How does gitleaks differ to Github token scanning?
|
||||||
* [Github recently announced](https://blog.github.com/2018-10-16-future-of-software/#github-token-scanning-for-public-repositories-public-beta) a new capbility to their cloud platform that detects exposed credentials for a number of common services and platforms and automatically notifies the provider for revocation or similar action. Gitleaks provides a similar detection capability for non-github cloud users, in which repositories can be easily audited and results provided in a number of formats.
|
* [Github recently announced](https://blog.github.com/2018-10-16-future-of-software/#github-token-scanning-for-public-repositories-public-beta) a new capability to their cloud platform that detects exposed credentials for a number of common services and platforms and automatically notifies the provider for revocation or similar action. Gitleaks provides a similar detection capability for non-Github cloud users, in which repositories can be easily audited and results provided in a number of formats.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -117,11 +117,7 @@ func auditGithubRepos() ([]Leak, error) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if opts.GithubUser != "" {
|
if opts.GithubUser != "" {
|
||||||
if opts.IncludePrivate {
|
pagedGithubRepos, resp, err = githubClient.Repositories.List(ctx, opts.GithubUser, githubOptions)
|
||||||
pagedGithubRepos, resp, err = githubClient.Repositories.List(ctx, "", githubOptions)
|
|
||||||
} else {
|
|
||||||
pagedGithubRepos, resp, err = githubClient.Repositories.List(ctx, opts.GithubUser, githubOptions)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
done = true
|
done = true
|
||||||
}
|
}
|
||||||
@@ -147,12 +143,8 @@ func auditGithubRepos() ([]Leak, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if opts.Disk {
|
if opts.Disk {
|
||||||
ownerDir, err = ioutil.TempDir(dir, opts.GithubUser)
|
ownerDir, _ = ioutil.TempDir(dir, opts.GithubUser)
|
||||||
os.RemoveAll(ownerDir)
|
|
||||||
}
|
}
|
||||||
for _, githubRepo := range githubRepos {
|
for _, githubRepo := range githubRepos {
|
||||||
repo, err := cloneGithubRepo(githubRepo)
|
repo, err := cloneGithubRepo(githubRepo)
|
||||||
@@ -199,10 +191,7 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
||||||
}
|
}
|
||||||
if opts.IncludePrivate {
|
if sshAuth != nil {
|
||||||
if sshAuth == nil {
|
|
||||||
return nil, fmt.Errorf("no ssh auth available")
|
|
||||||
}
|
|
||||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||||
URL: *githubRepo.SSHURL,
|
URL: *githubRepo.SSHURL,
|
||||||
Auth: sshAuth,
|
Auth: sshAuth,
|
||||||
@@ -213,10 +202,7 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if opts.IncludePrivate {
|
if sshAuth != nil {
|
||||||
if sshAuth == nil {
|
|
||||||
return nil, fmt.Errorf("no ssh auth available")
|
|
||||||
}
|
|
||||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
URL: *githubRepo.SSHURL,
|
URL: *githubRepo.SSHURL,
|
||||||
Auth: sshAuth,
|
Auth: sshAuth,
|
||||||
|
|||||||
@@ -20,6 +20,15 @@ regex = '''(?i)facebook.*['\"][0-9a-f]{32}['\"]'''
|
|||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "Twitter"
|
description = "Twitter"
|
||||||
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
||||||
|
[[regexes]]
|
||||||
|
description = "Telegram"
|
||||||
|
regex = '''(?i)telegram.*['\"][0-9]{1,12}+:[0-9a-zA-Z-]{32,44}['\"]'''
|
||||||
|
[[regexes]]
|
||||||
|
description = "PGP"
|
||||||
|
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
||||||
|
[[regexes]]
|
||||||
|
description = "Slack token"
|
||||||
|
regex = '''xox[baprs]-.*'''
|
||||||
|
|
||||||
[whitelist]
|
[whitelist]
|
||||||
regexes = [
|
regexes = [
|
||||||
|
|||||||
+33
-269
@@ -8,6 +8,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
git "gopkg.in/src-d/go-git.v4"
|
git "gopkg.in/src-d/go-git.v4"
|
||||||
@@ -34,16 +35,6 @@ files = [
|
|||||||
".go",
|
".go",
|
||||||
]
|
]
|
||||||
`
|
`
|
||||||
const testWhitelistBranch = `
|
|
||||||
[[regexes]]
|
|
||||||
description = "AWS"
|
|
||||||
regex = '''AKIA[0-9A-Z]{16}'''
|
|
||||||
|
|
||||||
[whitelist]
|
|
||||||
branches = [
|
|
||||||
"origin/master",
|
|
||||||
]
|
|
||||||
`
|
|
||||||
|
|
||||||
const testWhitelistRegex = `
|
const testWhitelistRegex = `
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
@@ -87,35 +78,6 @@ entropy = [
|
|||||||
]
|
]
|
||||||
`
|
`
|
||||||
|
|
||||||
var benchmarkRepo *RepoDescriptor
|
|
||||||
var benchmarkLeaksRepo *RepoDescriptor
|
|
||||||
|
|
||||||
func getBenchmarkLeaksRepo() *RepoDescriptor {
|
|
||||||
if benchmarkLeaksRepo != nil {
|
|
||||||
return benchmarkLeaksRepo
|
|
||||||
}
|
|
||||||
leaksR, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: "https://github.com/gitleakstest/gronit.git",
|
|
||||||
})
|
|
||||||
benchmarkLeaksRepo = &RepoDescriptor{
|
|
||||||
repository: leaksR,
|
|
||||||
}
|
|
||||||
return benchmarkLeaksRepo
|
|
||||||
}
|
|
||||||
|
|
||||||
func getBenchmarkRepo() *RepoDescriptor {
|
|
||||||
if benchmarkRepo != nil {
|
|
||||||
return benchmarkRepo
|
|
||||||
}
|
|
||||||
bmRepo, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: "https://github.com/apple/swift-package-manager.git",
|
|
||||||
})
|
|
||||||
benchmarkRepo = &RepoDescriptor{
|
|
||||||
repository: bmRepo,
|
|
||||||
}
|
|
||||||
return benchmarkRepo
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetRepo(t *testing.T) {
|
func TestGetRepo(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
dir, err = ioutil.TempDir("", "gitleaksTestRepo")
|
dir, err = ioutil.TempDir("", "gitleaksTestRepo")
|
||||||
@@ -167,17 +129,15 @@ func TestGetRepo(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Repo: "https://github.com/gitleakstest/private",
|
Repo: "https://github.com/gitleakstest/private",
|
||||||
IncludePrivate: true,
|
|
||||||
},
|
},
|
||||||
description: "test private repo",
|
description: "test private repo",
|
||||||
expectedErrMsg: "invalid auth method",
|
expectedErrMsg: "invalid auth method",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Repo: "https://github.com/gitleakstest/private",
|
Repo: "https://github.com/gitleakstest/private",
|
||||||
IncludePrivate: true,
|
Disk: true,
|
||||||
Disk: true,
|
|
||||||
},
|
},
|
||||||
description: "test private repo",
|
description: "test private repo",
|
||||||
expectedErrMsg: "invalid auth method",
|
expectedErrMsg: "invalid auth method",
|
||||||
@@ -264,13 +224,12 @@ func TestRun(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
GithubOrg: "gitleakstestorg",
|
Repo: "git@github.com:gitleakstest/gronit.git",
|
||||||
IncludePrivate: true,
|
SSHKey: "trash",
|
||||||
SSHKey: "reallyreallyreallyreallywrongpath",
|
|
||||||
},
|
},
|
||||||
description: "test private org no ssh",
|
description: "test leak",
|
||||||
numLeaks: 0,
|
numLeaks: 0,
|
||||||
expectedErrMsg: "unable to generate ssh key: open reallyreallyreallyreallywrongpath: no such file or directory",
|
expectedErrMsg: "unable to generate ssh key: open trash: no such file or directory",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
@@ -370,7 +329,7 @@ func TestWriteReport(t *testing.T) {
|
|||||||
Message: "get",
|
Message: "get",
|
||||||
Author: "some",
|
Author: "some",
|
||||||
File: "sleep",
|
File: "sleep",
|
||||||
Branch: "thxu",
|
Date: time.Now(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +402,6 @@ func TestWriteReport(t *testing.T) {
|
|||||||
func testTomlLoader() string {
|
func testTomlLoader() string {
|
||||||
tmpDir, _ := ioutil.TempDir("", "whiteListConfigs")
|
tmpDir, _ := ioutil.TempDir("", "whiteListConfigs")
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "regex"), []byte(testWhitelistRegex), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "regex"), []byte(testWhitelistRegex), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "branch"), []byte(testWhitelistBranch), 0644)
|
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
|
||||||
ioutil.WriteFile(path.Join(tmpDir, "repo"), []byte(testWhitelistRepo), 0644)
|
ioutil.WriteFile(path.Join(tmpDir, "repo"), []byte(testWhitelistRepo), 0644)
|
||||||
@@ -485,17 +443,16 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
testOpts Options
|
testOpts Options
|
||||||
description string
|
description string
|
||||||
expectedErrMsg string
|
expectedErrMsg string
|
||||||
numLeaks int
|
numLeaks int
|
||||||
repo *RepoDescriptor
|
repo *RepoDescriptor
|
||||||
whiteListFiles []*regexp.Regexp
|
whiteListFiles []*regexp.Regexp
|
||||||
whiteListCommits map[string]bool
|
whiteListCommits map[string]bool
|
||||||
whiteListBranches []string
|
whiteListRepos []*regexp.Regexp
|
||||||
whiteListRepos []*regexp.Regexp
|
whiteListRegexes []*regexp.Regexp
|
||||||
whiteListRegexes []*regexp.Regexp
|
configPath string
|
||||||
configPath string
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
@@ -507,42 +464,7 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
description: "two leaks present limit goroutines",
|
description: "two leaks present limit goroutines",
|
||||||
numLeaks: 2,
|
numLeaks: 2,
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
MaxGoRoutines: 4,
|
Threads: 4,
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
repo: leaksRepo,
|
|
||||||
description: "audit specific bad branch",
|
|
||||||
numLeaks: 2,
|
|
||||||
testOpts: Options{
|
|
||||||
Branch: "master",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
repo: leaksRepo,
|
|
||||||
description: "audit specific good branch",
|
|
||||||
numLeaks: 0,
|
|
||||||
testOpts: Options{
|
|
||||||
Branch: "dev",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
repo: leaksRepo,
|
|
||||||
description: "audit all branch",
|
|
||||||
numLeaks: 6,
|
|
||||||
testOpts: Options{
|
|
||||||
AuditAllRefs: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
repo: leaksRepo,
|
|
||||||
description: "audit all branch whitelist 1",
|
|
||||||
numLeaks: 4,
|
|
||||||
testOpts: Options{
|
|
||||||
AuditAllRefs: true,
|
|
||||||
},
|
|
||||||
whiteListBranches: []string{
|
|
||||||
"origin/master",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -593,15 +515,6 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
configPath: path.Join(configsDir, "regex"),
|
configPath: path.Join(configsDir, "regex"),
|
||||||
numLeaks: 0,
|
numLeaks: 0,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
repo: leaksRepo,
|
|
||||||
description: "toml whitelist branch",
|
|
||||||
configPath: path.Join(configsDir, "branch"),
|
|
||||||
testOpts: Options{
|
|
||||||
AuditAllRefs: true,
|
|
||||||
},
|
|
||||||
numLeaks: 4,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "toml whitelist file",
|
description: "toml whitelist file",
|
||||||
@@ -634,28 +547,28 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Entropy: 4.7,
|
Entropy: 4.7,
|
||||||
},
|
},
|
||||||
numLeaks: 7,
|
numLeaks: 6,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "Audit until specific commit",
|
description: "Audit until specific commit",
|
||||||
numLeaks: 1,
|
numLeaks: 2,
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Commit: "f6839959b7bbdcd23008f1fb16f797f35bcd3a0c",
|
Commit: "f6839959b7bbdcd23008f1fb16f797f35bcd3a0c",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "commit depth = 1, no leaks",
|
description: "commit depth = 1, one leak",
|
||||||
numLeaks: 0,
|
numLeaks: 1,
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Depth: 1,
|
Depth: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "commit depth = 2, one leak",
|
description: "commit depth = 2, two leaks",
|
||||||
numLeaks: 1,
|
numLeaks: 2,
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Depth: 2,
|
Depth: 2,
|
||||||
},
|
},
|
||||||
@@ -663,7 +576,7 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
{
|
{
|
||||||
repo: leaksRepo,
|
repo: leaksRepo,
|
||||||
description: "toml entropy range",
|
description: "toml entropy range",
|
||||||
numLeaks: 422,
|
numLeaks: 284,
|
||||||
configPath: path.Join(configsDir, "entropy"),
|
configPath: path.Join(configsDir, "entropy"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -698,11 +611,6 @@ func TestAuditRepo(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
whiteListCommits = nil
|
whiteListCommits = nil
|
||||||
}
|
}
|
||||||
if test.whiteListBranches != nil {
|
|
||||||
whiteListBranches = test.whiteListBranches
|
|
||||||
} else {
|
|
||||||
whiteListBranches = nil
|
|
||||||
}
|
|
||||||
if test.whiteListRegexes != nil {
|
if test.whiteListRegexes != nil {
|
||||||
whiteListRegexes = test.whiteListRegexes
|
whiteListRegexes = test.whiteListRegexes
|
||||||
} else {
|
} else {
|
||||||
@@ -751,45 +659,24 @@ func TestOptionGuard(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
IncludePrivate: true,
|
GithubUser: "fakeUser",
|
||||||
GithubOrg: "fakeOrg",
|
GithubOrg: "fakeOrg",
|
||||||
},
|
|
||||||
description: "private org no githubtoken",
|
|
||||||
expectedErrMsg: "user/organization private repos require env var GITHUB_TOKEN to be set",
|
|
||||||
githubToken: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testOpts: Options{
|
|
||||||
IncludePrivate: true,
|
|
||||||
GithubUser: "fakeUser",
|
|
||||||
},
|
|
||||||
description: "private user no githubtoken",
|
|
||||||
expectedErrMsg: "user/organization private repos require env var GITHUB_TOKEN to be set",
|
|
||||||
githubToken: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testOpts: Options{
|
|
||||||
IncludePrivate: true,
|
|
||||||
GithubUser: "fakeUser",
|
|
||||||
GithubOrg: "fakeOrg",
|
|
||||||
},
|
},
|
||||||
description: "double owner",
|
description: "double owner",
|
||||||
expectedErrMsg: "github user and organization set",
|
expectedErrMsg: "github user and organization set",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
IncludePrivate: true,
|
GithubOrg: "fakeOrg",
|
||||||
GithubOrg: "fakeOrg",
|
OwnerPath: "/dev/null",
|
||||||
OwnerPath: "/dev/null",
|
|
||||||
},
|
},
|
||||||
description: "local and remote target",
|
description: "local and remote target",
|
||||||
expectedErrMsg: "github organization set and local owner path",
|
expectedErrMsg: "github organization set and local owner path",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
IncludePrivate: true,
|
GithubUser: "fakeUser",
|
||||||
GithubUser: "fakeUser",
|
OwnerPath: "/dev/null",
|
||||||
OwnerPath: "/dev/null",
|
|
||||||
},
|
},
|
||||||
description: "local and remote target",
|
description: "local and remote target",
|
||||||
expectedErrMsg: "github user set and local owner path",
|
expectedErrMsg: "github user set and local owner path",
|
||||||
@@ -919,126 +806,3 @@ func TestLoadToml(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkAuditRepo1Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 1
|
|
||||||
benchmarkRepo = getBenchmarkRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditRepo2Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 2
|
|
||||||
benchmarkRepo = getBenchmarkRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditRepo4Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 4
|
|
||||||
benchmarkRepo = getBenchmarkRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditRepo8Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 8
|
|
||||||
benchmarkRepo = getBenchmarkRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditRepo10Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 10
|
|
||||||
benchmarkRepo = getBenchmarkRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditRepo100Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 100
|
|
||||||
benchmarkRepo = getBenchmarkRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditRepo1000Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 1000
|
|
||||||
benchmarkRepo = getBenchmarkRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func BenchmarkAuditLeakRepo1Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 1
|
|
||||||
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditLeakRepo2Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 2
|
|
||||||
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditLeakRepo4Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 4
|
|
||||||
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditLeakRepo8Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 8
|
|
||||||
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAuditLeakRepo10Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 10
|
|
||||||
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func BenchmarkAuditLeakRepo100Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 100
|
|
||||||
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func BenchmarkAuditLeakRepo1000Proc(b *testing.B) {
|
|
||||||
loadToml()
|
|
||||||
opts.MaxGoRoutines = 1000
|
|
||||||
benchmarkLeaksRepo = getBenchmarkLeaksRepo()
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
auditGitRepo(benchmarkRepo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -37,15 +37,15 @@ import (
|
|||||||
|
|
||||||
// Leak represents a leaked secret or regex match.
|
// Leak represents a leaked secret or regex match.
|
||||||
type Leak struct {
|
type Leak struct {
|
||||||
Line string `json:"line"`
|
Line string `json:"line"`
|
||||||
Commit string `json:"commit"`
|
Commit string `json:"commit"`
|
||||||
Offender string `json:"offender"`
|
Offender string `json:"offender"`
|
||||||
Type string `json:"reason"`
|
Type string `json:"reason"`
|
||||||
Message string `json:"commitMsg"`
|
Message string `json:"commitMsg"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
File string `json:"file"`
|
File string `json:"file"`
|
||||||
Branch string `json:"branch"`
|
Repo string `json:"repo"`
|
||||||
Repo string `json:"repo"`
|
Date time.Time `json:"date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoDescriptor contains a src-d git repository and other data about the repo
|
// RepoDescriptor contains a src-d git repository and other data about the repo
|
||||||
@@ -60,12 +60,11 @@ type RepoDescriptor struct {
|
|||||||
// Options for gitleaks
|
// Options for gitleaks
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// remote target options
|
// remote target options
|
||||||
Repo string `short:"r" long:"repo" description:"Repo url to audit"`
|
Repo string `short:"r" long:"repo" description:"Repo url to audit"`
|
||||||
GithubUser string `long:"github-user" description:"Github user to audit"`
|
GithubUser string `long:"github-user" description:"Github user to audit"`
|
||||||
GithubOrg string `long:"github-org" description:"Github organization to audit"`
|
GithubOrg string `long:"github-org" description:"Github organization to audit"`
|
||||||
GithubURL string `long:"github-url" default:"https://api.github.com/" description:"GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/"`
|
GithubURL string `long:"github-url" default:"https://api.github.com/" description:"GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/"`
|
||||||
GithubPR string `long:"github-pr" description:"Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set"`
|
GithubPR string `long:"github-pr" description:"Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set"`
|
||||||
IncludePrivate bool `short:"p" long:"private" description:"Include private repos in audit"`
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
@@ -73,7 +72,6 @@ type Options struct {
|
|||||||
GitLabOrg string `long:"gitlab-org" description:"Organization url to audit"`
|
GitLabOrg string `long:"gitlab-org" description:"Organization url to audit"`
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Branch string `short:"b" long:"branch" description:"branch name to audit (defaults to HEAD)"`
|
|
||||||
Commit string `short:"c" long:"commit" description:"sha of commit to stop at"`
|
Commit string `short:"c" long:"commit" description:"sha of commit to stop at"`
|
||||||
Depth int `long:"depth" description:"maximum commit depth"`
|
Depth int `long:"depth" description:"maximum commit depth"`
|
||||||
|
|
||||||
@@ -82,14 +80,13 @@ type Options struct {
|
|||||||
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
|
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
|
||||||
|
|
||||||
// Process options
|
// Process options
|
||||||
MaxGoRoutines int `long:"max-go" description:"Maximum number of concurrent go-routines gitleaks spawns"`
|
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
|
||||||
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
||||||
AuditAllRefs bool `long:"all-refs" description:"run audit on all refs"`
|
SingleSearch string `long:"single-search" description:"single regular expression to search for"`
|
||||||
SingleSearch string `long:"single-search" description:"single regular expression to search for"`
|
ConfigPath string `long:"config" description:"path to gitleaks config"`
|
||||||
ConfigPath string `long:"config" description:"path to gitleaks config"`
|
SSHKey string `long:"ssh-key" description:"path to ssh key"`
|
||||||
SSHKey string `long:"ssh-key" description:"path to ssh key"`
|
ExcludeForks bool `long:"exclude-forks" description:"exclude forks for organization/user audits"`
|
||||||
ExcludeForks bool `long:"exclude-forks" description:"exclude forks for organization/user audits"`
|
Entropy float64 `long:"entropy" short:"e" description:"Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)"`
|
||||||
Entropy float64 `long:"entropy" short:"e" description:"Include entropy checks during audit. Entropy scale: 0.0(no entropy) - 8.0(max entropy)"`
|
|
||||||
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
||||||
|
|
||||||
// Output options
|
// Output options
|
||||||
@@ -108,11 +105,10 @@ type Config struct {
|
|||||||
Regex string
|
Regex string
|
||||||
}
|
}
|
||||||
Whitelist struct {
|
Whitelist struct {
|
||||||
Files []string
|
Files []string
|
||||||
Regexes []string
|
Regexes []string
|
||||||
Commits []string
|
Commits []string
|
||||||
Branches []string
|
Repos []string
|
||||||
Repos []string
|
|
||||||
}
|
}
|
||||||
Misc struct {
|
Misc struct {
|
||||||
Entropy []string
|
Entropy []string
|
||||||
@@ -123,12 +119,12 @@ type gitDiff struct {
|
|||||||
content string
|
content string
|
||||||
commit *object.Commit
|
commit *object.Commit
|
||||||
filePath string
|
filePath string
|
||||||
branchName string
|
|
||||||
repoName string
|
repoName string
|
||||||
githubCommit *github.RepositoryCommit
|
githubCommit *github.RepositoryCommit
|
||||||
sha string
|
sha string
|
||||||
message string
|
message string
|
||||||
author string
|
author string
|
||||||
|
date time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type entropyRange struct {
|
type entropyRange struct {
|
||||||
@@ -137,7 +133,7 @@ type entropyRange struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultGithubURL = "https://api.github.com/"
|
const defaultGithubURL = "https://api.github.com/"
|
||||||
const version = "1.15.0"
|
const version = "1.19.1"
|
||||||
const errExit = 2
|
const errExit = 2
|
||||||
const leakExit = 1
|
const leakExit = 1
|
||||||
const defaultConfig = `
|
const defaultConfig = `
|
||||||
@@ -146,53 +142,47 @@ const defaultConfig = `
|
|||||||
# is set, gitleaks will load configurations from that path. If option --config-path is set, gitleaks will load
|
# is set, gitleaks will load configurations from that path. If option --config-path is set, gitleaks will load
|
||||||
# configurations from that path. Gitleaks does not whitelist anything by default.
|
# configurations from that path. Gitleaks does not whitelist anything by default.
|
||||||
|
|
||||||
|
|
||||||
title = "gitleaks config"
|
title = "gitleaks config"
|
||||||
# add regexes to the regex table
|
# add regexes to the regex table
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "AWS"
|
description = "AWS"
|
||||||
regex = '''AKIA[0-9A-Z]{16}'''
|
regex = '''AKIA[0-9A-Z]{16}'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "RKCS8"
|
description = "PKCS8"
|
||||||
regex = '''-----BEGIN PRIVATE KEY-----'''
|
regex = '''-----BEGIN PRIVATE KEY-----'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "RSA"
|
description = "RSA"
|
||||||
regex = '''-----BEGIN RSA PRIVATE KEY-----'''
|
regex = '''-----BEGIN RSA PRIVATE KEY-----'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "Github"
|
|
||||||
regex = '''(?i)github.*['\"][0-9a-zA-Z]{35,40}['\"]'''
|
|
||||||
[[regexes]]
|
|
||||||
description = "SSH"
|
description = "SSH"
|
||||||
regex = '''-----BEGIN OPENSSH PRIVATE KEY-----'''
|
regex = '''-----BEGIN OPENSSH PRIVATE KEY-----'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
|
description = "PGP"
|
||||||
|
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
||||||
|
[[regexes]]
|
||||||
description = "Facebook"
|
description = "Facebook"
|
||||||
regex = '''(?i)facebook.*['\"][0-9a-f]{32}['\"]'''
|
regex = '''(?i)facebook(.{0,4})?['\"][0-9a-f]{32}['\"]'''
|
||||||
[[regexes]]
|
[[regexes]]
|
||||||
description = "Twitter"
|
description = "Twitter"
|
||||||
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
|
regex = '''(?i)twitter(.{0,4})?['\"][0-9a-zA-Z]{35,44}['\"]'''
|
||||||
|
[[regexes]]
|
||||||
|
description = "Github"
|
||||||
|
regex = '''(?i)github(.{0,4})?['\"][0-9a-zA-Z]{35,40}['\"]'''
|
||||||
|
[[regexes]]
|
||||||
|
description = "Slack"
|
||||||
|
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||||
|
|
||||||
[whitelist]
|
[whitelist]
|
||||||
#regexes = [
|
files = [
|
||||||
# "AKAIMYFAKEAWKKEY",
|
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||||
#]
|
]
|
||||||
|
|
||||||
#files = [
|
|
||||||
# "(.*?)(jpg|gif|doc|pdf|bin)$"
|
|
||||||
#]
|
|
||||||
|
|
||||||
#commits = [
|
#commits = [
|
||||||
# "BADHA5H1",
|
# "BADHA5H1",
|
||||||
# "BADHA5H2",
|
# "BADHA5H2",
|
||||||
#]
|
#]
|
||||||
|
|
||||||
#branches = [
|
|
||||||
# "dev/goodrepo"
|
|
||||||
#]
|
|
||||||
|
|
||||||
#repos = [
|
#repos = [
|
||||||
# "mygoodrepo"
|
# "mygoodrepo"
|
||||||
#]
|
#]
|
||||||
|
|
||||||
[misc]
|
[misc]
|
||||||
#entropy = [
|
#entropy = [
|
||||||
# "3.3-4.30"
|
# "3.3-4.30"
|
||||||
@@ -207,19 +197,21 @@ var (
|
|||||||
whiteListRegexes []*regexp.Regexp
|
whiteListRegexes []*regexp.Regexp
|
||||||
whiteListFiles []*regexp.Regexp
|
whiteListFiles []*regexp.Regexp
|
||||||
whiteListCommits map[string]bool
|
whiteListCommits map[string]bool
|
||||||
whiteListBranches []string
|
|
||||||
whiteListRepos []*regexp.Regexp
|
whiteListRepos []*regexp.Regexp
|
||||||
entropyRanges []entropyRange
|
entropyRanges []entropyRange
|
||||||
fileDiffRegex *regexp.Regexp
|
fileDiffRegex *regexp.Regexp
|
||||||
sshAuth *ssh.PublicKeys
|
sshAuth *ssh.PublicKeys
|
||||||
dir string
|
dir string
|
||||||
maxGo int
|
threads int
|
||||||
totalCommits int64
|
totalCommits int64
|
||||||
|
commitMap = make(map[string]bool)
|
||||||
|
cMutex = &sync.Mutex{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
maxGo = runtime.GOMAXPROCS(0) / 2
|
// threads = runtime.GOMAXPROCS(0) / 2
|
||||||
|
threads = 1
|
||||||
regexes = make(map[string]*regexp.Regexp)
|
regexes = make(map[string]*regexp.Regexp)
|
||||||
whiteListCommits = make(map[string]bool)
|
whiteListCommits = make(map[string]bool)
|
||||||
}
|
}
|
||||||
@@ -280,13 +272,11 @@ func run() ([]Leak, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if opts.IncludePrivate {
|
sshAuth, err = getSSHAuth()
|
||||||
// if including private repos use ssh as authentication
|
if err != nil {
|
||||||
sshAuth, err = getSSHAuth()
|
return leaks, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Disk {
|
if opts.Disk {
|
||||||
// temporary directory where all the gitleaks plain clones will reside
|
// temporary directory where all the gitleaks plain clones will reside
|
||||||
dir, err = ioutil.TempDir("", "gitleaks")
|
dir, err = ioutil.TempDir("", "gitleaks")
|
||||||
@@ -319,8 +309,7 @@ func run() ([]Leak, error) {
|
|||||||
leaks = append(leaksFromRepo, leaks...)
|
leaks = append(leaksFromRepo, leaks...)
|
||||||
}
|
}
|
||||||
} else if opts.GithubOrg != "" || opts.GithubUser != "" {
|
} else if opts.GithubOrg != "" || opts.GithubUser != "" {
|
||||||
// Audit a github owner -- a user or organization. If you want to include
|
// Audit a github owner -- a user or organization.
|
||||||
// private repos you must pass a --private/-p option and have your ssh keys set
|
|
||||||
leaks, err = auditGithubRepos()
|
leaks, err = auditGithubRepos()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return leaks, err
|
return leaks, err
|
||||||
@@ -343,9 +332,9 @@ func writeReport(leaks []Leak) error {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
w := csv.NewWriter(f)
|
w := csv.NewWriter(f)
|
||||||
w.Write([]string{"repo", "line", "commit", "offender", "reason", "commitMsg", "author", "file", "branch"})
|
w.Write([]string{"repo", "line", "commit", "offender", "reason", "commitMsg", "author", "file", "date"})
|
||||||
for _, leak := range leaks {
|
for _, leak := range leaks {
|
||||||
w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.Type, leak.Message, leak.Author, leak.File, leak.Branch})
|
w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.Type, leak.Message, leak.Author, leak.File, leak.Date.Format(time.RFC3339)})
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
} else {
|
} else {
|
||||||
@@ -355,9 +344,7 @@ func writeReport(leaks []Leak) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// cloneRepo clones a repo to memory(default) or to disk if the --disk option is set. If you want to
|
// cloneRepo clones a repo to memory(default) or to disk if the --disk option is set.
|
||||||
// clone a private repo you must set the --private/-p option, use a ssh target, and have your ssh keys
|
|
||||||
// configured. If you want to audit a local repo, getRepo will load up a repo located at --repo-path
|
|
||||||
func cloneRepo() (*RepoDescriptor, error) {
|
func cloneRepo() (*RepoDescriptor, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
@@ -372,7 +359,7 @@ func cloneRepo() (*RepoDescriptor, error) {
|
|||||||
if opts.Disk {
|
if opts.Disk {
|
||||||
log.Infof("cloning %s", opts.Repo)
|
log.Infof("cloning %s", opts.Repo)
|
||||||
cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo))))
|
cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo))))
|
||||||
if opts.IncludePrivate {
|
if strings.HasPrefix(opts.Repo, "git") {
|
||||||
repo, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{
|
repo, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{
|
||||||
URL: opts.Repo,
|
URL: opts.Repo,
|
||||||
Progress: os.Stdout,
|
Progress: os.Stdout,
|
||||||
@@ -385,11 +372,11 @@ func cloneRepo() (*RepoDescriptor, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else if opts.RepoPath != "" {
|
} else if opts.RepoPath != "" {
|
||||||
log.Infof("opening %s", opts.Repo)
|
log.Infof("opening %s", opts.RepoPath)
|
||||||
repo, err = git.PlainOpen(opts.RepoPath)
|
repo, err = git.PlainOpen(opts.RepoPath)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("cloning %s", opts.Repo)
|
log.Infof("cloning %s", opts.Repo)
|
||||||
if opts.IncludePrivate {
|
if strings.HasPrefix(opts.Repo, "git") {
|
||||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
URL: opts.Repo,
|
URL: opts.Repo,
|
||||||
Progress: os.Stdout,
|
Progress: os.Stdout,
|
||||||
@@ -411,9 +398,7 @@ func cloneRepo() (*RepoDescriptor, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// auditGitRepo beings an audit on a git repository by checking the default HEAD branch, all branches, or
|
// auditGitRepo beings an audit on a git repository
|
||||||
// a single branch depending on what gitleaks is configured to do. Note when I say branch I really
|
|
||||||
// mean reference as these branches are read only.
|
|
||||||
func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
@@ -424,149 +409,94 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
return leaks, fmt.Errorf("skipping %s, whitelisted", repo.name)
|
return leaks, fmt.Errorf("skipping %s, whitelisted", repo.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ref, err := repo.repository.Head()
|
|
||||||
|
// clear commit cache
|
||||||
|
commitMap = make(map[string]bool)
|
||||||
|
|
||||||
|
refs, err := repo.repository.Storer.IterReferences()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return leaks, err
|
return leaks, err
|
||||||
}
|
}
|
||||||
|
err = refs.ForEach(func(ref *plumbing.Reference) error {
|
||||||
if opts.AuditAllRefs {
|
if ref.Name().IsTag() {
|
||||||
skipBranch := false
|
|
||||||
refs, err := repo.repository.Storer.IterReferences()
|
|
||||||
if err != nil {
|
|
||||||
return leaks, err
|
|
||||||
}
|
|
||||||
err = refs.ForEach(func(ref *plumbing.Reference) error {
|
|
||||||
for _, b := range whiteListBranches {
|
|
||||||
if strings.HasSuffix(string(ref.Name()), b) {
|
|
||||||
skipBranch = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if skipBranch {
|
|
||||||
skipBranch = false
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
branchLeaks := auditGitReference(repo, ref)
|
|
||||||
for _, leak := range branchLeaks {
|
|
||||||
leaks = append(leaks, leak)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
|
||||||
} else {
|
|
||||||
if opts.Branch != "" {
|
|
||||||
foundBranch := false
|
|
||||||
refs, _ := repo.repository.Storer.IterReferences()
|
|
||||||
branch := strings.Split(opts.Branch, "/")[len(strings.Split(opts.Branch, "/"))-1]
|
|
||||||
err = refs.ForEach(func(refBranch *plumbing.Reference) error {
|
|
||||||
if strings.Split(refBranch.Name().String(), "/")[len(strings.Split(refBranch.Name().String(), "/"))-1] == branch {
|
|
||||||
foundBranch = true
|
|
||||||
ref = refBranch
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if foundBranch == false {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
leaks = auditGitReference(repo, ref)
|
branchLeaks := auditGitReference(repo, ref)
|
||||||
}
|
for _, leak := range branchLeaks {
|
||||||
|
leaks = append(leaks, leak)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
return leaks, err
|
return leaks, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// auditGitReference beings the audit for a git reference. This function will
|
// auditGitReference beings the audit for a git reference. This function will
|
||||||
// traverse the git reference and audit each line of each diff. Set maximum concurrency with
|
// traverse the git reference and audit each line of each diff.
|
||||||
// the --max-go option (default is set to the number of cores on your cpu).
|
|
||||||
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
prevCommit *object.Commit
|
|
||||||
semaphore chan bool
|
|
||||||
repoName string
|
repoName string
|
||||||
leaks []Leak
|
leaks []Leak
|
||||||
|
commitCount int
|
||||||
commitWg sync.WaitGroup
|
commitWg sync.WaitGroup
|
||||||
mutex = &sync.Mutex{}
|
mutex = &sync.Mutex{}
|
||||||
commitCount int
|
semaphore chan bool
|
||||||
)
|
)
|
||||||
repoName = repo.name
|
repoName = repo.name
|
||||||
if opts.MaxGoRoutines != 0 {
|
if opts.Threads != 0 {
|
||||||
maxGo = opts.MaxGoRoutines
|
threads = opts.Threads
|
||||||
}
|
}
|
||||||
|
if opts.RepoPath != "" {
|
||||||
|
threads = 1
|
||||||
|
}
|
||||||
|
semaphore = make(chan bool, threads)
|
||||||
|
|
||||||
semaphore = make(chan bool, maxGo)
|
|
||||||
cIter, err := repo.repository.Log(&git.LogOptions{From: ref.Hash()})
|
cIter, err := repo.repository.Log(&git.LogOptions{From: ref.Hash()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err = cIter.ForEach(func(c *object.Commit) error {
|
err = cIter.ForEach(func(c *object.Commit) error {
|
||||||
if c.Hash.String() == opts.Commit || (opts.Depth != 0 && commitCount == opts.Depth) {
|
if commitMap[c.Hash.String()] {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cMutex.Lock()
|
||||||
|
commitMap[c.Hash.String()] = true
|
||||||
|
cMutex.Unlock()
|
||||||
|
if c == nil || c.Hash.String() == opts.Commit || (opts.Depth != 0 && commitCount == opts.Depth) {
|
||||||
cIter.Close()
|
cIter.Close()
|
||||||
return errors.New("ErrStop")
|
return errors.New("ErrStop")
|
||||||
}
|
}
|
||||||
commitCount = commitCount + 1
|
commitCount = commitCount + 1
|
||||||
totalCommits = totalCommits + 1
|
totalCommits = totalCommits + 1
|
||||||
if whiteListCommits[c.Hash.String()] {
|
if whiteListCommits[c.Hash.String()] {
|
||||||
prevCommit = c
|
|
||||||
log.Infof("skipping commit: %s\n", c.Hash.String())
|
log.Infof("skipping commit: %s\n", c.Hash.String())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if prevCommit != nil {
|
|
||||||
if whiteListCommits[prevCommit.Hash.String()] {
|
|
||||||
prevCommit = c
|
|
||||||
log.Infof("skipping commit: %s\n", c.Hash.String())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commitWg.Add(1)
|
err = c.Parents().ForEach(func(parent *object.Commit) error {
|
||||||
semaphore <- true
|
commitWg.Add(1)
|
||||||
go func(c *object.Commit, prevCommit *object.Commit) {
|
semaphore <- true
|
||||||
var (
|
go func(c *object.Commit, parent *object.Commit) {
|
||||||
filePath string
|
var (
|
||||||
skipFile bool
|
filePath string
|
||||||
)
|
skipFile bool
|
||||||
defer func() {
|
)
|
||||||
commitWg.Done()
|
defer func() {
|
||||||
<-semaphore
|
commitWg.Done()
|
||||||
if r := recover(); r != nil {
|
<-semaphore
|
||||||
log.Warnf("recoverying from panic on commit %s, likely large diff causing panic", c.Hash.String())
|
if r := recover(); r != nil {
|
||||||
}
|
log.Warnf("recoverying from panic on commit %s, likely large diff causing panic", c.Hash.String())
|
||||||
}()
|
|
||||||
|
|
||||||
if prevCommit == nil {
|
|
||||||
t, _ := c.Tree()
|
|
||||||
files := t.Files()
|
|
||||||
err := files.ForEach(func(file *object.File) error {
|
|
||||||
content, err := file.Contents()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
diff := gitDiff{
|
}()
|
||||||
branchName: string(ref.Name()),
|
patch, err := c.Patch(parent)
|
||||||
repoName: repoName,
|
|
||||||
filePath: file.Name,
|
|
||||||
content: content,
|
|
||||||
sha: c.Hash.String(),
|
|
||||||
author: c.Author.String(),
|
|
||||||
message: c.Message,
|
|
||||||
}
|
|
||||||
chunkLeaks := inspect(diff)
|
|
||||||
for _, leak := range chunkLeaks {
|
|
||||||
mutex.Lock()
|
|
||||||
leaks = append(leaks, leak)
|
|
||||||
mutex.Unlock()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("problem generating diff for commit: %s\n", c.Hash.String())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
patch, err := c.Patch(prevCommit)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("problem generating patch for commit: %s\n", c.Hash.String())
|
log.Warnf("problem generating patch for commit: %s\n", c.Hash.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, f := range patch.FilePatches() {
|
for _, f := range patch.FilePatches() {
|
||||||
|
if f.IsBinary() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
skipFile = false
|
skipFile = false
|
||||||
from, to := f.Files()
|
from, to := f.Files()
|
||||||
filePath = "???"
|
filePath = "???"
|
||||||
@@ -588,13 +518,13 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
for _, chunk := range chunks {
|
for _, chunk := range chunks {
|
||||||
if chunk.Type() == 1 || chunk.Type() == 2 {
|
if chunk.Type() == 1 || chunk.Type() == 2 {
|
||||||
diff := gitDiff{
|
diff := gitDiff{
|
||||||
branchName: string(ref.Name()),
|
repoName: repoName,
|
||||||
repoName: repoName,
|
filePath: filePath,
|
||||||
filePath: filePath,
|
content: chunk.Content(),
|
||||||
content: chunk.Content(),
|
sha: c.Hash.String(),
|
||||||
sha: prevCommit.Hash.String(),
|
author: c.Author.String(),
|
||||||
author: prevCommit.Author.String(),
|
message: c.Message,
|
||||||
message: prevCommit.Message,
|
date: c.Author.When,
|
||||||
}
|
}
|
||||||
chunkLeaks := inspect(diff)
|
chunkLeaks := inspect(diff)
|
||||||
for _, leak := range chunkLeaks {
|
for _, leak := range chunkLeaks {
|
||||||
@@ -605,9 +535,9 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}(c, parent)
|
||||||
}(c, prevCommit)
|
return nil
|
||||||
prevCommit = c
|
})
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
commitWg.Wait()
|
commitWg.Wait()
|
||||||
@@ -682,9 +612,9 @@ func addLeak(leaks []Leak, line string, offender string, leakType string, diff g
|
|||||||
Type: leakType,
|
Type: leakType,
|
||||||
Author: diff.author,
|
Author: diff.author,
|
||||||
File: diff.filePath,
|
File: diff.filePath,
|
||||||
Branch: diff.branchName,
|
|
||||||
Repo: diff.repoName,
|
Repo: diff.repoName,
|
||||||
Message: diff.message,
|
Message: diff.message,
|
||||||
|
Date: diff.date,
|
||||||
}
|
}
|
||||||
if opts.Redact {
|
if opts.Redact {
|
||||||
leak.Offender = "REDACTED"
|
leak.Offender = "REDACTED"
|
||||||
@@ -773,8 +703,10 @@ func optsGuard() error {
|
|||||||
return fmt.Errorf("github organization set and local owner path")
|
return fmt.Errorf("github organization set and local owner path")
|
||||||
} else if opts.GithubUser != "" && opts.OwnerPath != "" {
|
} else if opts.GithubUser != "" && opts.OwnerPath != "" {
|
||||||
return fmt.Errorf("github user set and local owner path")
|
return fmt.Errorf("github user set and local owner path")
|
||||||
} else if opts.IncludePrivate && os.Getenv("GITHUB_TOKEN") == "" && (opts.GithubOrg != "" || opts.GithubUser != "") {
|
}
|
||||||
return fmt.Errorf("user/organization private repos require env var GITHUB_TOKEN to be set")
|
|
||||||
|
if opts.Threads > runtime.GOMAXPROCS(0) {
|
||||||
|
return fmt.Errorf("%d available threads", runtime.GOMAXPROCS(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the URL Parse and error checking here, so we can skip it later
|
// do the URL Parse and error checking here, so we can skip it later
|
||||||
@@ -866,7 +798,6 @@ func loadToml() error {
|
|||||||
regexes[regex.Description] = regexp.MustCompile(regex.Regex)
|
regexes[regex.Description] = regexp.MustCompile(regex.Regex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
whiteListBranches = config.Whitelist.Branches
|
|
||||||
whiteListCommits = make(map[string]bool)
|
whiteListCommits = make(map[string]bool)
|
||||||
for _, commit := range config.Whitelist.Commits {
|
for _, commit := range config.Whitelist.Commits {
|
||||||
whiteListCommits[commit] = true
|
whiteListCommits[commit] = true
|
||||||
@@ -921,14 +852,22 @@ func getSSHAuth() (*ssh.PublicKeys, error) {
|
|||||||
if opts.SSHKey != "" {
|
if opts.SSHKey != "" {
|
||||||
sshKeyPath = opts.SSHKey
|
sshKeyPath = opts.SSHKey
|
||||||
} else {
|
} else {
|
||||||
c, _ := user.Current()
|
// try grabbing default
|
||||||
|
c, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
sshKeyPath = fmt.Sprintf("%s/.ssh/id_rsa", c.HomeDir)
|
sshKeyPath = fmt.Sprintf("%s/.ssh/id_rsa", c.HomeDir)
|
||||||
}
|
}
|
||||||
sshAuth, err := ssh.NewPublicKeysFromFile("git", sshKeyPath, "")
|
sshAuth, err := ssh.NewPublicKeysFromFile("git", sshKeyPath, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to generate ssh key: %v", err)
|
if strings.HasPrefix(opts.Repo, "git") {
|
||||||
|
// if you are attempting to clone a git repo via ssh and supply a bad ssh key,
|
||||||
|
// the clone will fail.
|
||||||
|
return nil, fmt.Errorf("unable to generate ssh key: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sshAuth, err
|
return sshAuth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (leak Leak) log() {
|
func (leak Leak) log() {
|
||||||
|
|||||||
Reference in new issue
Block a user