annotation prototype

This commit is contained in:
Mzack9999 2022-04-04 09:32:41 +02:00
parent 39d8a43ce7
commit 7b032b1733
3 changed files with 27 additions and 0 deletions

View File

@ -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
}

View File

@ -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 {

View 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
}
}