-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
executable file
·435 lines (356 loc) · 10.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
package main
import (
"fmt"
"net/url"
"time"
"log"
"flag"
"strings"
"os"
. "xssGo/source"
"github.com/tebeka/selenium"
"github.com/serge1peshcoff/selenium-go-conditions"
)
func init() {
InitEntities()
// Init logging
var err error
LogFile, err = os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
log.SetOutput(LogFile)
InitLogger(LogFile, LogFile, LogFile, true)
}
// TODO : bad urls için map yap, kontrolu daha kolay, ok := map[sth]
// FIXME: There is a bug for crawling, urls need to be parsed and analyzed.
//5 https://www.numbeo.com/cost-of-living/country_result.jsp?country=Croatia
//6 https://www.numbeo.com/cost-of-living/country_result.jsp?country=Gambia
func main() {
//LogDebug("debug message hello 1")
//LogInfo("info message")
//LogError("error message")
flagURL := flag.String("url","http://192.168.56.101","Target Url to be scanned")
flagLevel := flag.Int("level",3,"Scan Depth Level")
flagLogin := flag.String("loginPage","","Authenticate via login page.")
flagCookie := flag.String("cookieFile","","Authenticate via cookies. Give path of cookie file as json")
flagPayload := flag.String("payloadFile","payloads.txt","Set Payloads from file")
flagHeadless := flag.Bool("headless",false,"Browser can run as headless")
flagBlackList := flag.String("blackList","","Forbid some links to be visited via giving comma seperated list")
flagHelp := flag.Bool("help",false,"Print usage")
flag.Parse()
if *flagHelp {
PrintUsage()
os.Exit(1)
}
UrlSTR = *flagURL
//UrlSTR = "https://www.numbeo.com"
UrlParsed, _ = url.Parse(UrlSTR)
Host = UrlParsed.Host
// add the first target to list
TargetURLsORIGINAL[UrlSTR] = Empty{}
TargetURLsALTERED[UrlSTR] = Empty{}
Level = *flagLevel
ReadPayloads(*flagPayload)
if *flagBlackList != "" {
blackList := *flagBlackList
arr := strings.Split(blackList,",")
BadUrls = append(BadUrls,arr...)
}
browserArgs := []string{"--disable-xss-auditor"}
browserArgs = append(browserArgs, "--proxy-server=localhost:8888")
if *flagHeadless {
browserArgs = append(browserArgs, "--headless")
browserArgs = append(browserArgs, "--disable-gpu")
}
// start chrome driver
CD.InitDriver(browserArgs)
fmt.Println("")
defer CD.StopDriver()
// open the initial url in both browsers
err := Bow.Open(UrlSTR)
if err != nil {
LogError(err)
}
if err := CD.WebDriver.Get(UrlSTR); err != nil {
LogError(err)
}
if *flagLogin != "" {
LoginURL = *flagLogin
LoginToBow(LoginURL)
CD.LoginToChromeAuto(LoginURL,LoginInformation)
}else if *flagCookie != "" {
// reading from file
cs,err := ReadCookiesFromFile(*flagCookie)
if err != nil {
LogError(err)
panic(err)
}
// setting cookies to bow browser
SetCookiesToBow(cs)
// setting cookies to chrome
cookies := ConvertCookiesToGolang(cs)
CD.SetCookiesToChrome(*flagURL,cookies)
}
StartTime = time.Now()
defer finishTime()
fmt.Println("Page traversal operation is started:")
log.Println("Page traversal operation is started:")
//crawling
//CrawlURL(UrlSTR)
if Level > 1 {
for i := 2; i <= Level; i++ {
for tempURL, _ := range TargetURLsORIGINAL {
CrawlURL(tempURL)
}
}
}
time.Sleep(250*time.Millisecond)
//
//TargetURLsALTERED["http://localhost/dvwa/vulnerabilities/xss_d/?default=English"] = Empty{}
//TargetURLsALTERED["http://localhost/dvwa/vulnerabilities/xss_r/?name=cemal"] = Empty{}
//TargetURLsALTERED["http://localhost/dvwa/vulnerabilities/xss_s/"] = Empty{}
// List of target Urls
i := 1
fmt.Println("List of Target Urls:")
log.Println("List of Target Urls:")
for u, _ := range TargetURLsALTERED {
fmt.Println(i, u)
i++
}
time.Sleep(250*time.Millisecond)
// Add one extra url to list
//targetURLs["http://localhost/dvwa/vulnerabilities/xss_d/?default=English"] = empty{}
for u := range TargetURLsALTERED {
CD.Mutex.Lock()
SendToProxy(u)
CD.Mutex.Unlock()
//time.Sleep(10*time.Second)
}
//// Query Parameters
//log.Println("Query parameters are going to be tested")
//fmt.Println("Query parameters are going to be tested")
//for u := range TargetURLsALTERED {
// ControlQueryParameters(u)
//}
//time.Sleep(250*time.Millisecond)
//
//// Form input variables
//log.Println("Form inputs are going to be tested")
//fmt.Println("Form inputs are going to be tested")
//for u := range TargetURLsORIGINAL {
// ControlFormInputs(u)
//}
// Output, Vulnerable URLs
fmt.Println("")
fmt.Println("vulnerable urls:")
j := 1
for i, v := range VulnerableURLs {
fmt.Println(j, ":", i, " payload:", v.Payload)
j++
}
// ###### tests ######
//cd.trySelection("http://localhost/dvwa/security.php")
}
func finishTime() {
fmt.Println("Time Elapsed:", time.Since(StartTime))
}
func SendToProxy(u string) {
// TODO : ilk acilista stored xss yakalamaya calis
// Navigate to the url
//tempUrl := u + "$DONOTTOUCH"
//if err := CD.WebDriver.Get(tempUrl); err != nil {
// LogError(err)
//}
//// TODO : page may have its own pop-up. Detect it and store in storedXssUrl dictionary.
//err := CD.WebDriver.WaitWithTimeout(conditions.ElementIsLocated(selenium.ByTagName, "html"), 150*time.Millisecond)
////if err != nil {
//// err := CD.WebDriver.AcceptAlert()
//// if err != nil {
//// LogDebug(err)
//// } else {
//// VulnerableURLs[u] = Empty{Payload:"stored"}
//// fmt.Println("stored xss " , u)
//// LogInfo("stored xss ------------> ", u)
//// return
//// }
////}
//if err != nil {
// alertText, err2 := CD.WebDriver.AlertText()
// if err2 != nil {
// LogDebug("error waiting alert box:", err2)
// } else if err2 == nil {
// LogInfo("xss found. alert text:", alertText, " URL:", u)
// err = CD.WebDriver.DismissAlert()
// if err != nil {
// LogDebug(err)
// }
// err = CD.WebDriver.AcceptAlert()
// if err != nil {
// LogDebug(err)
// }
//
// fmt.Println("bulundu-possible stored")
// VulnerableURLs[u] = Empty{Payload: "stored"}
// return
// }
//}
originalURL, _ := url.Parse(u)
// testing query parameters
q := originalURL.Query()
if len(q) > 0 {
//CD.Mutex.Lock()
for _, payload := range Payloads {
// SET PAYLOAD
payloadSetter := "http://localhost/payload$" + payload
fmt.Println("payload: " + payload)
if err := CD.WebDriver.Get(payloadSetter); err != nil {
LogError(err)
}
//fmt.Println(tempUrl)
// Navigate to the url
if err := CD.WebDriver.Get(u); err != nil {
LogError(err)
}
//time.Sleep(5*time.Second)
// first try to load the page and see <html> tag
err := CD.WebDriver.WaitWithTimeout(conditions.ElementIsLocated(selenium.ByTagName, "html"), 150*time.Millisecond)
if err != nil {
alertText, err2 := CD.WebDriver.AlertText()
if err2 != nil {
LogDebug("error waiting alert box:", err2)
} else if err2 == nil {
LogInfo("xss found. alert text:", alertText, " URL:", u)
err = CD.WebDriver.DismissAlert()
if err != nil {
LogDebug(err)
}
err = CD.WebDriver.AcceptAlert()
if err != nil {
LogDebug(err)
}
fmt.Println("bulundu")
VulnerableURLs[u] = Empty{Payload: payload}
break
} else {
LogInfo("xss not found. URL:", u)
}
} else {
// if there is no timeout it means page is loaded.
LogInfo("xss not found. URL:", u)
}
//fmt.Println("sending to test query parameter "+ u)
//if CD.PageTest(u) {
// fmt.Println("Bulundu..")
// if _, contains := VulnerableURLs[u]; !contains {
// VulnerableURLs[u] = Empty{Payload:payload}
// }
// break
//}
}
//CD.Mutex.Unlock()
}
//time.Sleep(5*time.Second)
// testing form parameters
// navigate to page
found := false
for _,payload := range Payloads {
//CD.Mutex.Lock()
if found {
//break
}
// SET PAYLOAD
payloadSetter := "http://localhost/payload$" + payload
if err := CD.WebDriver.Get(payloadSetter); err != nil {
LogError(err)
}
if err := CD.WebDriver.Get(u); err != nil {
LogError(err)
}
forms, err := CD.WebDriver.FindElements(selenium.ByXPATH, "//form")
if err != nil {
LogDebug("form could not be found.")
LogDebug(err)
}
if len(forms) >= 1 {
fmt.Println("form inputs are going to be tested =>"+ u)
for _, form := range forms {
//find all inputs inside the form
inputs, err := form.FindElements(selenium.ByXPATH, "//input")
if err != nil {
LogDebug("input could not be found. ERROR:")
LogDebug(err)
continue
}
// for each input
for _, input := range inputs {
InputType, err := input.GetAttribute("type")
if err != nil {
LogDebug("input type could not be found. ERROR:")
LogDebug(err)
}
if InputType == "text" || InputType == "password" {
input.Clear()
// send random inputs
input.SendKeys("123")
}
}
textareas, err := form.FindElements(selenium.ByXPATH, "//textarea")
if err != nil {
LogDebug("input could not be found. ERROR:")
LogDebug(err)
} else {
// for each textarea
for _, textarea := range textareas {
// send random inputs
textarea.SendKeys("123")
}
}
button, err := form.FindElement(selenium.ByXPATH, "//input[@type='submit']")
button.Click()
err = CD.WebDriver.WaitWithTimeout(conditions.ElementIsLocated(selenium.ByTagName, "html"), 150*time.Millisecond)
if err != nil {
//time.Sleep(100 * time.Millisecond)
_, err2 := CD.WebDriver.AlertText()
if err2 != nil {
LogDebug(err2)
//debug //fmt.Println("error waiting alert box:",err2)
} else if err2 == nil { //&& && alertText != "" strings.Contains(payload, alertText) {
LogInfo("xss found. payload:", payload, " URL:", u)
fmt.Println("xss found. payload:", payload, " URL:", u)
err = CD.WebDriver.DismissAlert()
if err != nil {
LogError(err)
//debug fmt.Println(Err)
}
err = CD.WebDriver.AcceptAlert()
if err != nil {
LogError(err)
//debug fmt.Println(Err)
}
VulnerableURLs[u] = Empty{Payload:payload}
//CD.WebDriver.DismissAlert()
found = true
return
} else {
LogInfo("xss not found. URL:", u)
}
}
}
}else{
break
}
//CD.Mutex.Unlock()
}
}
// TODO ## List ##
// TODO Better Logging and stdout mechanizm (seperated)
// TODO Implement Go routines and sync , maybe workers
// To increase the speed run on all cores of CPU
// TODO click all buttons for the possibility of having another target link
// FIXME Implement cookie insertion for bow
// DONE Command line arguments with flag
// Welcome message
// Usage
// Get Black-list (jpg,png,pdf..)
// Payloads from file