mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 04:25:31 +00:00
final \r\n with body - Fixes #535
This commit is contained in:
parent
d08cd93838
commit
68b3ef8ffa
@ -114,7 +114,11 @@ func (r *requestGenerator) makeHTTPRequestFromModel(ctx context.Context, data st
|
||||
|
||||
// makeHTTPRequestFromRaw creates a *http.Request from a raw request
|
||||
func (r *requestGenerator) makeHTTPRequestFromRaw(ctx context.Context, baseURL, data string, values, payloads map[string]interface{}) (*generatedRequest, error) {
|
||||
data += "\r\n"
|
||||
// add "\r\n" only to RCF compliant requests without body
|
||||
if !rawHasBody(data) {
|
||||
data += "\r\n"
|
||||
}
|
||||
|
||||
return r.handleRawWithPaylods(ctx, data, baseURL, values, payloads)
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@ -116,3 +118,27 @@ func handleDecompression(resp *http.Response, bodyOrig []byte) (bodyDec []byte,
|
||||
}
|
||||
return bodyOrig, nil
|
||||
}
|
||||
|
||||
// rawHasBody checks if a RFC compliant request has the body
|
||||
func rawHasBody(data string) bool {
|
||||
b := bufio.NewReader(strings.NewReader(data))
|
||||
req, err := http.ReadRequest(b)
|
||||
if err == io.EOF {
|
||||
return false
|
||||
}
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if req.Body == http.NoBody {
|
||||
return false
|
||||
}
|
||||
|
||||
// It's enough to read a chunk to check the presence of the body
|
||||
body, err := ioutil.ReadAll(io.LimitReader(req.Body, 512))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return len(body) > 0
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user