-
Notifications
You must be signed in to change notification settings - Fork 55
/
main.go
146 lines (141 loc) · 4.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
)
func main() {
takeInput()
fmt.Println(banner, "")
fmt.Println("\n ")
if len(args) > 0 {
fmt.Println("Processing arguments...")
for i := 0; i < len(args); i++ {
arg := args[i]
if strings.HasSuffix(arg, ".txt") {
fmt.Println("Reading file content from " + arg + "...")
readFile(arg)
} else if urlValidation.MatchString(arg) {
allURLs = append(allURLs, arg)
} else if arg == "slow" || arg == "-slow" || arg == "--slow" {
*slowScan = true
} else if arg == "dig" || arg == "-dig" || arg == "--dig" {
*digMode = true
} else if arg == "notify" || arg == "-notify" || arg == "--notify" {
*notify = true
} else if arg == "log-errors" || arg == "-log-errors" || arg == "--log-errors" {
*errorLogging = true
} else if arg == "full" || arg == "--full" || arg == "-full" {
readCredsFile()
} else if arg == "max-size" || arg == "-max-size" || arg == "--max-size" {
if i+1 < len(args) {
maxSizeStr := args[i+1]
_, err := strconv.Atoi(maxSizeStr)
if err != nil {
log.Fatalln("Invalid max size:", maxSizeStr, ".. [Exiting!]")
} else {
maxFileSize = maxSizeStr
}
} else {
log.Fatalln("Missing max size argument.. [Exiting!]")
}
i++ // Skip the next argument since it has been processed
} else if arg == "search" || arg == "-search" || arg == "--search" {
if i+1 < len(args) {
if strings.Contains(args[i+1], ":::") {
keywords := strings.Split(args[i+1], ":::")
for _, keyword := range keywords {
if strings.HasSuffix(keyword, ".txt") {
file, err := os.Open(keyword)
if err != nil {
log.Fatalln("[Error] Looks like the tool is facing some issue while loading the specified file. [", err.Error(), "]")
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
scanKeywords = append(scanKeywords, scanner.Text())
}
} else {
scanKeywords = append(scanKeywords, keyword)
}
}
} else {
if strings.HasSuffix(args[i+1], ".txt") {
file, err := os.Open(args[i+1])
if err != nil {
log.Fatalln("[Error] Looks like the tool is facing some issue while loading the specified file. [", err.Error(), "]")
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
scanKeywords = append(scanKeywords, scanner.Text())
}
} else {
scanKeywords = append(scanKeywords, args[i+1])
}
}
} else {
log.Fatalln("Missing search argument.. [Exiting!]")
}
i++ // Skip the next argument since it has been processed
} else if arg == "save" || arg == "-save" || arg == "--save" {
if i+1 < len(args) {
if strings.HasSuffix(args[i+1], ".txt") || strings.HasSuffix(args[i+1], ".json") {
saveOutput = args[i+1]
} else {
saveOutput = "output.json"
}
} else {
saveOutput = "output.json"
}
i++ // Skip the next argument since it has been processed
}
}
if *notify {
notifyErr := loadNotifyConfig()
if notifyErr != nil {
fmt.Println("Looks like these is some issue with your notifyconfig file:", notifyErr)
toJSON()
os.Exit(1)
}
}
allURLs = formatURL(allURLs)
if len(allURLs) > 0 {
listS3BucketFiles(allURLs)
if len(iniFileListData.Scannable) > 0 {
if len(iniFileListData.NotScannable) > 0 {
bucketlootOutput.Skipped = iniFileListData.NotScannable
}
bucketlootOutput.Scanned = iniFileListData.Scannable
fmt.Println("\n ")
fmt.Println("Discovered a total of " + strconv.Itoa(iniFileListData.TotalFiles) + " bucket files...")
fmt.Println("Total bucket files of interest: " + strconv.Itoa(iniFileListData.TotalIntFiles))
fmt.Println("\n ")
if *slowScan {
fmt.Println("Starting to scan the files... [SLOW]")
} else {
fmt.Println("Starting to scan the files... [FAST]")
}
for _, bucketEntry := range iniFileListData.ScanData {
if *slowScan {
scanS3FilesSlow(bucketEntry.IntFiles, bucketEntry.URL)
} else {
scanS3FilesFast(bucketEntry.IntFiles, bucketEntry.URL)
}
}
toJSON()
} else {
fmt.Println("Oops.. Looks like no interesting buckets were discovered! Aborting the scan...")
bucketlootOutput.Skipped = iniFileListData.NotScannable
toJSON()
}
} else {
log.Fatalln("Looks like no valid URLs/domains were specified.. [Exiting!]")
}
} else {
fmt.Println("Looks like no arguments were specified.. [Exiting!]")
}
}