-
Notifications
You must be signed in to change notification settings - Fork 648
fix: JSON/CSV output empty for host discovery scans (#1611) #1612
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
fix: JSON/CSV output empty for host discovery scans (#1611) #1612
Conversation
…#1611) Console and file output were empty when running host discovery scans with -json or -csv flags. The data was being created but never serialized to the output buffer. - Fix console JSON output by using data.JSON() and writing to buffer - Fix console CSV output by initializing headers and writing row - Fix file JSON/CSV output by handling empty ports case
WalkthroughOutput logic in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pkg/runner/output.gopkg/runner/runner.go
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/runner/output.go (2)
pkg/port/port.go (1)
Port(10-17)pkg/protocol/protocol.go (1)
Protocol(7-7)
🔇 Additional comments (2)
pkg/runner/output.go (2)
210-217: LGTM! Host discovery JSON output correctly handled.The zero-port case now properly marshals the result and writes it with a newline, ensuring JSON output is produced for host discovery scans where no ports are found.
276-286: LGTM! Host discovery CSV output correctly handled.The zero-port case now writes a single CSV row using the pre-initialized data, ensuring CSV output is produced for host discovery scans. The else block maintains the existing per-port row emission for regular port scans.
| if r.options.JSON { | ||
| b, _ := data.JSON(r.options.ExcludeOutputFields) | ||
| buffer.Write(b) | ||
| gologger.Silent().Msgf("%s", buffer.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix JSON formatting and error handling.
Two issues with the JSON console output for host discovery:
- Line 1162 writes JSON bytes without a newline, inconsistent with the pattern used elsewhere (e.g., line 1085 uses
fmt.Sprintf("%s\n", b)). - Line 1161 ignores the error from
data.JSON(), which could hide marshaling failures.
🔎 Proposed fix
if r.options.JSON {
- b, _ := data.JSON(r.options.ExcludeOutputFields)
- buffer.Write(b)
+ b, err := data.JSON(r.options.ExcludeOutputFields)
+ if err != nil {
+ gologger.Error().Msgf("Could not marshal JSON for %s: %s\n", host, err)
+ continue
+ }
+ buffer.Write([]byte(fmt.Sprintf("%s\n", b)))
gologger.Silent().Msgf("%s", buffer.String())🤖 Prompt for AI Agents
In pkg/runner/runner.go around lines 1160 to 1163, the JSON output to the
console neglects error handling from data.JSON(...) and writes bytes without a
trailing newline; change to capture and check the error returned by
data.JSON(r.options.ExcludeOutputFields), handle/report the error via gologger
(and avoid ignoring it), and when successful write the JSON bytes followed by a
newline (or use fmt.Sprintf("%s\n", b) / buffer.Write with an explicit '\n')
before calling gologger.Silent().Msgf so output formatting matches other JSON
paths.
|
Thanks for the PR, @sheikhshaheerimran habibi! |
|
@dogancanbakir Most welcome. I Iook forward to actively contribute to this project. |
Summary
Closes #1611
Test plan
sudo ./naabu -host hackerone.com -json -snshows JSON outputsudo ./naabu -host hackerone.com -csv -snshows CSV outputsudo ./naabu -host hackerone.com -json -sn -o out.jsonwrites to filesudo ./naabu -host hackerone.com -csv -sn -o out.csvwrites to file./naabu -host hackerone.com -p 80,443 -jsonSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.