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

do not mark as seen twice #499

Merged
merged 1 commit into from
Jun 24, 2024
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
10 changes: 6 additions & 4 deletions runner/output_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,29 @@ 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))
}

// 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()))
Expand Down
2 changes: 1 addition & 1 deletion runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading