Skip to content

Commit f681a48

Browse files
committed
Code quality improvement
1 parent f6cd2e9 commit f681a48

15 files changed

+52
-44
lines changed

cmd/payload.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package cmd
33
import (
44
"strconv"
55

6+
"github.com/hahwul/dalfox/v2/pkg/generating"
67
"github.com/hahwul/dalfox/v2/pkg/optimization"
78
"github.com/hahwul/dalfox/v2/pkg/printing"
89
"github.com/hahwul/dalfox/v2/pkg/scanning"
9-
"github.com/hahwul/dalfox/v2/pkg/generating"
1010
"github.com/spf13/cobra"
1111
)
1212

@@ -16,6 +16,7 @@ var remotePayloadbox, remotePortswigger bool
1616
var entityGF, entityEventHandler, entityUsefulTags, entitySpecialChars bool
1717
var urlEncode bool
1818

19+
// Object is Type of PayloadObject
1920
type Object struct {
2021
Use bool
2122
Name string

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var rootCmd = &cobra.Command{
3333
},
3434
}
3535

36+
// Execute is run rootCmd
3637
func Execute() {
3738
if err := rootCmd.Execute(); err != nil {
3839
fmt.Println(err)

pkg/generating/bulk.go

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package generating
22

33
import (
4-
"strings"
54
"strconv"
5+
"strings"
66

77
"github.com/hahwul/dalfox/v2/pkg/scanning"
88
)
@@ -11,35 +11,36 @@ type objectPayload struct {
1111
Listener func() ([]string, int)
1212
}
1313

14-
func GenerateBulkPayload() ([]string, int){
15-
var result []string
16-
size := 0
17-
var objs []objectPayload
18-
seq := 0
19-
outSeq := 0
20-
_=outSeq
21-
objs = append(objs, objectPayload{Listener: scanning.GetPortswiggerPayload})
22-
objs = append(objs, objectPayload{Listener: scanning.GetCommonPayload})
23-
objs = append(objs, objectPayload{Listener: scanning.GetHTMLPayload})
24-
objs = append(objs, objectPayload{Listener: scanning.GetInJsPayload})
25-
objs = append(objs, objectPayload{Listener: scanning.GetAttrPayload})
26-
for _, obj := range objs {
27-
lst,_ := obj.Listener()
28-
nlst, outSeq := setPayloadVauleForBulk(lst, seq)
29-
seq = outSeq
30-
for i,v := range nlst {
31-
size = size + i
32-
result = append(result, v)
33-
}
14+
// GenerateBulkPayload is func of Make Bulk Payload
15+
func GenerateBulkPayload() ([]string, int) {
16+
var result []string
17+
size := 0
18+
var objs []objectPayload
19+
seq := 0
20+
outSeq := 0
21+
_ = outSeq
22+
objs = append(objs, objectPayload{Listener: scanning.GetPortswiggerPayload})
23+
objs = append(objs, objectPayload{Listener: scanning.GetCommonPayload})
24+
objs = append(objs, objectPayload{Listener: scanning.GetHTMLPayload})
25+
objs = append(objs, objectPayload{Listener: scanning.GetInJsPayload})
26+
objs = append(objs, objectPayload{Listener: scanning.GetAttrPayload})
27+
for _, obj := range objs {
28+
lst, _ := obj.Listener()
29+
nlst, outSeq := setPayloadVauleForBulk(lst, seq)
30+
seq = outSeq
31+
for i, v := range nlst {
32+
size = size + i
33+
result = append(result, v)
3434
}
35+
}
3536
return result, size
3637
}
3738

3839
// setPayloadVauleForBulk is change alert/prompt/conrifm value using sequence
3940
func setPayloadVauleForBulk(payloads []string, inSeq int) ([]string, int) {
4041
var result []string
4142
seq := inSeq
42-
for _,payload := range payloads {
43+
for _, payload := range payloads {
4344
temp := strings.ReplaceAll(payload, "alert(1)", "alert(DALFOX_ALERT_VALUE)")
4445
temp = strings.ReplaceAll(temp, "alert(document.domain)", "alert(DALFOX_ALERT_VALUE)")
4546
temp = strings.ReplaceAll(temp, "\\u0061lert(1)", "\\u0061lert(DALFOX_ALERT_VALUE)")

pkg/model/param.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package model
22

3+
// Param is type of Paramters (Parameter analysis output)
34
type Param struct {
45
Type string
56
Key string

pkg/optimization/inspectionParam.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/hahwul/dalfox/v2/pkg/model"
55
)
66

7+
// CheckInspectionParam is Checking Inspection
78
func CheckInspectionParam(options model.Options, k string) bool {
89
if len(options.UniqParam) > 0 {
910
for _, selectedParam := range options.UniqParam {

pkg/printing/multispin.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
spinner "github.com/briandowns/spinner"
55
)
66

7+
// DrawSpinner is drawing spinner
78
func DrawSpinner(s *spinner.Spinner, t map[string]int, pointer int) {
89
s.Suffix = " Running..."
910
}

pkg/scanning/headless.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hahwul/dalfox/v2/pkg/model"
1111
)
1212

13+
// CheckXSSWithHeadless is XSS Testing with headless browser
1314
func CheckXSSWithHeadless(url string, options model.Options) bool {
1415
// create chrome instance
1516
check := false
@@ -30,30 +31,30 @@ func CheckXSSWithHeadless(url string, options model.Options) bool {
3031
cancel()
3132
} else {
3233
go func() {
33-
chromedp.Run(ctx,page.HandleJavaScriptDialog(true),)
34+
chromedp.Run(ctx, page.HandleJavaScriptDialog(true))
3435
}()
3536
}
3637
}
3738
})
38-
39+
3940
/*
40-
var headers map[string]interface{}
41+
var headers map[string]interface{}
4142
4243
43-
if options.Header != "" {
44-
h := strings.Split(options.Header, ": ")
45-
if len(h) > 1 {
46-
headers[h[0]] = h[1]
44+
if options.Header != "" {
45+
h := strings.Split(options.Header, ": ")
46+
if len(h) > 1 {
47+
headers[h[0]] = h[1]
48+
}
4749
}
48-
}
4950
50-
if options.Cookie != "" {
51-
headers["Cookie"] = options.Cookie
52-
}
51+
if options.Cookie != "" {
52+
headers["Cookie"] = options.Cookie
53+
}
5354
54-
if options.UserAgent != "" {
55-
headers["User-Agent"] = options.UserAgent
56-
}
55+
if options.UserAgent != "" {
56+
headers["User-Agent"] = options.UserAgent
57+
}
5758
*/
5859

5960
/*
@@ -64,7 +65,7 @@ func CheckXSSWithHeadless(url string, options model.Options) bool {
6465
&res,
6566
))
6667
*/
67-
68+
6869
err := chromedp.Run(ctx,
6970
chromedp.Navigate(url),
7071
// wait for footer element is visible (ie, page is loaded)

pkg/scanning/parameterAnlaysis.go

+1
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ func ParameterAnalysis(target string, options model.Options, rl *rateLimiter) ma
400400
return params
401401
}
402402

403+
// GetPType is Get Parameter Type
403404
func GetPType(av string) string {
404405
if strings.Contains(av, "PTYPE: URL") {
405406
return "-URL"

pkg/scanning/payload.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
)
1010

11+
// Asset is type of Assets
1112
type Asset struct {
1213
Line string
1314
Size string

pkg/scanning/poc.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hahwul/dalfox/v2/pkg/model"
99
)
1010

11+
// MakePoC is making poc codes
1112
func MakePoC(poc string, req *http.Request, options model.Options) string {
1213
if options.PoCType == "http-request" {
1314
requestDump, err := httputil.DumpRequestOut(req, true)

pkg/scanning/scan.go

-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
209209
}
210210
}
211211
}
212-
213212
for k, v := range options.PathReflection {
214213
if len(parsedURL.Path) == 0 {
215214
str := options.AuroraObject.Yellow("dalfoxpathtest").String()
@@ -256,7 +255,6 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
256255
// Injected pattern
257256
injectedPoint := strings.Split(v, "/")
258257
injectedPoint = injectedPoint[1:]
259-
260258
for _, ip := range injectedPoint {
261259
var arr []string
262260
if strings.Contains(ip, "inJS") {

pkg/scanning/sendReq.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ func SendReq(req *http.Request, payload string, options model.Options) (string,
332332
rLog.WithField("data2", "vrs").Debug(false)
333333
return str, resp, false, false, nil
334334
}
335-
} else {
336-
return "", resp, false, false, err
337335
}
336+
return "", resp, false, false, err
338337
}

pkg/scanning/staticAnlaysis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func StaticAnalysis(target string, options model.Options, rl *rateLimiter) (map[
4040
paths := strings.Split(target, "/")
4141

4242
// case of https://domain/ + @
43-
for idx, _ := range paths {
43+
for idx := range paths {
4444
if idx > 2 {
4545
id := idx - 3
4646
_ = id

pkg/scanning/waf.go

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"regexp"
66
)
77

8+
// WAFPattern is type of WAF Patterns
89
type WAFPattern struct {
910
Name string
1011
Body string

pkg/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
_ "github.com/hahwul/dalfox/v2/pkg/server/docs"
1111
"github.com/labstack/echo/v4"
1212
"github.com/labstack/echo/v4/middleware"
13-
"github.com/swaggo/echo-swagger"
13+
echoSwagger "github.com/swaggo/echo-swagger"
1414
"github.com/tylerb/graceful"
1515
)
1616

0 commit comments

Comments
 (0)