Skip to content
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

fix raw req single slash issue #4955

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions cmd/integration-test/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ var httpTestcases = []TestCaseInfo{
{Path: "protocols/http/multi-request.yaml", TestCase: &httpMultiRequest{}},
{Path: "protocols/http/http-matcher-extractor-dy-extractor.yaml", TestCase: &httpMatcherExtractorDynamicExtractor{}},
{Path: "protocols/http/multi-http-var-sharing.yaml", TestCase: &httpMultiVarSharing{}},
{Path: "protocols/http/raw-path-single-slash.yaml", TestCase: &httpRawPathSingleSlash{}},
{Path: "protocols/http/raw-unsafe-path-single-slash.yaml", TestCase: &httpRawUnsafePathSingleSlash{}},
}

type httpMultiVarSharing struct{}
Expand Down Expand Up @@ -1560,3 +1562,53 @@ func (h *httpMultiRequest) Execute(filePath string) error {

return expectResultsCount(results, 1)
}

type httpRawPathSingleSlash struct{}

func (h *httpRawPathSingleSlash) Execute(filepath string) error {
expectedPath := "/index.php"
results, err := testutils.RunNucleiBinaryAndGetCombinedOutput(debug, []string{"-t", filepath, "-u", "scanme.sh/index.php", "-debug-req"})
if err != nil {
return err
}

var actual string
for _, v := range strings.Split(results, "\n") {
if strings.Contains(v, "GET") {
parts := strings.Fields(v)
if len(parts) == 3 {
actual = parts[1]
}
}
}

if actual != expectedPath {
return fmt.Errorf("expected: %v\n\nactual: %v", expectedPath, actual)
}
return nil
}

type httpRawUnsafePathSingleSlash struct{}

func (h *httpRawUnsafePathSingleSlash) Execute(filepath string) error {
expectedPath := "/index.php"
results, err := testutils.RunNucleiBinaryAndGetCombinedOutput(debug, []string{"-t", filepath, "-u", "scanme.sh/index.php", "-debug-req"})
if err != nil {
return err
}

var actual string
for _, v := range strings.Split(results, "\n") {
if strings.Contains(v, "GET") {
parts := strings.Fields(v)
if len(parts) == 3 {
actual = parts[1]
}
}
}

if actual != expectedPath {
return fmt.Errorf("expected: %v\n\nactual: %v", expectedPath, actual)
}
return nil
}
13 changes: 13 additions & 0 deletions integration_tests/protocols/http/raw-path-single-slash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: raw-path-single-slash

info:
name: Test RAW HTTP Template with single slash
author: pdteam
severity: info

requests:
- raw:
- |
GET / HTTP/1.1
Host: {{Hostname}}
Origin: {{BaseURL}}
15 changes: 15 additions & 0 deletions integration_tests/protocols/http/raw-unsafe-path-single-slash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: raw-unsafe-path-single-slash

info:
name: Test RAW Unsafe HTTP Template with single slash
author: pdteam
severity: info

requests:
- raw:
- |+
GET / HTTP/1.1
Host: {{Hostname}}
Origin: {{BaseURL}}

unsafe: true
14 changes: 14 additions & 0 deletions pkg/protocols/http/raw/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ func Parse(request string, inputURL *urlutil.URL, unsafe, disablePathAutomerge b
}
}
} else {
// Edgecase if raw request is
// GET / HTTP/1.1
//use case: https://github.com/projectdiscovery/nuclei/issues/4921
if rawrequest.Path == "/" && cloned.Path != "" {
rawrequest.Path = ""
}

if disablePathAutomerge {
cloned.Path = ""
}
Expand All @@ -97,6 +104,13 @@ func Parse(request string, inputURL *urlutil.URL, unsafe, disablePathAutomerge b
default:
cloned := inputURL.Clone()
cloned.Params.IncludeEquals = true
Comment on lines 105 to 106
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR , but sharing here for context , since we will need to remove IncludeEquals hack we use now

// Edgecase if raw request is
// GET / HTTP/1.1
//use case: https://github.com/projectdiscovery/nuclei/issues/4921
if rawrequest.Path == "/" {
rawrequest.Path = ""
}

if disablePathAutomerge {
cloned.Path = ""
}
Expand Down
Loading