From b1d5252cb198806f67e54afb3f8381f21c7e2b96 Mon Sep 17 00:00:00 2001 From: Dogan Can Bakir <65292895+dogancanbakir@users.noreply.github.com> Date: Mon, 24 Jun 2024 23:12:28 +0300 Subject: [PATCH] do not mark as seen twice (#499) --- runner/output_writer.go | 10 ++++++---- runner/runner.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/runner/output_writer.go b/runner/output_writer.go index e6205e6f..80b989b8 100644 --- a/runner/output_writer.go +++ b/runner/output_writer.go @@ -41,19 +41,21 @@ func (o *OutputWriter) Write(data []byte) { } } -func (o *OutputWriter) findDuplicate(data string) bool { +func (o *OutputWriter) findDuplicate(data string, markAsSeen bool) bool { // check if we've already printed this data itemHash := sha1.Sum([]byte(data)) if o.cache.Contains(itemHash) { return true } - o.cache.Add(itemHash, struct{}{}) + if markAsSeen { + o.cache.Add(itemHash, struct{}{}) + } return false } // WriteString writes the string taken as input using only func (o *OutputWriter) WriteString(data string) { - if o.findDuplicate(data) { + if o.findDuplicate(data, true) { return } o.Write([]byte(data)) @@ -61,7 +63,7 @@ func (o *OutputWriter) WriteString(data string) { // WriteJsonData writes the result taken as input in JSON format func (o *OutputWriter) WriteJsonData(data sources.Result) { - if o.findDuplicate(fmt.Sprintf("%s:%d", data.IP, data.Port)) { + if o.findDuplicate(fmt.Sprintf("%s:%d", data.IP, data.Port), true) { return } o.Write([]byte(data.JSON())) diff --git a/runner/runner.go b/runner/runner.go index c0ce711e..96aca722 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -86,7 +86,7 @@ func (r *Runner) Run(ctx context.Context) error { if result.Host != "" || r.options.OutputFile != "" { searchFor = append(searchFor, result.Host) } - if stringsutil.ContainsAny(outData, searchFor...) && !r.outputWriter.findDuplicate(outData) { + if stringsutil.ContainsAny(outData, searchFor...) && !r.outputWriter.findDuplicate(outData, false) { if r.options.Verbose { // if output is verbose include source name gologger.Info().Label(result.Source).Msg(outData)