-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpentest.go
More file actions
895 lines (812 loc) · 33.3 KB
/
pentest.go
File metadata and controls
895 lines (812 loc) · 33.3 KB
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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
package cmd
import (
// Standard
"strings"
// Generated
common "github.com/Method-Security/webscan/generated/go/common"
nuclei "github.com/Method-Security/webscan/generated/go/common/nuclei"
discover "github.com/Method-Security/webscan/generated/go/discover"
pentestapplicationfern "github.com/Method-Security/webscan/generated/go/pentest/application"
pentestapplicationscanfern "github.com/Method-Security/webscan/generated/go/pentest/application/scan"
pentestcmswordpressfern "github.com/Method-Security/webscan/generated/go/pentest/cms/wordpress"
pentestroutefern "github.com/Method-Security/webscan/generated/go/pentest/route"
waf "github.com/Method-Security/webscan/generated/go/pentest/waf"
// Internal
pentestapplication "github.com/Method-Security/webscan/internal/pentest/application"
pentestapplicationscan "github.com/Method-Security/webscan/internal/pentest/application/scan"
pentestcmswordpress "github.com/Method-Security/webscan/internal/pentest/cms/wordpress"
pentestroute "github.com/Method-Security/webscan/internal/pentest/route"
pentestwafdetect "github.com/Method-Security/webscan/internal/pentest/waf/detect"
// Utils
nucleihelpers "github.com/Method-Security/webscan/utils/nuclei/helpers"
requesthelpers "github.com/Method-Security/webscan/utils/request/helpers"
// External
cobra "github.com/spf13/cobra"
)
// InitPentestCommand initializes the 'pentest' command and its subcommands for the CLI.
func (a *WebScan) InitPentestCommand() {
// Pentest Command
// Subcommands: general, route
pentestCmd := &cobra.Command{
Use: "pentest",
Short: "Perform various pentest scans",
Long: `Perform various pentest scans to identify web applications, routes, and static assets.`,
}
// Application Command
// Subcommands: dast, scan
pentestApplicationCmd := &cobra.Command{
Use: "application",
Short: "Dast targets to discover previously unknown vulnerabilities",
Long: `Dast targets to discover previously unknown vulnerabilities`,
}
// Dast Command
pentestApplicationDastCmd := &cobra.Command{
Use: "dast",
Short: "Dast targets to discover previously unknown vulnerabilities",
Long: "Dast targets to discover previously unknown vulnerabilities",
Run: func(cmd *cobra.Command, args []string) {
defer a.OutputSignal.PanicHandler(cmd.Context())
// Targets flag
targets, err := cmd.Flags().GetStringSlice("targets")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Dast Flags
// Dast Categories flag
dastCategoriesListStr, err := cmd.Flags().GetStringSlice("dast-categories")
if err != nil {
a.OutputSignal.AddError(err)
return
}
dastCategories := make([]pentestapplicationfern.PentestApplicationDastCategory, 0, len(dastCategoriesListStr))
for _, dc := range dastCategoriesListStr {
dastCategory, err := pentestapplicationfern.NewPentestApplicationDastCategoryFromString(dc)
if err != nil {
a.OutputSignal.AddError(err)
return
}
dastCategories = append(dastCategories, dastCategory)
}
// Dast Parameters flag
dastRequestParamsStr, err := cmd.Flags().GetString("dast-request-params")
if err != nil {
a.OutputSignal.AddError(err)
return
}
dastRequestParams, err := nucleihelpers.ParseParameterString(dastRequestParamsStr)
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Dast Methods flag
httpMethodsStr, err := cmd.Flags().GetStringSlice("http-methods")
if err != nil {
a.OutputSignal.AddError(err)
return
}
httpMethods := make([]common.HttpMethod, 0, len(httpMethodsStr))
for _, ms := range httpMethodsStr {
m, err := common.NewHttpMethodFromString(strings.ToUpper(ms))
if err != nil {
a.OutputSignal.AddError(err)
return
}
httpMethods = append(httpMethods, m)
}
// Config flags
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
threads, err := cmd.Flags().GetInt("threads")
if err != nil {
a.OutputSignal.AddError(err)
return
}
proxy, err := cmd.Flags().GetString("proxy")
if err != nil {
a.OutputSignal.AddError(err)
return
}
if err := nucleihelpers.ValidateProxy(proxy); err != nil {
a.OutputSignal.AddError(err)
return
}
verboseLogs, err := cmd.Flags().GetBool("verbose-logs")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalRateLimit, err := cmd.Flags().GetInt("global-rate-limit")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalTimeout, err := cmd.Flags().GetInt("global-timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Set config
config := getPentestApplicationDastConfig(targets, dastCategories, httpMethods, dastRequestParams, timeout, threads, &proxy, verboseLogs, globalRateLimit, globalTimeout)
// Generate a report
rep, err := pentestapplication.RunPentestApplicationDast(cmd.Context(), config)
if err != nil {
a.OutputSignal.AddError(err)
return
}
a.OutputSignal.Content = rep
},
}
// Target Flags
pentestApplicationDastCmd.Flags().StringSlice("targets", []string{}, "Targets to be scanned")
// Dast Config Flags
pentestApplicationDastCmd.Flags().StringSlice("dast-categories", []string{}, "Dast Categories (ie. XSS, SQLI, RFI, etc.)")
pentestApplicationDastCmd.Flags().String("dast-request-params", "", "Base64 JSON blob of request parameters that will be fuzzed")
pentestApplicationDastCmd.Flags().StringSlice("http-methods", []string{}, "HTTP methods to use (e.g. GET,POST,PUT)")
// Config Flags
pentestApplicationDastCmd.Flags().Int("timeout", 30, "Timeout per request in seconds")
pentestApplicationDastCmd.Flags().Int("threads", 25, "Number of threads")
pentestApplicationDastCmd.Flags().String("proxy", "", "Optional HTTP proxy URL")
pentestApplicationDastCmd.Flags().Bool("verbose-logs", false, "Verbose logs")
pentestApplicationDastCmd.Flags().Int("global-rate-limit", 0, "Global rate limit (requests per second, 0 = no limit)")
pentestApplicationDastCmd.Flags().Int("global-timeout", 0, "Maximum total scan time in seconds (0 means no timout)")
// Mark Required Flags
_ = pentestApplicationDastCmd.MarkFlagRequired("targets")
_ = pentestApplicationDastCmd.MarkFlagRequired("http-methods")
// Add Command to 'Application' Command
pentestApplicationCmd.AddCommand(pentestApplicationDastCmd)
// Scan Command
// Subcommands: cves, misconfiguration, technologies
pentestApplicationScanCmd := &cobra.Command{
Use: "scan",
Short: "Scan targets for vulnerabilities",
Long: `Scan targets for vulnerabilities`,
}
// CVE Scan Command
pentestApplicationCveCmd := &cobra.Command{
Use: "cve",
Short: "Scan targets for CVEs",
Long: `Scan targets for CVEs`,
Run: func(cmd *cobra.Command, args []string) {
defer a.OutputSignal.PanicHandler(cmd.Context())
// Targets flag
targets, err := cmd.Flags().GetStringSlice("targets")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Scan Flags
years, err := cmd.Flags().GetStringSlice("years")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Config flags
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
threads, err := cmd.Flags().GetInt("threads")
if err != nil {
a.OutputSignal.AddError(err)
return
}
proxy, err := cmd.Flags().GetString("proxy")
if err != nil {
a.OutputSignal.AddError(err)
return
}
if err := nucleihelpers.ValidateProxy(proxy); err != nil {
a.OutputSignal.AddError(err)
return
}
verboseLogs, err := cmd.Flags().GetBool("verbose-logs")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalRateLimit, err := cmd.Flags().GetInt("global-rate-limit")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalTimeout, err := cmd.Flags().GetInt("global-timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Set config
config := getPentestApplicationCveConfig(targets, years, timeout, threads, proxy, verboseLogs, globalRateLimit, globalTimeout)
// Generate a report
rep, err := pentestapplicationscan.RunPentestApplicationCveScan(cmd.Context(), config)
if err != nil {
a.OutputSignal.AddError(err)
return
}
a.OutputSignal.Content = rep
},
}
// Target Flags
pentestApplicationCveCmd.Flags().StringSlice("targets", []string{}, "Targets to be scanned")
// Config Flags
pentestApplicationCveCmd.Flags().StringSlice("years", []string{}, "Restrict CVE scans to particular years (default is all available years)")
pentestApplicationCveCmd.Flags().Int("timeout", 30, "Timeout per request in seconds")
pentestApplicationCveCmd.Flags().Int("threads", 25, "Number of threads")
pentestApplicationCveCmd.Flags().String("proxy", "", "Optional HTTP proxy URL")
pentestApplicationCveCmd.Flags().Bool("verbose-logs", false, "Verbose logs")
pentestApplicationCveCmd.Flags().Int("global-rate-limit", 0, "Global rate limit (requests per second, 0 = no limit)")
pentestApplicationCveCmd.Flags().Int("global-timeout", 0, "Maximum total scan time in seconds (0 means no timout)")
// Mark Required Flags
_ = pentestApplicationCveCmd.MarkFlagRequired("targets")
// Add Command to 'Scan' Command
pentestApplicationScanCmd.AddCommand(pentestApplicationCveCmd)
// Misconfiguration Scan Command
pentestApplicationMisconfigurationCmd := &cobra.Command{
Use: "misconfiguration",
Short: "Scan targets for security misconfigurations",
Long: `Scan targets for security misconfigurations using nuclei templates. This command leverages nuclei to identify common security misconfigurations such as improper HTTP headers, insecure server configurations, and other security weaknesses.`,
Run: func(cmd *cobra.Command, args []string) {
defer a.OutputSignal.PanicHandler(cmd.Context())
// Targets flag
targets, err := cmd.Flags().GetStringSlice("targets")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Misconfiguration Flags
misconfigurationCategories, err := cmd.Flags().GetStringSlice("misconfiguration-categories")
if err != nil {
a.OutputSignal.AddError(err)
return
}
misconfigurationCategoriesEnumList := []pentestapplicationscanfern.MisconfigurationCategory{}
for _, t := range misconfigurationCategories {
misconfigurationCategoriesEnumList = append(misconfigurationCategoriesEnumList, pentestapplicationscanfern.MisconfigurationCategory(t))
}
// Config flags
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
threads, err := cmd.Flags().GetInt("threads")
if err != nil {
a.OutputSignal.AddError(err)
return
}
proxy, err := cmd.Flags().GetString("proxy")
if err != nil {
a.OutputSignal.AddError(err)
return
}
if err := nucleihelpers.ValidateProxy(proxy); err != nil {
a.OutputSignal.AddError(err)
return
}
verboseLogs, err := cmd.Flags().GetBool("verbose-logs")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalRateLimit, err := cmd.Flags().GetInt("global-rate-limit")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalTimeout, err := cmd.Flags().GetInt("global-timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Set config
config := getPentestApplicationMisconfigurationConfig(targets, misconfigurationCategoriesEnumList, timeout, threads, proxy, verboseLogs, globalRateLimit, globalTimeout)
// Generate a report
rep, err := pentestapplicationscan.RunPentestApplicationMisconfigurationScan(cmd.Context(), config)
if err != nil {
a.OutputSignal.AddError(err)
return
}
a.OutputSignal.Content = rep
},
}
// Target Flags
pentestApplicationMisconfigurationCmd.Flags().StringSlice("targets", []string{}, "Targets to be scanned")
// Misconfiguration Flags
pentestApplicationMisconfigurationCmd.Flags().StringSlice("misconfiguration-categories", []string{}, "Categories of misconfigurations to scan for")
// Config Flags
pentestApplicationMisconfigurationCmd.Flags().Int("timeout", 30, "Timeout per request in seconds")
pentestApplicationMisconfigurationCmd.Flags().Int("threads", 25, "Number of threads")
pentestApplicationMisconfigurationCmd.Flags().String("proxy", "", "Optional HTTP proxy URL")
pentestApplicationMisconfigurationCmd.Flags().Bool("verbose-logs", false, "Verbose logs")
pentestApplicationMisconfigurationCmd.Flags().Int("global-rate-limit", 0, "Global rate limit (requests per second, 0 = no limit)")
pentestApplicationMisconfigurationCmd.Flags().Int("global-timeout", 0, "Maximum total scan time in seconds (0 means no timout)")
// Mark Required Flags
_ = pentestApplicationMisconfigurationCmd.MarkFlagRequired("targets")
// Add Command to 'Scan' Command
pentestApplicationScanCmd.AddCommand(pentestApplicationMisconfigurationCmd)
// Technologies Scan Command
pentestApplicationTechnologyCmd := &cobra.Command{
Use: "technology",
Short: "Scan targets for technology-specific vulnerabilities",
Long: `Scan targets for technology-specific vulnerabilities using nuclei templates. This command leverages nuclei to identify vulnerabilities in specific technologies, frameworks, and applications.`,
Run: func(cmd *cobra.Command, args []string) {
defer a.OutputSignal.PanicHandler(cmd.Context())
// Targets flag
targets, err := cmd.Flags().GetStringSlice("targets")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Technology Flags
technologyTypes, err := cmd.Flags().GetStringSlice("technology-types")
if err != nil {
a.OutputSignal.AddError(err)
return
}
technologyTypesEnumList := []pentestapplicationscanfern.TechnologyType{}
for _, t := range technologyTypes {
technologyTypesEnumList = append(technologyTypesEnumList, pentestapplicationscanfern.TechnologyType(t))
}
// Config flags
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
threads, err := cmd.Flags().GetInt("threads")
if err != nil {
a.OutputSignal.AddError(err)
return
}
proxy, err := cmd.Flags().GetString("proxy")
if err != nil {
a.OutputSignal.AddError(err)
return
}
if err := nucleihelpers.ValidateProxy(proxy); err != nil {
a.OutputSignal.AddError(err)
return
}
verboseLogs, err := cmd.Flags().GetBool("verbose-logs")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalRateLimit, err := cmd.Flags().GetInt("global-rate-limit")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalTimeout, err := cmd.Flags().GetInt("global-timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Set config
config := getPentestApplicationTechnologyConfig(targets, technologyTypesEnumList, timeout, threads, proxy, verboseLogs, globalRateLimit, globalTimeout)
// Generate a report
rep, err := pentestapplicationscan.RunPentestApplicationTechnologyScan(cmd.Context(), config)
if err != nil {
a.OutputSignal.AddError(err)
return
}
a.OutputSignal.Content = rep
},
}
// Target Flags
pentestApplicationTechnologyCmd.Flags().StringSlice("targets", []string{}, "Targets to be scanned")
// Technology Flags
pentestApplicationTechnologyCmd.Flags().StringSlice("technology-types", []string{}, "Technologies to scan for")
// Config Flags
pentestApplicationTechnologyCmd.Flags().Int("timeout", 30, "Timeout per request in seconds")
pentestApplicationTechnologyCmd.Flags().Int("threads", 25, "Number of threads")
pentestApplicationTechnologyCmd.Flags().String("proxy", "", "Optional HTTP proxy URL")
pentestApplicationTechnologyCmd.Flags().Bool("verbose-logs", false, "Verbose logs")
pentestApplicationTechnologyCmd.Flags().Int("global-rate-limit", 0, "Global rate limit (requests per second, 0 = no limit)")
pentestApplicationTechnologyCmd.Flags().Int("global-timeout", 0, "Maximum total scan time in seconds (0 means no timout)")
// Mark Required Flags
_ = pentestApplicationTechnologyCmd.MarkFlagRequired("targets")
// Add Command to 'Scan' Command
pentestApplicationScanCmd.AddCommand(pentestApplicationTechnologyCmd)
// Add Command to 'Application' Command
pentestApplicationCmd.AddCommand(pentestApplicationScanCmd)
// Add Command to 'Pentest' Command
pentestCmd.AddCommand(pentestApplicationCmd)
// CMS Command
// Subcommands: wordpress
pentestCmsCmd := &cobra.Command{
Use: "cms",
Short: "Detect CMS Application vulnerabilities",
Long: `Analyze CMS Applications to detect potential vulnerabilities.`,
}
pentestCmsWordpressCmd := &cobra.Command{
Use: "wordpress",
Short: "Detect WordPress vulnerabilities",
Long: `Analyze WordPress to detect potential vulnerabilities.`,
}
pentestCmsWordpressXmlrpcFunctionsExposedCmd := &cobra.Command{
Use: "xmlrpc-functions-exposed",
Short: "Perform xmlrpc functions exposed tests against a target",
Long: `Perform xmlrpc functions exposed tests against a target`,
Run: func(cmd *cobra.Command, args []string) {
defer a.OutputSignal.PanicHandler(cmd.Context())
// Target flags
targets, err := cmd.Flags().GetStringSlice("targets")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Config flags
successfulOnly, err := cmd.Flags().GetBool("successful-only")
if err != nil {
a.OutputSignal.AddError(err)
return
}
verifyTLS, err := cmd.Flags().GetBool("verify-tls")
if err != nil {
a.OutputSignal.AddError(err)
return
}
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
retries, err := cmd.Flags().GetInt("retries")
if err != nil {
a.OutputSignal.AddError(err)
return
}
sleep, err := cmd.Flags().GetInt("sleep")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Load configuration
config := getPentestCmsWordpressXmlrpcFunctionsExposedConfig(targets, successfulOnly, verifyTLS, timeout, retries, sleep)
// Generate report
report := pentestcmswordpress.PerformWordpressXMLRPCFunctionsExposed(cmd.Context(), config)
if len(report.Errors) > 0 {
a.OutputSignal.Status = 1
}
a.OutputSignal.Content = report
},
}
// Target Flags
pentestCmsWordpressXmlrpcFunctionsExposedCmd.Flags().StringSlice("targets", []string{}, "Targets to be scanned")
// Config Flags
pentestCmsWordpressXmlrpcFunctionsExposedCmd.Flags().Bool("successful-only", false, "Only include successful results in the report")
pentestCmsWordpressXmlrpcFunctionsExposedCmd.Flags().Bool("verify-tls", false, "Verify TLS certificates when making HTTPS requests")
pentestCmsWordpressXmlrpcFunctionsExposedCmd.Flags().Int("timeout", 30, "Timeout per request in seconds")
pentestCmsWordpressXmlrpcFunctionsExposedCmd.Flags().Int("retries", 0, "Number of times to retry a request if it fails")
pentestCmsWordpressXmlrpcFunctionsExposedCmd.Flags().Int("sleep", 0, "Number of seconds to sleep between requests")
// Mark Required Flags
_ = pentestCmsWordpressXmlrpcFunctionsExposedCmd.MarkFlagRequired("targets")
// Add Command to 'Wordpress' Command
pentestCmsWordpressCmd.AddCommand(pentestCmsWordpressXmlrpcFunctionsExposedCmd)
// Add Command to 'CMS' Command
pentestCmsCmd.AddCommand(pentestCmsWordpressCmd)
// Add Command to 'Pentest' Command
pentestCmd.AddCommand(pentestCmsCmd)
// Route Command
// Subcommands: static-asset-takeover
pentestRouteCmd := &cobra.Command{
Use: "route",
Short: "Detect route vulnerabilities",
Long: `Analyze routes to detect potential vulnerabilities.`,
}
// Static Asset Takeover Command
pentestRouteStaticAssetTakeoverCmd := &cobra.Command{
Use: "static-asset-takeover",
Short: "Detect webpage static asset takeover vulnerabilities",
Long: `Analyze webpages to detect potential takeover vulnerabilities through misconfigured CDNs or storage services.`,
Run: func(cmd *cobra.Command, args []string) {
defer a.OutputSignal.PanicHandler(cmd.Context())
// Get Target flag
target, err := cmd.Flags().GetString("target")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Get Config flags
fingerprintPaths, err := cmd.Flags().GetStringSlice("fingerprint-file-paths")
if err != nil {
a.OutputSignal.AddError(err)
return
}
detect404Responses, err := cmd.Flags().GetBool("detect-404-responses")
if err != nil {
a.OutputSignal.AddError(err)
return
}
successfulOnly, err := cmd.Flags().GetBool("successful-only")
if err != nil {
a.OutputSignal.AddError(err)
return
}
maxRedirects, err := cmd.Flags().GetInt("max-redirects")
if err != nil {
a.OutputSignal.AddError(err)
return
}
verifyTLS, err := cmd.Flags().GetBool("verify-tls")
if err != nil {
a.OutputSignal.AddError(err)
return
}
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
threads, err := cmd.Flags().GetInt("threads")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Get Request Method flag
requestMethodConfig, err := requesthelpers.GetRequestMethodFlags(cmd)
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Set Config
config := getPentestRouteStaticAssetTakeoverConfig(target, fingerprintPaths, detect404Responses, successfulOnly, maxRedirects, verifyTLS, timeout, threads, requestMethodConfig.RequestMethodEnum, requestMethodConfig.HeadlessConfig, requestMethodConfig.BrowserbaseConfig)
// Generate a report
report := pentestroute.DetectStaticAssetTakeovers(cmd.Context(), config, requestMethodConfig.BrowserbaseSecrets)
a.OutputSignal.Content = report
},
}
// Target Flags
pentestRouteStaticAssetTakeoverCmd.Flags().String("target", "", "URL target to analyze for static asset takeover")
// Config Flags
pentestRouteStaticAssetTakeoverCmd.Flags().StringSlice("fingerprint-file-paths", []string{}, "Paths to fingerprint definition files")
pentestRouteStaticAssetTakeoverCmd.Flags().Bool("detect-404-responses", false, "Detect 404 responses as potential takeover responses")
pentestRouteStaticAssetTakeoverCmd.Flags().Bool("successful-only", false, "Only show successful takeover attempts")
pentestRouteStaticAssetTakeoverCmd.Flags().Int("max-redirects", 10, "Maximum number of redirects to follow")
pentestRouteStaticAssetTakeoverCmd.Flags().Bool("verify-tls", false, "Verify TLS certificates when making HTTPS requests")
pentestRouteStaticAssetTakeoverCmd.Flags().Int("timeout", 30, "Timeout per request in seconds")
pentestRouteStaticAssetTakeoverCmd.Flags().Int("threads", 0, "Number of concurrent threads for scanning")
// Request Method Flags for all capture subcommands
pentestRouteStaticAssetTakeoverCmd.Flags().String("request-method", "STANDARD", "Request method to use (standard, headless, browserbase)")
pentestRouteStaticAssetTakeoverCmd.Flags().String("headless-path", "", "Path to headless browser executable")
pentestRouteStaticAssetTakeoverCmd.Flags().Int("min-dom-stabalize-time", 20, "Minimum time to wait for DOM stabilization in seconds")
pentestRouteStaticAssetTakeoverCmd.Flags().String("browserbase-token", "", "Browserbase API token for cloud browser access")
pentestRouteStaticAssetTakeoverCmd.Flags().String("browserbase-project", "", "Browserbase project ID")
pentestRouteStaticAssetTakeoverCmd.Flags().Bool("browserbase-proxy", false, "Use Browserbase proxy for requests")
pentestRouteStaticAssetTakeoverCmd.Flags().StringSlice("browserbase-countries", []string{}, "List of countries to use for Browserbase proxy")
// Mark Required Flags
_ = pentestRouteStaticAssetTakeoverCmd.MarkFlagRequired("target")
// Add Command to 'Static Asset' Command
pentestRouteCmd.AddCommand(pentestRouteStaticAssetTakeoverCmd)
// Waf Command
// Subcommands: waf
pentestWafCmd := &cobra.Command{
Use: "waf",
Short: "Web Application Firewall detection and analysis",
Long: `Detect and analyze Web Application Firewalls (WAFs) protecting web applications to identify ` +
`their types, configurations, and potential bypass techniques.`,
}
pentestWafDetectCmd := &cobra.Command{
Use: "detect",
Short: "Actively detect WAFs protecting web applications",
Long: "Actively detect and identify Web Application Firewalls (WAFs) protecting web applications.",
Run: func(cmd *cobra.Command, args []string) {
defer a.OutputSignal.PanicHandler(cmd.Context())
// Targets flag
targets, err := cmd.Flags().GetStringSlice("targets")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Waf Flags
// Waf Parameters flag
routeRequestParamsStr, err := cmd.Flags().GetString("route-request-params")
if err != nil {
a.OutputSignal.AddError(err)
return
}
routeRequestParams, err := nucleihelpers.ParseParameterString(routeRequestParamsStr)
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Waf Methods flag
httpMethodsStr, err := cmd.Flags().GetStringSlice("http-methods")
if err != nil {
a.OutputSignal.AddError(err)
return
}
httpMethods := make([]common.HttpMethod, 0, len(httpMethodsStr))
for _, ms := range httpMethodsStr {
m, err := common.NewHttpMethodFromString(strings.ToUpper(ms))
if err != nil {
a.OutputSignal.AddError(err)
return
}
httpMethods = append(httpMethods, m)
}
// Config flags
timeout, err := cmd.Flags().GetInt("timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
threads, err := cmd.Flags().GetInt("threads")
if err != nil {
a.OutputSignal.AddError(err)
return
}
proxy, err := cmd.Flags().GetString("proxy")
if err != nil {
a.OutputSignal.AddError(err)
return
}
if err := nucleihelpers.ValidateProxy(proxy); err != nil {
a.OutputSignal.AddError(err)
return
}
verboseLogs, err := cmd.Flags().GetBool("verbose-logs")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalRateLimit, err := cmd.Flags().GetInt("global-rate-limit")
if err != nil {
a.OutputSignal.AddError(err)
return
}
globalTimeout, err := cmd.Flags().GetInt("global-timeout")
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Set config
config := getPentestWafDetectConfig(targets, routeRequestParams, httpMethods, timeout, threads, proxy, verboseLogs, globalRateLimit, globalTimeout)
// Generate a report
rep, err := pentestwafdetect.RunPentestWafDetect(cmd.Context(), config)
if err != nil {
a.OutputSignal.AddError(err)
return
}
a.OutputSignal.Content = rep
},
}
// Target Flags
pentestWafDetectCmd.Flags().StringSlice("targets", []string{}, "Targets to be scanned")
// Waf Config Flags
pentestWafDetectCmd.Flags().String("route-request-params", "", "Base64 JSON blob of request parameters that will be injected")
pentestWafDetectCmd.Flags().StringSlice("http-methods", []string{}, "HTTP methods to use (e.g. GET,POST,PUT)")
// Config Flags
pentestWafDetectCmd.Flags().Int("timeout", 30, "Timeout per request in seconds")
pentestWafDetectCmd.Flags().Int("threads", 25, "Number of threads")
pentestWafDetectCmd.Flags().String("proxy", "", "Optional HTTP proxy URL")
pentestWafDetectCmd.Flags().Bool("verbose-logs", false, "Verbose logs")
pentestWafDetectCmd.Flags().Int("global-rate-limit", 0, "Global rate limit (requests per second, 0 = no limit)")
pentestWafDetectCmd.Flags().Int("global-timeout", 0, "Maximum total scan time in seconds (0 means no timout)")
// Mark Required Flags
_ = pentestWafDetectCmd.MarkFlagRequired("targets")
_ = pentestWafDetectCmd.MarkFlagRequired("http-methods")
// Add Command to 'Waf' Command
pentestWafCmd.AddCommand(pentestWafDetectCmd)
// Add Command to 'Pentest' Command
pentestCmd.AddCommand(pentestWafCmd)
// Add Command to 'Pentest' Command
pentestCmd.AddCommand(pentestRouteCmd)
// Add Command to 'Root'
a.RootCmd.AddCommand(pentestCmd)
}
// getPentestApplicationDastConfig builds the config for dast pentest.
func getPentestApplicationDastConfig(targets []string, dastCategories []pentestapplicationfern.PentestApplicationDastCategory, httpMethods []common.HttpMethod, dastRequestParams []*nuclei.RequestParameter, timeout int, threads int, proxy *string, verboseLogs bool, globalRateLimit int, globalTimeout int) pentestapplicationfern.PentestApplicationDastConfig {
config := pentestapplicationfern.PentestApplicationDastConfig{
Targets: targets,
DastCategories: dastCategories,
DastRequestParams: dastRequestParams,
HttpMethods: httpMethods,
Timeout: timeout,
Threads: threads,
Proxy: proxy,
VerboseLogs: verboseLogs,
GlobalRateLimit: max(0, globalRateLimit),
GlobalTimeout: max(0, globalTimeout),
}
return config
}
// getPentestApplicationCveConfig builds the config for scan pentest.
func getPentestApplicationCveConfig(targets []string, years []string, timeout int, threads int, proxy string, verboseLogs bool, globalRateLimit int, globalTimeout int) pentestapplicationscanfern.PentestApplicationCveConfig {
config := pentestapplicationscanfern.PentestApplicationCveConfig{
Targets: targets,
Years: years,
Timeout: timeout,
Threads: threads,
Proxy: &proxy,
VerboseLogs: verboseLogs,
GlobalRateLimit: max(0, globalRateLimit),
GlobalTimeout: max(0, globalTimeout),
}
return config
}
// getPentestApplicationMisconfigurationConfig builds the config for scan pentest.
func getPentestApplicationMisconfigurationConfig(targets []string, misconfigurationCategories []pentestapplicationscanfern.MisconfigurationCategory, timeout int, threads int, proxy string, verboseLogs bool, globalRateLimit int, globalTimeout int) pentestapplicationscanfern.PentestApplicationMisconfigurationConfig {
config := pentestapplicationscanfern.PentestApplicationMisconfigurationConfig{
Targets: targets,
MisconfigurationCategories: misconfigurationCategories,
Timeout: timeout,
Threads: threads,
Proxy: &proxy,
VerboseLogs: verboseLogs,
GlobalRateLimit: max(0, globalRateLimit),
GlobalTimeout: max(0, globalTimeout),
}
return config
}
// getPentestApplicationTechnologiesConfig builds the config for scan pentest.
func getPentestApplicationTechnologyConfig(targets []string, technologyTypes []pentestapplicationscanfern.TechnologyType, timeout int, threads int, proxy string, verboseLogs bool, globalRateLimit int, globalTimeout int) pentestapplicationscanfern.PentestApplicationTechnologyConfig {
config := pentestapplicationscanfern.PentestApplicationTechnologyConfig{
Targets: targets,
TechnologyTypes: technologyTypes,
Timeout: timeout,
Threads: threads,
Proxy: &proxy,
VerboseLogs: verboseLogs,
GlobalRateLimit: max(0, globalRateLimit),
GlobalTimeout: max(0, globalTimeout),
}
return config
}
// getPentestCmsWordpressXmlrpcFunctionsExposedConfig builds the config for wordpress xmlrpc function auth pentest.
func getPentestCmsWordpressXmlrpcFunctionsExposedConfig(targets []string, successfulOnly bool, verifyTLS bool, timeout int, retries int, sleep int) pentestcmswordpressfern.PentestCmsWordpressXmlrpcFunctionsExposedConfig {
config := pentestcmswordpressfern.PentestCmsWordpressXmlrpcFunctionsExposedConfig{
Targets: targets,
SuccessfulOnly: successfulOnly,
VerifyTls: verifyTLS,
Timeout: timeout,
Retries: retries,
Sleep: sleep,
}
return config
}
// getPentestRouteStaticAssetTakeoverConfig builds the config for static asset takeover pentest.
func getPentestRouteStaticAssetTakeoverConfig(target string, fingerprintFilePaths []string, detect404Responses bool, successfulOnly bool, maxRedirects int, verifyTLS bool, timeout int, threads int, requestMethod common.RequestMethod, headlessConfig *common.HeadlessRequestConfig, browserBaseConfig *common.BrowserbaseRequestConfig) pentestroutefern.PentestRouteStaticAssetTakeoverConfig {
// Create Route Capture Config
routeCaptureConfig := &discover.DiscoverRouteConfig{
Target: target,
CollectStaticAssets: true,
IgnoreCrossDomain: false,
SpiderDepth: 1,
VerifyTls: verifyTLS,
Timeout: max(timeout, 0),
Threads: max(threads, 0),
RequestMethod: requestMethod,
MaxRedirects: maxRedirects,
HeadlessConfig: headlessConfig,
BrowserbaseConfig: browserBaseConfig,
}
// Create Static Asset Takeover Config with nested route capture config
config := pentestroutefern.PentestRouteStaticAssetTakeoverConfig{
RouteCaptureConfig: routeCaptureConfig,
FingerprintFilePaths: fingerprintFilePaths,
Detect404Responses: detect404Responses,
SuccessfulOnly: successfulOnly,
}
return config
}
// getPentestWafDetectConfig builds the config for waf detect pentest.
func getPentestWafDetectConfig(targets []string, routeRequestParams []*nuclei.RequestParameter, httpMethods []common.HttpMethod, timeout int, threads int, proxy string, verboseLogs bool, globalRateLimit int, globalTimeout int) waf.PentestWafDetectConfig {
config := waf.PentestWafDetectConfig{
Targets: targets,
RouteRequestParameters: routeRequestParams,
HttpMethods: httpMethods,
Timeout: timeout,
Threads: threads,
Proxy: &proxy,
VerboseLogs: verboseLogs,
GlobalRateLimit: max(0, globalRateLimit),
GlobalTimeout: max(0, globalTimeout),
}
return config
}