Merge pull request #1790 from projectdiscovery/issue-1772-payload

Adding support to skip unused payloads
This commit is contained in:
Sandeep Singh 2022-04-01 23:35:33 +05:30 committed by GitHub
commit c0b45fac4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,11 @@
package http
import (
"bytes"
"fmt"
"strings"
json "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/projectdiscovery/fileutil"
@ -293,6 +295,25 @@ func (request *Request) Compile(options *protocols.ExecuterOptions) error {
}
}
// tries to drop unused payloads - by marshaling sections that might contain the payload
unusedPayloads := make(map[string]struct{})
requestSectionsToCheck := []interface{}{
request.customHeaders, request.Headers, request.Matchers,
request.Extractors, request.Body, request.Path, request.Raw,
}
if requestSectionsToCheckData, err := json.Marshal(requestSectionsToCheck); err == nil {
for payload := range request.Payloads {
if bytes.Contains(requestSectionsToCheckData, []byte(payload)) {
continue
}
unusedPayloads[payload] = struct{}{}
}
}
for payload := range unusedPayloads {
delete(request.Payloads, payload)
}
if len(request.Payloads) > 0 {
request.generator, err = generators.New(request.Payloads, request.AttackType.Value, request.options.TemplatePath, request.options.Catalog)
if err != nil {