forked from redhuntlabs/BucketLoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
const.go
169 lines (147 loc) · 5.23 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
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 blacklistExtensions []string
var isBlacklisted int
var regexList map[string]string
var urlAssets []string
var domAssets []string
var subAssets []string
var slowScan *bool
var errorLogging *bool
var fullScan *bool
var scanKeywords []string
var urlsFileList []fileListEntry
var iniFileListData fileListData
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
//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"`
}
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"`
} `json:"Secrets"`
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"`
} `json:"Secrets"`
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"`
}
func init() {
bucketlootOutput.Version = "1.0"
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())
}
regexJSON, err := ioutil.ReadFile("regexes.json")
if err != nil {
log.Fatal(err)
}
if err := json.Unmarshal((regexJSON), ®exList); err != nil {
fmt.Println(err)
return
}
}
const banner = `
,.--'''''''''--., ____ _ _ _ _
(\'-.,_____,.-'/) | _ \ | | | | | | | |
\\-.,_____,.-// | |_) |_ _ ___| | _____| |_| | ___ ___ | |_
;\\ //| | _ <| | | |/ __| |/ / _ \ __| | / _ \ / _ \| __|
| \\ ___ // | | |_) | |_| | (__| < __/ |_| |___| (_) | (_) | |_
| '-[___]-' | |____/ \__,_|\___|_|\_\___|\__|______\___/ \___/ \__|
| |
| | An Automated S3 Bucket Inspector
| | Developed by Umair Nehri (@umair9747) and Owais Shaikh (@4f77616973)
''-.,_____,.-''
`