mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 05:25:25 +00:00
annotation prototype
This commit is contained in:
parent
39d8a43ce7
commit
7b032b1733
@ -288,6 +288,8 @@ func (r *requestGenerator) handleRawWithPayloads(ctx context.Context, rawRequest
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parseAnnotations(rawRequest, req)
|
||||
|
||||
return &generatedRequest{request: request, meta: generatorValues, original: r.request, dynamicValues: finalValues, interactshURLs: r.interactshURLs}, nil
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/projectdiscovery/rawhttp/client"
|
||||
"github.com/projectdiscovery/stringsutil"
|
||||
)
|
||||
|
||||
// Request defines a basic HTTP raw request
|
||||
@ -39,10 +40,15 @@ func Parse(request, baseURL string, unsafe bool) (*Request, error) {
|
||||
rawRequest.UnsafeRawBytes = []byte(request)
|
||||
}
|
||||
reader := bufio.NewReader(strings.NewReader(request))
|
||||
read_line:
|
||||
s, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read request: %w", err)
|
||||
}
|
||||
// ignore all annotations
|
||||
if stringsutil.HasPrefixAny(s, "@") {
|
||||
goto read_line
|
||||
}
|
||||
|
||||
parts := strings.Split(s, " ")
|
||||
if len(parts) < 3 && !unsafe {
|
||||
|
||||
19
v2/pkg/protocols/http/request_annotations.go
Normal file
19
v2/pkg/protocols/http/request_annotations.go
Normal file
@ -0,0 +1,19 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// @Host:target overrides the input target with the annotated one (similar to self-contained requests)
|
||||
var reHostAnnotation = regexp.MustCompile(`(?m)^@Host:(.+)$`)
|
||||
|
||||
// parseAnnotations and override requests settings
|
||||
func parseAnnotations(rawRequest string, request *http.Request) {
|
||||
// parse request for known ovverride annotations
|
||||
if hosts := reHostAnnotation.FindStringSubmatch(rawRequest); len(hosts) > 0 {
|
||||
host := strings.TrimSpace(hosts[1])
|
||||
request.URL.Host = host
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user