Automatic target merge in network templates (#3904)

* skip visited actual addressess

* removed test

* adding disable clustering support
This commit is contained in:
Mzack9999 2023-07-06 18:03:52 +02:00 committed by GitHub
parent 305ac6a143
commit 3dca03163c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,29 @@
id: same-target
info:
name: same-target
author: pdteam
severity: info
description: Riak is a distributed NoSQL key-value data store that offers high availability, fault tolerance, operational simplicity, and scalability.
network:
- host:
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
- "{{Hostname}}"
inputs:
- data: "PING\r\n"
read-size: 4
matchers:
- type: word
part: data
words:
- "PONG"

View File

@ -12,6 +12,7 @@ var networkTestcases = map[string]testutils.TestCase{
"network/multi-step.yaml": &networkMultiStep{},
"network/self-contained.yaml": &networkRequestSelContained{},
"network/variables.yaml": &networkVariables{},
"network/same-address.yaml": &networkBasic{},
}
const defaultStaticPort = 5431

View File

@ -29,6 +29,7 @@ import (
protocolutils "github.com/projectdiscovery/nuclei/v2/pkg/protocols/utils"
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
errorutil "github.com/projectdiscovery/utils/errors"
mapsutil "github.com/projectdiscovery/utils/maps"
)
var _ protocols.Request = &Request{}
@ -57,9 +58,16 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, metadata,
variablesMap := request.options.Variables.Evaluate(variables)
variables = generators.MergeMaps(variablesMap, variables, request.options.Constants)
visitedAddressess := make(mapsutil.Map[string, struct{}])
for _, kv := range request.addresses {
actualAddress := replacer.Replace(kv.address, variables)
if visitedAddressess.Has(actualAddress) && !request.options.Options.DisableClustering {
continue
}
visitedAddressess.Set(actualAddress, struct{}{})
if err := request.executeAddress(variables, actualAddress, address, input.MetaInput.Input, kv.tls, previous, callback); err != nil {
outputEvent := request.responseToDSLMap("", "", "", address, "")
callback(&output.InternalWrappedEvent{InternalEvent: outputEvent})
@ -110,7 +118,6 @@ func (request *Request) executeRequestWithPayloads(variables map[string]interfac
conn net.Conn
err error
)
if host, _, err := net.SplitHostPort(actualAddress); err == nil {
hostname = host
}