Merge pull request #3433 from projectdiscovery/dependabot/go_modules/v2/google.golang.org/protobuf-1.29.1

chore(deps): bump google.golang.org/protobuf from 1.29.0 to 1.29.1 in /v2
dev
Mzack9999 2023-03-17 17:51:30 +01:00 committed by GitHub
commit f4b0625d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 50 additions and 47 deletions

View File

@ -25,6 +25,7 @@ import (
)
var httpTestcases = map[string]testutils.TestCase{
// TODO: excluded due to parsing errors with console
// "http/raw-unsafe-request.yaml": &httpRawUnsafeRequest{},
"http/get-headers.yaml": &httpGetHeaders{},
"http/get-query-string.yaml": &httpGetQueryString{},
@ -122,7 +123,15 @@ func (d *httpDefaultMatcherCondition) Execute(filePath string) error {
ts := httptest.NewServer(router)
defer ts.Close()
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL+"/interactsh", debug)
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL+"/status", debug)
if err != nil {
return err
}
if err := expectResultsCount(results, 1); err != nil {
return err
}
results, err = testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL+"/interactsh", debug)
if err != nil {
return err
}
@ -132,12 +141,7 @@ func (d *httpDefaultMatcherCondition) Execute(filePath string) error {
if err := expectResultsCount(results, 1); err != nil {
return err
}
results, err = testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL+"/status", debug)
if err != nil {
return err
}
return expectResultsCount(results, 1)
return nil
}
type httpInteractshStopAtFirstMatchRequest struct{}

View File

@ -9,6 +9,7 @@ import (
"github.com/logrusorgru/aurora"
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
sliceutil "github.com/projectdiscovery/utils/slice"
)
var (
@ -62,7 +63,9 @@ func main() {
os.Exit(1)
}
failedTestTemplatePaths := runTests(toMap(toSlice(customTests)))
customTestsList := normalizeSplit(customTests)
failedTestTemplatePaths := runTests(customTestsList)
if len(failedTestTemplatePaths) > 0 {
if githubAction {
@ -87,8 +90,8 @@ func debugTests() {
}
}
func runTests(customTemplatePaths map[string]struct{}) map[string]struct{} {
failedTestTemplatePaths := map[string]struct{}{}
func runTests(customTemplatePaths []string) []string {
var failedTestTemplatePaths []string
for proto, testCases := range protocolTests {
if len(customTemplatePaths) == 0 {
@ -96,9 +99,9 @@ func runTests(customTemplatePaths map[string]struct{}) map[string]struct{} {
}
for templatePath, testCase := range testCases {
if len(customTemplatePaths) == 0 || contains(customTemplatePaths, templatePath) {
if len(customTemplatePaths) == 0 || sliceutil.Contains(customTemplatePaths, templatePath) {
if failedTemplatePath, err := execute(testCase, templatePath); err != nil {
failedTestTemplatePaths[failedTemplatePath] = struct{}{}
failedTestTemplatePaths = append(failedTestTemplatePaths, failedTemplatePath)
}
}
}
@ -124,25 +127,6 @@ func expectResultsCount(results []string, expectedNumber int) error {
return nil
}
func toSlice(value string) []string {
if strings.TrimSpace(value) == "" {
return []string{}
}
return strings.Split(value, ",")
}
func toMap(slice []string) map[string]struct{} {
result := make(map[string]struct{}, len(slice))
for _, value := range slice {
if _, ok := result[value]; !ok {
result[value] = struct{}{}
}
}
return result
}
func contains(input map[string]struct{}, value string) bool {
_, ok := input[value]
return ok
func normalizeSplit(str string) []string {
return strings.Split(strings.TrimSpace(str), ",")
}

View File

@ -201,7 +201,7 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.29.0 // indirect
google.golang.org/protobuf v1.29.1 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/corvus-ch/zbase32.v1 v1.0.0 // indirect
)

View File

@ -739,8 +739,8 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.29.0 h1:44S3JjaKmLEE4YIkjzexaP+NzZsudE3Zin5Njn/pYX0=
google.golang.org/protobuf v1.29.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.29.1 h1:7QBf+IK2gx70Ap/hDsOmam3GE0v9HicjfEdAxE62UoM=
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -66,14 +66,29 @@ type InternalEvent map[string]interface{}
// InternalWrappedEvent is a wrapped event with operators result added to it.
type InternalWrappedEvent struct {
// Mutex is internal field which is implicitly used
// to synchronize callback(event) and interactsh polling updates
// Refer protocols/http.Request.ExecuteWithResults for more details
sync.RWMutex
InternalEvent InternalEvent
Results []*ResultEvent
OperatorsResult *operators.Result
UsesInteractsh bool
// Mutex is internal field which is implicitly used
// to synchronize callback(event) and interactsh polling updates
// Refer protocols/http.Request.ExecuteWithResults for more details
Mutex sync.Mutex
}
func (iwe *InternalWrappedEvent) HasOperatorResult() bool {
iwe.RLock()
defer iwe.RUnlock()
return iwe.OperatorsResult != nil
}
func (iwe *InternalWrappedEvent) SetOperatorResult(operatorResult *operators.Result) {
iwe.Lock()
defer iwe.Unlock()
iwe.OperatorsResult = operatorResult
}
// ResultEvent is a wrapped result event for a single nuclei output.

View File

@ -93,7 +93,7 @@ func (e *Executer) Execute(input *contextargs.Context) (bool, error) {
// If no results were found, and also interactsh is not being used
// in that case we can skip it, otherwise we've to show failure in
// case of matcher-status flag.
if event.OperatorsResult == nil && !event.UsesInteractsh {
if !event.HasOperatorResult() && !event.UsesInteractsh {
if err := e.options.Output.WriteFailure(event.InternalEvent); err != nil {
gologger.Warning().Msgf("Could not write failure event to output: %s\n", err)
}

View File

@ -12,7 +12,7 @@ func WriteResult(data *output.InternalWrappedEvent, output output.Writer, progre
// Handle the case where no result found for the template.
// In this case, we just show misc information about the failed
// match for the template.
if data.OperatorsResult == nil {
if !data.HasOperatorResult() {
return false
}
var matched bool

View File

@ -222,8 +222,9 @@ func (c *Client) processInteractionForRequest(interaction *server.Interaction, d
if data.Event.OperatorsResult != nil {
data.Event.OperatorsResult.Merge(result)
} else {
data.Event.OperatorsResult = result
data.Event.SetOperatorResult(result)
}
data.Event.Results = data.MakeResultFunc(data.Event)
for _, event := range data.Event.Results {
event.Interaction = interaction
@ -351,8 +352,9 @@ type RequestData struct {
// RequestEvent is the event for a network request sent by nuclei.
func (c *Client) RequestEvent(interactshURLs []string, data *RequestData) {
data.Event.Mutex.Lock()
defer data.Event.Mutex.Unlock()
data.Event.Lock()
defer data.Event.Unlock()
for _, interactshURL := range interactshURLs {
id := strings.TrimRight(strings.TrimSuffix(interactshURL, c.hostname), ".")

View File

@ -399,9 +399,7 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, dynamicVa
// to avoid conflicts with `callback` mutex is used here and in Interactsh.RequestEvent
// Note: this only happens if requests > 1 and interactsh matcher is used
// TODO: interactsh logic in nuclei needs to be refactored to avoid such situations
event.Mutex.Lock()
callback(event)
event.Mutex.Unlock()
}, generator.currentIndex)
// If a variable is unresolved, skip all further requests