mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 20:55:28 +00:00
fix(runner): handle multiple resps in GetLazyAuthFetchCallback
the callback logic does not properly accumulate results from multiple responses Signed-off-by: Dwi Siswanto <git@dw1.io>
This commit is contained in:
parent
ff5734ba15
commit
5ef37da8f4
@ -105,13 +105,13 @@ func GetLazyAuthFetchCallback(opts *AuthLazyFetchOptions) authx.LazyFetchSecret
|
|||||||
var finalErr error
|
var finalErr error
|
||||||
ctx.OnResult = func(e *output.InternalWrappedEvent) {
|
ctx.OnResult = func(e *output.InternalWrappedEvent) {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
finalErr = fmt.Errorf("no result found for template: %s", d.TemplatePath)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !e.HasOperatorResult() {
|
if !e.HasOperatorResult() {
|
||||||
finalErr = fmt.Errorf("no result found for template: %s", d.TemplatePath)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// dynamic values
|
// dynamic values
|
||||||
for k, v := range e.OperatorsResult.DynamicValues {
|
for k, v := range e.OperatorsResult.DynamicValues {
|
||||||
// Iterate through all the values and choose the
|
// Iterate through all the values and choose the
|
||||||
@ -123,31 +123,37 @@ func GetLazyAuthFetchCallback(opts *AuthLazyFetchOptions) authx.LazyFetchSecret
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// named extractors
|
// named extractors
|
||||||
for k, v := range e.OperatorsResult.Extracts {
|
for k, v := range e.OperatorsResult.Extracts {
|
||||||
if len(v) > 0 {
|
if len(v) > 0 {
|
||||||
|
// NOTE(dwisiswant0): Only set if we don't already have a
|
||||||
|
// value -- or -- if the new value is non-empty.
|
||||||
|
if _, exists := data[k]; !exists || data[k] == "" {
|
||||||
data[k] = v[0]
|
data[k] = v[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(data) == 0 {
|
|
||||||
if e.OperatorsResult.Matched {
|
|
||||||
finalErr = fmt.Errorf("match found but no (dynamic/extracted) values found for template: %s", d.TemplatePath)
|
|
||||||
} else {
|
|
||||||
finalErr = fmt.Errorf("no match or (dynamic/extracted) values found for template: %s", d.TemplatePath)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// log result of template in result file/screen
|
// log result of template in result file/screen
|
||||||
_ = writer.WriteResult(e, opts.ExecOpts.Output, opts.ExecOpts.Progress, opts.ExecOpts.IssuesClient)
|
_ = writer.WriteResult(e, opts.ExecOpts.Output, opts.ExecOpts.Progress, opts.ExecOpts.IssuesClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := tmpl.Executer.ExecuteWithResults(ctx)
|
_, err := tmpl.Executer.ExecuteWithResults(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
finalErr = err
|
finalErr = err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(data) == 0 && finalErr == nil {
|
||||||
|
finalErr = fmt.Errorf("no extracted values found for template: %s", d.TemplatePath)
|
||||||
|
}
|
||||||
|
|
||||||
// store extracted result in auth context
|
// store extracted result in auth context
|
||||||
d.Extracted = data
|
d.Extracted = data
|
||||||
if finalErr != nil && opts.OnError != nil {
|
if finalErr != nil && opts.OnError != nil {
|
||||||
opts.OnError(finalErr)
|
opts.OnError(finalErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalErr
|
return finalErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user