-
Notifications
You must be signed in to change notification settings - Fork 130
/
web-cache-vulnerability-scanner.go
607 lines (509 loc) · 19.2 KB
/
web-cache-vulnerability-scanner.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"log"
"net/http"
"net/url"
"os"
"strings"
"time"
"github.com/Hackmanit/Web-Cache-Vulnerability-Scanner/pkg"
"golang.org/x/net/http2"
)
const version = "1.3.0"
var (
currentDate string
report pkg.Report
completedFile *os.File
proxyURL *url.URL
headerList []string
parameterList []string
noTestPreference bool
excluded map[string]bool
added map[string]bool
)
func main() {
//pkg.ReadConfigFile()
pkg.ParseFlags(version)
pkg.Statistics = map[string]int{}
/*****************************/
/**** SET EXPORT STRUCT ****/
report.Name = "Web_Cache_Vulnerability_Scanner"
report.Version = version
report.Config = &pkg.Config
currentDate = time.Now().Format("2006-01-02_15-04-05")
report.Date = currentDate
report.Duration = "Not finished yet"
/***************************/
//Create generatePath directory
if pkg.Config.GeneratePath != "./" {
if !strings.HasSuffix(pkg.Config.GeneratePath, "/") {
pkg.Config.GeneratePath += "/"
}
if _, err := os.Stat(pkg.Config.GeneratePath); err != nil {
if os.IsNotExist(err) {
err := os.Mkdir(pkg.Config.GeneratePath, 0755)
if err != nil {
msg := fmt.Sprintf("Error while creating Directory: %s\n", err.Error())
pkg.PrintFatal(msg)
}
}
}
}
// Check pkg.Config if Log shall be printed or no logs shall be made
/* Setting Logoutput to Log file and stdout */
f, err := os.OpenFile(pkg.Config.GeneratePath+currentDate+"_WCVS_Log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
msg := fmt.Sprintf("Error while creating/opening Log File: %s\n", err.Error())
pkg.PrintFatal(msg)
}
defer f.Close()
//wrt := io.MultiWriter(f, os.Stdout)
//log.SetOutput(wrt)
log.SetOutput(f)
report.Command = fmt.Sprint(os.Args)
report.Command = strings.TrimPrefix(report.Command, "[")
report.Command = strings.TrimSuffix(report.Command, "]")
pkg.PrintVerbose(report.Command, pkg.NoColor, 2)
/******************************************/
if pkg.Config.Verbosity < 0 || pkg.Config.Verbosity > 2 {
msg := fmt.Sprintf("%d is not a valid verbosity between 0 and 2!\n", pkg.Config.Verbosity)
pkg.PrintFatal(msg)
}
/* print copyright etc */
pkg.PrintVerbose("Published by Hackmanit under http://www.apache.org/licenses/LICENSE-2.0\n", pkg.NoColor, 1)
pkg.PrintVerbose("Author: Maximilian Hildebrand\n", pkg.NoColor, 1)
pkg.PrintVerbose("Repository: https://github.com/Hackmanit/Web-Cache-Vulnerability-Scanner\n\n", pkg.NoColor, 1)
msg := fmt.Sprintf("WCVS v%s started at %s\n", version, currentDate)
pkg.PrintVerbose(msg, pkg.NoColor, 1)
start := time.Now()
noTestPreference = true
if pkg.Config.OnlyTest != "" && pkg.Config.SkipTest != "" {
msg = "You can't set both doTest and dontTest\n"
pkg.PrintFatal(msg)
} else if pkg.Config.OnlyTest != "" {
noTestPreference = false
} else if pkg.Config.SkipTest != "" {
noTestPreference = false
}
if pkg.Config.GenerateReport {
pkg.GenerateReport(report, currentDate)
}
if pkg.Config.GenerateCompleted {
completedFile = createCompletedURLs()
}
/***************************/
/* Setting up proxy (e.g. burp), if wanted */
proxyURL = setProxy()
/*******************************************/
// Reading header wordlist, only if it is needed
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "header") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "header")) {
headerList = pkg.ReadLocalFile(pkg.Config.HeaderWordlist, "header")
}
// Reading parameter wordlist, only if it is needed
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "parameter") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "parameter")) {
parameterList = pkg.ReadLocalFile(pkg.Config.QueryWordlist, "parameter")
}
/*******************************************************/
excluded = make(map[string]bool)
for _, u := range pkg.Config.RecExclude {
u = strings.TrimSuffix(u, "\r")
u = strings.TrimSpace(u)
// check if empty or is a comment
if u == "" || strings.HasPrefix(u, "//") {
continue
}
if !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "https://") {
msg = fmt.Sprintf("URL %s doesn't begin with http:// or https:// and gets skipped\n", u)
pkg.Print(msg, pkg.Yellow)
continue
}
excluded[u] = true
}
added = make(map[string]bool)
var testUrls []string
for _, u := range pkg.Config.Urls {
u = strings.TrimSuffix(u, "\r")
u = strings.TrimSpace(u)
// check if empty or is a comment
if u == "" || strings.HasPrefix(u, "//") {
continue
}
if !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "https://") {
prefix := "https"
if pkg.Config.UseHTTP {
prefix = "http"
}
msg = fmt.Sprintf("URL %s gets the prefix %s\n", u, prefix)
pkg.PrintVerbose(msg, pkg.Yellow, 2)
u = prefix + "://" + u
}
added[u] = true
testUrls = append(testUrls, u)
}
for i, u := range testUrls {
var recUrls []string
var progress string
progress = fmt.Sprintf("(%d/%d)", i+1, len(testUrls))
runTests(0, u, progress, &recUrls, "sub_")
for rec := 1; rec <= pkg.Config.Recursivity; rec++ {
var urlsToAdd []string
for ii, uu := range recUrls {
if ii != 0 && ii == pkg.Config.RecLimit {
msg = "RecLimit was reached. The next URL - if available - will be tested\n"
pkg.Print(msg, pkg.NoColor)
break
}
progress = fmt.Sprintf("(%d/%d):(%d/%d)", i+1, len(testUrls), ii+1, len(recUrls))
runTests(rec, uu, progress, &urlsToAdd, "crawl_")
}
recUrls = urlsToAdd
}
}
/* Scan finished */
msg = "Successfully finished the scan\n"
pkg.PrintVerbose(msg, pkg.NoColor, 1)
duration := time.Since(start)
msg = fmt.Sprintf("Duration: %s\n\n", duration)
pkg.PrintVerbose(msg, pkg.NoColor, 1)
/****************/
if pkg.Config.GenerateReport {
report.Duration = duration.String()
pkg.GenerateReport(report, currentDate)
}
}
func runTests(rec int, u string, progress string, foundUrls *[]string, stat string) {
var repWebsite pkg.ReportWebsite
var err error
repWebsite.URL = u
msg := fmt.Sprintf("\nTesting website%s: %s\n", progress, u)
pkg.Print(msg, pkg.NoColor)
pkg.Print("===============================================================\n", pkg.NoColor)
/* Setting up client: cookies and noredirect */
msg = "Setting up client\n"
pkg.PrintVerbose(msg, pkg.NoColor, 2)
// Setting cookies, specified by setcookies
pkg.Config.Website.Cookies = []*http.Cookie{}
for _, c := range pkg.Config.Cookies {
c = strings.TrimSuffix(c, "\r")
c = strings.TrimSpace(c)
if c == "" {
continue
} else if !strings.Contains(c, "=") {
msg = "Specified cookie %s doesn't contain a = and will be skipped\n"
pkg.PrintVerbose(msg, pkg.NoColor, 2)
continue
} else {
cSlice := strings.SplitAfterN(c, "=", 2)
cSlice[0] = strings.TrimSuffix(cSlice[0], "=")
cookie := http.Cookie{
Name: cSlice[0],
Value: cSlice[1],
}
pkg.Config.Website.Cookies = append(pkg.Config.Website.Cookies, &cookie)
}
}
timeOutDuration := time.Duration(time.Duration(pkg.Config.TimeOut) * time.Second)
clientNoRedir := &http.Client{
CheckRedirect: func(redirRequest *http.Request, via []*http.Request) error {
/* Commented out, because it unnecessary bloats up logs, especially for 301/302 links
msg := fmt.Sprintf("Redirect Request denied: %s\n", redirRequest.Header)
pkg.PrintVerbose(msg, pkg.Yellow, 2)
*/
return http.ErrUseLastResponse
},
Timeout: timeOutDuration,
}
http.DefaultClient = clientNoRedir
pkg.Statistics[stat+"total"]++
// retrieve cookies, headers etc. Only setStatusCode if no cookies shall be accepted. Otherwise the next request with set Cookies sets the status code
if !pkg.Config.DeclineCookies {
pkg.Config.Website, err = pkg.GetWebsite(u, false, false)
} else {
pkg.Config.Website, err = pkg.GetWebsite(u, true, false)
}
if err != nil {
repWebsite.HasError = true
repWebsite.ErrorMessages = append(repWebsite.ErrorMessages, err.Error())
report.Websites = append(report.Websites, repWebsite)
msg := fmt.Sprintf("Couldn't test url: %s\n", err.Error())
pkg.Print(msg, pkg.Red)
pkg.Statistics[stat+"noconnection"]++
return
}
if strings.HasPrefix(pkg.Config.Website.Body, "<html><head><title>Burp Suite") {
msg := fmt.Sprintf("Couldn't connect to given url: \n%s\n", pkg.Config.Website.Body)
pkg.Print(msg, pkg.Red)
pkg.Statistics[stat+"noconnection"]++
return
}
if !pkg.Config.DeclineCookies {
// retrieve response with all cookies set
pkg.Config.Website, err = pkg.GetWebsite(u, true, false)
if err != nil {
repWebsite.HasError = true
repWebsite.ErrorMessages = append(repWebsite.ErrorMessages, err.Error())
report.Websites = append(report.Websites, repWebsite)
msg := fmt.Sprintf("Couldn't test url: %s\n", err.Error())
pkg.Print(msg, pkg.Red)
return
}
}
// check if there's a cache and the cachebuster works
var errSlice []error
var alwaysMiss bool
pkg.Config.Website.Cache, alwaysMiss, errSlice = pkg.CheckCache(stat)
for _, err := range errSlice {
if err != nil {
repWebsite.HasError = true
repWebsite.ErrorMessages = append(repWebsite.ErrorMessages, err.Error())
}
}
/* dont return when there's an error. Because the crawler shall be run anyways. Also there might was a cachebuster found and an error for an other cachebuster which doesnt matter
if len(errSlice) > 0 && !pkg.Config.Force {
return
}
*/
// retrieve response with cachebuster if cachebuster was found
if pkg.Config.Website.Cache.CBwasFound {
pkg.Config.Website, err = pkg.GetWebsite(u, true, true)
if err != nil {
repWebsite.HasError = true
repWebsite.ErrorMessages = append(repWebsite.ErrorMessages, err.Error())
report.Websites = append(report.Websites, repWebsite)
msg := fmt.Sprintf("Couldn't test url: %s\n", err.Error())
pkg.Print(msg, pkg.Red)
pkg.Statistics[stat+"errorcachebuster"]++
return
}
}
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "decep") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "decep")) {
msg = addSeparator("Web Cache Deception")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
if alwaysMiss || pkg.Config.Website.Cache.Indicator == "" {
pkg.Statistics[stat+"deceptiontested"]++
repWebsite.Results = append(repWebsite.Results, pkg.TestWebCacheDeception())
} else {
msg = "The response already gets cached!"
pkg.Print(msg+"\n", pkg.Yellow)
}
} else {
msg = addSeparator("Skipping Web Cache Deception")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/*******************************************/
if pkg.Config.Website.Cache.CBwasFound || pkg.Config.Force {
pkg.Statistics[stat+"poisoningtested"]++
/* Testing for cookie poisoning */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "cookie") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "cookie")) {
msg = addSeparator("Cookie Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
repWebsite.Results = append(repWebsite.Results, pkg.ScanCookies())
if len(pkg.Config.Website.Cookies) == 0 {
msg = "There were no cookies to test!"
pkg.Print(msg+"\n", pkg.Yellow)
repWebsite.Results[len(repWebsite.Results)-1].ErrorMessages = append(repWebsite.Results[len(repWebsite.Results)-1].ErrorMessages, msg)
repWebsite.Results[len(repWebsite.Results)-1].HasError = true
}
} else {
msg = addSeparator("Skipping Cookie Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/*****************************/
/* Testing for css poisoning */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "css") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "css")) {
msg = addSeparator("CSS Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
repWebsite.Results = append(repWebsite.Results, pkg.ScanCSS())
} else {
msg = addSeparator("Skipping CSS Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/*****************************/
/* Testing for multiple forwarding headers for poisoning */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "forward") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "forward")) {
msg = addSeparator("Multiple Forwarding Headers Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
repWebsite.Results = append(repWebsite.Results, pkg.ScanForwardingHeaders())
} else {
msg = addSeparator("Skipping Multiple Forwarding Headers Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/*************************************************************/
/* Testing for HTTP request smuggling poisoning */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "smuggl") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "smuggl")) {
msg = addSeparator("HTTP Request Smuggling Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
repWebsite.Results = append(repWebsite.Results, pkg.ScanHTTPRequestSmuggling(proxyURL))
} else {
msg = addSeparator("Skipping HTTP Request Smuggling Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/*************************************************************/
/* Testing for multiple Cache Poisoned Denial Of Service Techniques */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "dos") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "dos")) {
msg = addSeparator("Cache Poisoned Denial Of Service")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
repWebsite.Results = append(repWebsite.Results, pkg.DOS())
} else {
msg = addSeparator("Skipping Cache Poisoned Denial Of Service")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/***********************************************************/
/* Testing for header poisoning */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "header") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "header")) {
msg = addSeparator("Header Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
repWebsite.Results = append(repWebsite.Results, pkg.ScanHeaders(headerList))
} else {
msg = addSeparator("Skipping Header Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/********************************/
/* Testing for query parameter poisoning */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "parameter") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "parameter")) {
msg = addSeparator("Query Parameter Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
repWebsite.Results = append(repWebsite.Results, pkg.ScanParameters(parameterList))
} else {
msg = addSeparator("Skipping Query Parameter Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/*****************************************/
/* Testing for Fat GET */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "fat") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "fat")) {
msg = addSeparator("Fat GET Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
if pkg.Config.DoPost {
msg = "Can't check for Fat GET Poisoning, because POST was specified\n"
pkg.PrintVerbose(msg, pkg.Yellow, 1)
} else {
repWebsite.Results = append(repWebsite.Results, pkg.ScanFatGET())
}
} else {
msg = addSeparator("Skipping Fat GET Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/**********************/
/* Testing for Parameter Cloaking */
if noTestPreference || strings.Contains(pkg.Config.OnlyTest, "cloaking") || (pkg.Config.SkipTest != "" && !strings.Contains(pkg.Config.SkipTest, "cloaking")) {
msg = addSeparator("Parameter Cloaking Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
if pkg.Config.DoPost {
msg = "Can't check for Parameter Cloaking Poisoning, because POST was specified\n"
pkg.PrintVerbose(msg, pkg.Yellow, 1)
} else {
repWebsite.Results = append(repWebsite.Results, pkg.ScanParameterCloaking())
}
} else {
msg = addSeparator("Skipping Parameter Cloaking Poisoning")
pkg.PrintVerbose(msg, pkg.NoColor, 1)
}
/**********************************/
}
/* Check for linked files */
if pkg.Config.Recursivity > rec {
msg = fmt.Sprintf("\nChecking recursively for urls (%d/%d)\n", rec+1, pkg.Config.Recursivity)
pkg.Print(msg, pkg.NoColor)
tempUrls := pkg.CrawlUrls(added, excluded)
if len(tempUrls) > 0 {
msg = fmt.Sprintf("Found %d urls", len(tempUrls))
pkg.Print(msg, pkg.NoColor)
msg = "Adding the following urls to the Queue:"
pkg.PrintVerbose(msg, pkg.NoColor, 1)
pkg.PrintVerbose("\n", pkg.NoColor, 0)
for _, u := range tempUrls {
pkg.PrintVerbose(u+"\n", pkg.NoColor, 1)
}
*foundUrls = append(*foundUrls, tempUrls...)
} else {
msg = "No urls were found to add to the queue"
pkg.Print(msg, pkg.NoColor)
}
}
/**************************/
if pkg.Config.GenerateCompleted {
_, err = completedFile.WriteString(u + "\n")
if err != nil {
pkg.Print("Couldn't write to WCVS_Completed File: %s\n"+err.Error(), pkg.Red)
}
}
if pkg.Config.GenerateReport {
for _, r := range repWebsite.Results {
if r.Vulnerable {
repWebsite.Vulnerable = true
break
}
}
report.Websites = append(report.Websites, repWebsite)
report.Vulnerable = report.Vulnerable || repWebsite.Vulnerable
pkg.PrintNewLine()
pkg.GenerateReport(report, currentDate)
}
pkg.Print("===============================================================\n\n", pkg.NoColor)
}
func addSeparator(msg string) string {
separator := " --------------------------------------------------------------"
return fmt.Sprintf("\n%s\n| %s\n%s\n", separator, msg, separator)
}
func createCompletedURLs() *os.File {
completedPath := pkg.Config.GeneratePath + currentDate + "_WCVS_Completed"
_, err := os.Stat(completedPath)
var file *os.File
defer file.Close()
if !os.IsNotExist(err) {
msg := fmt.Sprintf("The file %s will be overwritten, as it already exists\n", completedPath)
pkg.PrintVerbose(msg, pkg.Yellow, 1)
file, err = os.OpenFile(completedPath, os.O_WRONLY, 0666)
} else {
file, err = os.Create(completedPath)
}
if err != nil {
msg := "Couldn't create WCVS_Completed file: " + err.Error() + "\n"
pkg.PrintFatal(msg)
}
return file
}
/* Setting proxy with specified proxyURL and proxyCertPath */
func setProxy() *url.URL {
if pkg.Config.ProxyCertPath != "" {
proxyURL, err := url.Parse(pkg.Config.ProxyURL)
if err != nil {
msg := "setProxy: url.Parse: " + err.Error() + "\n"
pkg.PrintFatal(msg)
}
caCert, err := os.ReadFile(pkg.Config.ProxyCertPath)
if err != nil {
msg := "setProxy: ioutil.ReadFile: " + err.Error() + "\n"
pkg.PrintFatal(msg)
}
//caCertPool,err := x509.SystemCertPool()
// führt zu crypto/x509: system root pool is not available on Windows
caCertPool := x509.NewCertPool()
ok := caCertPool.AppendCertsFromPEM(caCert)
if !ok {
msg := "setProxy: could not append cert\n"
pkg.PrintFatal(msg)
}
tlsConfig := &tls.Config{RootCAs: caCertPool,
InsecureSkipVerify: true}
tr := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: tlsConfig}
err = http2.ConfigureTransport(tr)
if err != nil {
msg := fmt.Sprintf("setProxy: Cannot switch to HTTP2: %s\n", err.Error())
pkg.PrintFatal(msg)
}
http.DefaultTransport = tr
return proxyURL
} else {
tlsConfig := &tls.Config{InsecureSkipVerify: true}
tr := &http.Transport{
TLSClientConfig: tlsConfig}
http.DefaultTransport = tr
return nil
}
}