mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 11:25:26 +00:00
added support for multiple raw requests
This commit is contained in:
parent
f5b6474a11
commit
ec7cd50e22
@ -39,8 +39,8 @@ type HTTPRequest struct {
|
|||||||
Redirects bool `yaml:"redirects,omitempty"`
|
Redirects bool `yaml:"redirects,omitempty"`
|
||||||
// MaxRedirects is the maximum number of redirects that should be followed.
|
// MaxRedirects is the maximum number of redirects that should be followed.
|
||||||
MaxRedirects int `yaml:"max-redirects,omitempty"`
|
MaxRedirects int `yaml:"max-redirects,omitempty"`
|
||||||
// Raw contains a raw request
|
// Raw contains raw requests
|
||||||
Raw string `yaml:"raw,omitempty"`
|
Raw []string `yaml:"raw,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMatchersCondition returns the condition for the matcher
|
// GetMatchersCondition returns the condition for the matcher
|
||||||
@ -66,7 +66,7 @@ func (r *HTTPRequest) MakeHTTPRequest(baseURL string) ([]*retryablehttp.Request,
|
|||||||
"Hostname": hostname,
|
"Hostname": hostname,
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Raw != "" {
|
if len(r.Raw) > 0 {
|
||||||
return r.makeHTTPRequestFromRaw(baseURL, values)
|
return r.makeHTTPRequestFromRaw(baseURL, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,35 +98,42 @@ func (r *HTTPRequest) makeHTTPRequestFromModel(baseURL string, values map[string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// makeHTTPRequestFromRaw creates a *http.Request from a raw request
|
// makeHTTPRequestFromRaw creates a *http.Request from a raw request
|
||||||
func (r *HTTPRequest) makeHTTPRequestFromRaw(baseURL string, values map[string]interface{}) ([]*retryablehttp.Request, error) {
|
func (r *HTTPRequest) makeHTTPRequestFromRaw(baseURL string, values map[string]interface{}) (requests []*retryablehttp.Request, err error) {
|
||||||
// Replace the dynamic variables in the URL if any
|
for _, raw := range r.Raw {
|
||||||
t := fasttemplate.New(r.Raw, "{{", "}}")
|
// Add trailing line
|
||||||
raw := t.ExecuteString(values)
|
raw += "\n"
|
||||||
|
|
||||||
// Build a parsed request from raw
|
// Replace the dynamic variables in the URL if any
|
||||||
parsedReq, err := http.ReadRequest(bufio.NewReader(strings.NewReader(raw)))
|
t := fasttemplate.New(raw, "{{", "}}")
|
||||||
if err != nil {
|
raw := t.ExecuteString(values)
|
||||||
return nil, err
|
|
||||||
|
// Build a parsed request from raw
|
||||||
|
parsedReq, err := http.ReadRequest(bufio.NewReader(strings.NewReader(raw)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// requests generated from http.ReadRequest have incorrect RequestURI, so they
|
||||||
|
// cannot be used to perform another request directly, we need to generate a new one
|
||||||
|
// with the new target url
|
||||||
|
finalURL := fmt.Sprintf("%s%s", baseURL, parsedReq.URL)
|
||||||
|
req, err := http.NewRequest(r.Method, finalURL, parsedReq.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy headers
|
||||||
|
req.Header = parsedReq.Header
|
||||||
|
|
||||||
|
request, err := r.fillRequest(req, values)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
requests = append(requests, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// requests generated from http.ReadRequest have incorrect RequestURI, so they
|
return requests, nil
|
||||||
// cannot be used to perform another request directly, we need to generate a new one
|
|
||||||
// with the new target url
|
|
||||||
finalURL := fmt.Sprintf("%s%s", baseURL, parsedReq.URL)
|
|
||||||
req, err := http.NewRequest(r.Method, finalURL, parsedReq.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy headers
|
|
||||||
req.Header = parsedReq.Header
|
|
||||||
|
|
||||||
request, err := r.fillRequest(req, values)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return []*retryablehttp.Request{request}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HTTPRequest) fillRequest(req *http.Request, values map[string]interface{}) (*retryablehttp.Request, error) {
|
func (r *HTTPRequest) fillRequest(req *http.Request, values map[string]interface{}) (*retryablehttp.Request, error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user