Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record all requests and responses to the results #4786

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5aa929a
misc update
ehsandeep Oct 20, 2023
75357b1
chore(deps): bump github.com/gin-gonic/gin from 1.9.0 to 1.9.1 (#4252)
dependabot[bot] Oct 20, 2023
cc46f57
Merge branch 'dev'
ehsandeep Oct 20, 2023
2d14849
Merge branch 'dev'
ehsandeep Oct 26, 2023
19567fb
chore(deps): bump github.com/docker/docker (#4316)
dependabot[bot] Nov 1, 2023
9606591
Merge branch 'dev'
ehsandeep Nov 2, 2023
9f18a99
fix README_CN.md typos (#4369)
Nov 14, 2023
85d888b
Merge branch 'dev'
ehsandeep Nov 18, 2023
106ab84
Merge branch 'dev'
ehsandeep Nov 18, 2023
918b62b
Merge remote-tracking branch 'origin'
ehsandeep Nov 30, 2023
3a7a073
Merge remote-tracking branch 'origin'
ehsandeep Dec 9, 2023
2a7e15d
Merge remote-tracking branch 'origin'
ehsandeep Dec 17, 2023
6072a2f
Merge remote-tracking branch 'origin'
ehsandeep Dec 21, 2023
c3b39be
version update
ehsandeep Dec 21, 2023
5eac841
Merge remote-tracking branch 'origin'
ehsandeep Jan 8, 2024
7f2558f
Merge remote-tracking branch 'origin'
ehsandeep Jan 10, 2024
b38bcdf
Merge remote-tracking branch 'origin'
ehsandeep Jan 18, 2024
1f38d6b
Merge remote-tracking branch 'origin'
ehsandeep Jan 22, 2024
669eee2
Merge remote-tracking branch 'origin'
ehsandeep Jan 30, 2024
7d031d9
Merge remote-tracking branch 'origin'
ehsandeep Feb 1, 2024
0f4ad12
Merge remote-tracking branch 'origin'
ehsandeep Feb 2, 2024
3f77437
Record all requests and responses to the results
cn-kali-team Feb 22, 2024
81daa13
updata
cn-kali-team Oct 18, 2024
2d0846e
fix merge conflict
cn-kali-team Oct 18, 2024
0a4836d
fix merge conflict
cn-kali-team Oct 21, 2024
d6b989a
Update pkg/types/types.go
cn-kali-team Oct 22, 2024
bf792d1
steps
cn-kali-team Oct 22, 2024
f0d85f0
remove limit
cn-kali-team Nov 2, 2024
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
1 change: 1 addition & 0 deletions cmd/nuclei/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ on extensive configurability, massive extensibility and ease of use.`)

flagSet.CreateGroup("output", "Output",
flagSet.StringVarP(&options.Output, "output", "o", "", "output file to write found issues/vulnerabilities"),
flagSet.BoolVarP(&options.IncludeChain, "include-chain", "irc", false, "include all http request, response chain in json|l output"),
flagSet.BoolVarP(&options.StoreResponse, "store-resp", "sresp", false, "store all request/response passed through nuclei to output directory"),
flagSet.StringVarP(&options.StoreResponseDir, "store-resp-dir", "srd", runner.DefaultDumpTrafficOutputFolder, "store all request/response passed through nuclei to custom directory"),
flagSet.BoolVar(&options.Silent, "silent", false, "display findings only"),
Expand Down
15 changes: 14 additions & 1 deletion pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type StandardWriter struct {
traceFile io.WriteCloser
errorFile io.WriteCloser
severityColors func(severity.Severity) string
includeChain bool
storeResponse bool
storeResponseDir string
omitTemplate bool
Expand Down Expand Up @@ -130,6 +131,13 @@ func (iwe *InternalWrappedEvent) SetOperatorResult(operatorResult *operators.Res
iwe.OperatorsResult = operatorResult
}

type Steps struct {
// Request is the optional, dumped request for the match.
Request string `json:"request,omitempty"`
// Response is the optional, dumped response for the match.
Response string `json:"response,omitempty"`
}

// ResultEvent is a wrapped result event for a single nuclei output.
type ResultEvent struct {
// Template is the relative filename for the template
Expand Down Expand Up @@ -169,6 +177,8 @@ type ResultEvent struct {
Request string `json:"request,omitempty"`
// Response is the optional, dumped response for the match.
Response string `json:"response,omitempty"`
// Storage request and response list.
Steps []Steps `json:"steps,omitempty"`
// Metadata contains any optional metadata for the event
Metadata map[string]interface{} `json:"meta,omitempty"`
// IP is the IP address for the found result event.
Expand Down Expand Up @@ -265,6 +275,7 @@ func NewStandardWriter(options *types.Options) (*StandardWriter, error) {
traceFile: traceOutput,
errorFile: errorOutput,
severityColors: colorizer.New(auroraColorizer),
includeChain: options.IncludeChain,
storeResponse: options.StoreResponse,
storeResponseDir: options.StoreResponseDir,
omitTemplate: options.OmitTemplate,
Expand All @@ -286,7 +297,9 @@ func (w *StandardWriter) Write(event *ResultEvent) error {
event.CURLCommand = redactKeys(event.CURLCommand, w.KeysToRedact)
event.Matched = redactKeys(event.Matched, w.KeysToRedact)
}

if !w.includeChain {
event.Steps = make([]Steps, 0)
}
event.Timestamp = time.Now()

var data []byte
Expand Down
32 changes: 30 additions & 2 deletions pkg/protocols/common/helpers/writer/writer.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
package writer

import (
"fmt"

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v3/pkg/output"
"github.com/projectdiscovery/nuclei/v3/pkg/progress"
"github.com/projectdiscovery/nuclei/v3/pkg/reporting"
)

// WriteResult is a helper for writing results to the output
func WriteResult(data *output.InternalWrappedEvent, output output.Writer, progress progress.Progress, issuesClient reporting.Client) bool {
func WriteResult(data *output.InternalWrappedEvent, outputs output.Writer, progress progress.Progress, issuesClient reporting.Client) bool {
// 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.HasOperatorResult() {
return false
}
var matched bool
steps := make([]output.Steps, 0)
if types, ok := data.InternalEvent["type"]; ok {
switch types.(string) {
case "dns":
request, request_ok := data.InternalEvent["request"]
response, response_ok := data.InternalEvent["raw"]
if request_ok && response_ok {
steps = append(steps, output.Steps{Request: fmt.Sprintf("%v", request), Response: fmt.Sprintf("%v", response)})
}
case "http":
index := 0
for {
index = index + 1
key := fmt.Sprintf("http_%d", index)
request, request_ok := data.InternalEvent[fmt.Sprintf("%s_request", key)]
response, response_ok := data.InternalEvent[fmt.Sprintf("%s_response", key)]
if !request_ok || !response_ok {
break
}
steps = append(steps, output.Steps{Request: request.(string), Response: response.(string)})
}
default:

}
}
for _, result := range data.Results {
result.Steps = steps
if issuesClient != nil {
if err := issuesClient.CreateIssue(result); err != nil {
gologger.Warning().Msgf("Could not create issue on tracker: %s", err)
}
}
if err := output.Write(result); err != nil {
if err := outputs.Write(result); err != nil {
gologger.Warning().Msgf("Could not write output event: %s\n", err)
}
if !matched {
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ type Options struct {
ShowMatchLine bool
// EnablePprof enables exposing pprof runtime information with a webserver.
EnablePprof bool
// Include all requests, response chains in JSON line output
IncludeChain bool
// StoreResponse stores received response to output directory
StoreResponse bool
// StoreResponseDir stores received response to custom directory
Expand Down
Loading