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
7 changes: 1 addition & 6 deletions v2/pkg/protocols/http/build_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ func (r *requestGenerator) makeSelfContainedRequest(ctx context.Context, data st
generators.BuildPayloadFromOptions(r.request.options.Options),
)

// in case cases (eg requests signing, some variables uses default values if missing)
if defaultList := GetVariablesDefault(r.request.Signature.Value); defaultList != nil {
values = generators.MergeMaps(defaultList, values)
}

parts[1] = replacer.Replace(parts[1], values)
if len(dynamicValues) > 0 {
parts[1] = replacer.Replace(parts[1], dynamicValues)
Expand Down Expand Up @@ -211,7 +206,7 @@ func baseURLWithTemplatePrefs(data string, parsed *url.URL, isRaw bool) (string,
// parsed.RawQuery = ""

// ex: {{BaseURL}}/metrics?user=xxx
dataURLrelpath := strings.TrimLeft(data, "{{BaseURL}}") //nolint:all
dataURLrelpath := strings.TrimPrefix(data, "{{BaseURL}}")

if dataURLrelpath == "" || dataURLrelpath == "/" {
// just attach raw query to data
Expand Down
11 changes: 4 additions & 7 deletions v2/pkg/protocols/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,19 +768,16 @@ func (request *Request) handleSignature(generatedRequest *generatedRequest) erro
switch request.Signature.Value {
case AWSSignature:
var awsSigner signer.Signer
vars := request.options.Options.Vars.AsMap()
allvars := generators.MergeMaps(request.options.Options.Vars.AsMap(), generatedRequest.dynamicValues)
awsopts := signer.AWSOptions{
AwsID: types.ToString(vars["aws-id"]),
AwsSecretToken: types.ToString(vars["aws-secret"]),
AwsID: types.ToString(allvars["aws-id"]),
AwsSecretToken: types.ToString(allvars["aws-secret"]),
}
// type ctxkey string
ctx := context.WithValue(context.Background(), signer.SignerArg("service"), generatedRequest.dynamicValues["service"])
ctx = context.WithValue(ctx, signer.SignerArg("region"), generatedRequest.dynamicValues["region"])

awsSigner, err := signerpool.Get(request.options.Options, &signerpool.Configuration{SignerArgs: &awsopts})
if err != nil {
return err
}
ctx := signer.GetCtxWithArgs(allvars, signer.AwsDefaultVars)
err = awsSigner.SignHTTP(ctx, generatedRequest.request.Request)
if err != nil {
return err
Expand Down
10 changes: 0 additions & 10 deletions v2/pkg/protocols/http/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,3 @@ func GetVariablesNamesSkipList(signature SignatureType) map[string]interface{} {
return nil
}
}

// GetVariablesNamesSkipList depending on the signature type
func GetVariablesDefault(signature SignatureType) map[string]interface{} {
switch signature {
case AWSSignature:
return signer.AwsDefaultVars
default:
return nil
}
}
3 changes: 2 additions & 1 deletion v2/pkg/protocols/http/signer/aws-sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ var AwsSkipList = map[string]interface{}{
}

var AwsDefaultVars = map[string]interface{}{
"region": "us-east-2",
"region": "us-east-2",
"service": "sts",
}

var AwsInternalOnlyVars = map[string]interface{}{
Expand Down
20 changes: 20 additions & 0 deletions v2/pkg/protocols/http/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"net/http"

"github.com/projectdiscovery/nuclei/v2/pkg/types"
)

// An Argument that can be passed to Signer
Expand Down Expand Up @@ -32,3 +34,21 @@ func NewSigner(args SignerArgs) (signer Signer, err error) {
return nil, errors.New("unknown signature arguments type")
}
}

// GetCtxWithArgs creates and returns context with signature args
func GetCtxWithArgs(maps ...map[string]interface{}) context.Context {
var region, service string
for _, v := range maps {
for key, val := range v {
if key == "region" && region == "" {
region = types.ToString(val)
}
if key == "service" && service == "" {
service = types.ToString(val)
}
}
}
// type ctxkey string
ctx := context.WithValue(context.Background(), SignerArg("service"), service)
return context.WithValue(ctx, SignerArg("region"), region)
}