Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
improved plain output
Dustin Decker089b5c90632d
diff --git a/main.go b/main.goindex 7a7a635fb..6417d986c 100644--- a/main.go+++ b/main.go@@ -8,9 +8,7 @@ import ("os""runtime""strconv"- "strings"- "github.com/fatih/color""github.com/sirupsen/logrus"kingpin "gopkg.in/alecthomas/kingpin.v2"@@ -18,7 +16,6 @@ import ("github.com/trufflesecurity/trufflehog/pkg/decoders""github.com/trufflesecurity/trufflehog/pkg/engine""github.com/trufflesecurity/trufflehog/pkg/output"- "github.com/trufflesecurity/trufflehog/pkg/pb/source_metadatapb""github.com/trufflesecurity/trufflehog/pkg/sources/git")@@ -120,21 +117,11 @@ func main() {log.Fatal("s3 not implemented")}- yellowPrinter := color.New(color.FgYellow)- greenPrinter := color.New(color.FgHiGreen)- redPrinter := color.New(color.FgRed)- whitePrinter := color.New(color.FgWhite)-if !*jsonLegacy && !*jsonOut {fmt.Printf("π·ππ· TruffleHog. Unearth your secrets. π·ππ·\n\n")}for r := range e.ResultsChan() {- out := outputFormat{- DetectorType: r.Result.DetectorType.String(),- Verified: r.Result.Verified,- MetaData: r.SourceMetadata,- }switch {case *jsonLegacy:@@ -151,40 +138,8 @@ func main() {}fmt.Println(string(out))default:- meta, err := structToMap(out.MetaData.Data)- if err != nil {- logrus.WithError(err).Fatal("could not marshal result")- }-- yellowPrinter.Print("Found result π·π\n")- greenPrinter.Printf("Detector Type: %s\n", out.DetectorType)- if out.Verified {- redPrinter.Print("Verified: true\n")- } else {- whitePrinter.Print("Verified: false\n")- }- for _, data := range meta {- for k, v := range data {- greenPrinter.Printf("%s: %s\n", strings.Title(k), v)- }- }- fmt.Println("")+ output.PrintPlainOutput(&r)}}- logrus.Infof("scanned %d chunks", e.ChunksScanned())-}--func structToMap(obj interface{}) (m map[string]map[string]interface{}, err error) {- data, err := json.Marshal(obj)- if err != nil {- return- }- err = json.Unmarshal(data, &m)- return-}--type outputFormat struct {- DetectorType string- Verified bool- *source_metadatapb.MetaData+ logrus.Debugf("scanned %d chunks", e.ChunksScanned())}diff --git a/pkg/engine/git.go b/pkg/engine/git.goindex fce2d209a..81e38adfb 100644--- a/pkg/engine/git.go+++ b/pkg/engine/git.go@@ -70,6 +70,7 @@ func (e *Engine) ScanGit(ctx context.Context, repoPath, gitScanBranch, headRef s}).Debug("resolved common merge base between references")scanOptions = &gogit.LogOptions{+ All: true,From: *headHash,Order: gogit.LogOrderCommitterTime,PathFilter: func(s string) bool { return filter.Pass(s) },diff --git a/pkg/output/plain.go b/pkg/output/plain.gonew file mode 100644index 000000000..85fe7b593--- /dev/null+++ b/pkg/output/plain.go@@ -0,0 +1,62 @@+package output++import (+ "encoding/json"+ "fmt"+ "strings"++ "github.com/fatih/color"+ "github.com/sirupsen/logrus"+ "github.com/trufflesecurity/trufflehog/pkg/detectors"+ "github.com/trufflesecurity/trufflehog/pkg/pb/source_metadatapb"+)++var (+ yellowPrinter = color.New(color.FgYellow)+ greenPrinter = color.New(color.FgHiGreen)+ whitePrinter = color.New(color.FgWhite)+)++func PrintPlainOutput(r *detectors.ResultWithMetadata) {+ out := outputFormat{+ DetectorType: r.Result.DetectorType.String(),+ Verified: r.Result.Verified,+ MetaData: r.SourceMetadata,+ }++ meta, err := structToMap(out.MetaData.Data)+ if err != nil {+ logrus.WithError(err).Fatal("could not marshal result")+ }++ printer := greenPrinter++ if out.Verified {+ yellowPrinter.Print("Found verified result π·π\n")+ } else {+ printer = whitePrinter+ whitePrinter.Print("Found unverified result π·πβ\n")+ }+ printer.Printf("Detector Type: %s\n", out.DetectorType)+ for _, data := range meta {+ for k, v := range data {+ printer.Printf("%s: %s\n", strings.Title(k), v)+ }+ }+ fmt.Println("")+}++func structToMap(obj interface{}) (m map[string]map[string]interface{}, err error) {+ data, err := json.Marshal(obj)+ if err != nil {+ return+ }+ err = json.Unmarshal(data, &m)+ return+}++type outputFormat struct {+ DetectorType string+ Verified bool+ *source_metadatapb.MetaData+}