mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-22 03:45:26 +00:00
Improving projectfile http request matching
This commit is contained in:
parent
c1b55d06a6
commit
d1944c76b9
@ -1,12 +1,20 @@
|
|||||||
package projectfile
|
package projectfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/projectdiscovery/hmap/store/hybrid"
|
"github.com/projectdiscovery/hmap/store/hybrid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotFound = errors.New("not found")
|
||||||
|
regexUserAgent = regexp.MustCompile(`(?mi)\r\nUser-Agent: .+\r\n`)
|
||||||
|
regexDefaultInteract = regexp.MustCompile(`(?mi)[a-zA-Z1-9%.]+interact.sh`)
|
||||||
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Path string
|
Path string
|
||||||
Cleanup bool
|
Cleanup bool
|
||||||
@ -31,15 +39,22 @@ func New(options *Options) (*ProjectFile, error) {
|
|||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pf *ProjectFile) cleanupData(data []byte) []byte {
|
||||||
|
// ignore all user agents
|
||||||
|
data = regexUserAgent.ReplaceAll(data, []byte("\r\n"))
|
||||||
|
// ignore interact markers
|
||||||
|
return regexDefaultInteract.ReplaceAll(data, []byte(""))
|
||||||
|
}
|
||||||
|
|
||||||
func (pf *ProjectFile) Get(req []byte) (*http.Response, error) {
|
func (pf *ProjectFile) Get(req []byte) (*http.Response, error) {
|
||||||
reqHash, err := hash(req)
|
reqHash, err := hash(pf.cleanupData(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, ok := pf.hm.Get(reqHash)
|
data, ok := pf.hm.Get(reqHash)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("not found")
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpRecord HTTPRecord
|
var httpRecord HTTPRecord
|
||||||
@ -52,7 +67,7 @@ func (pf *ProjectFile) Get(req []byte) (*http.Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pf *ProjectFile) Set(req []byte, resp *http.Response, data []byte) error {
|
func (pf *ProjectFile) Set(req []byte, resp *http.Response, data []byte) error {
|
||||||
reqHash, err := hash(req)
|
reqHash, err := hash(pf.cleanupData(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user