Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pkg/input/formats/openapi/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package openapi

import (
"fmt"
"maps"
"slices"

"github.com/getkin/kin-openapi/openapi3"
Expand Down Expand Up @@ -162,9 +163,7 @@ func openAPIExample(schema *openapi3.Schema, cache map[*openapi3.Schema]*cachedS
return nil, ErrNoExample
}

for k, v := range value {
example[k] = v
}
maps.Copy(example, value)
}
return example, nil
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/js/gojs/gojs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gojs

import (
"context"
"maps"
"reflect"
"sync"

Expand Down Expand Up @@ -103,9 +104,7 @@ func wrapModuleFunc(runtime *goja.Runtime, fn interface{}) interface{} {
}

func (p *GojaModule) Set(objects Objects) Module {
for k, v := range objects {
p.sets[k] = v
}
maps.Copy(p.sets, objects)
return p
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/operators/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package operators

import (
"fmt"
"maps"
"strconv"
"strings"

Expand Down Expand Up @@ -218,9 +219,7 @@ func (r *Result) Merge(result *Result) {
r.DynamicValues[k] = sliceutil.Dedupe(append(r.DynamicValues[k], v...))
}
}
for k, v := range result.PayloadValues {
r.PayloadValues[k] = v
}
maps.Copy(r.PayloadValues, result.PayloadValues)
}

// MatchFunc performs matching operation for a matcher on model and returns true or false.
Expand Down
5 changes: 2 additions & 3 deletions pkg/projectfile/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/gob"
"encoding/hex"
"io"
"maps"
"net/http"
)

Expand Down Expand Up @@ -85,9 +86,7 @@ func toInternalResponse(resp *http.Response, body []byte) *InternalResponse {
intResp.HTTPMinor = resp.ProtoMinor
intResp.StatusCode = resp.StatusCode
intResp.StatusReason = resp.Status
for k, v := range resp.Header {
intResp.Headers[k] = v
}
maps.Copy(intResp.Headers, resp.Header)
intResp.Body = body
return intResp
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocols/common/generators/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package generators

import (
"github.com/pkg/errors"
"maps"

"github.com/projectdiscovery/nuclei/v3/pkg/catalog"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
Expand Down Expand Up @@ -32,9 +33,7 @@ func New(payloads map[string]interface{}, attackType AttackType, templatePath st
if err != nil {
return nil, errors.Wrap(err, "could not parse payloads with aggression")
}
for k, v := range values {
payloadsFinal[k] = v
}
maps.Copy(payloadsFinal, values)
default:
payloadsFinal[payloadName] = v
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocols/common/generators/maps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generators

import (
maps0 "maps"
"reflect"
)

Expand Down Expand Up @@ -47,9 +48,7 @@ func MergeMapsMany(maps ...interface{}) map[string][]string {
func MergeMaps(maps ...map[string]interface{}) map[string]interface{} {
merged := make(map[string]interface{})
for _, m := range maps {
for k, v := range m {
merged[k] = v
}
maps0.Copy(merged, m)
}
return merged
}
Expand Down
9 changes: 3 additions & 6 deletions pkg/protocols/dns/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dns
import (
"encoding/hex"
"fmt"
maps0 "maps"
"strings"
"sync"

Expand Down Expand Up @@ -181,12 +182,8 @@ func (request *Request) execute(input *contextargs.Context, domain string, metad
// expose response variables in proto_var format
// this is no-op if the template is not a multi protocol template
request.options.AddTemplateVars(input.MetaInput, request.Type(), request.ID, outputEvent)
for k, v := range previous {
outputEvent[k] = v
}
for k, v := range vars {
outputEvent[k] = v
}
maps0.Copy(outputEvent, previous)
maps0.Copy(outputEvent, vars)
// add variables from template context before matching/extraction
if request.options.HasTemplateCtx(input.MetaInput) {
outputEvent = generators.MergeMaps(outputEvent, request.options.GetTemplateCtx(input.MetaInput).GetAll())
Expand Down
9 changes: 3 additions & 6 deletions pkg/protocols/file/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"io"
"maps"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -276,9 +277,7 @@ func (request *Request) findMatchesWithReader(reader io.Reader, input *contextar

gologger.Verbose().Msgf("[%s] Processing file %s chunk %s/%s", request.options.TemplateID, filePath, processedBytes, totalBytesString)
dslMap := request.responseToDSLMap(lineContent, input.MetaInput.Input, filePath)
for k, v := range previous {
dslMap[k] = v
}
maps.Copy(dslMap, previous)
// add vars to template context
request.options.AddTemplateVars(input.MetaInput, request.Type(), request.ID, dslMap)
// add template context variables to DSL map
Expand Down Expand Up @@ -347,9 +346,7 @@ func (request *Request) buildEvent(input, filePath string, fileMatches []FileMat
exprLines := make(map[string][]int)
exprBytes := make(map[string][]int)
internalEvent := request.responseToDSLMap("", input, filePath)
for k, v := range previous {
internalEvent[k] = v
}
maps.Copy(internalEvent, previous)
for _, fileMatch := range fileMatches {
exprLines[fileMatch.Expr] = append(exprLines[fileMatch.Expr], fileMatch.Line)
exprBytes[fileMatch.Expr] = append(exprBytes[fileMatch.Expr], fileMatch.ByteIndex)
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocols/http/operators.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http

import (
"maps"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -108,9 +109,7 @@ func (request *Request) getMatchPart(part string, data output.InternalEvent) (st
// responseToDSLMap converts an HTTP response to a map for use in DSL matching
func (request *Request) responseToDSLMap(resp *http.Response, host, matched, rawReq, rawResp, body, headers string, duration time.Duration, extra map[string]interface{}) output.InternalEvent {
data := make(output.InternalEvent, 12+len(extra)+len(resp.Header)+len(resp.Cookies()))
for k, v := range extra {
data[k] = v
}
maps.Copy(data, extra)
for _, cookie := range resp.Cookies() {
request.setHashOrDefault(data, strings.ToLower(cookie.Name), cookie.Value)
}
Expand Down
9 changes: 3 additions & 6 deletions pkg/protocols/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"io"
"maps"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -974,12 +975,8 @@ func (request *Request) executeRequest(input *contextargs.Context, generatedRequ
if request.options.Interactsh != nil {
request.options.Interactsh.MakePlaceholders(generatedRequest.interactshURLs, outputEvent)
}
for k, v := range previousEvent {
finalEvent[k] = v
}
for k, v := range outputEvent {
finalEvent[k] = v
}
maps.Copy(finalEvent, previousEvent)
maps.Copy(finalEvent, outputEvent)

// Add to history the current request number metadata if asked by the user.
if request.NeedsRequestCondition() {
Expand Down
9 changes: 3 additions & 6 deletions pkg/protocols/javascript/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"maps"
"net"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -304,9 +305,7 @@ func (request *Request) ExecuteWithResults(target *contextargs.Context, dynamicV
templateCtx := request.options.GetTemplateCtx(input.MetaInput)

payloadValues := generators.BuildPayloadFromOptions(request.options.Options)
for k, v := range dynamicValues {
payloadValues[k] = v
}
maps.Copy(payloadValues, dynamicValues)

payloadValues["Hostname"] = hostPort
payloadValues["Host"] = hostname
Expand Down Expand Up @@ -620,9 +619,7 @@ func (request *Request) generateEventData(input *contextargs.Context, values map
}

data := make(map[string]interface{})
for k, v := range values {
data[k] = v
}
maps.Copy(data, values)
data["type"] = request.Type().String()
data["request-pre-condition"] = beautifyJavascript(request.PreCondition)
data["request"] = beautifyJavascript(request.Code)
Expand Down
17 changes: 5 additions & 12 deletions pkg/protocols/network/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package network
import (
"encoding/hex"
"fmt"
maps0 "maps"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -375,9 +376,7 @@ func (request *Request) executeRequestWithPayloads(variables map[string]interfac
// Run any internal extractors for the request here and add found values to map.
if request.CompiledOperators != nil {
values := request.CompiledOperators.ExecuteInternalExtractors(map[string]interface{}{input.Name: bufferStr}, request.Extract)
for k, v := range values {
payloads[k] = v
}
maps0.Copy(payloads, values)
}
}
}
Expand Down Expand Up @@ -427,15 +426,9 @@ func (request *Request) executeRequestWithPayloads(variables map[string]interfac
if request.options.StopAtFirstMatch {
outputEvent["stop-at-first-match"] = true
}
for k, v := range previous {
outputEvent[k] = v
}
for k, v := range interimValues {
outputEvent[k] = v
}
for k, v := range inputEvents {
outputEvent[k] = v
}
maps0.Copy(outputEvent, previous)
maps0.Copy(outputEvent, interimValues)
maps0.Copy(outputEvent, inputEvents)
if request.options.Interactsh != nil {
request.options.Interactsh.MakePlaceholders(interactshURLs, outputEvent)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocols/offlinehttp/operators.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package offlinehttp

import (
"maps"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -103,9 +104,7 @@ func getMatchPart(part string, data output.InternalEvent) (string, bool) {
// responseToDSLMap converts an HTTP response to a map for use in DSL matching
func (request *Request) responseToDSLMap(resp *http.Response, host, matched, rawReq, rawResp, body, headers string, duration time.Duration, extra map[string]interface{}) output.InternalEvent {
data := make(output.InternalEvent, 12+len(extra)+len(resp.Header)+len(resp.Cookies()))
for k, v := range extra {
data[k] = v
}
maps.Copy(data, extra)
for _, cookie := range resp.Cookies() {
data[strings.ToLower(cookie.Name)] = cookie.Value
}
Expand Down
9 changes: 3 additions & 6 deletions pkg/protocols/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ssl

import (
"fmt"
"maps"
"net"
"strings"
"time"
Expand Down Expand Up @@ -206,9 +207,7 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, dynamicVa

requestOptions := request.options
payloadValues := generators.BuildPayloadFromOptions(request.options.Options)
for k, v := range dynamicValues {
payloadValues[k] = v
}
maps.Copy(payloadValues, dynamicValues)

payloadValues["Hostname"] = hostPort
payloadValues["Host"] = hostname
Expand Down Expand Up @@ -271,9 +270,7 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, dynamicVa
jsonDataString := string(jsonData)

data := make(map[string]interface{})
for k, v := range payloadValues {
data[k] = v
}
maps.Copy(data, payloadValues)
data["type"] = request.Type().String()
data["response"] = jsonDataString
data["host"] = input.MetaInput.Input
Expand Down
13 changes: 4 additions & 9 deletions pkg/protocols/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/tls"
"fmt"
"io"
"maps"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -274,12 +275,8 @@ func (request *Request) executeRequestWithPayloads(target *contextargs.Context,
request.options.AddTemplateVars(target.MetaInput, request.Type(), request.ID, data)
data = generators.MergeMaps(data, request.options.GetTemplateCtx(target.MetaInput).GetAll())

for k, v := range previous {
data[k] = v
}
for k, v := range events {
data[k] = v
}
maps.Copy(data, previous)
maps.Copy(data, events)

event := eventcreator.CreateEventWithAdditionalOptions(request, data, requestOptions.Options.Debug || requestOptions.Options.DebugResponse, func(internalWrappedEvent *output.InternalWrappedEvent) {
internalWrappedEvent.OperatorsResult.PayloadValues = payloadValues
Expand Down Expand Up @@ -337,9 +334,7 @@ func (request *Request) readWriteInputWebsocket(conn net.Conn, payloadValues map
// Run any internal extractors for the request here and add found values to map.
if request.CompiledOperators != nil {
values := request.CompiledOperators.ExecuteInternalExtractors(map[string]interface{}{req.Name: bufferStr}, protocols.MakeDefaultExtractFunc)
for k, v := range values {
inputEvents[k] = v
}
maps.Copy(inputEvents, values)
}
}
}
Expand Down
Loading