-
Notifications
You must be signed in to change notification settings - Fork 55
/
const.go
254 lines (218 loc) · 7.48 KB
/
const.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
)
var args []string
var allURLs []string
var bucketFileRE = regexp.MustCompile(`(?m)(?i)<key>(.+?)<\/key>`)
var bucketSizeRE = regexp.MustCompile(`(?i)<Size>(.+?)<\/Size>`)
var urlRE = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`)
var urlValidation = regexp.MustCompile(`^(?:(?:https?|ftp):\/\/)?(?:www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+(?:\/[^\s]*)?$`)
var urlsRE = regexp.MustCompile(`(http[s]?:\/\/[^\s\/]+)\b`)
var blacklistExtensions []string
var isBlacklisted int
var diggedURLs []string
var urlAssets []string
var regexList map[string]string
var domAssets []string
var unscannable []string
var subAssets []string
var slowScan *bool
var digMode *bool
var notify *bool
var errorLogging *bool
var fullScan *bool
var scanKeywords []string
var urlsFileList []fileListEntry
var iniFileListData fileListData
var vulnerableFileChecks []vulnFilesStruct
var maxFileSize string
var keywordSearch string
var saveOutput string
var awsCreds string
var awsBucketNameRe = regexp.MustCompile(`<Name>(.+?)<\/Name>`)
//VAR DECLARATION FOR BUCKETLOOT OUTPUT
var bucketlootOutput bucketLootOpStruct
// STRUCT FOR STORING SECRET REGEXES
type Rule struct {
Regex string `json:"Regex"`
Severity string `json:"Severity"`
Title string `json:"Title"`
}
var rules []Rule
// BELOW IS THE STRUCTURE FOR PARSING THE VULNFILES JSON FILE
type vulnFilesStruct struct {
Name string `json:"Name"`
Type string `json:"Type"`
Match string `json:"Match"`
IsRegex bool `json:"isRegex"`
}
//BELOW STRUCT ARE RELATED TO URLS WHOSE FILES ARE EXTRACTED.
//First struct is for a single entry of ScanData array. It stores all the scannable bucket entries
// Allfiles - all the files that are present in the bucket, irrespective of extension
// Intfiles - all interesting files that are to be scanned
// Second struct stores the array of first struct as well as 2 other arrays, scannable and notscannable which shows how many urls from input
// can be scanned and how many are ignored because of errors during requests, private buckets, error during deserialisation etc.
type fileListEntry struct {
URL string `json:"url"`
AllFiles []string `json:"allFiles"`
IntFiles []string `json:"intFiles"`
}
type fileListData struct {
ScanData []fileListEntry `json:"scanData"`
Scannable []string `json:"scannable"`
NotScannable []string `json:"notScannable"`
TotalIntFiles int
TotalFiles int
}
//BELOW ARE THE STRUCTS FOR BUCKETLOOT OUTPUT
//FIRST ONE IS THE STRUCT FORMAT FOR A SINGLE BUCKET SCAN RESULT
//SECOND IS THE OUTPUT FORMAT THAT BUCKETLOOT RETURNS IN TOTAL
type bucketlootAssetStruct struct {
URL string `json:"url"`
Domain string `json:"domain"`
Subdomain string `json:"subdomain"`
}
type bucketlootSecretStruct struct {
Name string `json:"name"`
URL string `json:"url"`
Severity string `json:"severity"`
}
type bucketlootSensitiveFileStruct struct {
Name string `json:"name"`
URL string `json:"url"`
}
type bucketlootKeywordStruct struct {
URL string `json:"url"`
Keyword string `json:"keyword"`
Type string `json:"type"`
}
type bucketLootResStruct struct {
BucketUrl string `json:"bucketUrl"`
Assets []struct {
URL string `json:"url"`
Domain string `json:"domain"`
Subdomain string `json:"subdomain"`
} `json:"Assets"`
Secrets []struct {
Name string `json:"name"`
URL string `json:"url"`
Severity string `json:"severity"`
} `json:"Secrets"`
SensitiveFiles []struct {
Name string `json:"name"`
URL string `json:"url"`
} `json:"SensitiveFiles"`
Keywords []struct {
URL string `json:"url"`
Keyword string `json:"keyword"`
Type string `json:"type"`
} `json:"Keywords,omitempty"`
}
type bucketLootOpStruct struct {
Results []struct {
BucketUrl string `json:"bucketUrl"`
Assets []struct {
URL string `json:"url"`
Domain string `json:"domain"`
Subdomain string `json:"subdomain"`
} `json:"Assets"`
Secrets []struct {
Name string `json:"name"`
URL string `json:"url"`
Severity string `json:"severity"`
} `json:"Secrets"`
SensitiveFiles []struct {
Name string `json:"name"`
URL string `json:"url"`
} `json:"SensitiveFiles"`
Keywords []struct {
URL string `json:"url"`
Keyword string `json:"keyword"`
Type string `json:"type"`
} `json:"Keywords,omitempty"`
} `json:"Results"`
Version string `json:"version"`
Scanned []string `json:"Scanned"`
Skipped []string `json:"Skipped"`
Errors []string `json:"Errors,omitempty"`
}
// STRUCT FOR DECODING CREDENTIALS.JSON
type platformCreds []struct {
Platform string `json:"platform"`
Credentials string `json:"credentials"`
}
// STRUCT FOR DECODING notificationConfig.json
type notifyconf struct {
Discord string `json:"Discord"`
Slack string `json:"Slack"`
}
var platforms []notifyconf
func init() {
bucketlootOutput.Version = "2.0"
//READ THE BLACKLIST EXTENSIONS FILE
file, err := os.Open("blacklist.txt")
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() {
blacklistExtensions = append(blacklistExtensions, scanner.Text())
}
//READ THE REGEX JSON FILE AND PARSE IT
regFile, err := os.Open("regexes.json")
if err != nil {
log.Fatalf("Error opening file: %v", err)
}
defer file.Close()
decoder := json.NewDecoder(regFile)
if err := decoder.Decode(&rules); err != nil {
log.Fatalf("Error decoding JSON: %v", err)
}
//READ THE VULNFILES JSON FILE AND PARSE IT
// Read the JSON file into a byte slice
data, err := ioutil.ReadFile("vulnFiles.json")
if err != nil {
fmt.Println("Error reading the JSON file:", err)
return
}
// Unmarshal the JSON data into the extensions slice
err = json.Unmarshal(data, &vulnerableFileChecks)
if err != nil {
fmt.Println("Error unmarshaling JSON:", err)
return
}
}
func uniqueStrings(input []string) []string {
// Create a map to store unique strings
uniqueMap := make(map[string]bool)
// Create a result slice to hold unique entries
uniqueEntries := []string{}
for _, str := range input {
if !uniqueMap[str] {
// If the string is not in the map, add it to the result slice and mark it as seen in the map
uniqueEntries = append(uniqueEntries, str)
uniqueMap[str] = true
}
}
return uniqueEntries
}
const banner = `
,.--'''''''''--., ____ _ _ _ _
(\'-.,_____,.-'/) | _ \ | | | | | | | |
\\-.,_____,.-// | |_) |_ _ ___| | _____| |_| | ___ ___ | |_
;\\ //| | _ <| | | |/ __| |/ / _ \ __| | / _ \ / _ \| __|
| \\ ___ // | | |_) | |_| | (__| < __/ |_| |___| (_) | (_) | |_
| '-[___]-' | |____/ \__,_|\___|_|\_\___|\__|______\___/ \___/ \__|
| |
| | An Automated S3 Bucket Inspector
| | Developed by Umair Nehri (@umair9747) and Kunal Aggarwal (@KunalAggarwal)
''-.,_____,.-''
`