-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 2987 fuzz options #3355
Merged
Merged
Issue 2987 fuzz options #3355
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86272e4
Add override fuzzing type and mode flags
ShubhamRasal 6be249f
Update english readme
ShubhamRasal b4fd3ff
Fix failing tests
ShubhamRasal 15db06a
Add the integration tests
ShubhamRasal 994de81
Merge branch 'dev' into issue_2987_fuzz_options
ShubhamRasal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
id: fuzz-query | ||
|
||
info: | ||
name: Basic Fuzz URL Query | ||
author: pdteam | ||
severity: info | ||
|
||
requests: | ||
- method: GET | ||
path: | ||
- "{{BaseURL}}" | ||
fuzzing: | ||
- part: query | ||
type: postfix | ||
mode: multiple | ||
keys: ["id","name"] | ||
fuzz: ["fuzz-word"] | ||
matchers-condition: and | ||
matchers: | ||
- type: word | ||
part: body | ||
words: | ||
- "fuzz-word" | ||
- type: word | ||
part: header | ||
words: | ||
- "text/html" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
id: fuzz-type | ||
|
||
info: | ||
name: Basic Fuzz URL Query | ||
author: pdteam | ||
severity: info | ||
|
||
requests: | ||
- method: GET | ||
path: | ||
- "{{BaseURL}}" | ||
fuzzing: | ||
- part: query | ||
type: postfix | ||
mode: single | ||
keys: ["id"] | ||
fuzz: ["fuzz-word"] | ||
matchers-condition: and | ||
matchers: | ||
- type: word | ||
part: body | ||
words: | ||
- "fuzz-word" | ||
- type: word | ||
part: header | ||
words: | ||
- "text/html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
|
||
"github.com/julienschmidt/httprouter" | ||
"github.com/projectdiscovery/nuclei/v2/pkg/output" | ||
"github.com/projectdiscovery/nuclei/v2/pkg/testutils" | ||
) | ||
|
||
var fuzzingTestCases = map[string]testutils.TestCase{ | ||
"fuzz/fuzz-mode.yaml": &fuzzModeOverride{}, | ||
"fuzz/fuzz-type.yaml": &fuzzTypeOverride{}, | ||
"fuzz/fuzz-query.yaml": &httpFuzzQuery{}, | ||
} | ||
|
||
type httpFuzzQuery struct{} | ||
|
||
// Execute executes a test case and returns an error if occurred | ||
func (h *httpFuzzQuery) Execute(filePath string) error { | ||
router := httprouter.New() | ||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
w.Header().Set("Content-Type", "text/html") | ||
value := r.URL.Query().Get("id") | ||
fmt.Fprintf(w, "This is test matcher text: %v", value) | ||
}) | ||
ts := httptest.NewTLSServer(router) | ||
defer ts.Close() | ||
|
||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL+"/?id=example", debug) | ||
if err != nil { | ||
return err | ||
} | ||
return expectResultsCount(results, 1) | ||
} | ||
|
||
type fuzzModeOverride struct{} | ||
|
||
// Execute executes a test case and returns an error if occurred | ||
func (h *fuzzModeOverride) Execute(filePath string) error { | ||
router := httprouter.New() | ||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
w.Header().Set("Content-Type", "text/html") | ||
value := r.URL.Query().Get("id") | ||
fmt.Fprintf(w, "This is test matcher text: %v", value) | ||
Check warning Code scanning / CodeQL Reflected cross-site scripting
Cross-site scripting vulnerability due to [user-provided value](1).
|
||
}) | ||
ts := httptest.NewTLSServer(router) | ||
defer ts.Close() | ||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL+"/?id=example&name=nuclei", false, "-fuzzing-mode", "single", "-json") | ||
if err != nil { | ||
return err | ||
} | ||
if err = expectResultsCount(results, 1); err != nil { | ||
return err | ||
} | ||
var event output.ResultEvent | ||
err = json.Unmarshal([]byte(results[0]), &event) | ||
if err != nil { | ||
return fmt.Errorf("could not unmarshal event: %s", err) | ||
} | ||
|
||
// Check whether the matched value url query params are correct | ||
// default fuzzing mode is multiple in template, so all query params should be fuzzed | ||
// but using -fm flag we are overriding fuzzing mode to single, | ||
// so only one query param should be fuzzed, and the other should be the same | ||
|
||
//parse url to get query params | ||
matchedURL, err := url.Parse(event.Matched) | ||
if err != nil { | ||
return err | ||
} | ||
values, err := url.ParseQuery(matchedURL.RawQuery) | ||
if err != nil { | ||
return err | ||
} | ||
if values.Get("name") != "nuclei" { | ||
return fmt.Errorf("expected fuzzing should not override the name nuclei got %s", values.Get("name")) | ||
} | ||
return nil | ||
} | ||
|
||
type fuzzTypeOverride struct{} | ||
|
||
// Execute executes a test case and returns an error if occurred | ||
func (h *fuzzTypeOverride) Execute(filePath string) error { | ||
router := httprouter.New() | ||
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
w.Header().Set("Content-Type", "text/html") | ||
value := r.URL.Query().Get("id") | ||
fmt.Fprintf(w, "This is test matcher text: %v", value) | ||
Check warning Code scanning / CodeQL Reflected cross-site scripting
Cross-site scripting vulnerability due to [user-provided value](1).
|
||
}) | ||
ts := httptest.NewTLSServer(router) | ||
defer ts.Close() | ||
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL+"?id=example", false, "-fuzzing-type", "replace", "-json") | ||
if err != nil { | ||
return err | ||
} | ||
if err = expectResultsCount(results, 1); err != nil { | ||
return err | ||
} | ||
var event output.ResultEvent | ||
err = json.Unmarshal([]byte(results[0]), &event) | ||
if err != nil { | ||
return fmt.Errorf("could not unmarshal event: %s", err) | ||
} | ||
|
||
// check whether the matched url query params are fuzzed | ||
// default fuzzing type in template is postfix but we are overriding it to replace | ||
// so the matched url query param should be replaced with fuzz-word | ||
|
||
//parse url to get query params | ||
matchedURL, err := url.Parse(event.Matched) | ||
if err != nil { | ||
return err | ||
} | ||
values, err := url.ParseQuery(matchedURL.RawQuery) | ||
if err != nil { | ||
return err | ||
} | ||
if values.Get("id") != "fuzz-word" { | ||
return fmt.Errorf("expected id to be fuzz-word, got %s", values.Get("id")) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Reflected cross-site scripting