mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 04:34:46 +01:00
yamlizing
This commit is contained in:
1 parent
0fa6a79a25
commit
6f5079c193
4 files changed
+74
-53
No files matched your search
@@ -83,21 +83,6 @@ func checkShannonEntropy(target string, entropy64Cutoff int, entropyHexCutoff in
|
|||||||
|
|
||||||
// containsStopWords checks if there are any stop words in target
|
// containsStopWords checks if there are any stop words in target
|
||||||
func containsStopWords(target string) bool {
|
func containsStopWords(target string) bool {
|
||||||
stopWords := []string{
|
|
||||||
"setting",
|
|
||||||
"Setting",
|
|
||||||
"SETTING",
|
|
||||||
"info",
|
|
||||||
"Info",
|
|
||||||
"INFO",
|
|
||||||
"env",
|
|
||||||
"Env",
|
|
||||||
"ENV",
|
|
||||||
"environment",
|
|
||||||
"Environment",
|
|
||||||
"ENVIRONMENT",
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, stopWord := range stopWords {
|
for _, stopWord := range stopWords {
|
||||||
if strings.Contains(target, stopWord) {
|
if strings.Contains(target, stopWord) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
regexes:
|
||||||
|
- '[g|G][i|I][t|T][h|H][u|U][b|B].*(=|:=|<-).*\w+.*'
|
||||||
|
- '[a|A][w|W][s|S].*(=|:=|:|<-).*\w+.*'
|
||||||
|
- '[h|H][e|E][r|R][o|O][k|K][u|U].*(=|:=|<-).*\w+.*'
|
||||||
|
- '[f|F][a|A][c|C][e|E][b|B][o|O][o|O][k|K].*(=|:=|<-).*\w+.*'
|
||||||
|
- '[t|T][w|W][i|I][t|T][t|T][e|E][r|R].*(=|:=|<-).*\w+.*'
|
||||||
|
- '[r|R][e|E][d|D][d|D][i|I][t|T].*(=|:=|<-).*\w+.*'
|
||||||
|
- '[t|T][w|W][i|I][l|L][i|I][o|O].*(=|:=|<-).*\w+.*'
|
||||||
|
|
||||||
|
stopwords:
|
||||||
|
- 'setting'
|
||||||
|
- 'Setting'
|
||||||
|
- 'SETTING'
|
||||||
|
- 'info'
|
||||||
|
- 'Info'
|
||||||
|
- 'INFO'
|
||||||
|
- 'env'
|
||||||
|
- 'Env'
|
||||||
|
- 'ENV'
|
||||||
|
- 'environment'
|
||||||
|
- 'Environment'
|
||||||
|
- 'ENVIRONMENT'
|
||||||
|
|
||||||
@@ -3,44 +3,64 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
appRoot string
|
appRoot string
|
||||||
regexes map[string]*regexp.Regexp
|
regexes []*regexp.Regexp
|
||||||
|
stopWords []string
|
||||||
assignRegex *regexp.Regexp
|
assignRegex *regexp.Regexp
|
||||||
base64Chars string
|
base64Chars string
|
||||||
hexChars string
|
hexChars string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// config
|
||||||
|
type conf struct {
|
||||||
|
Regexes []string `yaml:"regexes"`
|
||||||
|
StopWords []string `yaml:"stopwords"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RepoElem used for parsing json from github api
|
||||||
|
type RepoElem struct {
|
||||||
|
RepoURL string `json:"html_url"`
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var (
|
||||||
|
err error
|
||||||
|
c conf
|
||||||
|
)
|
||||||
|
|
||||||
appRoot, err = os.Getwd()
|
appRoot, err = os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Can't get working dir: %s", err)
|
log.Fatalf("Can't get working dir: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO update regex to look for things like:
|
|
||||||
// TODO ability to add/filter regex
|
|
||||||
// client("AKAI32fJ334...",
|
|
||||||
regexes = map[string]*regexp.Regexp{
|
|
||||||
"github": regexp.MustCompile(`[g|G][i|I][t|T][h|H][u|U][b|B].*(=|:=|<-).*\w+.*`),
|
|
||||||
"aws": regexp.MustCompile(`[a|A][w|W][s|S].*(=|:=|:|<-).*\w+.*`),
|
|
||||||
"heroku": regexp.MustCompile(`[h|H][e|E][r|R][o|O][k|K][u|U].*(=|:=|<-).*\w+.*`),
|
|
||||||
"facebook": regexp.MustCompile(`[f|F][a|A][c|C][e|E][b|B][o|O][o|O][k|K].*(=|:=|<-).*\w+.*`),
|
|
||||||
"twitter": regexp.MustCompile(`[t|T][w|W][i|I][t|T][t|T][e|E][r|R].*(=|:=|<-).*\w+.*`),
|
|
||||||
"reddit": regexp.MustCompile(`[r|R][e|E][d|D][d|D][i|I][t|T].*(=|:=|<-).*\w+.*`),
|
|
||||||
"twilio": regexp.MustCompile(`[t|T][w|W][i|I][l|L][i|I][o|O].*(=|:=|<-).*\w+.*`),
|
|
||||||
}
|
|
||||||
assignRegex = regexp.MustCompile(`(=|:|:=|<-)`)
|
|
||||||
base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
||||||
hexChars = "1234567890abcdefABCDEF"
|
hexChars = "1234567890abcdefABCDEF"
|
||||||
|
|
||||||
|
// read config
|
||||||
|
ymlFile, err := ioutil.ReadFile("config.yml")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("could not load config.yml #%v ", err)
|
||||||
|
}
|
||||||
|
err = yaml.Unmarshal(ymlFile, &c)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Unmarshal: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// regex from config
|
||||||
|
stopWords = c.StopWords
|
||||||
|
for _, re := range c.Regexes {
|
||||||
|
regexes = append(regexes, regexp.MustCompile(re))
|
||||||
|
}
|
||||||
|
assignRegex = regexp.MustCompile(`(=|:|:=|<-)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -57,10 +77,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoElem used for parsing json from github api
|
|
||||||
type RepoElem struct {
|
|
||||||
RepoURL string `json:"html_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// repoScan attempts to parse all repo urls from an organization or user
|
// repoScan attempts to parse all repo urls from an organization or user
|
||||||
func repoScan(opts *Options) []RepoElem {
|
func repoScan(opts *Options) []RepoElem {
|
||||||
|
|||||||
+14
-17
@@ -6,19 +6,16 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO regex on type.. user/organization can be treated as the same:
|
const usage = `usage: gitleaks [options] <url>
|
||||||
// hittps://github.com/<user or org>
|
|
||||||
// hittps://github.com/<user or org>/repo
|
|
||||||
const usage = `usage: gitleaks [git link] [options]
|
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-c Concurrency factor (potential number of git files open)
|
-c Concurrency factor
|
||||||
-u Git user url
|
-u --user Git user url
|
||||||
-r Git repo url
|
-r --repo Git repo url
|
||||||
-o Git organization url
|
-o --org Git organization url
|
||||||
-s Strict mode uses stopwords in checks.go
|
-s --strict Strict mode uses stopwords in config.yml
|
||||||
-e Base64 entropy cutoff, default is 70
|
-e --b64Entropy Base64 entropy cutoff, default is 70
|
||||||
-x Hex entropy cutoff, default is 40
|
-x --hexEntropy Hex entropy cutoff, default is 40
|
||||||
-h --help Display this message
|
-h --help Display this message
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -78,19 +75,19 @@ func parseOptions(args []string) *Options {
|
|||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
switch arg {
|
switch arg {
|
||||||
case "-s":
|
case "-s", "--strict":
|
||||||
opts.Strict = true
|
opts.Strict = true
|
||||||
case "-e":
|
case "-e", "--b64Entropy":
|
||||||
opts.B64EntropyCutoff = optionsNextInt(args, &i)
|
opts.B64EntropyCutoff = optionsNextInt(args, &i)
|
||||||
case "-x":
|
case "-x", "--hexEntropy":
|
||||||
opts.HexEntropyCutoff = optionsNextInt(args, &i)
|
opts.HexEntropyCutoff = optionsNextInt(args, &i)
|
||||||
case "-c":
|
case "-c":
|
||||||
opts.Concurrency = optionsNextInt(args, &i)
|
opts.Concurrency = optionsNextInt(args, &i)
|
||||||
case "-o":
|
case "-o", "--org":
|
||||||
opts.OrgURL = optionsNextString(args, &i)
|
opts.OrgURL = optionsNextString(args, &i)
|
||||||
case "-u":
|
case "-u", "--user":
|
||||||
opts.UserURL = optionsNextString(args, &i)
|
opts.UserURL = optionsNextString(args, &i)
|
||||||
case "-r":
|
case "-r", "--repo":
|
||||||
opts.RepoURL = optionsNextString(args, &i)
|
opts.RepoURL = optionsNextString(args, &i)
|
||||||
case "-h", "--help":
|
case "-h", "--help":
|
||||||
help()
|
help()
|
||||||
|
|||||||
Reference in new issue
Block a user