forked from rashahacks/jsmon-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
318 lines (293 loc) · 14.5 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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package main
import (
"flag"
"fmt"
"os"
"strings"
)
type stringSliceFlag []string
func (s *stringSliceFlag) String() string {
return strings.Join(*s, ", ")
}
func (s *stringSliceFlag) Set(value string) error {
*s = append(*s, value)
return nil
}
func main() {
scanUrl := flag.String("scanUrl", "", "URL to be rescanned by jsmonId.")
uploadUrl := flag.String("uploadUrl", "", "URL to upload for scanning")
apiKeyFlag := flag.String("apikey", "", "API key for authentication")
scanFileId := flag.String("scanFile", "", " File to be rescanned by fileId.")
uploadFile := flag.String("uploadFile", "", "File to upload giving path to the file locally.")
getAllResults := flag.String("getAutomationData", "", "Get all automation results")
size := flag.Int("size", 10000, "Number of results to fetch (default 10000)")
fileTypes := flag.String("fileTypes", "", "files type (e.g. pdf,txt)")
getScannerResultsFlag := flag.Bool("getScannerData", false, "Get scanner results")
cron := flag.String("cron", "", "Set cronjob.")
cronNotification := flag.String("notifications", "", "Set cronjob notification channel.")
cronTime := flag.Int64("time", 0, "Set cronjob time.")
cronType := flag.String("vulnerabilitiesType", "", "Set type[URLs, Analysis, Scanner] of cronjob.")
cronDomains := flag.String("domains", "", "Set domains for cronjob.")
cronDomainsNotify := flag.String("domainsNotify", "", "Set notify(true/false) for each domain for cronjob.")
viewurls := flag.Bool("urls", false, "view all urls")
viewurlsSize := flag.Int("urlSize", 10, "Number of URLs to fetch")
scanDomainFlag := flag.String("scanDomain", "", "Domain to automate scan")
wordsFlag := flag.String("words", "", "Comma-separated list of words to include in the scan")
urlswithmultipleResponse := flag.Bool("changedUrls", false, "View changed JS URLs.")
getDomainsFlag := flag.Bool("getDomains", false, "Get all domains for the user.")
var headers stringSliceFlag
flag.Var(&headers, "H", "Custom headers in the format 'Key: Value' (can be used multiple times)")
addCustomWordsFlag := flag.String("addCustomWords", "", "add custom words to the scan")
usageFlag := flag.Bool("usage", false, "View user profile")
viewfiles := flag.Bool("getFiles", false, "view all files")
viewEmails := flag.String("getEmails", "", "Get all emails for specified domains.")
s3domains := flag.String("getS3Domains", "", "get all S3Domains for specified domains")
ips := flag.String("getIps", "", "Get all IPs for specified domains")
gql := flag.String("getGqlOps", "", "Get graph QL operations")
domainUrl := flag.String("getDomainUrls", "", "Get Domain URLs for specified domains")
apiPath := flag.String("getApiPaths", "", "Get the APIs for specified domains")
fileExtensionUrls := flag.String("getFileExtensionUrls", "", "Get URLs containing any file type.")
socialMediaUrls := flag.String("getSocialMediaUrls", "", "Get URLs for social media sites.")
domainStatus := flag.String("getDomainStatus", "", "Get the availabilty of domains")
queryParamsUrls := flag.String("getQueryParamsUrls", "", "Get URLs containing query params for specified domain.")
localhostUrls := flag.String("getLocalhostUrls", "", "Get URLs with localhost in the hostname.")
filteredPortUrls := flag.String("getUrlsWithPorts", "", "Get URLs with port numbers in the hostname")
s3DomainsInvalid := flag.String("getS3DomainsInvalid", "", "Get available S3 domains (404 status).")
compareFlag := flag.String("compare", "", "Compare two js responses by jsmon_ids (format: JSMON_ID1,JSMON_ID2)")
reverseSearchResults := flag.String("reverseSearchResults", "", "Specify the input type (e.g., emails, domainname)")
//getResultByValue := flag.String("value", "", "Specify the input value")
createWordListFlag := flag.String("createWordList", "", "creates a new word list from domains")
searchUrlsByDomainFlag := flag.String("searchUrlsByDomain", "", "Search URLs by domain")
getResultByJsmonId := flag.String("getResultByJsmonId", "", "Get automation results by jsmon ID.")
getResultByFileId := flag.String("getResultByFileId", "", "Get automation results by file ID.")
rescanDomainFlag := flag.String("rescanDomain", "", "Rescan all URLs for a specific domain")
totalAnalysisDataFlag := flag.Bool("totalAnalysisData", false, "total count of overall analysis data")
flag.Usage = func() {
fmt.Printf("Usage of %s:\n", os.Args[0])
fmt.Printf(" %s [flags]\n\n", os.Args[0])
fmt.Println("Flags:")
// Input section
fmt.Fprintf(os.Stderr, "\nINPUT:\n")
fmt.Fprintf(os.Stderr, " -scanUrl <jsmonId> URL to be rescanned by jsmonId.\n")
fmt.Fprintf(os.Stderr, " -uploadUrl <URL> URL to upload for scanning.\n")
fmt.Fprintf(os.Stderr, " -scanFile <fileId> File to be rescanned by fileId.\n")
fmt.Fprintf(os.Stderr, " -uploadFile <local file path> File to upload (local path)\n")
fmt.Fprintf(os.Stderr, " -scanDomain <domainName> Domain to automate scan\n")
// Authentication section
fmt.Fprintf(os.Stderr, "\nAUTHENTICATION:\n")
fmt.Fprintf(os.Stderr, " -apikey <XXXXXX-XXXX-XXXX-XXXX-XXXXXX> API key for authentication\n")
// Output section
fmt.Fprintf(os.Stderr, "\nOUTPUT:\n")
fmt.Fprintf(os.Stderr, " -getAutomationData <domainName> Get all automation results.\n")
fmt.Fprintf(os.Stderr, " -getScannerData Get scanner results.\n")
fmt.Fprintf(os.Stderr, " -getUrls View all URLs.\n")
fmt.Fprintf(os.Stderr, " -urlSize int Number of URLs to fetch (default 10).\n")
fmt.Fprintf(os.Stderr, " -getFiles View all files.\n")
fmt.Fprintf(os.Stderr, " -fileTypes <types> Specify file types (e.g., pdf,txt), use ',' as separator.\n")
fmt.Fprintf(os.Stderr, " -usage View user profile.\n")
fmt.Fprintf(os.Stderr, " -changedUrls View changed JS URLs.\n")
// Cronjob section
// fmt.Fprintf(os.Stderr, "\nCRON JOB:\n")
// fmt.Fprintf(os.Stderr, " -cron <string> Set, update, or stop cronjob\n")
// fmt.Fprintf(os.Stderr, " -notifications <string> Set cronjob notification channel\n")
// fmt.Fprintf(os.Stderr, " -time <int> Set cronjob time\n")
// fmt.Fprintf(os.Stderr, " -vulnerabilitiesType <type> Set type of cronjob (URLs, Analysis, Scanner)\n")
// fmt.Fprintf(os.Stderr, " -domains <string> Set domains for cronjob\n")
// fmt.Fprintf(os.Stderr, " -domainsNotify <true/false> Set notification for each domain\n")
// Additional options
fmt.Fprintf(os.Stderr, "\nADDITIONAL OPTIONS:\n")
fmt.Fprintf(os.Stderr, " -H <Key: Value> Custom headers (can be used multiple times).\n")
fmt.Fprintf(os.Stderr, " -words <words> Comma-separated list of words to include in the scan.\n")
fmt.Fprintf(os.Stderr, " -getDomains Get all domains for the user.\n")
fmt.Fprintf(os.Stderr, " -getEmails <domain> Get all emails for specified domains.\n")
fmt.Fprintf(os.Stderr, " -getS3Domains <domain> Get all S3 domains for specified domains.\n")
fmt.Fprintf(os.Stderr, " -getIps <domain> Get all IPs for specified domains.\n")
fmt.Fprintf(os.Stderr, " -getDomainUrls <domain> Get domain URLs for specified domains.\n")
fmt.Fprintf(os.Stderr, " -getApiPaths <domain> Get API paths for specified domains.\n")
fmt.Fprintf(os.Stderr, " -getFileExtensionUrls <domain> Get URLs containing any file type.\n")
fmt.Fprintf(os.Stderr, " -getSocialMediaUrls <domain> Get URLs for social media sites.\n")
fmt.Fprintf(os.Stderr, " -getDomainStatus <domain> Get availability status of domains.\n")
fmt.Fprintf(os.Stderr, " -getQueryParamsUrls <domain> Get URLs containing query params for specified domain.\n")
fmt.Fprintf(os.Stderr, " -getLocalhostUrls <domain> Get URLs with localhost in the hostname.\n")
fmt.Fprintf(os.Stderr, " -getUrlsWithPorts <domain> Get URLs with port numbers in the hostname.\n")
fmt.Fprintf(os.Stderr, " -getS3DomainsInvalid <domain> Get available S3 domains (404 status).\n")
fmt.Fprintf(os.Stderr, " -rescanDomain <domain> Rescan all URLs for a specific domain.\n")
fmt.Fprintf(os.Stderr, " -searchUrlsByDomain <domain> Search URLs by domain.\n")
fmt.Fprintf(os.Stderr, " -compare <ID1,ID2> Compare two JS responses by IDs (format: ID1,ID2).\n")
fmt.Fprintf(os.Stderr, " -getGqlOps <domain> Get GraphQL operations for specified domains.\n")
fmt.Fprintf(os.Stderr, " -totalAnalysisData Get total count of overall analysis data.\n")
fmt.Fprintf(os.Stderr, " -getResultByJsmonId <ID> Get automation results by jsmon ID.\n")
fmt.Fprintf(os.Stderr, " -getResultByFileId <ID> Get automation results by file ID.\n")
// Automation results section
fmt.Fprintf(os.Stderr, "\nAUTOMATION RESULTS BY FIELD:\n")
fmt.Fprintf(os.Stderr, " -reverseSearchResults <field>=<value>\n")
fmt.Fprintf(os.Stderr, " Search by field : emails, domainname, extracteddomains, s3domains, url, extractedurls, ipv4addresses, ipv6addresses, jwttokens, gqlquery, gqlmutation, guids, apipaths, vulnerabilities, nodemodules, domainstatus, queryparamsurls, socialmediaurls, filterdporturls, gqlfragment, s3domainsinvalid, fileextensionurls, localhosturls.\n")
}
flag.Parse()
if *apiKeyFlag != "" {
setAPIKey(*apiKeyFlag)
} else {
err := loadAPIKey()
if err != nil {
fmt.Println("Error loading API key:", err)
fmt.Println("Please provide an API key using the -apikey flag.")
os.Exit(1)
}
}
if flag.NFlag() == 0 || (flag.NFlag() == 1 && *apiKeyFlag != "") {
fmt.Println("No action specified. Use -h or --help for usage information.")
flag.Usage()
os.Exit(1)
}
switch {
case *scanFileId != "":
scanFileEndpoint(*scanFileId)
case *uploadFile != "":
uploadFileEndpoint(*uploadFile, headers)
case *viewurls:
viewUrls(*viewurlsSize)
case *viewfiles:
viewFiles()
case *uploadUrl != "":
uploadUrlEndpoint(*uploadUrl, headers)
case *rescanDomainFlag != "":
rescanDomain(*rescanDomainFlag)
case *totalAnalysisDataFlag:
totalAnalysisData()
case *searchUrlsByDomainFlag != "":
searchUrlsByDomain(*searchUrlsByDomainFlag)
case *urlswithmultipleResponse:
urlsmultipleResponse()
case *viewEmails != "":
domains := strings.Split(*viewEmails, ",")
for i, domain := range domains {
domains[i] = strings.TrimSpace(domain)
}
getEmails(domains)
case *getResultByJsmonId != "":
getAutomationResultsByJsmonId(strings.TrimSpace(*getResultByJsmonId))
case *reverseSearchResults != "":
parts := strings.SplitN(*reverseSearchResults, "=", 2)
if len(parts) != 2 {
fmt.Println("Invalid format for reverseSearchResults. Use field=value format.")
return
}
field := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
getAutomationResultsByInput(field, value)
case *getResultByFileId != "":
getAutomationResultsByFileId(strings.TrimSpace(*getResultByFileId))
case *s3domains != "":
domains := strings.Split(*s3domains, ",")
for i, domain := range domains {
domains[i] = strings.TrimSpace(domain)
}
getS3Domains(domains)
case *ips != "":
domains := strings.Split(*ips, ",")
for i, domain := range domains {
domains[i] = strings.TrimSpace(domain)
}
getAllIps(domains)
case *gql != "":
domains := strings.Split(*gql, ",")
for i, domain := range domains {
domains[i] = strings.TrimSpace(domain)
}
getGqlOps(domains)
case *domainUrl != "":
domains := strings.Split(*domainUrl, ",")
for i, domain := range domains {
domains[i] = strings.TrimSpace(domain)
}
getDomainUrls(domains)
case *apiPath != "":
domains := strings.Split(*apiPath, ",")
for i, domain := range domains {
domains[i] = strings.TrimSpace(domain)
}
getApiPaths(domains)
case *getScannerResultsFlag:
getScannerResults()
case *scanUrl != "":
rescanUrlEndpoint(*scanUrl)
case *cron == "start":
StartCron(*cronNotification, *cronTime, *cronType, *cronDomains, *cronDomainsNotify)
case *cron == "stop":
StopCron()
case *getDomainsFlag:
getDomains()
case *fileExtensionUrls != "":
extensions := strings.Split(*fileTypes, ",")
for i, extension := range extensions {
extensions[i] = strings.TrimSpace(extension)
}
getAllFileExtensionUrls(*fileExtensionUrls, extensions, *size)
case *domainStatus != "":
// domains := strings.Split(*domainStatus, ",")
// for i, domain := range domains {
// domains[i] = strings.TrimSpace(domain)
// }
getAllDomainsStatus(*domainStatus, *size)
case *socialMediaUrls != "":
getAllSocialMediaUrls(*socialMediaUrls, *size)
case *queryParamsUrls != "":
getAllQueryParamsUrls(*queryParamsUrls, *size)
case *localhostUrls != "":
getAllLocalhostUrls(*localhostUrls, *size)
case *filteredPortUrls != "":
getAllFilteredPortUrls(*filteredPortUrls, *size)
case *s3DomainsInvalid != "":
getAllS3DomainsInvalid(*s3DomainsInvalid, *size)
case *compareFlag != "":
ids := strings.Split(*compareFlag, ",")
if len(ids) != 2 {
fmt.Println("Invalid format for compare. Use: JSMON_ID1,JSMON_ID2")
os.Exit(1)
}
compareEndpoint(strings.TrimSpace(ids[0]), strings.TrimSpace(ids[1]))
case *cron == "update":
UpdateCron(*cronNotification, *cronType, *cronDomains, *cronDomainsNotify, *cronTime)
case *getAllResults != "":
getAllAutomationResults(*getAllResults, *size)
case *scanDomainFlag != "":
words := []string{}
if *wordsFlag != "" {
words = strings.Split(*wordsFlag, ",")
}
fmt.Printf("Domain: %s, Words: %v\n", *scanDomainFlag, words)
automateScanDomain(*scanDomainFlag, words)
case *usageFlag:
callViewProfile()
case *createWordListFlag != "":
domains := strings.Split(*createWordListFlag, ",")
createWordList(domains)
case *addCustomWordsFlag != "":
words := strings.Split(*addCustomWordsFlag, ",")
addCustomWordUser(words)
default:
fmt.Println("No valid action specified.")
flag.Usage()
os.Exit(1)
}
}
// type Args struct {
// Cron string
// CronNotification string
// CronTime int64
// CronType string
// }
// func parseArgs() Args {
// //CRON JOB FLAGS ->
// cron := flag.String("cron", "", "Set cronjob.")
// cronNotification := flag.String("notifications", "", "Set cronjob notification.")
// cronTime := flag.Int64("time", 0, "Set cronjob time.")
// cronType := flag.String("type", "", "Set type of cronjob.")
// flag.Parse()
// return Args{
// Cron: *cron,
// CronNotification: *cronNotification,
// CronTime: *cronTime,
// CronType: *cronType,
// }
// }