Skip to content

Commit 5116070

Browse files
committed
Advanced mode : filters more than just entropy
1 parent 437a6f1 commit 5116070

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"nuxt.isNuxtApp": false
3+
}

main.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"math"
88
"os"
9+
"regexp"
910
"slices"
1011
"strings"
1112
"sync"
@@ -18,18 +19,19 @@ const (
1819
minCharactersDefault = 8
1920
resultCountDefault = 10
2021
exploreHiddenDefault = false
21-
extensionsToIgnoreDefault = ".pdf,.png,.jpg,.jpeg,.zip,.mp4,.gif,.ttf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.mp3,.wav,.avi,.mov,.ogg,.wasm,.pyc"
22+
extensionsToIgnoreDefault = ".pyc,yarn.lock,go.mod,go.sum,go.work.sum,package-lock.json,.wasm,.pdf"
2223
)
2324

2425
// CLI options. Will be initialized by flags
2526
var (
26-
minCharacters int // Minimum number of characters to consider computing entropy
27-
resultCount int // Number of results to display
28-
exploreHidden bool // Ignore hidden files and folders
29-
extensions []string // List of file extensions to include. Empty string means all files
30-
extensionsToIgnore []string // List of file extensions to ignore. Empty string means all files
31-
discrete bool // Discrete mode, don't show the line, only the entropy and file
32-
includeBinaryFiles bool // Include binary files in search.
27+
minCharacters int // Minimum number of characters to consider computing entropy
28+
resultCount int // Number of results to display
29+
exploreHidden bool // Ignore hidden files and folders
30+
extensions []string // List of file extensions to include. Empty string means all files
31+
extensionsToIgnore []string // List of file extensions to ignore. Empty string means all files
32+
discrete bool // Discrete mode, don't show the line, only the entropy and file
33+
includeBinaryFiles bool // Include binary files in search.
34+
disableAdvancedMode bool // Advanced mode : filters more than just entropy
3335
)
3436

3537
type Entropy struct {
@@ -54,6 +56,8 @@ type Entropies struct {
5456
maxLength int
5557
}
5658

59+
var mediaBase64Regex = regexp.MustCompile(`(audio|video|image|font)\/[-+.\w]+;base64`)
60+
5761
// Add assumes that es contains an ordered list of entropies of length es.maxLength.
5862
// It preserves ordering, and inserts an additional value e, if it has high enough entropy.
5963
// In that case, the entry with lowest entropy is rejected.
@@ -64,6 +68,19 @@ func (es *Entropies) Add(e Entropy) {
6468
return
6569
}
6670

71+
if !disableAdvancedMode {
72+
line := strings.ToLower(e.Line)
73+
line = strings.ReplaceAll(line, "'", "")
74+
line = strings.ReplaceAll(line, "\"", "")
75+
if mediaBase64Regex.MatchString(line) ||
76+
strings.HasPrefix(line, "http") ||
77+
strings.Contains(line, "abcdefghijklmnopqrstuvwxyz") ||
78+
strings.Contains(line, "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz") {
79+
return
80+
}
81+
82+
}
83+
6784
es.mu.Lock()
6885
defer es.mu.Unlock()
6986

@@ -93,11 +110,12 @@ func main() {
93110
extensionsToIgnoreFlag := flag.String("ignore-ext", "", "Ignore files with these suffixes. Comma separated list, e.g. -ignore-ext min.css,_test.go,pdf,Test.php. Adds ignored extensions to the default ones.")
94111
noDefaultExtensionsToIgnore := flag.Bool("ignore-ext-no-defaults", false, "Remove the default ignored extensions (default "+extensionsToIgnoreDefault+")")
95112
discreteFlag := flag.Bool("discrete", false, "Only show the entropy and file, not the line containing the possible secret")
96-
binaryFilesFlag := flag.Bool("binary", false, "Include binary files in search. Slows down the search and may not be useful. A file is considered binary if the first line is not valid utf8.")
113+
binaryFilesFlag := flag.Bool("binaries", false, "Include binary files in search. Slows down the search and creates many false positives. A file is considered binary if the first line is not valid utf8.")
114+
disableAdvancedModeFlag := flag.Bool("dumb", false, "Just dumb entropy. Disable filters that removes alphabets, urls, base64 encoded images and other false positives.")
97115

98116
flag.CommandLine.Usage = func() {
99117
fmt.Fprintf(flag.CommandLine.Output(), "%s [flags] file1 file2 file3 ...\n", os.Args[0])
100-
fmt.Fprintf(flag.CommandLine.Output(), "Example: %s -top 10 -ext go,py,js .\n", os.Args[0])
118+
fmt.Fprintf(flag.CommandLine.Output(), "Example: %s -top 10 -ext go,py,js,yaml,json .\n", os.Args[0])
101119
fmt.Fprintln(flag.CommandLine.Output(), "Finds the highest entropy strings in files. The higher the entropy, the more random the string is. Useful for finding secrets (and alphabets, it seems).")
102120
fmt.Fprintln(flag.CommandLine.Output(), "Please support me on GitHub: https://github.com/EwenQuim")
103121
flag.PrintDefaults()
@@ -110,6 +128,7 @@ func main() {
110128
exploreHidden = *exploreHiddenFlag
111129
discrete = *discreteFlag
112130
includeBinaryFiles = *binaryFilesFlag
131+
disableAdvancedMode = *disableAdvancedModeFlag
113132
extensions = strings.Split(*extensionsFlag, ",")
114133
extensionsToIgnoreString := *extensionsToIgnoreFlag + "," + extensionsToIgnoreDefault
115134
if *noDefaultExtensionsToIgnore {

0 commit comments

Comments
 (0)