nuclei/v2/pkg/protocols/http/fuzz/parts_test.go
Ice3man b9472cf7e1
Added fuzzing support for query params + var dump feature (#2679)
* Added fuzzing support for query params + var dump feature

* Added query-fuzz integration test

* Fixed payloads + added keys-regex fuzz parameter

* Fixed interactsh not working + misc

* Fixed evaluation + added global variables/dsl support to payloads

* Misc fixes related to variables evaluations

* Added http variables support to fuzz

* misc

* Misc

* Added testing playground + misc renaming

* Added support for path and raw request to fuzzing

* Fixed fuzz integration test

* Fixed variable unresolved issue

* Add multiple parameter support with same name

* Added parameter value as 'value' dsl variable for parts

Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
2022-11-01 20:28:50 +05:30

79 lines
2.5 KiB
Go

package fuzz
import (
"net/url"
"testing"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
"github.com/stretchr/testify/require"
)
func TestExecuteQueryPartRule(t *testing.T) {
parsed, _ := url.Parse("http://localhost:8080/?url=localhost&mode=multiple&file=passwdfile")
options := &protocols.ExecuterOptions{
Interactsh: &interactsh.Client{},
}
t.Run("single", func(t *testing.T) {
rule := &Rule{
ruleType: postfixRuleType,
partType: queryPartType,
modeType: singleModeType,
options: options,
}
var generatedURL []string
err := rule.executeQueryPartRule(&ExecuteRuleInput{
URL: parsed,
Callback: func(gr GeneratedRequest) bool {
generatedURL = append(generatedURL, gr.Request.URL.String())
return true
},
}, "1337'")
require.NoError(t, err, "could not execute part rule")
require.ElementsMatch(t, []string{
"http://localhost:8080/?file=passwdfile&mode=multiple&url=localhost1337%27",
"http://localhost:8080/?file=passwdfile&mode=multiple1337%27&url=localhost",
"http://localhost:8080/?file=passwdfile1337%27&mode=multiple&url=localhost",
}, generatedURL, "could not get generated url")
})
t.Run("multiple", func(t *testing.T) {
rule := &Rule{
ruleType: postfixRuleType,
partType: queryPartType,
modeType: multipleModeType,
options: options,
}
var generatedURL string
err := rule.executeQueryPartRule(&ExecuteRuleInput{
URL: parsed,
Callback: func(gr GeneratedRequest) bool {
generatedURL = gr.Request.URL.String()
return true
},
}, "1337'")
require.NoError(t, err, "could not execute part rule")
require.Equal(t, "http://localhost:8080/?file=passwdfile1337%27&mode=multiple1337%27&url=localhost1337%27", generatedURL, "could not get generated url")
})
}
func TestExecuteReplaceRule(t *testing.T) {
tests := []struct {
ruleType ruleType
value string
replacement string
expected string
}{
{replaceRuleType, "test", "replacement", "replacement"},
{prefixRuleType, "test", "prefix", "prefixtest"},
{postfixRuleType, "test", "postfix", "testpostfix"},
{infixRuleType, "", "infix", "infix"},
{infixRuleType, "0", "infix", "0infix"},
{infixRuleType, "test", "infix", "teinfixst"},
}
for _, test := range tests {
rule := &Rule{ruleType: test.ruleType}
returned := rule.executeReplaceRule(nil, test.value, test.replacement)
require.Equal(t, test.expected, returned, "could not get correct value")
}
}