Skip to content

Commit c4ddce0

Browse files
committed
fix: preserve trailing slash in URLs and prevent path normalization
1 parent dcc36a4 commit c4ddce0

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

cmd/api.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"bufio"
55
"crypto/tls"
66
"fmt"
7-
"github.com/fatih/color"
8-
"github.com/slicingmelon/go-rawurlparser"
97
"io"
108
"log"
119
"net"
@@ -15,6 +13,8 @@ import (
1513
"os"
1614
"strings"
1715
"time"
16+
17+
"github.com/fatih/color"
1818
)
1919

2020
// parseFile reads a file given its filename and returns a list containing each of its lines.
@@ -85,19 +85,17 @@ func request(method, uri string, headers []header, proxy *url.URL, rateLimit boo
8585
}
8686

8787
// Use raw URL parser instead
88-
parsedURL, err := rawurlparser.RawURLParse(uri)
88+
parsedURL, err := url.Parse(uri)
8989
if err != nil {
9090
log.Println(err)
9191
}
9292

93-
// Create new request
93+
parsedURL.RawPath = parsedURL.Path
94+
9495
req := &http.Request{
9596
Method: method,
96-
URL: &url.URL{
97-
Scheme: parsedURL.Scheme,
98-
Host: parsedURL.Host,
99-
Opaque: parsedURL.Path,
100-
},
97+
Host: parsedURL.Host,
98+
URL: parsedURL,
10199
Header: make(http.Header),
102100
Close: true,
103101
}

cmd/requester.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"unicode"
1616

1717
"github.com/fatih/color"
18-
"github.com/slicingmelon/go-rawurlparser"
1918
"github.com/zenthangplus/goccm"
2019
)
2120

@@ -503,7 +502,7 @@ func requestEndPaths(options RequestOptions) {
503502
go func(line string) {
504503
defer w.Done()
505504

506-
statusCode, response, err := request(options.method, options.uri+line, options.headers, options.proxy, options.rateLimit, options.timeout, options.redirect)
505+
statusCode, response, err := request(options.method, joinURL(options.uri, line), options.headers, options.proxy, options.rateLimit, options.timeout, options.redirect)
507506
if err != nil {
508507
log.Println(err)
509508
}
@@ -515,7 +514,7 @@ func requestEndPaths(options RequestOptions) {
515514
}
516515

517516
result := Result{
518-
line: options.uri + line,
517+
line: joinURL(options.uri, line),
519518
statusCode: statusCode,
520519
contentLength: len(response),
521520
defaultReq: false,
@@ -538,7 +537,7 @@ func requestMidPaths(options RequestOptions) {
538537
x := strings.Split(options.uri, "/")
539538
var uripath string
540539

541-
parsedURL, err := rawurlparser.RawURLParse(options.uri)
540+
parsedURL, err := url.Parse(options.uri)
542541
if err != nil {
543542
log.Println(err)
544543
}
@@ -595,7 +594,7 @@ func requestMidPaths(options RequestOptions) {
595594
func requestDoubleEncoding(options RequestOptions) {
596595
color.Cyan("\n━━━━━━━━━━━━━━━ DOUBLE-ENCODING ━━━━━━━━━━━━━━")
597596

598-
parsedURL, err := rawurlparser.RawURLParse(options.uri)
597+
parsedURL, err := url.Parse(options.uri)
599598
if err != nil {
600599
log.Println(err)
601600
return
@@ -725,7 +724,7 @@ func parseCurlOutput(output string, httpVersion string) Result {
725724
func requestPathCaseSwitching(options RequestOptions) {
726725
color.Cyan("\n━━━━━━━━━━━━ PATH CASE SWITCHING ━━━━━━━━━━━━━")
727726

728-
parsedURL, err := rawurlparser.RawURLParse(options.uri)
727+
parsedURL, err := url.Parse(options.uri)
729728
if err != nil {
730729
log.Println(err)
731730
return
@@ -830,6 +829,17 @@ func randomLine(filePath string) (string, error) {
830829
return randomLine, nil
831830
}
832831

832+
// joinURL safely joins a base URL and a path, preserving slashes
833+
func joinURL(base string, path string) string {
834+
if !strings.HasSuffix(base, "/") && !strings.HasPrefix(path, "/") {
835+
return base + "/" + path
836+
}
837+
if strings.HasSuffix(base, "/") && strings.HasPrefix(path, "/") {
838+
return base + path[1:]
839+
}
840+
return base + path
841+
}
842+
833843
// requester is the main function that runs all the tests.
834844
func requester(uri string, proxy string, userAgent string, reqHeaders []string, bypassIP string, folder string, method string, verbose bool, techniques []string, banner bool, rateLimit bool, timeout int, redirect bool, randomAgent bool) {
835845
// Set up proxy if provided.

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ go 1.19
44

55
require (
66
github.com/fatih/color v1.18.0
7-
github.com/slicingmelon/go-rawurlparser v0.2.8
87
github.com/spf13/cobra v1.5.0
98
github.com/spf13/viper v1.13.0
109
github.com/zenthangplus/goccm v1.1.2
11-
github.com/slicingmelon/go-rawurlparser v0.2.8
1210
)
1311

1412
require (

0 commit comments

Comments
 (0)