Skip to content

Find, verify, and analyze leaked credentials

improve plain output

Dustin Decker8afa57cee4a8
diff --git a/go.mod b/go.mod
index 5b252cd78..0f577133d 100644
--- a/go.mod
+++ b/go.mod
@@ -12,6 +12,7 @@ require (
github.com/bradleyfalzon/ghinstallation v1.1.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/envoyproxy/protoc-gen-validate v0.6.3
+ github.com/fatih/color v1.13.0
github.com/go-errors/errors v1.4.2
github.com/go-git/go-git/v5 v5.4.2
github.com/google/go-github/v41 v41.0.0
diff --git a/go.sum b/go.sum
index 9d049a6ab..fe17d9680 100644
--- a/go.sum
+++ b/go.sum
@@ -134,6 +134,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v0.6.3 h1:HkntewfZJ9RofA/FX38zBCeIAqlLDFLbAI6eTpZqFJw=
github.com/envoyproxy/protoc-gen-validate v0.6.3/go.mod h1:dyJXwwfPK2VSqiB9Klm1J6romD608Ba7Hij42vrOBCo=
+github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
+github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
@@ -287,8 +289,10 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
github.com/lyft/protoc-gen-star v0.6.0/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
+github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
+github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
@@ -484,6 +488,7 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
diff --git a/main.go b/main.go
index 566ef4a05..4baa01358 100644
--- a/main.go
+++ b/main.go
@@ -8,7 +8,9 @@ import (
"os"
"runtime"
"strconv"
+ "strings"
+ "github.com/fatih/color"
"github.com/sirupsen/logrus"
kingpin "gopkg.in/alecthomas/kingpin.v2"
@@ -115,20 +117,21 @@ func main() {
log.Fatal("s3 not implemented")
}
- stdoutLogger := logrus.New()
- stdoutLogger.SetOutput(os.Stdout)
- stdoutLogger.SetFormatter(&logrus.TextFormatter{})
+ yellowPrinter := color.New(color.FgYellow)
+ greenPrinter := color.New(color.FgHiGreen)
+ redPrinter := color.New(color.FgRed)
+ whitePrinter := color.New(color.FgWhite)
+
+ fmt.Printf("πŸ·πŸ”‘πŸ· TruffleHog. Unearth your secrets. πŸ·πŸ”‘πŸ·\n\n")
for r := range e.ResultsChan() {
type outputFormat struct {
DetectorType string
- SourceType string
Verified bool
*source_metadatapb.MetaData
}
output := outputFormat{
DetectorType: r.Result.DetectorType.String(),
- SourceType: r.SourceType.String(),
Verified: r.Result.Verified,
MetaData: r.SourceMetadata,
}
@@ -142,23 +145,34 @@ func main() {
}
fmt.Println(string(out))
} else {
- out, err := structToFields(output)
+ meta, err := structToMap(output.MetaData.Data)
if err != nil {
logrus.WithError(err).Fatal("could not marshal result")
}
- stdoutLogger.WithFields(out).Info("found secret")
+
+ yellowPrinter.Print("Found result πŸ·πŸ”‘\n")
+ greenPrinter.Printf("Detector Type: %s\n", output.DetectorType)
+ if output.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("")
}
}
logrus.Infof("scanned %d chunks", e.ChunksScanned())
}
-func structToFields(obj interface{}) (fields logrus.Fields, err error) {
+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, &fields)
+ err = json.Unmarshal(data, &m)
return
}